-
Notifications
You must be signed in to change notification settings - Fork 145
/
GraphClient.cs
113 lines (93 loc) · 4.13 KB
/
GraphClient.cs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Neo4jClient.ApiModels;
using Neo4jClient.Cypher;
using Neo4jClient.Execution;
using Neo4jClient.Transactions;
namespace Neo4jClient
{
public partial class GraphClient : IRawGraphClient, IInternalTransactionalGraphClient<HttpResponseMessage>, IDisposable
{
public GraphClient(Uri rootUri, string username = null, string password = null)
: this(rootUri, new HttpClientWrapper(username, password))
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.UseNagleAlgorithm = false;
}
public GraphClient(Uri rootUri, bool expect100Continue, bool useNagleAlgorithm, string username = null, string password = null)
: this(rootUri, new HttpClientWrapper(username, password))
{
ServicePointManager.Expect100Continue = expect100Continue;
ServicePointManager.UseNagleAlgorithm = useNagleAlgorithm;
}
public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
{
if (IsConnected)
{
return;
}
var stopwatch = Stopwatch.StartNew();
var operationCompletedArgs = new OperationCompletedEventArgs
{
QueryText = "Connect",
ResourcesReturned = 0
};
Action stopTimerAndNotifyCompleted = () =>
{
stopwatch.Stop();
operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
OnOperationCompleted(operationCompletedArgs);
};
try
{
configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
RootUri,
ExecutionConfiguration.Username,
ExecutionConfiguration.Password,
ExecutionConfiguration.Realm,
ExecutionConfiguration).ConfigureAwait(false);
RootApiResponse = configuration.ApiConfig;
if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
{
transactionManager = new TransactionManager(this);
}
rootNode = string.IsNullOrEmpty(RootApiResponse.ReferenceNode)
? null
: new RootNode(long.Parse(GetLastPathSegment(RootApiResponse.ReferenceNode)), this);
// http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
RootApiResponse.Version >= new Version(1, 8);
if (RootApiResponse.Version < new Version(2, 0))
cypherCapabilities = CypherCapabilities.Cypher19;
if (RootApiResponse.Version >= new Version(2, 2))
cypherCapabilities = CypherCapabilities.Cypher22;
if (RootApiResponse.Version >= new Version(2, 2, 6))
cypherCapabilities = CypherCapabilities.Cypher226;
if (RootApiResponse.Version >= new Version(2, 3))
cypherCapabilities = CypherCapabilities.Cypher23;
if (RootApiResponse.Version >= new Version(3, 0))
cypherCapabilities = CypherCapabilities.Cypher30;
}
catch (AggregateException ex)
{
Exception unwrappedException;
var wasUnwrapped = ex.TryUnwrap(out unwrappedException);
operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;
stopTimerAndNotifyCompleted();
if (wasUnwrapped)
throw unwrappedException;
throw;
}
catch (Exception e)
{
operationCompletedArgs.Exception = e;
stopTimerAndNotifyCompleted();
throw;
}
stopTimerAndNotifyCompleted();
}
}
}