-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectGraphCommand.cs
More file actions
58 lines (43 loc) · 1.6 KB
/
ConnectGraphCommand.cs
File metadata and controls
58 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Management.Automation;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents;
using System.Reflection;
namespace psCosmosGraph
{
[Cmdlet("Connect", "Graph")]
public class ConnectGraphCommand : PSCmdlet
{
[Parameter(Mandatory = true)]
public string Endpoint;
[Parameter(Mandatory = true)]
public string Authkey;
[Parameter(Mandatory = true)]
public string DBName;
[Parameter(Mandatory = true)]
public string CollectionName;
protected override void BeginProcessing()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_BindingRedirect;
DocumentClient client = new DocumentClient(
new Uri(Endpoint),
Authkey);
ResourceResponse<DocumentCollection> graph = client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DBName, CollectionName)).Result;
Config.Create(graph, client);
//base.BeginProcessing();
}
public static Assembly CurrentDomain_BindingRedirect(object sender, ResolveEventArgs args)
{
var name = new AssemblyName(args.Name);
switch (name.Name)
{
case "Newtonsoft.Json":
return typeof(Newtonsoft.Json.JsonSerializer).Assembly;
case "System.Collections.Immutable":
return Assembly.LoadFrom("System.Collections.Immutable.dll");
default:
return null;
}
}
}
}