Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellittledev committed Aug 18, 2020
1 parent 9d851b9 commit 089df23
Show file tree
Hide file tree
Showing 40 changed files with 1,910 additions and 1,922 deletions.
7 changes: 5 additions & 2 deletions SqlClient.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2041
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{FD7933BD-2A90-49EB-A4B2-95F9D3076BBD}"
ProjectSection(SolutionItems) = preProject
paket.dependencies = paket.dependencies
paket.lock = paket.lock
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{7ECDF2A7-A71C-43B5-AFF2-64468098B7B6}"
Expand All @@ -17,7 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
build.cmd = build.cmd
build.fsx = build.fsx
fsc.props = fsc.props
LICENSE.md = LICENSE.md
netfx.props = netfx.props
README.md = README.md
RELEASE_NOTES.md = RELEASE_NOTES.md
EndProjectSection
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'
services:

fsharpdata-sql:
image: nuitsjp/adventureworks:latest
#image: microsoft/mssql-server-linux:2017-latest
environment:
- SA_PASSWORD=M=qX7kYsg#Z@Ag3mX-tm
- ACCEPT_EULA=Y
- MSSQL_AGENT_ENABLED=true
ports:
- "1434:1433"
# volumes:
# - C:\\data:/sqldb

#Server=tcp:localhost,1434;Initial Catalog=AdventureWorks;User ID=sa;Password=P@ssw0rd!
2 changes: 1 addition & 1 deletion netfx.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" Condition="'$(TargetFramework)' != 'net40'" />
<!--<PackageReference Include="System.Data.SqlClient" Version="4.5.1" Condition="'$(TargetFramework)' != 'net40'" />-->
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.1" Condition="'$(TargetFramework)' != 'net40'" />
</ItemGroup>

Expand Down
29 changes: 7 additions & 22 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ github fsprojects/FSharp.TypeProviders.SDK:28a24a69ada68ebd1ad25226634f4608e4875

group Build
source https://www.nuget.org/api/v2/
framework: >= net451
framework: netstandard20
generate_load_scripts: on

nuget FAKE = 5.8.4
Expand All @@ -21,47 +21,32 @@ group Build

group DesignTime
source https://www.nuget.org/api/v2/
framework: >= net461,netstandard20
framework: netcoreapp2.0

nuget System.Configuration.ConfigurationManager
nuget System.Data.Common
nuget Microsoft.Data.SqlClient
nuget System.Runtime.Caching
nuget FSharp.Core
nuget Microsoft.SqlServer.TransactSql.ScriptDom
nuget Microsoft.SqlServer.Types


group Test
source https://www.nuget.org/api/v2/
framework: net461, netcoreapp2.0
framework: netcoreapp2.0

nuget FSharp.Core = 4.5.2
nuget Microsoft.Data.SqlClient
nuget System.Configuration.ConfigurationManager

nuget Microsoft.SqlServer.Types ~> 12

nuget Newtonsoft.Json
nuget xunit = 2.4.1
nuget xunit.runner.visualstudio = 2.4.1

group Net40
source https://www.nuget.org/api/v2/
framework: net40

nuget FSharp.Core = 4.1.18

group TestProjects
source https://www.nuget.org/api/v2/
framework: >= net40, netcoreapp2.0, netstandard2.0
framework: netcoreapp2.0, netstandard2.0

nuget FSharp.Core = 4.3.4

nuget Microsoft.Data.SqlClient
nuget System.Configuration.ConfigurationManager

group Samples
source https://www.nuget.org/api/v2/
framework: >= net40
framework: netcoreapp2.0

nuget FSharp.Core = 4.5.2

Expand Down
2,933 changes: 1,163 additions & 1,770 deletions paket.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/SqlClient.DesignTime/DesignTime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open System
open System.Reflection
open System.Data
open Microsoft.Data.SqlClient
open Microsoft.SqlServer.Server
open Microsoft.Data.SqlClient.Server
open System.Collections.Generic
open System.Diagnostics
open Microsoft.FSharp.Quotations
Expand Down Expand Up @@ -572,10 +572,8 @@ type DesignTime private() =

rowType.AddMember ctor
rowType.AddXmlDoc "User-Defined Table Type"

rowType


static member internal GetExecuteArgs(cmdProvidedType: ProvidedTypeDefinition, sqlParameters: Parameter list, udttsPerSchema: Dictionary<_, ProvidedTypeDefinition>, ?unitsOfMeasurePerSchema) =
[
for p in sqlParameters do
Expand All @@ -593,7 +591,7 @@ type DesignTime private() =
if p.Direction.HasFlag(ParameterDirection.Output)
then
ProvidedParameter(parameterName, parameterType = p.TypeInfo.ClrType.MakeByRefType(), isOut = true)
else
else
ProvidedParameter(parameterName, parameterType = p.GetProvidedType(?unitsOfMeasurePerSchema = unitsOfMeasurePerSchema), ?optionalValue = p.DefaultValue)
else
assert(p.Direction = ParameterDirection.Input)
Expand Down
49 changes: 29 additions & 20 deletions src/SqlClient.DesignTime/SingleFileChangeMonitor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@

open System
open System.IO
open System.Runtime.Caching
//open System.Runtime.Caching

type ChangeMonitor =
inherit IDisposable
abstract member NotifyOnChanged : (obj -> unit) -> unit
abstract member UniqueId : string

[<CompilerMessageAttribute("This API supports the FSharp.Data.SqlClient infrastructure and is not intended to be used directly from your code.", 101, IsHidden = true)>]
type internal SingleFileChangeMonitor(path) as this =
inherit ChangeMonitor()
//inherit ChangeMonitor()

let file = new FileInfo(path)
let watcher = new FileSystemWatcher( Path.GetDirectoryName(path) )

do
let dispose = ref true
try
watcher.NotifyFilter <- NotifyFilters.LastWrite ||| NotifyFilters.FileName
watcher.Changed.Add <| fun args -> this.TriggerOnFileChange(args.Name)
watcher.Deleted.Add <| fun args -> this.TriggerOnFileChange(args.Name)
watcher.Renamed.Add <| fun args -> this.TriggerOnFileChange(args.OldName)
watcher.Error.Add <| fun _ -> this.TriggerOnChange()
watcher.EnableRaisingEvents <- true
dispose := false
finally
base.InitializationComplete()
if !dispose
then
base.Dispose()

member private __.TriggerOnChange() = base.OnChanged(state = null)
watcher.NotifyFilter <- NotifyFilters.LastWrite ||| NotifyFilters.FileName
watcher.Changed.Add <| fun args -> this.TriggerOnFileChange(args.Name)
watcher.Deleted.Add <| fun args -> this.TriggerOnFileChange(args.Name)
watcher.Renamed.Add <| fun args -> this.TriggerOnFileChange(args.OldName)
watcher.Error.Add <| fun _ -> this.TriggerOnChange()
watcher.EnableRaisingEvents <- true

let onChangedEvent = new Event<_>()

[<CLIEvent>]
member this.OnChanged = onChangedEvent.Publish

member private this.TriggerOnChange() =
onChangedEvent.Trigger null

member private __.TriggerOnFileChange(fileName) =
if String.Compare(file.Name, fileName, StringComparison.OrdinalIgnoreCase) = 0
then
this.TriggerOnChange()

override __.UniqueId = path + string file.LastWriteTimeUtc.Ticks + string file.Length;
override __.Dispose( disposing) = if disposing then watcher.Dispose()
interface ChangeMonitor with
member __.NotifyOnChanged(callback) =
this.OnChanged.Add callback

member __.UniqueId = path + string file.LastWriteTimeUtc.Ticks + string file.Length;

interface IDisposable with
member this.Dispose() = watcher.Dispose()
4 changes: 2 additions & 2 deletions src/SqlClient.DesignTime/SingleRootTypeProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type SingleRootTypeProvider(config: TypeProviderConfig, providerName, parameters
let providerType = ProvidedTypeDefinition(assembly, nameSpace, providerName, Some typeof<obj>, hideObjectMethods = true, isErased = isErased)

providerType.DefineStaticParameters(
parameters = parameters,
parameters = parameters,
instantiationFunction = fun typeName args ->
match cache.TryGetValue(typeName) with
| true, cachedType -> cachedType.Value
Expand All @@ -28,7 +28,7 @@ type SingleRootTypeProvider(config: TypeProviderConfig, providerName, parameters
monitors
|> Seq.iter(fun m ->
match m with
| :? System.Runtime.Caching.ChangeMonitor as monitor ->
| :? ChangeMonitor as monitor ->
monitor.NotifyOnChanged(fun _ ->
cache.Remove(typeName)
this.Invalidate()
Expand Down
28 changes: 21 additions & 7 deletions src/SqlClient.DesignTime/SqlClient.DesignTime.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\netfx.props" />
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<!--<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>-->
<AssemblyName>FSharp.Data.SqlClient.DesignTime</AssemblyName>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand All @@ -12,8 +13,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.18" Condition="'$(TargetFramework)' == 'net40'" />
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition="'$(TargetFramework)' == 'net461'" />
<PackageReference Include="FSharp.Core" Version="4.6.0" />

<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="150.4573.2" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.3" />

<!--<PackageReference Include="FSharp.Core" Version="4.1.18" Condition="'$(TargetFramework)' == 'net40'" />-->
<!--<PackageReference Include="FSharp.Core" Version="4.3.4" Condition="'$(TargetFramework)' == 'net461'" />-->
<!--<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" Condition="'$(TargetFramework)' == 'net461'" />
<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="14.0.3811.1" />
Expand All @@ -33,11 +40,13 @@
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml" />
</ItemGroup>-->
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'net461'">
<Reference Include="System.Data" />
</ItemGroup>
-->
<ItemGroup>
<None Include="paket.references" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="..\..\paket-files\fsprojects\FSharp.TypeProviders.SDK\src\ProvidedTypes.fsi">
<Link>ProvidedTypes.fsi</Link>
Expand Down Expand Up @@ -67,20 +76,25 @@
<None Include="Scripts\ReverseLineOrderForNotex.fsx" />
<None Include="Scripts\XE.fsx" />
</ItemGroup>

<Target Name="CopyAssembliesToTPFolder" AfterTargets="Build">
<ItemGroup>
<DesignTimeAssemblies Include="$(OutputPath)\FSharp.Data.SqlClient.DesignTime.*" />
<DesignTimeAssemblies Include="$(OutputPath)\Microsoft.SqlServer.*.dll" />
<DesignTimeAssemblies Include="$(OutputPath)FSharp.Data.SqlClient.DesignTime.*" />
<DesignTimeAssemblies Include="$(OutputPath)Microsoft.Data.SqlClient.*" />
<DesignTimeAssemblies Include="$(OutputPath)Microsoft.SqlServer.*" />
<DesignTimeAssemblies Include="$(OutputPath)System.Configuration.ConfigurationManager.*" />
</ItemGroup>
<Copy SourceFiles="@(DesignTimeAssemblies)" DestinationFolder="..\..\bin\typeproviders\fsharp41\$(TargetFramework)" />
</Target>

<!--
<Target Name="CopyAssembliesToLegacyFolder" AfterTargets="Build" Condition="$(TargetFramework) == 'net40'">
<ItemGroup>
<DesignTimeAssemblies Include="$(OutputPath)\FSharp.Data.SqlClient.DesignTime.*" />
<DesignTimeAssemblies Include="$(OutputPath)\Microsoft.SqlServer.*.dll" />
</ItemGroup>
<Copy SourceFiles="@(DesignTimeAssemblies)" DestinationFolder="..\..\bin\$(TargetFramework)" />
</Target>
-->
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
1 change: 1 addition & 0 deletions src/SqlClient.DesignTime/SqlClientProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectoryFullPath)

let conn = new SqlConnection(designTimeConnectionString.Value)
failwith "Whaa"
use closeConn = conn.UseLocally()
conn.CheckVersion()
conn.LoadDataTypesMap()
Expand Down
7 changes: 6 additions & 1 deletion src/SqlClient.DesignTime/SqlCommandProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ type SqlCommandProvider(config : TypeProviderConfig) as this =
AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectoryFullPath)

let conn = new SqlConnection(designTimeConnectionString.Value)
use closeConn = conn.UseLocally()
use closeConn =
try
conn.OpenWithCloseOnDispose()
with
_ -> failwith "Could not open a connection to the database"

conn.CheckVersion()
conn.LoadDataTypesMap()

Expand Down
7 changes: 0 additions & 7 deletions src/SqlClient.DesignTime/paket.references
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
group DesignTime

System.Configuration.ConfigurationManager
System.Data.Common
System.Data.SqlClient
System.Runtime.Caching
Microsoft.SqlServer.TransactSql.ScriptDom
Microsoft.SqlServer.Types
Microsoft.Data.SqlClient
Loading

0 comments on commit 089df23

Please sign in to comment.