forked from coronabytes/dotnet-arangodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArangoContext.cs
134 lines (110 loc) · 4.61 KB
/
ArangoContext.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Core.Arango.Modules;
using Core.Arango.Modules.Internal;
using Core.Arango.Protocol;
using Core.Arango.Protocol.Internal;
namespace Core.Arango
{
/// <inheritdoc />
public class ArangoContext : IArangoContext
{
/// <summary>
/// </summary>
/// <param name="config">configuration</param>
public ArangoContext(IArangoConfiguration config)
{
Configuration = config ?? throw new ArgumentNullException(nameof(config));
User = new ArangoUserModule(this);
Collection = new ArangoCollectionModule(this);
View = new ArangoViewModule(this);
Database = new ArangoDatabaseModule(this);
Graph = new ArangoGraphModule(this);
Transaction = new ArangoTransactionModule(this);
Document = new ArangoDocumentModule(this);
Query = new ArangoQueryModule(this);
Index = new ArangoIndexModule(this);
Analyzer = new ArangoAnalyzerModule(this);
Function = new ArangoFunctionModule(this);
Foxx = new ArangoFoxxModule(this);
Backup = new ArangoBackupModule(this);
Pregel = new ArangoPregelModule(this);
}
/// <summary>
/// </summary>
/// <param name="cs">connection string</param>
/// <param name="settings">settings</param>
public ArangoContext(string cs, IArangoConfiguration settings = null)
{
Configuration = settings ?? new ArangoConfiguration();
Configuration.ConnectionString = cs;
User = new ArangoUserModule(this);
Collection = new ArangoCollectionModule(this);
View = new ArangoViewModule(this);
Database = new ArangoDatabaseModule(this);
Graph = new ArangoGraphModule(this);
Transaction = new ArangoTransactionModule(this);
Document = new ArangoDocumentModule(this);
Query = new ArangoQueryModule(this);
Index = new ArangoIndexModule(this);
Analyzer = new ArangoAnalyzerModule(this);
Function = new ArangoFunctionModule(this);
Foxx = new ArangoFoxxModule(this);
Backup = new ArangoBackupModule(this);
Pregel = new ArangoPregelModule(this);
}
/// <inheritdoc />
public IArangoUserModule User { get; }
/// <inheritdoc />
public IArangoDatabaseModule Database { get; }
/// <inheritdoc />
public IArangoCollectionModule Collection { get; }
/// <inheritdoc />
public IArangoViewModule View { get; }
/// <inheritdoc />
public IArangoGraphModule Graph { get; }
/// <inheritdoc />
public IArangoTransactionModule Transaction { get; }
/// <inheritdoc />
public IArangoDocumentModule Document { get; }
/// <inheritdoc />
public IArangoQueryModule Query { get; }
/// <inheritdoc />
public IArangoIndexModule Index { get; }
/// <inheritdoc />
public IArangoAnalyzerModule Analyzer { get; }
/// <inheritdoc />
public IArangoFunctionModule Function { get; }
/// <inheritdoc />
public IArangoConfiguration Configuration { get; }
/// <inheritdoc />
public IArangoFoxxModule Foxx { get; }
/// <inheritdoc />
public IArangoBackupModule Backup { get; }
/// <inheritdoc />
public IArangoPregelModule Pregel { get; }
/// <inheritdoc />
public async ValueTask<ArangoVersion> GetVersionAsync(CancellationToken cancellationToken = default)
{
var res = await Configuration.Transport.SendAsync<ArangoVersion>(HttpMethod.Get,
"/_db/_system/_api/version",
cancellationToken: cancellationToken);
var clean = Regex.Replace(res.Version, "[^0-9.]", string.Empty);
res.SemanticVersion = Version.Parse(clean);
return res;
}
/// <inheritdoc />
public async ValueTask<IReadOnlyCollection<string>> GetEndpointsAsync(CancellationToken cancellationToken = default)
{
var res = await Configuration.Transport.SendAsync<EndpointResponse>(HttpMethod.Get,
"/_api/cluster/endpoints", cancellationToken: cancellationToken);
return new ReadOnlyCollection<string>(res.Endpoints.Select(x => x.Endpoint).ToList());
}
}
}