Skip to content

Commit 6bb9df6

Browse files
committed
Initial commit of v2
1 parent ea1ad08 commit 6bb9df6

17 files changed

+93
-145
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "CosmosDbContext"]
2+
path = CosmosDbContext
3+
url = https://github.com/conwid/CosmosDbContext.git
4+
[submodule "CosmosDbAdoNetProvider"]
5+
path = CosmosDbAdoNetProvider
6+
url = https://github.com/conwid/CosmosDbAdoNetProvider.git

AzureCosmosDbDriver.sln

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ VisualStudioVersion = 15.0.27428.2037
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureCosmosDbDriver", "AzureDocumentDbDriver\AzureCosmosDbDriver.csproj", "{634AB57F-E052-459E-BC22-24933427D302}"
77
EndProject
8-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Submodules", "Submodules", "{644E6E41-1762-4335-8418-11363D883A33}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbAdoNetProvider", "CosmosDbAdoNetProvider\CosmosDbAdoNetProvider.csproj", "{4E685226-1E96-4E98-82EC-A70F1041C920}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbAdoNetProvider", "Submodules\CosmosDbAdoNetProvider\CosmosDbAdoNetProvider\CosmosDbAdoNetProvider.csproj", "{4E685226-1E96-4E98-82EC-A70F1041C920}"
11-
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbContext", "Submodules\CosmosDbContext\CosmosDbContext\CosmosDbContext.csproj", "{53C30B69-E08D-4A09-B996-21D3ED30E37D}"
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbContext", "CosmosDbContext\CosmosDbContext.csproj", "{53C30B69-E08D-4A09-B996-21D3ED30E37D}"
1311
EndProject
1412
Global
1513
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,10 +31,6 @@ Global
3331
GlobalSection(SolutionProperties) = preSolution
3432
HideSolutionNode = FALSE
3533
EndGlobalSection
36-
GlobalSection(NestedProjects) = preSolution
37-
{4E685226-1E96-4E98-82EC-A70F1041C920} = {644E6E41-1762-4335-8418-11363D883A33}
38-
{53C30B69-E08D-4A09-B996-21D3ED30E37D} = {644E6E41-1762-4335-8418-11363D883A33}
39-
EndGlobalSection
4034
GlobalSection(ExtensibilityGlobals) = postSolution
4135
SolutionGuid = {68C0AE25-FD57-464A-A5B7-46C740DA53CD}
4236
EndGlobalSection

AzureDocumentDbDriver/AzureCosmosDbDriver.csproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.22.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4747
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.22.0\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
4848
</Reference>
49-
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
50-
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
49+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
50+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
51+
<Private>True</Private>
5152
</Reference>
5253
<Reference Include="PresentationCore" />
5354
<Reference Include="PresentationFramework" />
@@ -106,19 +107,19 @@
106107
</Page>
107108
</ItemGroup>
108109
<ItemGroup>
109-
<ProjectReference Include="..\Submodules\CosmosDbAdoNetProvider\CosmosDbAdoNetProvider\CosmosDbAdoNetProvider.csproj">
110-
<Project>{4e685226-1e96-4e98-82ec-a70f1041c920}</Project>
110+
<ProjectReference Include="..\CosmosDbAdoNetProvider\CosmosDbAdoNetProvider.csproj">
111+
<Project>{4E685226-1E96-4E98-82EC-A70F1041C920}</Project>
111112
<Name>CosmosDbAdoNetProvider</Name>
112113
</ProjectReference>
113-
<ProjectReference Include="..\Submodules\CosmosDbContext\CosmosDbContext\CosmosDbContext.csproj">
114-
<Project>{53c30b69-e08d-4a09-b996-21d3ed30e37d}</Project>
114+
<ProjectReference Include="..\CosmosDbContext\CosmosDbContext.csproj">
115+
<Project>{53C30B69-E08D-4A09-B996-21D3ED30E37D}</Project>
115116
<Name>CosmosDbContext</Name>
116117
</ProjectReference>
117118
</ItemGroup>
118119
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
119120
<PropertyGroup>
120121
<PostBuildEvent>if $(ConfigurationName) == Debug DevDeploy.bat
121-
if $(ConfigurationName) == Release powershell.exe -file "ReleaseDeploy.ps1" -folder "$(TargetDir)"</PostBuildEvent>
122+
if $(ConfigurationName) == Release powershell.exe -file "ReleaseDeploy.ps1" -folder "$(TargetDir)</PostBuildEvent>
122123
</PropertyGroup>
123124
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.22.0\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.22.0\build\Microsoft.Azure.DocumentDB.targets')" />
124125
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

AzureDocumentDbDriver/Common/DriverHelper.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
using System.Dynamic;
88
using System.Data.Common;
99
using System.Data;
10+
using CosmosDbAdoNetProvider;
1011

11-
namespace AzureDocumentDbDriver.Common
12+
namespace AzureCosmosDbDriver.Common
1213
{
1314
public static class DriverHelper
1415
{
@@ -18,7 +19,9 @@ public static IEnumerable<string> GetAssembliesToAdd() =>
1819
new[]
1920
{
2021
"Microsoft.Azure.Documents.Client.dll",
21-
"Newtonsoft.Json.dll",
22+
"Newtonsoft.Json.dll",
23+
"CosmosDbAdoNetProvider.dll",
24+
"CosmosDbContext.dll"
2225
};
2326

2427

@@ -27,7 +30,9 @@ public static IEnumerable<string> GetNamespaceToAdd() =>
2730
{
2831
"Microsoft.Azure.Documents.Client",
2932
"System.Dynamic",
30-
"System.Collections.Generic"
33+
"System.Collections.Generic",
34+
"CosmosDbContext",
35+
"CosmosDbContext.Collection"
3136
};
3237

3338

@@ -51,17 +56,17 @@ public static ParameterDescriptor[] GetContextConstructorParameters(IConnectionI
5156
internal static IDbConnection GetIDbConnection(IConnectionInfo cxInfo)
5257
{
5358
Properties props = new Properties(cxInfo);
54-
return new DocumentDbConnection(props.Uri, props.AccountKey, props.Database);
59+
return new CosmosDbSqlConnection(props.Uri, props.AccountKey, props.Database);
5560
}
5661

5762
public static DbProviderFactory GetProviderFactory(IConnectionInfo cxInfo)
5863
{
59-
if (cxInfo.DatabaseInfo.Provider != DocumentDbProviderFactory.ProviderName)
64+
if (cxInfo.DatabaseInfo.Provider != CosmosDbSqlProviderFactory.ProviderName)
6065
{
61-
throw new NotSupportedException($"Only {DocumentDbProviderFactory.ProviderName} is supported; requested {cxInfo.DatabaseInfo.Provider}");
66+
throw new NotSupportedException($"Only {CosmosDbSqlProviderFactory.ProviderName} is supported; requested {cxInfo.DatabaseInfo.Provider}");
6267
}
6368
Properties props = new Properties(cxInfo);
64-
return new DocumentDbProviderFactory(props.Uri, props.AccountKey, props.Database);
69+
return new CosmosDbSqlProviderFactory(props.Uri, props.AccountKey, props.Database);
6570
}
6671

6772
public static object[] GetContextConstructorArguments(IConnectionInfo cxInfo)

AzureDocumentDbDriver/Common/Properties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Xml.Linq;
33
using LINQPad.Extensibility.DataContext;
44

5-
namespace AzureDocumentDbDriver.Common
5+
namespace AzureCosmosDbDriver.Common
66
{
77

88
public class Properties

AzureDocumentDbDriver/Common/SchemaBuilder.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using Microsoft.Azure.Documents;
1212
using Microsoft.Azure.Documents.Client;
1313

14-
namespace AzureDocumentDbDriver.Common
14+
namespace AzureCosmosDbDriver.Common
1515
{
1616
public static class SchemaBuilder
1717
{
@@ -60,32 +60,27 @@ public static List<ExplorerItem> GetSchemaAndBuildAssembly(Properties props, Ass
6060
return items;
6161
}
6262

63-
private static string GenerateCode(IEnumerable<ExplorerItem> collections, string nameSpace, string typeName, string database)
63+
private static string GenerateCode(IEnumerable<ExplorerItem> collections, string @namepace, string typeName, string database)
6464
{
65-
string code = $"namespace {nameSpace} {{";
65+
string code = $"namespace {@namepace} {{";
6666
code = code + "using Microsoft.Azure.Documents.Client;" +
6767
"using System;" +
6868
"using System.Linq; " +
6969
"using System.Dynamic;" +
70-
"using System.Collections.Generic;" +
71-
"using ContextLibrary;";
70+
"using System.Collections.Generic;" +
71+
"using CosmosDbContext.Collection;";
7272

73-
code = code + $"public abstract class {typeName} : BaseDocumentDbContext" +
73+
code = code + $"public abstract class {typeName} : CosmosDbContext.CosmosDbContext" +
7474
$"{{public {typeName}(string uri, string authKey, string database) : base (uri,authKey,database) {{}}";
7575
foreach (var collection in collections)
7676
{
77-
code = code + $" public IEnumerable<dynamic> {collection.Tag}" +
78-
"{" +
79-
"get {" +
80-
$" return base.CreateDocu mentQuery<ExpandoObject>(\"{collection.Tag}\").ToList().Cast<dynamic>().ToList();" +
81-
"}" +
82-
"}";
77+
code = code + $" [CosmosDbCollection] public ICosmosDbCollection<dynamic> {collection.Tag} {{ get; set; }}";
8378

8479
foreach (var sp in collection.Children.Single(s => s.Text == "Stored procedures").Children)
8580
{
8681
code = code + $" public IEnumerable<dynamic> {sp.Tag}(params dynamic[] parameters)" +
8782
"{" +
88-
$" return base.CreateDynamicStoredProcedureQuery(\"{sp.Tag}\",\"{collection.Tag}\", parameters).ToList();" +
83+
$" return base.ExecuteDynamicStoredProcedure(\"{sp.Tag}\",\"{collection.Tag}\", parameters).ToList();" +
8984
"}";
9085
}
9186
}
@@ -110,7 +105,8 @@ private static void BuildAssembly(string code, AssemblyName name, string driverF
110105
"System.Xml.dll",
111106
Path.Combine(driverFolder,"Microsoft.Azure.Documents.Client.dll"),
112107
Path.Combine(driverFolder,"Newtonsoft.Json.dll"),
113-
Path.Combine(driverFolder,"ContextLibrary.dll")
108+
Path.Combine(driverFolder,"CosmosDbContext.dll"),
109+
Path.Combine(driverFolder,"CosmosDbAdoNetProvider.dll"),
114110
};
115111
var options = new CompilerParameters(dependencies, name.CodeBase, includeDebug);
116112
results = codeProvider.CompileAssemblyFromSource(options, code);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xcopy /i/y *.dll "%localappdata%\LINQPad\Drivers\DataContext\4.6\AzureCosmosDbDriver\"
2-
xcopy /i/y *.pdb "%localappdata%\LINQPad\Drivers\DataContext\4.6\AzureCosmosDbDriver\"
1+
xcopy /i/y *.dll "%localappdata%\LINQPad\Drivers\DataContext\4.6\AzureCosmosDbDriver (no-strong-name)\"
2+
xcopy /i/y *.pdb "%localappdata%\LINQPad\Drivers\DataContext\4.6\AzureCosmosDbDriver (no-strong-name)\"

AzureDocumentDbDriver/Dynamic/ConnectionDialog.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Window x:Class="AzureDocumentDbDriver.Dynamic.ConnectionDialog"
1+
<Window x:Class="AzureCosmosDbDriver.Dynamic.ConnectionDialog"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
Title="CosmosDb Connection"

AzureDocumentDbDriver/Dynamic/ConnectionDialog.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
using System.Windows.Navigation;
1313
using System.Windows.Shapes;
1414
using LINQPad.Extensibility.DataContext;
15-
using ContextLibrary.DocumentDbProvider;
16-
using AzureDocumentDbDriver.Common;
15+
using AzureCosmosDbDriver.Common;
16+
using CosmosDbAdoNetProvider;
1717

18-
namespace AzureDocumentDbDriver.Dynamic
18+
namespace AzureCosmosDbDriver.Dynamic
1919
{
2020
/// <summary>
2121
/// Interaction logic for ConnectionDialog.xaml
@@ -26,7 +26,7 @@ public partial class ConnectionDialog : Window
2626

2727
public ConnectionDialog(IConnectionInfo cxInfo)
2828
{
29-
cxInfo.DatabaseInfo.Provider = DocumentDbProviderFactory.ProviderName;
29+
cxInfo.DatabaseInfo.Provider = CosmosDbSqlProviderFactory.ProviderName;
3030
DataContext = properties = new Properties (cxInfo);
3131
Background = SystemColors.ControlBrush;
3232
InitializeComponent ();

AzureDocumentDbDriver/Dynamic/DocumentDbDynamicDriver.cs

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,31 @@
44
using System.Reflection;
55
using LINQPad.Extensibility.DataContext;
66
using System.Data;
7-
using ContextLibrary;
87
using System.Data.Common;
98
using LINQPad;
10-
using ContextLibrary.DocumentDbProvider;
11-
using AzureDocumentDbDriver.Common;
9+
using AzureCosmosDbDriver.Common;
1210

13-
namespace AzureDocumentDbDriver.Dynamic
11+
namespace AzureCosmosDbDriver.Dynamic
1412
{
1513
public class Driver : DynamicDataContextDriver
1614
{
17-
public override string Name { get { return "CosmosDb Dynamic Driver"; } }
15+
public override string Name => "CosmosDb Dynamic Driver";
1816

19-
public override string Author { get { return DriverHelper.AuthorName; } }
17+
public override string Author => DriverHelper.AuthorName;
2018

19+
public override IEnumerable<string> GetAssembliesToAdd(IConnectionInfo cxInfo) => base.GetAssembliesToAdd(cxInfo).Concat(DriverHelper.GetAssembliesToAdd());
2120

22-
public override IEnumerable<string> GetAssembliesToAdd(IConnectionInfo cxInfo)
23-
{
24-
return base.GetAssembliesToAdd(cxInfo).Concat(DriverHelper.GetAssembliesToAdd());
25-
}
26-
27-
public override IEnumerable<string> GetNamespacesToAdd(IConnectionInfo cxInfo)
28-
{
29-
return base.GetNamespacesToAdd(cxInfo).Concat(DriverHelper.GetNamespaceToAdd());
30-
}
31-
32-
public override string GetConnectionDescription(IConnectionInfo cxInfo)
33-
{
34-
return DriverHelper.GetConnectionDescription(cxInfo);
35-
}
36-
21+
public override IEnumerable<string> GetNamespacesToAdd(IConnectionInfo cxInfo) => base.GetNamespacesToAdd(cxInfo).Concat(DriverHelper.GetNamespaceToAdd());
3722

38-
public override DbProviderFactory GetProviderFactory(IConnectionInfo cxInfo)
39-
{
40-
return DriverHelper.GetProviderFactory(cxInfo);
41-
}
23+
public override string GetConnectionDescription(IConnectionInfo cxInfo) => DriverHelper.GetConnectionDescription(cxInfo);
4224

43-
public override IDbConnection GetIDbConnection(IConnectionInfo cxInfo)
44-
{
45-
return DriverHelper.GetIDbConnection(cxInfo);
46-
}
25+
public override DbProviderFactory GetProviderFactory(IConnectionInfo cxInfo) => DriverHelper.GetProviderFactory(cxInfo);
4726

48-
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection)
49-
{
50-
return new Dynamic.ConnectionDialog(cxInfo).ShowDialog() == true;
51-
}
27+
public override IDbConnection GetIDbConnection(IConnectionInfo cxInfo) => DriverHelper.GetIDbConnection(cxInfo);
5228

29+
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) => new Dynamic.ConnectionDialog(cxInfo).ShowDialog() == true;
5330

54-
public override bool AreRepositoriesEquivalent(IConnectionInfo c1, IConnectionInfo c2)
55-
{
56-
return DriverHelper.AreRepositoriesEquivalent(c1, c2);
57-
}
31+
public override bool AreRepositoriesEquivalent(IConnectionInfo c1, IConnectionInfo c2) => DriverHelper.AreRepositoriesEquivalent(c1, c2);
5832
public override List<ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
5933
{
6034
return SchemaBuilder.GetSchemaAndBuildAssembly(
@@ -66,19 +40,10 @@ public override List<ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo cxI
6640
);
6741
}
6842

69-
public override void TearDownContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager, object[] constructorArguments)
70-
{
71-
((IDisposable)context).Dispose();
72-
}
73-
74-
public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo)
75-
{
76-
return DriverHelper.GetContextConstructorParameters(cxInfo);
77-
}
43+
public override void TearDownContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager, object[] constructorArguments) => ((IDisposable)context).Dispose();
7844

79-
public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo)
80-
{
81-
return DriverHelper.GetContextConstructorArguments(cxInfo);
82-
}
45+
public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo) => DriverHelper.GetContextConstructorParameters(cxInfo);
46+
47+
public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo) => DriverHelper.GetContextConstructorArguments(cxInfo);
8348
}
8449
}

0 commit comments

Comments
 (0)