├── .gitignore
├── .gitmodules
├── AzureCosmosDbDriver.sln
├── AzureDocumentDbDriver
├── AzureCosmosDbDriver.csproj
├── Common
│ ├── DriverHelper.cs
│ ├── Properties.cs
│ └── SchemaBuilder.cs
├── Connection.png
├── DevDeploy.bat
├── Dynamic
│ ├── ConnectionDialog.xaml
│ ├── ConnectionDialog.xaml.cs
│ └── DocumentDbDynamicDriver.cs
├── FailedConnection.png
├── Properties
│ └── AssemblyInfo.cs
├── ReleaseDeploy.ps1
├── Static
│ ├── ConnectionDialog.xaml
│ ├── ConnectionDialog.xaml.cs
│ └── DocumentDbStaticDriver.cs
├── app.config
├── header.xml
└── packages.config
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | #Key file
16 | *.pfx
17 |
18 | # Build results
19 | [Dd]ebug/
20 | [Dd]ebugPublic/
21 | [Rr]elease/
22 | [Rr]eleases/
23 | x64/
24 | x86/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # .NET Core
49 | project.lock.json
50 | project.fragment.lock.json
51 | artifacts/
52 | **/Properties/launchSettings.json
53 |
54 | *_i.c
55 | *_p.c
56 | *_i.h
57 | *.ilk
58 | *.meta
59 | *.obj
60 | *.pch
61 | *.pdb
62 | *.pgc
63 | *.pgd
64 | *.rsp
65 | *.sbr
66 | *.tlb
67 | *.tli
68 | *.tlh
69 | *.tmp
70 | *.tmp_proj
71 | *.log
72 | *.vspscc
73 | *.vssscc
74 | .builds
75 | *.pidb
76 | *.svclog
77 | *.scc
78 |
79 | # Chutzpah Test files
80 | _Chutzpah*
81 |
82 | # Visual C++ cache files
83 | ipch/
84 | *.aps
85 | *.ncb
86 | *.opendb
87 | *.opensdf
88 | *.sdf
89 | *.cachefile
90 | *.VC.db
91 | *.VC.VC.opendb
92 |
93 | # Visual Studio profiler
94 | *.psess
95 | *.vsp
96 | *.vspx
97 | *.sap
98 |
99 | # TFS 2012 Local Workspace
100 | $tf/
101 |
102 | # Guidance Automation Toolkit
103 | *.gpState
104 |
105 | # ReSharper is a .NET coding add-in
106 | _ReSharper*/
107 | *.[Rr]e[Ss]harper
108 | *.DotSettings.user
109 |
110 | # JustCode is a .NET coding add-in
111 | .JustCode
112 |
113 | # TeamCity is a build add-in
114 | _TeamCity*
115 |
116 | # DotCover is a Code Coverage Tool
117 | *.dotCover
118 |
119 | # Visual Studio code coverage results
120 | *.coverage
121 | *.coveragexml
122 |
123 | # NCrunch
124 | _NCrunch_*
125 | .*crunch*.local.xml
126 | nCrunchTemp_*
127 |
128 | # MightyMoose
129 | *.mm.*
130 | AutoTest.Net/
131 |
132 | # Web workbench (sass)
133 | .sass-cache/
134 |
135 | # Installshield output folder
136 | [Ee]xpress/
137 |
138 | # DocProject is a documentation generator add-in
139 | DocProject/buildhelp/
140 | DocProject/Help/*.HxT
141 | DocProject/Help/*.HxC
142 | DocProject/Help/*.hhc
143 | DocProject/Help/*.hhk
144 | DocProject/Help/*.hhp
145 | DocProject/Help/Html2
146 | DocProject/Help/html
147 |
148 | # Click-Once directory
149 | publish/
150 |
151 | # Publish Web Output
152 | *.[Pp]ublish.xml
153 | *.azurePubxml
154 | # TODO: Comment the next line if you want to checkin your web deploy settings
155 | # but database connection strings (with potential passwords) will be unencrypted
156 | *.pubxml
157 | *.publishproj
158 |
159 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
160 | # checkin your Azure Web App publish settings, but sensitive information contained
161 | # in these scripts will be unencrypted
162 | PublishScripts/
163 |
164 | # NuGet Packages
165 | *.nupkg
166 | # The packages folder can be ignored because of Package Restore
167 | **/packages/*
168 | # except build/, which is used as an MSBuild target.
169 | !**/packages/build/
170 | # Uncomment if necessary however generally it will be regenerated when needed
171 | #!**/packages/repositories.config
172 | # NuGet v3's project.json files produces more ignorable files
173 | *.nuget.props
174 | *.nuget.targets
175 |
176 | # Microsoft Azure Build Output
177 | csx/
178 | *.build.csdef
179 |
180 | # Microsoft Azure Emulator
181 | ecf/
182 | rcf/
183 |
184 | # Windows Store app package directories and files
185 | AppPackages/
186 | BundleArtifacts/
187 | Package.StoreAssociation.xml
188 | _pkginfo.txt
189 |
190 | # Visual Studio cache files
191 | # files ending in .cache can be ignored
192 | *.[Cc]ache
193 | # but keep track of directories ending in .cache
194 | !*.[Cc]ache/
195 |
196 | # Others
197 | ClientBin/
198 | ~$*
199 | *~
200 | *.dbmdl
201 | *.dbproj.schemaview
202 | *.jfm
203 | *.pfx
204 | *.publishsettings
205 | orleans.codegen.cs
206 |
207 | # Since there are multiple workflows, uncomment next line to ignore bower_components
208 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
209 | #bower_components/
210 |
211 | # RIA/Silverlight projects
212 | Generated_Code/
213 |
214 | # Backup & report files from converting an old project file
215 | # to a newer Visual Studio version. Backup files are not needed,
216 | # because we have git ;-)
217 | _UpgradeReport_Files/
218 | Backup*/
219 | UpgradeLog*.XML
220 | UpgradeLog*.htm
221 |
222 | # SQL Server files
223 | *.mdf
224 | *.ldf
225 | *.ndf
226 |
227 | # Business Intelligence projects
228 | *.rdl.data
229 | *.bim.layout
230 | *.bim_*.settings
231 |
232 | # Microsoft Fakes
233 | FakesAssemblies/
234 |
235 | # GhostDoc plugin setting file
236 | *.GhostDoc.xml
237 |
238 | # Node.js Tools for Visual Studio
239 | .ntvs_analysis.dat
240 | node_modules/
241 |
242 | # Typescript v1 declaration files
243 | typings/
244 |
245 | # Visual Studio 6 build log
246 | *.plg
247 |
248 | # Visual Studio 6 workspace options file
249 | *.opt
250 |
251 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
252 | *.vbw
253 |
254 | # Visual Studio LightSwitch build output
255 | **/*.HTMLClient/GeneratedArtifacts
256 | **/*.DesktopClient/GeneratedArtifacts
257 | **/*.DesktopClient/ModelManifest.xml
258 | **/*.Server/GeneratedArtifacts
259 | **/*.Server/ModelManifest.xml
260 | _Pvt_Extensions
261 |
262 | # Paket dependency manager
263 | .paket/paket.exe
264 | paket-files/
265 |
266 | # FAKE - F# Make
267 | .fake/
268 |
269 | # JetBrains Rider
270 | .idea/
271 | *.sln.iml
272 |
273 | # CodeRush
274 | .cr/
275 |
276 | # Python Tools for Visual Studio (PTVS)
277 | __pycache__/
278 | *.pyc
279 |
280 | # Cake - Uncomment if you are using it
281 | # tools/**
282 | # !tools/packages.config
283 |
284 | # Telerik's JustMock configuration file
285 | *.jmconfig
286 |
287 | # BizTalk build output
288 | *.btp.cs
289 | *.btm.cs
290 | *.odx.cs
291 | *.xsd.cs
292 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
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
7 |
--------------------------------------------------------------------------------
/AzureCosmosDbDriver.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27428.2037
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureCosmosDbDriver", "AzureDocumentDbDriver\AzureCosmosDbDriver.csproj", "{634AB57F-E052-459E-BC22-24933427D302}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbAdoNetProvider", "CosmosDbAdoNetProvider\CosmosDbAdoNetProvider.csproj", "{4E685226-1E96-4E98-82EC-A70F1041C920}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbContext", "CosmosDbContext\CosmosDbContext.csproj", "{53C30B69-E08D-4A09-B996-21D3ED30E37D}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {634AB57F-E052-459E-BC22-24933427D302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {634AB57F-E052-459E-BC22-24933427D302}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {634AB57F-E052-459E-BC22-24933427D302}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {634AB57F-E052-459E-BC22-24933427D302}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {68C0AE25-FD57-464A-A5B7-46C740DA53CD}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/AzureCosmosDbDriver.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {634AB57F-E052-459E-BC22-24933427D302}
8 | Library
9 | Properties
10 | AzureCosmosDbDriver
11 | AzureCosmosDbDriver
12 | v4.7.1
13 | 512
14 |
15 |
16 |
17 |
18 |
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 | true
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | C:\Program Files (x86)\LINQPad5\LINQPad.exe
45 |
46 |
47 | ..\packages\Microsoft.Azure.DocumentDB.1.22.0\lib\net45\Microsoft.Azure.Documents.Client.dll
48 |
49 |
50 | ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll
51 | True
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | MSBuild:Compile
69 | Designer
70 |
71 |
72 | MSBuild:Compile
73 | Designer
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | Dynamic\ConnectionDialog.xaml
82 | Code
83 |
84 |
85 |
86 |
87 | Static\ConnectionDialog.xaml
88 | Code
89 |
90 |
91 |
92 |
93 |
94 | Always
95 |
96 |
97 | Always
98 |
99 |
100 | Always
101 | Designer
102 |
103 |
104 |
105 |
106 | Designer
107 |
108 |
109 | Always
110 |
111 |
112 |
113 | Always
114 |
115 |
116 |
117 |
118 | {4E685226-1E96-4E98-82EC-A70F1041C920}
119 | CosmosDbAdoNetProvider
120 |
121 |
122 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}
123 | CosmosDbContext
124 |
125 |
126 |
127 |
128 | if $(ConfigurationName) == Debug DevDeploy.bat
129 | if $(ConfigurationName) == Release powershell.exe -NonInteractive -executionPolicy Unrestricted -file "ReleaseDeploy.ps1" -folder "$(TargetDir)
130 |
131 |
132 |
133 |
134 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
135 |
136 |
137 |
138 |
145 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Common/DriverHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using LINQPad.Extensibility.DataContext;
7 | using System.Dynamic;
8 | using System.Data.Common;
9 | using System.Data;
10 | using CosmosDbAdoNetProvider;
11 |
12 | namespace AzureCosmosDbDriver.Common
13 | {
14 | public static class DriverHelper
15 | {
16 | public static string AuthorName => "Akos Nagy";
17 |
18 | public static IEnumerable GetAssembliesToAdd() =>
19 | new[]
20 | {
21 | "Microsoft.Azure.Documents.Client.dll",
22 | "Newtonsoft.Json.dll",
23 | "CosmosDbAdoNetProvider.dll",
24 | "CosmosDbContext.dll"
25 | };
26 |
27 |
28 | public static IEnumerable GetNamespaceToAdd() =>
29 | new[]
30 | {
31 | "Microsoft.Azure.Documents.Client",
32 | "System.Dynamic",
33 | "System.Collections.Generic",
34 | "CosmosDbContext",
35 | "CosmosDbContext.Collection"
36 | };
37 |
38 |
39 | public static string GetConnectionDescription(IConnectionInfo cxInfo)
40 | {
41 | var props = new Properties(cxInfo);
42 | return $"{props.Uri}/{props.Database}";
43 | }
44 |
45 | public static ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo)
46 | {
47 | var stringTypeName = typeof(string).FullName;
48 | return new[] {
49 | new ParameterDescriptor("uri", stringTypeName),
50 | new ParameterDescriptor("authKey", stringTypeName),
51 | new ParameterDescriptor("database", stringTypeName)
52 | };
53 | }
54 |
55 | internal static IDbConnection GetIDbConnection(IConnectionInfo cxInfo)
56 | {
57 | var props = new Properties(cxInfo);
58 | return new CosmosDbSqlConnection(props.Uri, props.AccountKey, props.Database);
59 | }
60 |
61 | public static DbProviderFactory GetProviderFactory(IConnectionInfo cxInfo)
62 | {
63 | if (cxInfo.DatabaseInfo.Provider != CosmosDbSqlProviderFactory.ProviderName)
64 | {
65 | throw new NotSupportedException($"Only {CosmosDbSqlProviderFactory.ProviderName} is supported; requested {cxInfo.DatabaseInfo.Provider}");
66 | }
67 | var props = new Properties(cxInfo);
68 | return new CosmosDbSqlProviderFactory(props.Uri, props.AccountKey, props.Database);
69 | }
70 |
71 | public static object[] GetContextConstructorArguments(IConnectionInfo cxInfo)
72 | {
73 | var props = new Properties(cxInfo);
74 | return new object[] { props.Uri, props.AccountKey, props.Database };
75 | }
76 |
77 | internal static bool AreRepositoriesEquivalent(IConnectionInfo c1, IConnectionInfo c2)
78 | {
79 | var p1 = new Properties(c1);
80 | var p2 = new Properties(c2);
81 | return p1.AccountKey == p2.AccountKey;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Common/Properties.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using System.Xml.Linq;
3 | using LINQPad.Extensibility.DataContext;
4 |
5 | namespace AzureCosmosDbDriver.Common
6 | {
7 |
8 | public class Properties
9 | {
10 | private readonly IConnectionInfo cxInfo;
11 | private readonly XElement driverData;
12 |
13 | public Properties(IConnectionInfo cxInfo)
14 | {
15 | this.cxInfo = cxInfo;
16 | driverData = cxInfo.DriverData;
17 | }
18 |
19 | public ICustomTypeInfo CustomTypeInfo => cxInfo.CustomTypeInfo;
20 |
21 | public bool Persist
22 | {
23 | get => cxInfo.Persist;
24 | set => cxInfo.Persist = value;
25 | }
26 |
27 | public string Uri
28 | {
29 | get => (string)driverData.Element(nameof(Uri)) ?? string.Empty;
30 | set => driverData.SetElementValue(nameof(Uri), value);
31 | }
32 |
33 | public string AccountKey
34 | {
35 | get => (string)driverData.Element(nameof(AccountKey)) ?? string.Empty;
36 | set => driverData.SetElementValue(nameof(AccountKey), value);
37 | }
38 |
39 | public string Database
40 | {
41 | get => (string)driverData.Element(nameof(Database)) ?? string.Empty;
42 | set => driverData.SetElementValue(nameof(Database), value);
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Common/SchemaBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.CodeDom.Compiler;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Reflection;
7 | using System.Xml;
8 | using System.Xml.Linq;
9 | using LINQPad.Extensibility.DataContext;
10 | using Microsoft.CSharp;
11 | using Microsoft.Azure.Documents;
12 | using Microsoft.Azure.Documents.Client;
13 |
14 | namespace AzureCosmosDbDriver.Common
15 | {
16 | public static class SchemaBuilder
17 | {
18 | public static List GetSchema(Properties props)
19 | {
20 | using (var client = new DocumentClient(new Uri(props.Uri), props.AccountKey))
21 | {
22 | var database = client.CreateDatabaseQuery().AsEnumerable().Single(db => db.Id == props.Database);
23 | ExplorerItem dbItem = new ExplorerItem(database.Id, ExplorerItemKind.Schema, ExplorerIcon.Schema) { Children = new List() };
24 | var collections = client.CreateDocumentCollectionQuery(database.SelfLink).ToList();
25 | foreach (var collection in collections)
26 | {
27 | var collectionItem = new ExplorerItem(collection.Id, ExplorerItemKind.QueryableObject, ExplorerIcon.Table) { IsEnumerable = true, Tag = collection.Id, Children = new List() };
28 | dbItem.Children.Add(collectionItem);
29 | var sps = client.CreateStoredProcedureQuery(collection.SelfLink);
30 | var storedProceduresCategory = new ExplorerItem("Stored procedures", ExplorerItemKind.Category, ExplorerIcon.StoredProc) { Children = new List() };
31 | foreach (var sp in sps)
32 | {
33 | storedProceduresCategory.Children.Add(new ExplorerItem(sp.Id, ExplorerItemKind.QueryableObject, ExplorerIcon.StoredProc) { IsEnumerable = true, Tag = sp.Id, DragText = sp.Id, ToolTipText = sp.Body });
34 | }
35 |
36 | var udfs = client.CreateUserDefinedFunctionQuery(collection.SelfLink);
37 | var udfsCategory = new ExplorerItem("User-defined functions", ExplorerItemKind.Category, ExplorerIcon.ScalarFunction) { Children = new List() };
38 | foreach (var udf in udfs)
39 | {
40 | udfsCategory.Children.Add(new ExplorerItem(udf.Id, ExplorerItemKind.QueryableObject, ExplorerIcon.ScalarFunction) { IsEnumerable = true, Tag = udf.Id, DragText = "SELECT udf." + udf.Id, ToolTipText = udf.Body });
41 | }
42 | collectionItem.Children.Add(storedProceduresCategory);
43 | collectionItem.Children.Add(udfsCategory);
44 | }
45 | return new List { dbItem };
46 | }
47 | }
48 | public static List GetSchemaAndBuildAssembly(Properties props, AssemblyName name, ref string nameSpace, ref string typeName, string driverFolder)
49 | {
50 | var items = GetSchema(props);
51 | string code = GenerateCode(items[0].Children, nameSpace, typeName, props.Database);
52 | BuildAssembly(code, name, driverFolder);
53 | return items;
54 | }
55 |
56 | private static string GenerateCode(IEnumerable collections, string @namepace, string typeName, string database)
57 | {
58 | string code = $"namespace {@namepace} {{";
59 | code = code + "using Microsoft.Azure.Documents.Client;" +
60 | "using System;" +
61 | "using System.Linq; " +
62 | "using System.Dynamic;" +
63 | "using System.Collections.Generic;" +
64 | "using CosmosDbContext.Collection;";
65 |
66 | code = code + $"public abstract class {typeName} : CosmosDbContext.CosmosDbContext" +
67 | $"{{public {typeName}(string uri, string authKey, string database) : base (uri,authKey,database) {{}}";
68 | foreach (var collection in collections)
69 | {
70 | code = code + $" [CosmosDbCollection] public ICosmosDbCollection {collection.Tag} {{ get; set; }}";
71 | foreach (var sp in collection.Children.Single(s => s.Text == "Stored procedures").Children)
72 | {
73 | code = code + $" public IEnumerable {collection.Tag}_{sp.Tag}(params dynamic[] parameters)" +
74 | "{" +
75 | $" return base.ExecuteDynamicStoredProcedure(\"{sp.Tag}\",\"{collection.Tag}\", parameters).ToList();" +
76 | "}";
77 | }
78 | }
79 | code = code + "}}";
80 | return code;
81 | }
82 |
83 | private static void BuildAssembly(string code, AssemblyName name, string driverFolder)
84 | {
85 | #if DEBUG
86 | bool includeDebug = true;
87 | #else
88 | bool includeDebug = false;
89 | #endif
90 | CompilerResults results;
91 | using (var codeProvider = new CSharpCodeProvider(new Dictionary() { { "CompilerVersion", "v4.0" } }))
92 | {
93 | var dependencies = new string[] {
94 | "System.dll",
95 | "System.Core.dll",
96 | "System.Xml.dll",
97 | Path.Combine(driverFolder,"Microsoft.Azure.Documents.Client.dll"),
98 | Path.Combine(driverFolder,"Newtonsoft.Json.dll"),
99 | Path.Combine(driverFolder,"CosmosDbContext.dll"),
100 | Path.Combine(driverFolder,"CosmosDbAdoNetProvider.dll"),
101 | };
102 | var options = new CompilerParameters(dependencies, name.CodeBase, includeDebug);
103 | results = codeProvider.CompileAssemblyFromSource(options, code);
104 | }
105 | if (results.Errors.Count > 0)
106 | {
107 | throw new Exception("Cannot compile typed context: " + results.Errors[0].ErrorText + " (line " + results.Errors[0].Line + ")");
108 | }
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Connection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conwid/AzureDocumentDbDriver/f3934407aceccc91dd843c1d189d53a50d050bb5/AzureDocumentDbDriver/Connection.png
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/DevDeploy.bat:
--------------------------------------------------------------------------------
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)\"
3 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Dynamic/ConnectionDialog.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | Remember this connection
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Dynamic/ConnectionDialog.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 | using System.Windows.Controls;
7 | using System.Windows.Data;
8 | using System.Windows.Documents;
9 | using System.Windows.Input;
10 | using System.Windows.Media;
11 | using System.Windows.Media.Imaging;
12 | using System.Windows.Navigation;
13 | using System.Windows.Shapes;
14 | using LINQPad.Extensibility.DataContext;
15 | using AzureCosmosDbDriver.Common;
16 | using CosmosDbAdoNetProvider;
17 |
18 | namespace AzureCosmosDbDriver.Dynamic
19 | {
20 | ///
21 | /// Interaction logic for ConnectionDialog.xaml
22 | ///
23 | public partial class ConnectionDialog : Window
24 | {
25 | public ConnectionDialog(IConnectionInfo cxInfo)
26 | {
27 | cxInfo.DatabaseInfo.Provider = CosmosDbSqlProviderFactory.ProviderName;
28 | DataContext = new Properties(cxInfo);
29 | Background = SystemColors.ControlBrush;
30 | InitializeComponent();
31 | }
32 |
33 | private void btnOK_Click(object sender, RoutedEventArgs e) => DialogResult = true;
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Dynamic/DocumentDbDynamicDriver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using LINQPad.Extensibility.DataContext;
6 | using System.Data;
7 | using System.Data.Common;
8 | using LINQPad;
9 | using AzureCosmosDbDriver.Common;
10 |
11 | namespace AzureCosmosDbDriver.Dynamic
12 | {
13 | public class Driver : DynamicDataContextDriver
14 | {
15 | public override string Name => "CosmosDb Dynamic Driver";
16 |
17 | public override string Author => DriverHelper.AuthorName;
18 |
19 | public override IEnumerable GetAssembliesToAdd(IConnectionInfo cxInfo) => base.GetAssembliesToAdd(cxInfo).Concat(DriverHelper.GetAssembliesToAdd());
20 |
21 | public override IEnumerable GetNamespacesToAdd(IConnectionInfo cxInfo) => base.GetNamespacesToAdd(cxInfo).Concat(DriverHelper.GetNamespaceToAdd());
22 |
23 | public override string GetConnectionDescription(IConnectionInfo cxInfo) => DriverHelper.GetConnectionDescription(cxInfo);
24 |
25 | public override DbProviderFactory GetProviderFactory(IConnectionInfo cxInfo) => DriverHelper.GetProviderFactory(cxInfo);
26 |
27 | public override IDbConnection GetIDbConnection(IConnectionInfo cxInfo) => DriverHelper.GetIDbConnection(cxInfo);
28 |
29 | public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) => new Dynamic.ConnectionDialog(cxInfo).ShowDialog() == true;
30 |
31 | public override bool AreRepositoriesEquivalent(IConnectionInfo c1, IConnectionInfo c2) => DriverHelper.AreRepositoriesEquivalent(c1, c2);
32 | public override List GetSchemaAndBuildAssembly(IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
33 | {
34 | return SchemaBuilder.GetSchemaAndBuildAssembly(
35 | new Properties(cxInfo),
36 | assemblyToBuild,
37 | ref nameSpace,
38 | ref typeName,
39 | this.GetDriverFolder()
40 | );
41 | }
42 |
43 | public override void TearDownContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager, object[] constructorArguments) => ((IDisposable)context).Dispose();
44 |
45 | public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo) => DriverHelper.GetContextConstructorParameters(cxInfo);
46 |
47 | public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo) => DriverHelper.GetContextConstructorArguments(cxInfo);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/FailedConnection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/conwid/AzureDocumentDbDriver/f3934407aceccc91dd843c1d189d53a50d050bb5/AzureDocumentDbDriver/FailedConnection.png
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AzureCosmosDbDriver")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Akos Nagy")]
12 | [assembly: AssemblyProduct("AzureCosmosDbDriver")]
13 | [assembly: AssemblyCopyright("Copyright © 2017-2018 Akos Nagy")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("634ab57f-e052-459e-bc22-24933427d302")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("2.2.0.0")]
36 | [assembly: AssemblyFileVersion("2.2.0.0")]
37 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/ReleaseDeploy.ps1:
--------------------------------------------------------------------------------
1 | param ([string] $folder)
2 |
3 | $sourceFolder=[System.IO.Path]::Combine($folder.Replace('"',''))
4 | $targetFolder=[System.IO.Path]::Combine($sourceFolder,"ReleasePackage")
5 | $xmlFile=[System.IO.Path]::Combine($sourceFolder,"header.xml");
6 | $pngFiles=[System.IO.Path]::Combine($sourceFolder,"*.png");
7 | $dllFiles=[System.IO.Path]::Combine($sourceFolder,"*.dll")
8 | $zipFile=[System.IO.Path]::Combine($sourceFolder,"AzureCosmosDbDriver.lpx")
9 |
10 |
11 | If (Test-Path $targetFolder){
12 | Remove-Item $targetFolder -Recurse -Force
13 | }
14 |
15 | If (Test-Path $zipFile){
16 | Remove-Item $zipFile -Force
17 | }
18 |
19 | New-Item -ItemType directory -Path $targetFolder
20 | Copy-Item -Path $xmlFile -Destination $targetFolder
21 | Copy-Item -Path $pngFiles -Destination $targetFolder
22 | Copy-Item -Path $dllFiles -Destination $targetFolder
23 |
24 | Add-Type -AssemblyName System.IO.Compression.FileSystem
25 | $compressionLevel = [System.IO.Compression.CompressionLevel]::"Fastest"
26 | [System.IO.Compression.ZipFile]::CreateFromDirectory($targetFolder, $zipFile, $compressionLevel, $False)
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Static/ConnectionDialog.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 | Remember this connection
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Static/ConnectionDialog.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 | using System.Windows.Controls;
7 | using System.Windows.Data;
8 | using System.Windows.Documents;
9 | using System.Windows.Input;
10 | using System.Windows.Media;
11 | using System.Windows.Media.Imaging;
12 | using System.Windows.Navigation;
13 | using System.Windows.Shapes;
14 | using LINQPad.Extensibility.DataContext;
15 | using System.IO;
16 | using AzureCosmosDbDriver.Common;
17 | using CosmosDbContext;
18 | using CosmosDbAdoNetProvider;
19 |
20 | namespace AzureCosmosDbDriver.Static
21 | {
22 | ///
23 | /// Interaction logic for ConnectionDialog.xaml
24 | ///
25 | public partial class ConnectionDialog : Window
26 | {
27 | private readonly IConnectionInfo cxInfo;
28 | public ConnectionDialog(IConnectionInfo cxInfo)
29 | {
30 | cxInfo.DatabaseInfo.Provider = CosmosDbSqlProviderFactory.ProviderName;
31 | DataContext = new Properties(cxInfo);
32 | Background = SystemColors.ControlBrush;
33 | this.cxInfo = cxInfo;
34 | InitializeComponent();
35 | }
36 |
37 | private void btnOK_Click(object sender, RoutedEventArgs e) => DialogResult = true;
38 |
39 | void BrowseAssembly(object sender, RoutedEventArgs e)
40 | {
41 | var dialog = new Microsoft.Win32.OpenFileDialog() { Title = "Choose custom assembly", DefaultExt = ".dll" };
42 | if ((dialog.ShowDialog() ?? false) == true)
43 | {
44 | cxInfo.CustomTypeInfo.CustomAssemblyPath = dialog.FileName;
45 | }
46 | }
47 |
48 | private void ChooseType(object sender, RoutedEventArgs e)
49 | {
50 | string assemblyPath = cxInfo.CustomTypeInfo.CustomAssemblyPath;
51 | if (assemblyPath.Length == 0)
52 | {
53 | MessageBox.Show("First enter a path to an assembly.");
54 | return;
55 | }
56 |
57 | if (!File.Exists(assemblyPath))
58 | {
59 | MessageBox.Show("File '" + assemblyPath + "' does not exist.");
60 | return;
61 | }
62 |
63 | string[] customTypes;
64 | try
65 | {
66 | customTypes = cxInfo.CustomTypeInfo.GetCustomTypesInAssembly(typeof(CosmosDbContext.CosmosDbContext).FullName);
67 | }
68 | catch (Exception ex)
69 | {
70 | MessageBox.Show("Error obtaining custom types: " + ex.Message);
71 | return;
72 | }
73 | if (customTypes.Length == 0)
74 | {
75 | MessageBox.Show($"There are no public types in that assembly based on {typeof(CosmosDbContext.CosmosDbContext).FullName}.");
76 | return;
77 | }
78 |
79 | var result = (string)LINQPad.Extensibility.DataContext.UI.Dialogs.PickFromList("Choose Custom Type", customTypes);
80 | if (result != null)
81 | {
82 | cxInfo.CustomTypeInfo.CustomTypeName = result;
83 | }
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/Static/DocumentDbStaticDriver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Reflection;
6 | using LINQPad.Extensibility.DataContext;
7 | using System.Data.Common;
8 | using AzureCosmosDbDriver.Common;
9 |
10 | namespace AzureCosmosDbDriver.Static
11 | {
12 |
13 | public class Driver : StaticDataContextDriver
14 | {
15 | public override string Name => "CosmosDb Static Driver";
16 |
17 | public override string Author => DriverHelper.AuthorName;
18 |
19 | public override string GetConnectionDescription(IConnectionInfo cxInfo) => DriverHelper.GetConnectionDescription(cxInfo);
20 |
21 | public override DbProviderFactory GetProviderFactory(IConnectionInfo cxInfo) => DriverHelper.GetProviderFactory(cxInfo);
22 |
23 | public override IDbConnection GetIDbConnection(IConnectionInfo cxInfo) => DriverHelper.GetIDbConnection(cxInfo);
24 |
25 | public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) => new Static.ConnectionDialog(cxInfo).ShowDialog() == true;
26 |
27 | public override List GetSchema(IConnectionInfo cxInfo, Type customType) => SchemaBuilder.GetSchema(new Properties(cxInfo));
28 |
29 | public override void TearDownContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager, object[] constructorArguments) => ((IDisposable)context).Dispose();
30 |
31 | public override bool AreRepositoriesEquivalent(IConnectionInfo c1, IConnectionInfo c2) => DriverHelper.AreRepositoriesEquivalent(c1, c2);
32 |
33 | public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo) => DriverHelper.GetContextConstructorParameters(cxInfo);
34 |
35 | public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo) => DriverHelper.GetContextConstructorArguments(cxInfo);
36 |
37 | public override void InitializeContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
38 | {
39 | var typedCtx = (CosmosDbContext.CosmosDbContext)context;
40 | typedCtx.Log += query => executionManager.SqlTranslationWriter.WriteLine(query);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/header.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | AzureCosmosDbDriver.dll
4 | http://github.com/conwid
5 |
6 |
--------------------------------------------------------------------------------
/AzureDocumentDbDriver/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Akos Nagy (conwid) 2017
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Azure CosmosDb LinqPad Driver
2 |
3 | This is a LinqPad data context driver for Azure CosmosDb
4 |
5 | Check out my blogposts on the making of the driver:
6 |
7 | [http://dotnetfalcon.com/tag/linqpad/](http://dotnetfalcon.com/tag/linqpad/)
8 |
9 | ## Download the binaries
10 |
11 | Head over to the [releases](https://github.com/conwid/AzureDocumentDbDriver/releases) to download the binaries.
12 |
13 | ## Features
14 |
15 | For a detailed description of the currently supported features, please refer to the project [Wiki](https://github.com/conwid/AzureDocumentDbDriver/wiki).
16 |
17 | * Static datacontext driver that you can use if you have a prebuilt context using my context library
18 | * Dynamic datacontext driver if you want to get started fast
19 | * Querying CosmosDb document collections using LInQ with all the LinqPad integration that you like
20 | * Running CosmosDb stored procedures
21 | * Running CosmosDb UDFs
22 | * Support for executing raw SQL queries in the raw SQL LinqPad window
23 | * Support for executing raw SQL queries from the C# windows
24 | * Support for setting the FeedOptions for the underlying queries
25 | * Populating the SQL translation tab
26 |
27 | ## Contribution
28 |
29 | Every idea, issue or improvement is welcome. If you want to contribute, join the discussions under the issues or read the [Wiki](https://github.com/conwid/AzureDocumentDbDriver/wiki) on how to contribute and issue a PR.
30 |
31 | ## Disclaimer and license notes
32 |
33 | The driver is released under MIT license (check out the License file here in the repo).
34 |
35 | Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
36 |
37 | Also see the source code for every indication of reasonable attribution.
38 |
39 | I would like to thank all the people that helped me when I got stuck with the driver. Check out the discussions at StackOverflow:
40 |
41 | * [Grouping multiple LinqPad data context connections](http://stackoverflow.com/questions/43030475/grouping-multiple-linqpad-data-context-connections)
42 | * [LinqPad driver create custom IDbConnection](http://stackoverflow.com/questions/43076219/linqpad-driver-create-custom-idbconnection)
43 | * [Converting arbitrary json response to list of “things”](http://stackoverflow.com/questions/43214424/converting-arbitrary-json-response-to-list-of-things)
44 |
45 |
46 |
--------------------------------------------------------------------------------