-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddVertexCommand.cs
More file actions
83 lines (60 loc) · 2.17 KB
/
AddVertexCommand.cs
File metadata and controls
83 lines (60 loc) · 2.17 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using Microsoft.Azure.Graphs;
using System.Management.Automation;
using System.Reflection;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace psCosmosGraph
{
[Cmdlet("Add", "Vertex")]
public class AddVertexCommand : PSCmdlet
{
[Parameter()]
public string[] Vertex;
private List<Task<FeedResponse<dynamic>>> tasks = new List<Task<FeedResponse<dynamic>>>();
protected override void BeginProcessing()
{
// what the fuck is going on here?
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_BindingRedirect;
base.BeginProcessing();
}
protected override void ProcessRecord()
{
// what the fuck is going on here?
// AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_BindingRedirect;
var client = Config.Instance.Client;
foreach (var v in Vertex)
{
string q = $"g.AddV('node').property('id', '{v}')";
WriteVerbose(q);
IDocumentQuery<dynamic> query = client.CreateGremlinQuery<dynamic>(Config.Instance.Graph, q);
tasks.Add(query.ExecuteNextAsync());
}
//WriteObject(t.Result);
//base.ProcessRecord();
}
protected override void EndProcessing()
{
WriteVerbose("Waiting on tasks");
Task.WaitAll(tasks.ToArray());
base.EndProcessing();
}
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;
}
}
}
}