├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md └── src └── BorderEast.ArangoDB.Client ├── BorderEast.ArangoDB.Client.sln ├── BorderEast.ArangoDB.Client ├── ArangoClient.cs ├── BorderEast.ArangoDB.Client.csproj ├── Connection │ ├── Connection.cs │ ├── ConnectionPool.cs │ ├── HttpConnection.cs │ ├── Payload.cs │ └── Result.cs ├── Database │ ├── AQLCursor │ │ ├── AQLExtra.cs │ │ ├── AQLQuery.cs │ │ └── AQLResult.cs │ ├── ArangoDBContractResolver.cs │ ├── ArangoDatabase.cs │ ├── ArangoJsonConverter.cs │ ├── ArangoQuery.cs │ ├── ClientSettings.cs │ ├── ForeignKeyConverter.cs │ ├── Meta │ │ ├── ArangoFieldAttribute.cs │ │ ├── CollectionAttribute.cs │ │ ├── ForeignKey.cs │ │ ├── IArangoFieldAttribute.cs │ │ └── ICollectionAttribute.cs │ └── ProtocolType.cs ├── Enums.cs ├── Exception │ ├── DatabaseExistsException.cs │ ├── DatabaseNotFoundException.cs │ └── QueryExecutionException.cs ├── IArangoClient.cs ├── Models │ ├── ArangoBaseEntity.cs │ ├── ArangoUserEntity.cs │ ├── Collection │ │ ├── ArangoCollection.cs │ │ ├── ArangoKeyOptions.cs │ │ └── CollectionResult.cs │ ├── Database │ │ ├── DatabaseResult.cs │ │ ├── NewDatabase.cs │ │ └── NewDatabaseUser.cs │ ├── UpdatedDocument.cs │ └── User │ │ ├── AuthorizationData.cs │ │ ├── ExtraData.cs │ │ ├── SimplePassword.cs │ │ └── UserQuery.cs ├── Res │ ├── Msg.Designer.cs │ └── Msg.resx ├── Utils │ └── DynamicUtil.cs └── libs │ └── Arango.VelocyPack.dll ├── BorderEast.ArangoDB.ClientTest ├── ArangoDBClientTest.cs ├── BorderEast.ArangoDB.ClientTest.csproj ├── JsonTest.cs ├── MethodsTest.cs └── MockData │ ├── Author.cs │ ├── Book.cs │ ├── InsertManyUser.cs │ ├── MockSetup.cs │ └── User.cs └── ConsoleTestApp ├── ConsoleTestApp.csproj ├── Program.cs ├── Role.cs ├── User.cs └── VelocyStream.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | sudo: required 3 | language: csharp 4 | solution: BorderEast.ArangoDB.Client.sln 5 | mono: none 6 | dotnet: 2.0.0 7 | script: 8 | - cd ./src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client 9 | - dotnet restore 10 | - dotnet build 11 | - cd ../BorderEast.ArangoDB.ClientTest 12 | - dotnet restore 13 | - dotnet build 14 | - dotnet test 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Andrew Grothe 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 | 2 | ## Depricated: 3 | please use https://github.com/coronabytes/ArangoDB or https://github.com/Actify-Inc/arangodb-net-standard 4 | 5 | ### BorderEast.ArangoDB.Client 6 | .NETCoreApp 2.0 ArangoDB Client Driver 7 | 8 | Contributions welcome. 9 | 10 | ### AQL Based 11 | For those who like to write pure AQL queries for ultimate flexibility. This will mainly focus on AQL string queries at first with convience methods for Insert, Update, Delete etc. 12 | 13 | ### Managed Foreign Keys 14 | This client supports a managed foreign key feature. This allows an entity to include a `List` of another entity by setting a data annotation. This will work with two tables in the database but allow users to work the entity as if it was a single document. While this is duplicating some relational database features, this is the most common feature lacking in client libraries. 15 | 16 | ArangoDB has an excellent join feature via AQL, and this is the next logical step on the client side. [Please see the documentation for examples](https://github.com/bordereast/arangodb-net-core/wiki) 17 | 18 | ### Connection Pools 19 | This client manages connection pools. It has two connection pools, one for HTTP and one for VelocyStream(not implemented yet). All methods are Async and a connection is obtained immediatly before use and released immediatly afterwards. This is handled internally, so consumers won't need to worry about closing connections. Also, each HTTPClient object is left undisposed, but only used by one Database instance at a time. This cuts down on overhead of new connections but makes connection use consistent between the HTTP and yet to be implemented TCP protocols. Configurable to use the same HTTPClient for all connections, or differnt per connection. 20 | 21 | ### Other Features 22 | Document Update (PATCH) now returns the Arango old revision and new document. Will probably make this configurable to save network traffic. An UpdatedDocument class is returned from the `Client.DB().Update(id, item)` method. 23 | 24 | ### Feature Status 25 | Method | Status | Foreign Key Support 26 | --- | --- | --- 27 | AQL Query | Done | Manual 28 | GetByKeyAsync | Done | Auto 29 | UpdateAsync | Done | Auto 30 | DeleteAsync | Done | N/A 31 | InsertAsync | Done | Auto 32 | InsertManyAsync | Done | Auto 33 | GetAllAsync | Done | Auto 34 | GetAllKeysAsync | Done | N/A 35 | GetByExampleAsync | Done | Auto 36 | CreateCollection | Done | N/A 37 | 38 | ### Credits 39 | Based loosely on ideas taken from [ra0o0f](https://github.com/ra0o0f/arangoclient.net) and [yojimbo87](https://github.com/yojimbo87/ArangoDB-NET), this is a .NETCoreApp2 library. 40 | 41 | #### Contributions by 42 | 43 | [Irriss](https://github.com/irriss) 44 | 45 | [Arkos-LoG](https://github.com/Arkos-LoG) 46 | 47 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26403.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BorderEast.ArangoDB.Client", "BorderEast.ArangoDB.Client\BorderEast.ArangoDB.Client.csproj", "{BEF256FD-B337-485D-A113-0CD3F444C11D}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTestApp", "ConsoleTestApp\ConsoleTestApp.csproj", "{8F467441-6C10-4AAD-A657-20FF94D4F108}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BorderEast.ArangoDB.ClientTest", "BorderEast.ArangoDB.ClientTest\BorderEast.ArangoDB.ClientTest.csproj", "{04903EEA-9310-4EB6-B28D-BC011A0A170F}" 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 | {BEF256FD-B337-485D-A113-0CD3F444C11D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {BEF256FD-B337-485D-A113-0CD3F444C11D}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {BEF256FD-B337-485D-A113-0CD3F444C11D}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {BEF256FD-B337-485D-A113-0CD3F444C11D}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {8F467441-6C10-4AAD-A657-20FF94D4F108}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {8F467441-6C10-4AAD-A657-20FF94D4F108}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {8F467441-6C10-4AAD-A657-20FF94D4F108}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {8F467441-6C10-4AAD-A657-20FF94D4F108}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {04903EEA-9310-4EB6-B28D-BC011A0A170F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {04903EEA-9310-4EB6-B28D-BC011A0A170F}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {04903EEA-9310-4EB6-B28D-BC011A0A170F}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {04903EEA-9310-4EB6-B28D-BC011A0A170F}.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 = {DE97FE47-49CD-4F2F-A99E-6BB2292F4E20} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/ArangoClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using BorderEast.ArangoDB.Client.Database; 4 | using BorderEast.ArangoDB.Client.Connection; 5 | using BorderEast.ArangoDB.Client.Exception; 6 | 7 | namespace BorderEast.ArangoDB.Client 8 | { 9 | /// 10 | /// Entry point for interacting with ArangoDB. You only need one instance of this class, 11 | /// even if working with multiple databases, hence the Singleton pattern. 12 | /// 13 | public class ArangoClient : IArangoClient { 14 | private readonly string DEFAULT = Res.Msg.Default; 15 | private static ArangoClient _client = new ArangoClient(); 16 | internal readonly IDictionary databases = new SortedDictionary(); 17 | internal readonly IDictionary> pools = new SortedDictionary>(); 18 | 19 | private ArangoClient() { } 20 | 21 | /// 22 | /// Get the client instance 23 | /// 24 | /// 25 | public static ArangoClient Client() { 26 | return _client; 27 | } 28 | 29 | /// 30 | /// Setup your default database 31 | /// 32 | /// 33 | public void SetDefaultDatabase(ClientSettings defaultConnection) { 34 | if (databases.ContainsKey(DEFAULT)) { 35 | return; 36 | } 37 | databases.Add(DEFAULT, defaultConnection); 38 | pools.Add(DEFAULT, new ConnectionPool(() => new HttpConnection(defaultConnection))); 39 | } 40 | 41 | /// 42 | /// Convience method to get the default database. 43 | /// 44 | /// 45 | public ArangoDatabase DB() { 46 | if (!databases.ContainsKey(DEFAULT)) { 47 | return null; 48 | } 49 | 50 | return new ArangoDatabase(databases[DEFAULT], pools[DEFAULT]); 51 | } 52 | 53 | /// 54 | /// Get database by name 55 | /// 56 | /// 57 | /// 58 | public ArangoDatabase DB(string database) { 59 | if (!databases.ContainsKey(database)) { 60 | throw new DatabaseNotFoundException(Res.Msg.ArangoDbNotFound); 61 | } 62 | return new ArangoDatabase(databases[database], pools[database]); 63 | } 64 | 65 | /// 66 | /// Initialize a new database, does not actually create the db in Arango 67 | /// 68 | /// 69 | /// 70 | public ArangoDatabase InitDB(ClientSettings databaseSettings) { 71 | if (databases.ContainsKey(databaseSettings.DatabaseName)) { 72 | throw new DatabaseExistsException(Res.Msg.ArangoDbAlreadyExists); 73 | } 74 | databases.Add(databaseSettings.DatabaseName, databaseSettings); 75 | pools.Add(databaseSettings.DatabaseName, new ConnectionPool(() => new HttpConnection(databaseSettings))); 76 | return new ArangoDatabase(databases[databaseSettings.DatabaseName], pools[databaseSettings.DatabaseName]); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.2 5 | BorderEast.ArangoDB.Client 6 | 0.2.10-rc 7 | Border East 8 | DotNet Core ArangoDB Client 9 | false 10 | Attempting to fix Github Issue #7 11 | Copyright 2017 (c) Border East. All rights reserved. 12 | arangodb database-client netcore 13 | True 14 | 0.2.010-rc 15 | https://github.com/bordereast/arangodb-net-core/blob/master/LICENSE 16 | https://github.com/bordereast/arangodb-net-core 17 | https://avatars1.githubusercontent.com/u/27213082?v=3&s=200 18 | https://github.com/bordereast/arangodb-net-core 19 | git 20 | 1.0.2.0 21 | 1.0.2.0 22 | 23 | 24 | 25 | bin\Release\netcoreapp1.1\BorderEast.ArangoDB.Client.xml 26 | True 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | libs\Arango.VelocyPack.dll 39 | 40 | 41 | 42 | 43 | 44 | True 45 | True 46 | Msg.resx 47 | 48 | 49 | 50 | 51 | 52 | ResXFileCodeGenerator 53 | Msg.Designer.cs 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Connection/Connection.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace BorderEast.ArangoDB.Client.Connection 8 | { 9 | public interface IConnection 10 | { 11 | Task GetAsync(Payload payload); 12 | 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Connection/ConnectionPool.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database; 2 | using System; 3 | using System.Collections.Concurrent; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Connection 8 | { 9 | public class ConnectionPool 10 | { 11 | private ConcurrentBag _connections; 12 | private Func _objectGenerator; 13 | private readonly ClientSettings databaseSettings; 14 | 15 | public ConnectionPool(ClientSettings databaseSettings) { 16 | this.databaseSettings = databaseSettings; 17 | } 18 | 19 | public ConnectionPool(Func connectionsGenerator) { 20 | _connections = new ConcurrentBag(); 21 | _objectGenerator = connectionsGenerator ?? throw new ArgumentNullException("connectionsGenerator"); 22 | } 23 | 24 | public Connection GetConnection() { 25 | if (_connections.TryTake(out Connection connection)) { 26 | return connection; 27 | } 28 | 29 | return _objectGenerator(); 30 | } 31 | 32 | public void PutConnection(Connection connection) { 33 | _connections.Add(connection); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Connection/HttpConnection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Text; 5 | using BorderEast.ArangoDB.Client.Database; 6 | using System.Net.Http.Headers; 7 | using System.Threading.Tasks; 8 | using BorderEast.ArangoDB.Client.Exception; 9 | 10 | namespace BorderEast.ArangoDB.Client.Connection 11 | { 12 | public class HttpConnection : IConnection 13 | { 14 | private HttpClient client; 15 | private ClientSettings databaseSettings; 16 | 17 | public HttpConnection(ClientSettings databaseSettings) { 18 | 19 | this.databaseSettings = databaseSettings; 20 | 21 | bool isSystem = databaseSettings.DatabaseName == "_system"; 22 | 23 | if (databaseSettings.HTTPClient != null ) { 24 | client = databaseSettings.HTTPClient; 25 | } else { 26 | client = new HttpClient(); 27 | } 28 | 29 | if(client.BaseAddress == null) { 30 | client.BaseAddress = new Uri((databaseSettings.Protocol == ProtocolType.HTTPS ? "https" : "http") + 31 | "://" + databaseSettings.ServerAddress + ":" + databaseSettings.ServerPort + "/" 32 | + (isSystem ? string.Empty : string.Format("_db/{0}/", databaseSettings.DatabaseName))); 33 | } 34 | 35 | 36 | } 37 | 38 | private void AddHeaders(HttpRequestMessage message) { 39 | message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 40 | if (databaseSettings.DatabaseCredential != null) { 41 | message.Headers.Add( 42 | "Authorization", 43 | "Basic " + Convert.ToBase64String( 44 | Encoding.UTF8.GetBytes(databaseSettings.DatabaseCredential.UserName + ":" + databaseSettings.DatabaseCredential.Password))); 45 | } 46 | } 47 | 48 | public async Task GetAsync(Payload payload) { 49 | var message = new HttpRequestMessage(payload.Method, client.BaseAddress + payload.Path); 50 | 51 | AddHeaders(message); 52 | 53 | if (!string.IsNullOrEmpty(payload.Content)) { 54 | message.Content = new StringContent(payload.Content, Encoding.UTF8, "application/json"); 55 | } 56 | 57 | var responseTask = await client.SendAsync(message); 58 | 59 | if(responseTask.StatusCode == System.Net.HttpStatusCode.NotFound) { 60 | return null; 61 | } 62 | 63 | if (!responseTask.IsSuccessStatusCode 64 | && responseTask.StatusCode != System.Net.HttpStatusCode.BadRequest) //there is detailed info in Content for bad request 65 | throw new QueryExecutionException(responseTask.StatusCode.ToString(), (int)responseTask.StatusCode); 66 | 67 | Result result = new Result() 68 | { 69 | StatusCode = responseTask.StatusCode, 70 | Content = await responseTask.Content.ReadAsStringAsync() 71 | }; 72 | return result; 73 | } 74 | 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Connection/Payload.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Text; 5 | 6 | namespace BorderEast.ArangoDB.Client.Connection 7 | { 8 | public class Payload 9 | { 10 | public string Content { get; set; } 11 | 12 | public HttpMethod Method { get; set; } 13 | 14 | public string Path { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Connection/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | 6 | namespace BorderEast.ArangoDB.Client.Connection 7 | { 8 | public class Result 9 | { 10 | public string Content { get; set; } 11 | public HttpStatusCode StatusCode { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/AQLCursor/AQLExtra.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System.Collections.Generic; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database.AQLCursor { 6 | public class AQLExtra { 7 | 8 | [JsonProperty(PropertyName = "stats", NullValueHandling = NullValueHandling.Ignore)] 9 | public Dictionary Stats { get; set; } 10 | 11 | [JsonProperty(PropertyName = "warnings", NullValueHandling = NullValueHandling.Ignore)] 12 | public List Warnings { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/AQLCursor/AQLQuery.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Database.AQLCursor 8 | { 9 | public class AQLQuery 10 | { 11 | public AQLQuery() { 12 | Parameters = new Dictionary(); 13 | } 14 | 15 | [JsonProperty("query")] 16 | public string Query { get; set; } 17 | 18 | [JsonProperty(PropertyName = "bindVars", NullValueHandling = NullValueHandling.Ignore)] 19 | public Dictionary Parameters { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/AQLCursor/AQLResult.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System.Collections.Generic; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database.AQLCursor { 6 | public class AQLResult { 7 | 8 | [JsonProperty(PropertyName = "id", NullValueHandling = NullValueHandling.Ignore)] 9 | public string CursorId { get; set; } 10 | 11 | [JsonProperty(PropertyName = "result", NullValueHandling = NullValueHandling.Ignore)] 12 | public List Result { get; set; } 13 | 14 | [JsonProperty(PropertyName = "hasMore", NullValueHandling = NullValueHandling.Ignore)] 15 | public bool HasMore { get; set; } 16 | 17 | [JsonProperty(PropertyName = "extra", NullValueHandling = NullValueHandling.Ignore)] 18 | public AQLExtra Extra { get; set; } 19 | 20 | [JsonProperty(PropertyName = "error", NullValueHandling = NullValueHandling.Ignore)] 21 | public bool Error { get; set; } 22 | 23 | [JsonProperty(PropertyName = "code", NullValueHandling = NullValueHandling.Ignore)] 24 | public int Code { get; set; } 25 | 26 | [JsonProperty(PropertyName = "errorNum", NullValueHandling = NullValueHandling.Ignore)] 27 | public int ErrorNumber { get; set; } 28 | 29 | [JsonProperty(PropertyName = "errorMessage", NullValueHandling = NullValueHandling.Ignore)] 30 | public string ErrorMessage { get; set; } 31 | 32 | [JsonProperty(PropertyName = "cached", NullValueHandling = NullValueHandling.Ignore)] 33 | public bool Cached { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/ArangoDBContractResolver.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Serialization; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Database 8 | { 9 | public class ArangoDBContractResolver : DefaultContractResolver { 10 | public ArangoDBContractResolver() : base() 11 | { 12 | NamingStrategy = new DefaultNamingStrategy 13 | { 14 | ProcessDictionaryKeys = true, 15 | OverrideSpecifiedNames = false, 16 | ProcessExtensionDataNames = true 17 | }; 18 | 19 | IgnoreSerializableAttribute = false; 20 | IgnoreSerializableInterface = false; 21 | 22 | } 23 | public ArangoDBContractResolver(NamingStrategy namingStrategy) : base() 24 | { 25 | NamingStrategy = namingStrategy; 26 | 27 | IgnoreSerializableAttribute = false; 28 | IgnoreSerializableInterface = false; 29 | 30 | } 31 | 32 | protected override IValueProvider CreateMemberValueProvider(MemberInfo member) { 33 | IValueProvider provider = base.CreateMemberValueProvider(member); 34 | 35 | if (member.MemberType == MemberTypes.Property) { 36 | Type propType = ((PropertyInfo)member).PropertyType; 37 | TypeInfo propTypeInfo = propType.GetTypeInfo(); 38 | if (propTypeInfo.IsGenericType && 39 | propType.GetGenericTypeDefinition() == typeof(List<>)) { 40 | return new EmptyListValueProvider(provider, propType); 41 | } 42 | } 43 | 44 | return provider; 45 | } 46 | 47 | class EmptyListValueProvider : IValueProvider { 48 | private IValueProvider innerProvider; 49 | private object defaultValue; 50 | 51 | public EmptyListValueProvider(IValueProvider innerProvider, Type listType) { 52 | this.innerProvider = innerProvider; 53 | defaultValue = Activator.CreateInstance(listType); 54 | } 55 | 56 | public void SetValue(object target, object value) { 57 | innerProvider.SetValue(target, value ?? defaultValue); 58 | } 59 | 60 | public object GetValue(object target) { 61 | return innerProvider.GetValue(target) ?? defaultValue; 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/ArangoDatabase.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Connection; 2 | using BorderEast.ArangoDB.Client.Database.Meta; 3 | using BorderEast.ArangoDB.Client.Models; 4 | using BorderEast.ArangoDB.Client.Utils; 5 | using Newtonsoft.Json; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Dynamic; 9 | using System.Net.Http; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | using System.Reflection; 13 | using System.Linq; 14 | using BorderEast.ArangoDB.Client.Database.AQLCursor; 15 | using BorderEast.ArangoDB.Client.Models.Collection; 16 | using BorderEast.ArangoDB.Client.Models.Database; 17 | 18 | namespace BorderEast.ArangoDB.Client.Database 19 | { 20 | /// 21 | /// Public methods for interacting with ArangoDB 22 | /// 23 | public class ArangoDatabase 24 | { 25 | internal ClientSettings databaseSettings; 26 | private ConnectionPool connectionPool; 27 | 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | public ArangoDatabase(ClientSettings databaseSettings, ConnectionPool connectionPool) { 34 | this.databaseSettings = databaseSettings; 35 | this.connectionPool = connectionPool; 36 | } 37 | 38 | #region database 39 | 40 | /// 41 | /// Create a new database within Arango. Use the default DB to create new databases. 42 | /// 43 | /// 44 | /// 45 | public async Task CreateDatabase(NewDatabase database) 46 | { 47 | 48 | Payload payload = new Payload() 49 | { 50 | Content = JsonConvert.SerializeObject(database, databaseSettings.JsonSettings), 51 | Method = HttpMethod.Post, 52 | Path = string.Format("_api/database") 53 | }; 54 | 55 | var result = await GetResultAsync(payload); 56 | 57 | if (result == null) 58 | { 59 | return default(DatabaseResult); 60 | } 61 | 62 | var json = JsonConvert.DeserializeObject(result.Content); 63 | return json; 64 | 65 | } 66 | 67 | #endregion 68 | 69 | #region collections 70 | 71 | /// 72 | /// Create a collection based on the passed in dynamic object 73 | /// Example: CreateCollection(new { Name = somename}) 74 | /// 75 | /// 76 | /// 77 | /// 78 | public async Task CreateCollection(dynamic parameters) { 79 | 80 | var ctype = typeof(ArangoCollection); 81 | // get settable public properties of the type 82 | var props = ctype.GetProperties(BindingFlags.Public | BindingFlags.Instance) 83 | .Where(x => x.GetSetMethod() != null); 84 | 85 | // create an instance of the type 86 | var collection = Activator.CreateInstance(ctype); 87 | 88 | // set property values using reflection 89 | var values = DynamicUtil.DynamicToDict(parameters); 90 | foreach (var prop in props) { 91 | if (values.ContainsKey(prop.Name)) { 92 | prop.SetValue(collection, values[prop.Name]); 93 | } 94 | 95 | } 96 | 97 | return await CreateCollection(collection as ArangoCollection); 98 | } 99 | 100 | /// 101 | /// Create a collection based on the given ArangoCollection 102 | /// 103 | /// 104 | /// 105 | /// 106 | public async Task CreateCollection(ArangoCollection collection) { 107 | 108 | Payload payload = new Payload() 109 | { 110 | Content = JsonConvert.SerializeObject(collection, databaseSettings.JsonSettings), 111 | Method = HttpMethod.Post, 112 | Path = string.Format("_api/collection") 113 | }; 114 | 115 | var result = await GetResultAsync(payload); 116 | 117 | if (result == null) { 118 | return default(CollectionResult); 119 | } 120 | 121 | var json = JsonConvert.DeserializeObject(result.Content); 122 | return json; 123 | 124 | } 125 | 126 | 127 | #endregion 128 | 129 | #region query 130 | 131 | /// 132 | /// Ad hoc AQL query that will be serialized to give type T 133 | /// 134 | /// Entity class 135 | /// AQL query text 136 | /// ArangoQuery of T 137 | public ArangoQuery Query(string query) { 138 | return Query(query, null); 139 | } 140 | 141 | /// 142 | /// Ad hoc AQL query that will be serialized to give type T 143 | /// 144 | /// Entity class 145 | /// AQL query text 146 | /// Dynamic object of parmeters, use JSON names (_key instead of Key) 147 | /// ArangoQuery of T 148 | public ArangoQuery Query(string query, dynamic parameters) { 149 | Dictionary dParams = DynamicUtil.DynamicToDict(parameters); 150 | return Query(query, dParams); 151 | } 152 | 153 | /// 154 | /// Ad hoc AQL query that will be serialized to give type T 155 | /// 156 | /// Entity class 157 | /// AQL query text 158 | /// Dictionary of parmeters, use JSON names (_key instead of Key) 159 | /// ArangoQuery of T 160 | public ArangoQuery Query(string query, Dictionary parameters) { 161 | return new ArangoQuery(query, parameters, connectionPool, this); 162 | } 163 | 164 | private ArangoQuery Query(AQLQuery query) { 165 | return new ArangoQuery(query, connectionPool, this); 166 | } 167 | 168 | #endregion 169 | 170 | 171 | #region get 172 | 173 | public JsonSerializerSettings GetJsonSettings() { 174 | return databaseSettings.JsonSettings; 175 | } 176 | 177 | /// 178 | /// Get all keys of a given entity 179 | /// 180 | /// Entity type 181 | /// List of entity keys 182 | public async Task> GetAllKeysAsync() { 183 | return await Query("for x in @@col return x._key", 184 | new Dictionary { { "@col", DynamicUtil.GetTypeName(typeof(T)) } }).ToListAsync(); 185 | } 186 | 187 | 188 | /// 189 | /// Get entities by example 190 | /// 191 | /// Entity type 192 | /// Dynamic object of parmeters, use JSON names (_key instead of Key) 193 | /// List of entities 194 | public async Task> GetByExampleAsync(dynamic parameters) { 195 | Type type = typeof(T); 196 | ForeignKey fk = HasForeignKey(type); 197 | 198 | var q = BuildFKQuery(fk, type, parameters); 199 | return await Query(q).ToListAsync(); 200 | 201 | } 202 | 203 | /// 204 | /// Get entity by key 205 | /// 206 | /// Entity type 207 | /// Key of entity 208 | /// Single entity 209 | public async Task GetByKeyAsync(string key) { 210 | Type type = typeof(T); 211 | var typeName = DynamicUtil.GetTypeName(type); 212 | 213 | ForeignKey fk = HasForeignKey(type); 214 | 215 | if (fk.IsForeignKey) { 216 | var q = BuildFKQuery(fk, type, new { _key = key }); 217 | 218 | var r = await Query(q).ToListAsync(); 219 | return r.FirstOrDefault(); 220 | } 221 | 222 | Payload payload = new Payload() { 223 | Content = string.Empty, 224 | Method = HttpMethod.Get, 225 | Path = string.Format("_api/document/{0}/{1}", typeName, key) 226 | }; 227 | 228 | var result = await GetResultAsync(payload); 229 | 230 | if(result == null) { 231 | return default(T); 232 | } 233 | 234 | var json = JsonConvert.DeserializeObject(result.Content); 235 | return json; 236 | } 237 | 238 | /// 239 | /// Get all entities of given type 240 | /// 241 | /// Entity type 242 | /// List of entities 243 | public async Task> GetAllAsync() { 244 | var typeName = DynamicUtil.GetTypeName(typeof(T)); 245 | 246 | ForeignKey fk = HasForeignKey(typeof(T)); 247 | 248 | if (fk.IsForeignKey) { 249 | var q = BuildFKQuery(fk, typeof(T)); 250 | 251 | return await Query(q).ToListAsync(); 252 | } 253 | 254 | return await Query(string.Format("FOR x IN {0} RETURN x", typeName)).ToListAsync(); 255 | //new Dictionary{{ "col", typeName }}).ToListAsync(); 256 | } 257 | #endregion 258 | 259 | #region utility 260 | 261 | private AQLQuery BuildFKQuery(ForeignKey fk, Type baseType, dynamic parameters = null) { 262 | var q = new AQLQuery(); 263 | var parms = new Dictionary(); 264 | var sb = new StringBuilder(); 265 | Dictionary dParams = null; 266 | if(parameters != null) { 267 | dParams = DynamicUtil.DynamicToDict(parameters); 268 | } 269 | 270 | 271 | sb.Append("FOR x1 IN " + DynamicUtil.GetTypeName(baseType)); 272 | // parms.Add("@col", baseType.Name); 273 | 274 | if (fk.IsForeignKey) { 275 | for (var i = 0; i < fk.ForeignKeyTypes.Count; i++) { 276 | sb.AppendFormat(" LET {0} = ( FOR x IN x1.{1} FOR {0} IN {2} FILTER x == {0}._key RETURN {0}) ", 277 | "a" + i, // {0} 278 | fk.ForeignKeyTypes[i].Key.ToLowerInvariant(), // {1} 279 | fk.ForeignKeyTypes[i].Value.Name); // {2} 280 | } 281 | } 282 | 283 | // check for parameters 284 | if(dParams != null && dParams.Count > 0) { 285 | var dp = dParams.ToArray(); 286 | for(var i = 0; i < dp.Length; i++) { 287 | sb.AppendFormat(" FILTER x1.{0} == TO_STRING(@{1}) ", dp[i].Key, "pval" + i); 288 | parms.Add("pval" + i, dp[i].Value); 289 | } 290 | } 291 | 292 | if (fk.IsForeignKey) { 293 | sb.Append(" RETURN MERGE (x1, {"); 294 | 295 | for (var i = 0; i < fk.ForeignKeyTypes.Count; i++) { 296 | if (i > 0) { 297 | sb.Append(", "); 298 | } 299 | 300 | sb.AppendFormat("{1}: {0}", // Roles: a1 301 | "a" + i, // {0} 302 | fk.ForeignKeyTypes[i].Key.ToLowerInvariant()); // {2} 303 | } 304 | 305 | sb.Append(" }) "); 306 | } else { 307 | sb.Append(" RETURN x1 "); 308 | } 309 | 310 | q.Query = sb.ToString(); 311 | 312 | if(parms.Count > 0) { 313 | q.Parameters = parms; 314 | } 315 | 316 | return q; 317 | } 318 | 319 | private ForeignKey HasForeignKey(Type t) { 320 | ForeignKey fk = new ForeignKey(); 321 | // get custom CollectionAttribute 322 | var attribute = t.GetTypeInfo().GetCustomAttribute(); 323 | // if CollectionAttribute exists and sets HasForeignKey to true 324 | if (attribute != null && attribute.HasForeignKey) { 325 | fk.ForeignKeyTypes = new List>(); 326 | // iterate over properties and extract each one that has a foreign key 327 | foreach (var p in t.GetProperties()) { 328 | var jca = p.GetCustomAttribute(); 329 | if (jca != null) { 330 | if (jca.ConverterType == typeof(ForeignKeyConverter)) { 331 | var ta = p.PropertyType.GenericTypeArguments.FirstOrDefault(); 332 | fk.ForeignKeyTypes.Add(new KeyValuePair(p.Name, ta)); 333 | } 334 | } 335 | } 336 | fk.IsForeignKey = true; 337 | } else { 338 | fk.IsForeignKey = false; 339 | } 340 | 341 | return fk; 342 | } 343 | 344 | #endregion 345 | 346 | 347 | #region C*UD 348 | /// 349 | /// Update an entity 350 | /// 351 | /// Entity type 352 | /// Key of entity 353 | /// Entity with all or partial properties 354 | /// UpdatedDocument with complete new Entity 355 | public async Task> UpdateAsync(string key, T item) where T : ArangoBaseEntity { 356 | var typeName = DynamicUtil.GetTypeName(typeof(T)); 357 | 358 | HttpMethod method = new HttpMethod("PATCH"); 359 | 360 | item.UpdatedDateTime = DateTime.UtcNow; 361 | 362 | Payload payload = new Payload() 363 | { 364 | Content = JsonConvert.SerializeObject(item, databaseSettings.JsonSettings), 365 | Method = method, 366 | Path = string.Format("_api/document/{0}/{1}?mergeObjects=false&returnNew=true", typeName, key) 367 | }; 368 | 369 | var result = await GetResultAsync(payload); 370 | 371 | var json = JsonConvert.DeserializeObject>(result.Content, databaseSettings.JsonSettings); 372 | return json; 373 | } 374 | 375 | /// 376 | /// Delete an entity 377 | /// 378 | /// Entity type 379 | /// Entity key 380 | /// True for success, false on error 381 | public async Task DeleteAsync(string key) { 382 | var typeName = DynamicUtil.GetTypeName(typeof(T)); 383 | 384 | Payload payload = new Payload() 385 | { 386 | Content = string.Empty, 387 | Method = HttpMethod.Delete, 388 | Path = string.Format("_api/document/{0}/{1}?silent=true", typeName, key) 389 | }; 390 | 391 | var result = await GetResultAsync(payload); 392 | 393 | if(result.StatusCode == System.Net.HttpStatusCode.OK || 394 | result.StatusCode == System.Net.HttpStatusCode.Accepted) 395 | { 396 | return true; 397 | } else { 398 | return false; 399 | } 400 | 401 | } 402 | 403 | /// 404 | /// Insert entity 405 | /// 406 | /// Entity type 407 | /// Entity to insert 408 | /// UpdatedDocument with new entity 409 | public async Task> InsertAsync(T item) where T: ArangoBaseEntity { 410 | try { 411 | var typeName = DynamicUtil.GetTypeName(typeof(T)); 412 | 413 | item.CreatedDateTime = DateTime.UtcNow; 414 | 415 | Payload payload = new Payload() 416 | { 417 | Content = JsonConvert.SerializeObject(item, databaseSettings.JsonSettings), 418 | Method = HttpMethod.Post, 419 | Path = string.Format("_api/document/{0}/?returnNew=true", typeName) 420 | }; 421 | 422 | var result = await GetResultAsync(payload); 423 | 424 | var json = JsonConvert.DeserializeObject>(result.Content, databaseSettings.JsonSettings); 425 | return json; 426 | }catch(System.Exception e) { 427 | System.Diagnostics.Debug.WriteLine(e.StackTrace); 428 | return null; 429 | } 430 | } 431 | 432 | /// 433 | /// Insert entity(s) 434 | /// 435 | /// Entity type 436 | /// List of Entity(s) to insert 437 | /// UpdatedDocument(s) with new entity(s) 438 | public async Task>> InsertManyAsync(List items) where T : ArangoBaseEntity 439 | { 440 | try 441 | { 442 | var typeName = DynamicUtil.GetTypeName(typeof(T)); 443 | 444 | if (items.Count < 1) 445 | { 446 | return null; 447 | } 448 | 449 | items.ForEach(x => x.CreatedDateTime = DateTime.UtcNow); 450 | 451 | Payload payload = new Payload() 452 | { 453 | Content = JsonConvert.SerializeObject(items, databaseSettings.JsonSettings), 454 | Method = HttpMethod.Post, 455 | Path = $"_api/document/{typeName}/?returnNew=true" 456 | }; 457 | 458 | var result = await GetResultAsync(payload); 459 | 460 | var json = JsonConvert 461 | .DeserializeObject>>(result.Content, databaseSettings.JsonSettings); 462 | return json; 463 | } 464 | catch (System.Exception e) 465 | { 466 | System.Diagnostics.Debug.WriteLine(e.StackTrace); 467 | return null; 468 | } 469 | } 470 | #endregion 471 | 472 | #region internal 473 | internal async Task GetResultAsync(Payload payload) { 474 | 475 | // Get connection just before we use it 476 | IConnection connection = connectionPool.GetConnection(); 477 | 478 | Result result = await connection.GetAsync(payload); 479 | 480 | // Put connection back immediatly after use 481 | connectionPool.PutConnection(connection); 482 | return result; 483 | } 484 | 485 | #endregion 486 | 487 | } 488 | } 489 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/ArangoJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Linq; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Text; 9 | 10 | namespace BorderEast.ArangoDB.Client.Database 11 | { 12 | public class ArangoJsonConverter : JsonConverter { 13 | private readonly Type[] _types; 14 | public ArangoJsonConverter(params Type[] types) 15 | { 16 | _types = types; 17 | } 18 | public override bool CanConvert(Type objectType) { 19 | return true; 20 | } 21 | 22 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { 23 | throw new NotImplementedException(); 24 | } 25 | 26 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { 27 | JToken t = JToken.FromObject(value); 28 | var property = value.GetType().GetProperty("Username"); 29 | foreach(var attr in property.CustomAttributes) { 30 | foreach (var na in attr.NamedArguments) { 31 | var x = na.MemberName; 32 | var y = na.TypedValue.Value; 33 | } 34 | } 35 | JObject o = (JObject)t; 36 | } 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/ArangoQuery.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Connection; 2 | using BorderEast.ArangoDB.Client.Database.AQLCursor; 3 | using Newtonsoft.Json; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Net.Http; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Linq; 10 | using BorderEast.ArangoDB.Client.Exception; 11 | 12 | namespace BorderEast.ArangoDB.Client.Database 13 | { 14 | /// 15 | /// Strongy typed query builder 16 | /// 17 | /// 18 | public class ArangoQuery 19 | { 20 | private AQLQuery query; 21 | private ConnectionPool connectionPool; 22 | private ArangoDatabase database; 23 | 24 | 25 | internal ArangoQuery(string queryStr, ConnectionPool connectionPool, ArangoDatabase database) { 26 | this.connectionPool = connectionPool; 27 | this.database = database; 28 | query = new AQLQuery() 29 | { 30 | Query = queryStr 31 | }; 32 | } 33 | 34 | internal ArangoQuery(string queryStr, Dictionary parameters, 35 | ConnectionPool connectionPool, ArangoDatabase database) 36 | { 37 | this.connectionPool = connectionPool; 38 | this.database = database; 39 | query = new AQLQuery() 40 | { 41 | Query = queryStr, 42 | Parameters = parameters 43 | }; 44 | } 45 | 46 | internal ArangoQuery(AQLQuery aqlQuery, ConnectionPool connectionPool, ArangoDatabase database) { 47 | this.connectionPool = connectionPool; 48 | this.database = database; 49 | query = aqlQuery; 50 | } 51 | 52 | /// 53 | /// Add parameters to the query 54 | /// 55 | /// 56 | /// 57 | public ArangoQuery WithParameters(Dictionary parameters) { 58 | this.query.Parameters = parameters; 59 | return this; 60 | } 61 | 62 | /// 63 | /// Retrieve as List 64 | /// 65 | /// 66 | public async Task> ToListAsync() { 67 | 68 | Payload payload = new Payload() 69 | { 70 | Content = JsonConvert.SerializeObject(query, database.databaseSettings.JsonSettings), 71 | Method = HttpMethod.Post, 72 | Path = "_api/cursor" 73 | }; 74 | 75 | if (database.databaseSettings.IsDebug) { 76 | payload.Path += "?query=" + Convert.ToBase64String(Encoding.UTF8.GetBytes(query.Query)); 77 | } 78 | 79 | var result = await database.GetResultAsync(payload); 80 | if (result == null) { 81 | return null; 82 | } 83 | 84 | var json = JsonConvert.DeserializeObject>(result.Content); 85 | 86 | if (json.Error) 87 | throw new QueryExecutionException(json.ErrorMessage, json.ErrorNumber); 88 | 89 | return json.Result; 90 | } 91 | 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/ClientSettings.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Serialization; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Text; 8 | 9 | namespace BorderEast.ArangoDB.Client.Database 10 | { 11 | public class ClientSettings { 12 | 13 | public ClientSettings() { 14 | JsonSettings = new JsonSerializerSettings 15 | { 16 | ContractResolver = new ArangoDBContractResolver(), 17 | DateTimeZoneHandling = DateTimeZoneHandling.Utc, 18 | NullValueHandling = NullValueHandling.Include, 19 | DefaultValueHandling = DefaultValueHandling.Include, 20 | StringEscapeHandling = StringEscapeHandling.Default, 21 | Formatting = Formatting.Indented, 22 | ReferenceLoopHandling = ReferenceLoopHandling.Ignore 23 | }; 24 | } 25 | 26 | public ClientSettings(string serverAddress, int serverPort, ProtocolType protocolType, 27 | string systemPassword, string databaseName, string databaseUsername, string databasePassword, 28 | bool autoCreate, bool isDebug = false, ArangoDBContractResolver arangoDBContractResolver = null) 29 | { 30 | ServerAddress = serverAddress; 31 | ServerPort = serverPort; 32 | Protocol = protocolType; 33 | DatabaseName = databaseName; 34 | SystemCredential = new NetworkCredential("root", systemPassword); 35 | DatabaseCredential = new NetworkCredential(databaseUsername, databasePassword); 36 | AutoCreate = autoCreate; 37 | 38 | if (arangoDBContractResolver == null) 39 | { 40 | arangoDBContractResolver = new ArangoDBContractResolver(); 41 | } 42 | 43 | JsonSettings = new JsonSerializerSettings 44 | { 45 | ContractResolver = arangoDBContractResolver, 46 | DateTimeZoneHandling = DateTimeZoneHandling.Utc, 47 | NullValueHandling = NullValueHandling.Include, 48 | DefaultValueHandling = DefaultValueHandling.Include, 49 | StringEscapeHandling = StringEscapeHandling.Default, 50 | Formatting = Formatting.Indented, 51 | ReferenceLoopHandling = ReferenceLoopHandling.Ignore 52 | }; 53 | 54 | 55 | 56 | IsDebug = isDebug; 57 | } 58 | 59 | public JsonSerializerSettings JsonSettings { get; set; } 60 | 61 | public string ServerAddress { get; set; } 62 | 63 | public int ServerPort {get;set;} 64 | 65 | public ProtocolType Protocol { get; set; } 66 | 67 | public HttpClient HTTPClient { get; set; } 68 | 69 | public string DatabaseName { get; set; } 70 | 71 | public NetworkCredential SystemCredential { get; set; } 72 | 73 | public NetworkCredential DatabaseCredential { get; set; } 74 | 75 | public bool AutoCreate { get; set; } 76 | 77 | public bool IsDebug { get; set; } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/ForeignKeyConverter.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace BorderEast.ArangoDB.Client.Database 9 | { 10 | public class ForeignKeyConverter : JsonConverter { 11 | public override bool CanConvert(Type objectType) { 12 | return objectType.GetGenericTypeDefinition() == typeof(List<>); 13 | } 14 | 15 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { 16 | IList collection = (IList)value; 17 | 18 | writer.WriteStartArray(); 19 | foreach (var v in collection) { 20 | writer.WriteValue(GetId(v)); 21 | } 22 | 23 | writer.WriteEndArray(); 24 | } 25 | 26 | private string GetId(object obj) { 27 | PropertyInfo prop = obj.GetType().GetProperty("Key", typeof(string)); 28 | if (prop != null && prop.CanRead) { 29 | return (string)prop.GetValue(obj, null); 30 | } 31 | return null; 32 | } 33 | 34 | public override bool CanRead { get { return false; } } 35 | 36 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { 37 | throw new NotImplementedException(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/Meta/ArangoFieldAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database.Meta 6 | { 7 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] 8 | public class ArangoFieldAttribute : Attribute, IArangoFieldAttribute { 9 | 10 | public string Name { get; set; } 11 | 12 | public bool SerializeIgnore { get; set; } 13 | 14 | public string ForeignKeyTo { get; set; } 15 | 16 | public NamingConvention NamingType { get; set; } 17 | 18 | public ArangoField Field { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/Meta/CollectionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database.Meta 6 | { 7 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 8 | public class CollectionAttribute : Attribute, ICollectionAttribute { 9 | 10 | public Boolean HasForeignKey { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/Meta/ForeignKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database.Meta 6 | { 7 | internal class ForeignKey 8 | { 9 | internal bool IsForeignKey { get; set; } 10 | internal List> ForeignKeyTypes { get; set; } 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/Meta/IArangoFieldAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database.Meta 6 | { 7 | public interface IArangoFieldAttribute 8 | { 9 | string Name { get; set; } 10 | 11 | bool SerializeIgnore { get; set; } 12 | 13 | string ForeignKeyTo { get; set; } 14 | 15 | NamingConvention NamingType { get; set; } 16 | 17 | ArangoField Field { get; set; } 18 | } 19 | 20 | public enum ArangoField { 21 | None = 0, 22 | Id = 1, 23 | Key = 2, 24 | Handle = 3, 25 | Revision = 4, 26 | EdgeFrom = 5, 27 | EdgeTo = 6 28 | } 29 | 30 | public enum NamingConvention { 31 | UnChanged = 0, 32 | ToCamelCase = 1 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/Meta/ICollectionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database.Meta 6 | { 7 | public interface ICollectionAttribute 8 | { 9 | Boolean HasForeignKey { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Database/ProtocolType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Database 6 | { 7 | public enum ProtocolType { 8 | HTTP, 9 | HTTPS, 10 | TCP 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Enums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client 6 | { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Exception/DatabaseExistsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Exception 6 | { 7 | public class DatabaseExistsException : System.Exception 8 | { 9 | public DatabaseExistsException(string message) : base(message) { 10 | 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Exception/DatabaseNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | 6 | namespace BorderEast.ArangoDB.Client.Exception 7 | { 8 | public class DatabaseNotFoundException : System.Exception 9 | { 10 | public DatabaseNotFoundException(string message) :base(message) { 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Exception/QueryExecutionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Exception 6 | { 7 | public class QueryExecutionException : System.Exception 8 | { 9 | public int ErrorNumber { get; private set; } 10 | public QueryExecutionException(string message, int errorNum) : base(message) 11 | { 12 | ErrorNumber = errorNum; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/IArangoClient.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database; 2 | 3 | namespace BorderEast.ArangoDB.Client { 4 | 5 | /// 6 | /// Entry point for interacting with ArangoDB. You only need one instance of this class, 7 | /// even if working with multiple databases, hence the Singleton pattern. 8 | /// 9 | public interface IArangoClient { 10 | 11 | /// 12 | /// Convience method to get the default database. 13 | /// 14 | /// 15 | ArangoDatabase DB(); 16 | 17 | /// 18 | /// Get database by name 19 | /// 20 | /// 21 | /// 22 | ArangoDatabase DB(string database); 23 | 24 | /// 25 | /// Initialize a new database, does not actually create the db in Arango 26 | /// 27 | /// 28 | /// 29 | ArangoDatabase InitDB(ClientSettings databaseSettings); 30 | 31 | /// 32 | /// Setup your default database 33 | /// 34 | /// 35 | void SetDefaultDatabase(ClientSettings defaultConnection); 36 | } 37 | } -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/ArangoBaseEntity.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Models 8 | { 9 | /// 10 | /// Base entity class which all entities must inherit from 11 | /// 12 | public class ArangoBaseEntity { 13 | 14 | /// 15 | /// Id in format 'collection/key'. Only set internally. Use _id in ad hoc queries. 16 | /// 17 | [JsonProperty(PropertyName = "_id", NullValueHandling = NullValueHandling.Ignore)] 18 | public string Id { get; internal set; } 19 | 20 | /// 21 | /// Primary key of entity, as as you would the Id in other databases. Use _key in ad hoc queries. 22 | /// 23 | [JsonProperty(PropertyName = "_key", NullValueHandling = NullValueHandling.Ignore)] 24 | public string Key { get; set; } 25 | 26 | /// 27 | /// Revision of entity. Use _rev in ad hoc queries. 28 | /// 29 | [JsonProperty(PropertyName = "_rev", NullValueHandling = NullValueHandling.Ignore)] 30 | public string Revision { get; set; } 31 | public string CreatedBy { get; set; } 32 | public DateTime CreatedDateTime { get; set; } 33 | public string CreatedFunction { get; set; } 34 | public string UpdatedBy { get; set; } 35 | public DateTime UpdatedDateTime { get; set; } 36 | public string UpdatedFunction { get; set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/ArangoUserEntity.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using BorderEast.ArangoDB.Client.Models.User; 3 | using Newtonsoft.Json; 4 | using System.Collections.Generic; 5 | 6 | namespace BorderEast.ArangoDB.Client.Models { 7 | 8 | /// 9 | /// Represents the ArangoDB User with all known properties. Need to insert new 10 | /// Arango User via API. 11 | /// 12 | public class ArangoUserEntity : ArangoBaseEntity { 13 | 14 | /// 15 | /// Public constructor 16 | /// 17 | public ArangoUserEntity() { 18 | ConfigData = new Dictionary(); 19 | Databases = new Dictionary(); 20 | } 21 | 22 | [JsonProperty(PropertyName = "authData", NullValueHandling = NullValueHandling.Include)] 23 | [ArangoField(Name = "authData")] 24 | public AuthorizationData AuthData { get; set; } 25 | 26 | [JsonProperty(PropertyName = "configData", NullValueHandling = NullValueHandling.Include)] 27 | [ArangoField(Name = "configData")] 28 | public Dictionary ConfigData { get; set; } 29 | 30 | [JsonProperty(PropertyName = "databases", NullValueHandling = NullValueHandling.Include)] 31 | [ArangoField(Name = "databases")] 32 | public Dictionary Databases { get; set; } 33 | 34 | [JsonProperty(PropertyName = "user", NullValueHandling = NullValueHandling.Include)] 35 | [ArangoField(Name = "user")] 36 | public string User { get; set; } 37 | 38 | [JsonProperty(PropertyName = "userData", NullValueHandling = NullValueHandling.Include)] 39 | [ArangoField(Name = "userData")] 40 | public ExtraData UserData { get; set; } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/Collection/ArangoCollection.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Serialization; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace BorderEast.ArangoDB.Client.Models.Collection 9 | { 10 | public class ArangoCollection 11 | { 12 | 13 | 14 | public static ArangoCollection GetBasicDocumentType(string name) { 15 | return new ArangoCollection() 16 | { 17 | Name = name, 18 | Type = CollectionType.Document 19 | }; 20 | } 21 | 22 | public static ArangoCollection GetBasicEdgeType(string name) { 23 | return new ArangoCollection() 24 | { 25 | Name = name, 26 | Type = CollectionType.Edge 27 | }; 28 | } 29 | public static ArangoCollection GetAutoIncrementCollection(string name, CollectionType _type, int incrementBy, int initialOffsetValue, bool allowUserKeys) { 30 | return new ArangoCollection() 31 | { 32 | Name = name, 33 | Type = _type, 34 | KeyOptions = new ArangoKeyOptions() 35 | { 36 | Type = "autoincrement", 37 | Increment = incrementBy, 38 | Offset = initialOffsetValue, 39 | AllowUserKeys = allowUserKeys 40 | } 41 | }; 42 | } 43 | 44 | public enum CollectionType { 45 | Document = 2, 46 | Edge = 3 47 | } 48 | 49 | public ArangoCollection() { 50 | JournalSize = 1048576; 51 | ReplicationFactor = 1; 52 | KeyOptions = new ArangoKeyOptions 53 | { 54 | AllowUserKeys = true, 55 | Type = "traditional" 56 | }; 57 | WaitForSync = false; 58 | DoCompact = true; 59 | IsVolatile = false; 60 | ShardKeys = new[] { "_key" }; 61 | NumberOfShards = 1; 62 | Type = CollectionType.Document; 63 | IndexBuckets = 16; 64 | 65 | } 66 | 67 | 68 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 69 | public int JournalSize { get; set; } 70 | 71 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 72 | public int ReplicationFactor { get; set; } 73 | 74 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 75 | public ArangoKeyOptions KeyOptions { get; set; } 76 | 77 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 78 | public string Name { get; set; } 79 | 80 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 81 | public bool WaitForSync { get; set; } 82 | 83 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 84 | public bool DoCompact { get; set; } 85 | 86 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 87 | public bool IsVolatile { get; set; } 88 | 89 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 90 | public string[] ShardKeys { get; set; } 91 | 92 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 93 | public int NumberOfShards { get; set; } 94 | 95 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 96 | public bool IsSystem { get; set; } 97 | 98 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 99 | public CollectionType Type { get; set; } 100 | 101 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 102 | public int IndexBuckets { get; set; } 103 | 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/Collection/ArangoKeyOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BorderEast.ArangoDB.Client.Models.Collection 6 | { 7 | public class ArangoKeyOptions 8 | { 9 | public bool AllowUserKeys { get; set; } 10 | public string Type { get; set; } 11 | public int Increment { get; set; } 12 | public int Offset { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/Collection/CollectionResult.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Models.Collection 8 | { 9 | public class CollectionResult 10 | { 11 | [JsonProperty(PropertyName = "id", NullValueHandling = NullValueHandling.Include)] 12 | [ArangoField(Name = "id")] 13 | public string Id { get; set; } 14 | 15 | [JsonProperty(PropertyName = "name", NullValueHandling = NullValueHandling.Include)] 16 | [ArangoField(Name = "name")] 17 | public string Name { get; set; } 18 | 19 | [JsonProperty(PropertyName = "waitForSync", NullValueHandling = NullValueHandling.Include)] 20 | [ArangoField(Name = "waitForSync")] 21 | public bool WaitForSync { get; set; } 22 | 23 | [JsonProperty(PropertyName = "isVolatile", NullValueHandling = NullValueHandling.Include)] 24 | [ArangoField(Name = "isVolatile")] 25 | public bool IsVolatile { get; set; } 26 | 27 | [JsonProperty(PropertyName = "isSystem", NullValueHandling = NullValueHandling.Include)] 28 | [ArangoField(Name = "isSystem")] 29 | public bool IsSystem { get; set; } 30 | 31 | [JsonProperty(PropertyName = "status", NullValueHandling = NullValueHandling.Include)] 32 | [ArangoField(Name = "status")] 33 | public int Status { get; set; } 34 | 35 | [JsonProperty(PropertyName = "type", NullValueHandling = NullValueHandling.Include)] 36 | [ArangoField(Name = "type")] 37 | public ArangoCollection.CollectionType Type { get; set; } 38 | 39 | [JsonProperty(PropertyName = "error", NullValueHandling = NullValueHandling.Include)] 40 | [ArangoField(Name = "error")] 41 | public bool Error { get; set; } 42 | 43 | [JsonProperty(PropertyName = "code", NullValueHandling = NullValueHandling.Include)] 44 | [ArangoField(Name = "code")] 45 | public int StatusCode { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/Database/DatabaseResult.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Models.Database 8 | { 9 | public class DatabaseResult 10 | { 11 | 12 | [JsonProperty(PropertyName = "error", NullValueHandling = NullValueHandling.Ignore)] 13 | [ArangoField(Field = ArangoField.Id, Name = "error", NamingType = NamingConvention.UnChanged)] 14 | public bool Error { get; set; } 15 | 16 | [JsonProperty(PropertyName = "code", NullValueHandling = NullValueHandling.Ignore)] 17 | [ArangoField(Field = ArangoField.Id, Name = "code", NamingType = NamingConvention.UnChanged)] 18 | public int Code { get; set; } 19 | 20 | [JsonProperty(PropertyName = "result", NullValueHandling = NullValueHandling.Ignore)] 21 | [ArangoField(Field = ArangoField.Id, Name = "result", NamingType = NamingConvention.UnChanged)] 22 | public bool Result { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/Database/NewDatabase.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Models.Database 8 | { 9 | public class NewDatabase 10 | { 11 | 12 | [JsonProperty(PropertyName = "name", NullValueHandling = NullValueHandling.Ignore)] 13 | [ArangoField(Field = ArangoField.Id, Name = "name", NamingType = NamingConvention.UnChanged)] 14 | public string Name { get; set; } 15 | 16 | [JsonProperty(PropertyName = "users", NullValueHandling = NullValueHandling.Ignore)] 17 | [ArangoField(Field = ArangoField.Id, Name = "users", NamingType = NamingConvention.UnChanged)] 18 | public List Users { get; set; } 19 | 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/Database/NewDatabaseUser.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Models.Database 8 | { 9 | public class NewDatabaseUser 10 | { 11 | 12 | [JsonProperty(PropertyName = "username", NullValueHandling = NullValueHandling.Ignore)] 13 | [ArangoField(Field = ArangoField.Id, Name = "username", NamingType = NamingConvention.UnChanged)] 14 | public string Username { get; set; } 15 | 16 | [JsonProperty(PropertyName = "passwd", NullValueHandling = NullValueHandling.Ignore)] 17 | [ArangoField(Field = ArangoField.Id, Name = "passwd", NamingType = NamingConvention.UnChanged)] 18 | public string Password { get; set; } 19 | 20 | [JsonProperty(PropertyName = "active", NullValueHandling = NullValueHandling.Ignore)] 21 | [ArangoField(Field = ArangoField.Id, Name = "active", NamingType = NamingConvention.UnChanged)] 22 | public bool Active { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/UpdatedDocument.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BorderEast.ArangoDB.Client.Models 8 | { 9 | public class UpdatedDocument : ArangoBaseEntity 10 | { 11 | 12 | [JsonProperty(PropertyName = "_oldRev", NullValueHandling = NullValueHandling.Ignore)] 13 | [ArangoField(Field = ArangoField.Id, Name = "_oldRev", NamingType = NamingConvention.UnChanged)] 14 | public string OldRevision { get; set; } 15 | 16 | [JsonProperty(PropertyName = "new", NullValueHandling = NullValueHandling.Ignore)] 17 | [ArangoField(Field = ArangoField.Id, Name = "new", NamingType = NamingConvention.UnChanged)] 18 | public T New { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/User/AuthorizationData.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | 4 | namespace BorderEast.ArangoDB.Client.Models.User { 5 | public class AuthorizationData 6 | { 7 | [JsonProperty(PropertyName = "active", NullValueHandling = NullValueHandling.Include)] 8 | [ArangoField(Name = "active")] 9 | public bool Active { get; set; } 10 | 11 | [JsonProperty(PropertyName = "changePassword", NullValueHandling = NullValueHandling.Include)] 12 | [ArangoField(Name = "changePassword")] 13 | public bool ChangePassword { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/User/ExtraData.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System.Collections.Generic; 4 | 5 | namespace BorderEast.ArangoDB.Client.Models.User { 6 | public class ExtraData 7 | { 8 | public ExtraData() { 9 | Queries = new List(); 10 | } 11 | 12 | [JsonProperty(PropertyName = "name", NullValueHandling = NullValueHandling.Include)] 13 | [ArangoField(Name = "name")] 14 | public string Name { get; set; } 15 | 16 | [JsonProperty(PropertyName = "queries", NullValueHandling = NullValueHandling.Include)] 17 | [ArangoField(Name = "queries")] 18 | public List Queries { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/User/SimplePassword.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | 4 | namespace BorderEast.ArangoDB.Client.Models.User { 5 | public class SimplePassword { 6 | 7 | [JsonProperty(PropertyName = "hash", NullValueHandling = NullValueHandling.Include)] 8 | [ArangoField(Name = "hash")] 9 | public string Hash { get; set; } 10 | 11 | [JsonProperty(PropertyName = "method", NullValueHandling = NullValueHandling.Include)] 12 | [ArangoField(Name = "method")] 13 | public string Method { get; set; } 14 | 15 | [JsonProperty(PropertyName = "salt", NullValueHandling = NullValueHandling.Include)] 16 | [ArangoField(Name = "salt")] 17 | public string Salt { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Models/User/UserQuery.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using Newtonsoft.Json; 3 | using System.Collections.Generic; 4 | 5 | namespace BorderEast.ArangoDB.Client.Models.User { 6 | public class UserQuery 7 | { 8 | public UserQuery() { 9 | Parameter = new Dictionary(); 10 | } 11 | 12 | [JsonProperty(PropertyName = "name", NullValueHandling = NullValueHandling.Include)] 13 | [ArangoField(Name = "name")] 14 | public string Name { get; set; } 15 | 16 | [JsonProperty(PropertyName = "parameter", NullValueHandling = NullValueHandling.Include)] 17 | [ArangoField(Name = "parameter")] 18 | public Dictionary Parameter { get; set; } 19 | 20 | [JsonProperty(PropertyName = "value", NullValueHandling = NullValueHandling.Include)] 21 | [ArangoField(Name = "value")] 22 | public string Value { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Res/Msg.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BorderEast.ArangoDB.Client.Res { 12 | using System; 13 | using System.Reflection; 14 | 15 | 16 | /// 17 | /// A strongly-typed resource class, for looking up localized strings, etc. 18 | /// 19 | // This class was auto-generated by the StronglyTypedResourceBuilder 20 | // class via a tool like ResGen or Visual Studio. 21 | // To add or remove a member, edit your .ResX file then rerun ResGen 22 | // with the /str option, or rebuild your VS project. 23 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 24 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 25 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 26 | internal class Msg { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Msg() { 34 | } 35 | 36 | /// 37 | /// Returns the cached ResourceManager instance used by this class. 38 | /// 39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 40 | internal static global::System.Resources.ResourceManager ResourceManager { 41 | get { 42 | if (object.ReferenceEquals(resourceMan, null)) { 43 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BorderEast.ArangoDB.Client.Res.Msg", typeof(Msg).GetTypeInfo().Assembly); 44 | resourceMan = temp; 45 | } 46 | return resourceMan; 47 | } 48 | } 49 | 50 | /// 51 | /// Overrides the current thread's CurrentUICulture property for all 52 | /// resource lookups using this strongly typed resource class. 53 | /// 54 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 55 | internal static global::System.Globalization.CultureInfo Culture { 56 | get { 57 | return resourceCulture; 58 | } 59 | set { 60 | resourceCulture = value; 61 | } 62 | } 63 | 64 | /// 65 | /// Looks up a localized string similar to ArangoDb already exists. 66 | /// 67 | internal static string ArangoDbAlreadyExists { 68 | get { 69 | return ResourceManager.GetString("ArangoDbAlreadyExists", resourceCulture); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized string similar to ArangoDb not found. 75 | /// 76 | internal static string ArangoDbNotFound { 77 | get { 78 | return ResourceManager.GetString("ArangoDbNotFound", resourceCulture); 79 | } 80 | } 81 | 82 | /// 83 | /// Looks up a localized string similar to default. 84 | /// 85 | internal static string Default { 86 | get { 87 | return ResourceManager.GetString("Default", resourceCulture); 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Res/Msg.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | ArangoDb already exists 122 | 123 | 124 | ArangoDb not found 125 | 126 | 127 | default 128 | 129 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/Utils/DynamicUtil.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Dynamic; 6 | using System.Reflection; 7 | using System.Text; 8 | 9 | namespace BorderEast.ArangoDB.Client.Utils { 10 | internal class DynamicUtil { 11 | 12 | internal static string GetTypeName(Type t) { 13 | if (t.GetTypeInfo().GetCustomAttribute(typeof(JsonObjectAttribute)) is JsonObjectAttribute attr) { 14 | return attr.Id ?? t.Name; 15 | } 16 | return t.Name; 17 | } 18 | 19 | internal static Dictionary DynamicToDict(object dynamicObject) { 20 | var attr = BindingFlags.Public | BindingFlags.Instance; 21 | var dict = new Dictionary(); 22 | foreach (var property in dynamicObject.GetType().GetProperties(attr)) { 23 | if (property.CanRead) { 24 | dict.Add(property.Name, property.GetValue(dynamicObject, null)); 25 | } 26 | } 27 | return dict; 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/libs/Arango.VelocyPack.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bordereast/arangodb-net-core/c17262691a2b7d001244c4565ec5dfbb8d1ad5e0/src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.Client/libs/Arango.VelocyPack.dll -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/ArangoDBClientTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using BorderEast.ArangoDB.Client; 4 | using BorderEast.ArangoDB.Client.Database; 5 | using BorderEast.ArangoDB.Client.Exception; 6 | using System.Linq; 7 | using BorderEast.ArangoDB.ClientTest.MockData; 8 | 9 | namespace BorderEast.ArangoDB.ClientTest 10 | { 11 | 12 | public class ArangoDBClientTest { 13 | 14 | 15 | [Fact] 16 | public void DefaultClientBehavior() { 17 | var client = MockSetup.GetClient(); 18 | 19 | // should always be available after SetDefaultDatabase 20 | Assert.NotNull(client.DB()); 21 | 22 | } 23 | 24 | [Fact] 25 | public void CreateDatabase() { 26 | var client = MockSetup.GetClient(); 27 | MockSetup newsetup = new MockSetup(); 28 | var dbs = newsetup.settings; 29 | dbs.DatabaseName = "newtest"; 30 | 31 | // non-existant database should be created and returned 32 | Assert.IsType(client.InitDB(dbs)); 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/BorderEast.ArangoDB.ClientTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.2 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/JsonTest.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database; 2 | using BorderEast.ArangoDB.ClientTest.MockData; 3 | using Newtonsoft.Json; 4 | using Newtonsoft.Json.Serialization; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using Xunit; 10 | 11 | namespace BorderEast.ArangoDB.ClientTest 12 | { 13 | public class JsonTest 14 | { 15 | 16 | private readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings 17 | { 18 | ContractResolver = new ArangoDBContractResolver(), 19 | DateTimeZoneHandling = DateTimeZoneHandling.Utc, 20 | NullValueHandling = NullValueHandling.Include, 21 | DefaultValueHandling = DefaultValueHandling.Include, 22 | StringEscapeHandling = StringEscapeHandling.Default, 23 | Formatting = Formatting.Indented, 24 | ReferenceLoopHandling = ReferenceLoopHandling.Ignore 25 | }; 26 | private readonly JsonSerializerSettings JsonSettingsCamelCase = new JsonSerializerSettings 27 | { 28 | ContractResolver = new ArangoDBContractResolver(new CamelCaseNamingStrategy()), 29 | DateTimeZoneHandling = DateTimeZoneHandling.Utc, 30 | NullValueHandling = NullValueHandling.Include, 31 | DefaultValueHandling = DefaultValueHandling.Include, 32 | StringEscapeHandling = StringEscapeHandling.Default, 33 | Formatting = Formatting.Indented, 34 | ReferenceLoopHandling = ReferenceLoopHandling.Ignore 35 | }; 36 | 37 | [Fact] 38 | public void NullListTest() { 39 | 40 | var author = new Author() 41 | { 42 | Name = "Some Author" 43 | }; 44 | 45 | var jsonStr = JsonConvert.SerializeObject(author, JsonSettings); 46 | 47 | Author auth = JsonConvert.DeserializeObject(jsonStr); 48 | 49 | Assert.NotNull(auth.Books); 50 | } 51 | 52 | [Fact] 53 | public void CamelCaseTest() { 54 | 55 | var author = new Author() 56 | { 57 | Name = "Some Author", 58 | camelName = "Some Author" 59 | }; 60 | 61 | // Default is now same case as object name 62 | var jsonStr = JsonConvert.SerializeObject(author, JsonSettings); 63 | 64 | Assert.DoesNotContain("name", jsonStr); 65 | Assert.Contains("Name", jsonStr); 66 | Assert.Contains("camelName", jsonStr); 67 | 68 | jsonStr = JsonConvert.SerializeObject(author, JsonSettingsCamelCase); 69 | 70 | Assert.DoesNotContain("\"Name", jsonStr, StringComparison.InvariantCulture); 71 | Assert.Contains("name", jsonStr); 72 | Assert.Contains("camelName", jsonStr); 73 | } 74 | 75 | [Fact] 76 | public void ForeignKeyTest() { 77 | 78 | var author = new Author() 79 | { 80 | Name = "Some Author", 81 | Key = "newauth", 82 | Books = new List() 83 | { 84 | new Book() 85 | { 86 | Key = "newbook", 87 | Name = "A Book Title" 88 | } 89 | } 90 | }; 91 | 92 | var jsonStr = JsonConvert.SerializeObject(author, JsonSettings); 93 | 94 | // foreign key converter should only serialize the book key 95 | Assert.DoesNotContain(author.Books.First().Name, jsonStr); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/MethodsTest.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client; 2 | using BorderEast.ArangoDB.Client.Database; 3 | using BorderEast.ArangoDB.ClientTest.MockData; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using Xunit; 9 | 10 | namespace BorderEast.ArangoDB.ClientTest 11 | { 12 | 13 | public class MethodsTest { 14 | 15 | 16 | [Fact] 17 | public void GetByKeyAsync() 18 | { 19 | var client = MockSetup.GetClient(); 20 | Assert.NotNull(client.DB().GetByKeyAsync("1312460").Result); 21 | } 22 | 23 | 24 | [Fact] 25 | public void AQLSelectEntity() { 26 | 27 | var client = MockSetup.GetClient(); 28 | var user = client.DB().Query("for u in User return u").ToListAsync().Result.First(); 29 | 30 | Assert.IsType(user); 31 | } 32 | 33 | [Fact] 34 | public void GetAll() { 35 | var client = MockSetup.GetClient(); 36 | var users = client.DB().GetAllAsync().Result; 37 | Assert.Equal(4, users.Count()); 38 | } 39 | 40 | 41 | [Fact] 42 | public void CRUDMethods() { 43 | var client = MockSetup.GetClient(); 44 | 45 | var id = "1312460"; 46 | var user = new User() 47 | { 48 | Password = "passcode", 49 | Username = "jdoe" 50 | }; 51 | 52 | var inserted = client.DB().InsertAsync(user).Result; 53 | 54 | var insertUser = inserted.New; 55 | 56 | Assert.IsType(user); 57 | Assert.Equal("jdoe", insertUser.Username); 58 | Assert.Equal("passcode", insertUser.Password); 59 | Assert.Equal(id, inserted.Key); 60 | 61 | } 62 | 63 | [Fact] 64 | public void InsertManyAsyncTest() 65 | { 66 | var client = MockSetup.GetClient(); 67 | 68 | var id1 = "8633435"; 69 | var id2 = "8633439"; 70 | 71 | var listOfUsers = new List 72 | { 73 | new InsertManyUser() 74 | { 75 | Password = "passcode1", 76 | Username = "jdoe1" 77 | }, 78 | new InsertManyUser() 79 | { 80 | Password = "passcode2", 81 | Username = "jdoe2" 82 | }, 83 | }; 84 | 85 | var inserted = client.DB().InsertManyAsync(listOfUsers).Result; 86 | 87 | Assert.Equal(inserted.Count(), listOfUsers.Count()); 88 | 89 | var insertUser1 = inserted.First(); 90 | var insertUser2 = inserted.Last(); 91 | 92 | Assert.Equal("jdoe1", insertUser1.New.Username); 93 | Assert.Equal("passcode1", insertUser1.New.Password); 94 | Assert.Equal(id1, insertUser1.Key); 95 | 96 | Assert.Equal("jdoe2", insertUser2.New.Username); 97 | Assert.Equal("passcode2", insertUser2.New.Password); 98 | Assert.Equal(id2, insertUser2.Key); 99 | } 100 | 101 | [Fact] 102 | public void UpdateAsync() { 103 | 104 | var client = MockSetup.GetClient(); 105 | 106 | var id = "1312460"; 107 | var user = new User() 108 | { 109 | Password = "passcode", 110 | Username = "newpass" 111 | }; 112 | 113 | var updated = client.DB().UpdateAsync(id, user).Result; 114 | var updatedUser = updated.New; 115 | 116 | Assert.IsType(user); 117 | Assert.Equal("newpass", updatedUser.Password); 118 | } 119 | 120 | [Fact] 121 | public void GetByNullKeyAsync() { 122 | var client = MockSetup.GetClient(); 123 | Assert.Null(client.DB().GetByKeyAsync("1234").Result); 124 | } 125 | 126 | 127 | [Fact] 128 | public void DeleteAsync() { 129 | var client = MockSetup.GetClient(); 130 | Assert.True(client.DB().DeleteAsync("1127162").Result); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/MockData/Author.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database; 2 | using BorderEast.ArangoDB.Client.Database.Meta; 3 | using BorderEast.ArangoDB.Client.Models; 4 | using Newtonsoft.Json; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace BorderEast.ArangoDB.ClientTest.MockData 10 | { 11 | [Collection(HasForeignKey = true)] 12 | public class Author : ArangoBaseEntity { 13 | public string Name { get; set; } 14 | 15 | public string camelName { get; set; } 16 | 17 | [JsonConverter(typeof(ForeignKeyConverter))] 18 | public List Books { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/MockData/Book.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace BorderEast.ArangoDB.ClientTest.MockData 7 | { 8 | public class Book : ArangoBaseEntity 9 | { 10 | public string Name { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/MockData/InsertManyUser.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Models; 2 | using Newtonsoft.Json; 3 | 4 | namespace BorderEast.ArangoDB.ClientTest.MockData 5 | { 6 | public class InsertManyUser: ArangoBaseEntity { 7 | [JsonProperty(PropertyName = "userName", NullValueHandling = NullValueHandling.Ignore)] 8 | public string Username { get; set; } 9 | 10 | [JsonProperty(PropertyName = "passwd", NullValueHandling = NullValueHandling.Ignore)] 11 | public string Password { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/MockData/MockSetup.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client; 2 | using BorderEast.ArangoDB.Client.Database; 3 | using Newtonsoft.Json.Serialization; 4 | using RichardSzalay.MockHttp; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Net.Http; 8 | using System.Text; 9 | 10 | namespace BorderEast.ArangoDB.ClientTest.MockData 11 | { 12 | public class MockSetup 13 | { 14 | public MockHttpMessageHandler mockHttp = new MockHttpMessageHandler(); 15 | public ArangoClient client = ArangoClient.Client(); 16 | public ClientSettings settings = new ClientSettings() 17 | { 18 | DatabaseName = "_system", 19 | Protocol = ProtocolType.HTTP, 20 | ServerAddress = "localhost", 21 | ServerPort = 8529, 22 | SystemCredential = new System.Net.NetworkCredential("root", Environment.GetEnvironmentVariable("USERNAME")), 23 | DatabaseCredential = new System.Net.NetworkCredential("client-test", "client-test"), 24 | AutoCreate = true, 25 | HTTPClient = null, 26 | IsDebug = true 27 | }; 28 | 29 | public static ArangoClient GetClient() { 30 | MockSetup setup = new MockSetup(); 31 | if (setup.settings.HTTPClient == null) { 32 | setup.SetupRoutes(setup.mockHttp); 33 | setup.settings.HTTPClient = new System.Net.Http.HttpClient(setup.mockHttp); 34 | if(setup.client.DB() == null) { 35 | setup.client.SetDefaultDatabase(setup.settings); 36 | } 37 | } 38 | return setup.client; 39 | } 40 | 41 | private void SetupRoutes(MockHttpMessageHandler m) { 42 | m.When(HttpMethod.Post, "*/_api/document/User/?returnNew=true"). 43 | Respond("application/json", "{\"_id\":\"User/1312460\",\"_key\":\"1312460\",\"_rev\":\"_U0xbgLu---\",\"new\":{\"_key\":\"1312460\",\"_id\":\"User/1312460\",\"_rev\":\"_U0xbgLu---\",\"userName\":\"jdoe\",\"passwd\":\"passcode\"}}"); 44 | 45 | m.When(new HttpMethod("PATCH"), "*/_api/document/User/1312460?mergeObjects=false&returnNew=true"). 46 | Respond("application/json", "{\"_id\":\"User/1312460\",\"_key\":\"1313328\",\"_rev\":\"_U0xo_h2---\",\"new\":{\"_key\":\"1312460\",\"_id\":\"User/1312460\",\"_rev\":\"_U0xo_h2---\",\"userName\":\"jdoe\",\"passwd\":\"newpass\"}}"); 47 | 48 | m.When(HttpMethod.Delete, "*/_api/document/User/1127162?silent=true"). 49 | Respond("application/json", "{\"_id\":\"User/1127162\",\"_key\":\"1127162\",\"_rev\":\"_U0x1Nem---\"}"); 50 | 51 | m.When(HttpMethod.Get, "*/_api/document/User/1312460"). 52 | Respond("application/json", "{\"_key\":\"1312460\",\"_id\":\"User/1312460\",\"_rev\":\"_U0xbgLu---\",\"userName\":\"andrew\",\"passwd\":\"passcode\"}"); 53 | 54 | m.When(HttpMethod.Get, "*/_api/document/User/1234"). 55 | Respond(System.Net.HttpStatusCode.NotFound); 56 | 57 | m.When(HttpMethod.Post, "*/_api/cursor?query=Zm9yIHUgaW4gVXNlciByZXR1cm4gdQ=="). 58 | Respond("application/json", "{\"result\":[{\"_id\":\"User/1312460\",\"_key\":\"1312460\",\"_rev\":\"_U0xbgLu---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1314279\",\"_key\":\"1314279\",\"_rev\":\"_U0x1-he---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1313287\",\"_key\":\"1313287\",\"_rev\":\"_U0xnhJO---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1313328\",\"_key\":\"1313328\",\"_rev\":\"_U0xo_h2---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"}],\"hasMore\":false,\"cached\":false,\"extra\":{\"stats\":{\"writesExecuted\":0,\"writesIgnored\":0,\"scannedFull\":4,\"scannedIndex\":0,\"filtered\":0,\"executionTime\":9.999275207519531e-4},\"warnings\":[]},\"error\":false,\"code\":201}"); 59 | 60 | m.When(HttpMethod.Post, "*/_api/cursor?query=Zm9yIHggaW4gQEBjb2wgcmV0dXJuIHg="). 61 | Respond("application/json", "{\"result\":[{\"_id\":\"User/6489\",\"_key\":\"6489\",\"_rev\":\"_U02b8YG---\"},{\"_id\":\"User/6503\",\"_key\":\"6503\",\"_rev\":\"_U02cCh6---\"}],\"hasMore\":false,\"cached\":true,\"extra\":{},\"error\":false,\"code\":201}"); 62 | 63 | m.When(HttpMethod.Post, "*/_api/cursor?query=Zm9yIHggaW4gQEBjb2wgcmV0dXJuIHguX2tleQ=="). 64 | Respond("application/json", "{\"result\":[{\"_id\":\"User/1312460\",\"_key\":\"1312460\",\"_rev\":\"_U0xbgLu---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1314279\",\"_key\":\"1314279\",\"_rev\":\"_U0x1-he---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1313287\",\"_key\":\"1313287\",\"_rev\":\"_U0xnhJO---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1313328\",\"_key\":\"1313328\",\"_rev\":\"_U0xo_h2---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"}],\"hasMore\":false,\"cached\":false,\"extra\":{\"stats\":{\"writesExecuted\":0,\"writesIgnored\":0,\"scannedFull\":4,\"scannedIndex\":0,\"filtered\":0,\"executionTime\":9.999275207519531e-4},\"warnings\":[]},\"error\":false,\"code\":201}"); 65 | 66 | m.When(HttpMethod.Post, "*/_api/cursor?query=Rk9SIHgxIElOIFVzZXIgTEVUIGEwID0gKCBGT1IgeCBJTiB4MS5Sb2xlcyBGT1IgYTAgSU4gUm9sZSBGSUxURVIgeCA9PSBhMC5fa2V5IFJFVFVSTiBhMCkgIFJFVFVSTiBNRVJHRSAoeDEsIHtSb2xlczogYTAgfSkg"). 67 | Respond("application/json", "{\"result\":[{\"_id\":\"User/23773\",\"_key\":\"23773\",\"_rev\":\"_U06oZZ6---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/105253\",\"_key\":\"105253\",\"_rev\":\"_U1jIN4y---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"}],\"hasMore\":false,\"cached\":false,\"extra\":{\"stats\":{\"writesExecuted\":0,\"writesIgnored\":0,\"scannedFull\":2,\"scannedIndex\":2,\"filtered\":0,\"executionTime\":9.88006591796875e-4},\"warnings\":[]},\"error\":false,\"code\":201}"); 68 | 69 | m.When(HttpMethod.Post, "*/_api/cursor?query=Rk9SIHggSU4gVXNlciBSRVRVUk4geA=="). 70 | Respond("application/json", "{\"result\":[{\"_id\":\"User/1312460\",\"_key\":\"1312460\",\"_rev\":\"_U0xbgLu---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1314279\",\"_key\":\"1314279\",\"_rev\":\"_U0x1-he---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1313287\",\"_key\":\"1313287\",\"_rev\":\"_U0xnhJO---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"},{\"_id\":\"User/1313328\",\"_key\":\"1313328\",\"_rev\":\"_U0xo_h2---\",\"passwd\":\"passcode\",\"userName\":\"andrew\"}],\"hasMore\":false,\"cached\":false,\"extra\":{\"stats\":{\"writesExecuted\":0,\"writesIgnored\":0,\"scannedFull\":4,\"scannedIndex\":0,\"filtered\":0,\"executionTime\":9.999275207519531e-4},\"warnings\":[]},\"error\":false,\"code\":201}"); 71 | 72 | m.When(HttpMethod.Post, "*/_api/cursor"). 73 | Respond("application/json", "{\"result\":[\"6489\",\"6503\"],\"hasMore\":false,\"cached\":false,\"extra\":{\"stats\":{\"writesExecuted\":0,\"writesIgnored\":0,\"scannedFull\":2,\"scannedIndex\":0,\"filtered\":0,\"executionTime\":0},\"warnings\":[]},\"error\":false,\"code\":201}"); 74 | 75 | m.When(HttpMethod.Post, "*/_api/document/InsertManyUser/?returnNew=true"). 76 | Respond("application/json", "[{\"_id\":\"InsertManyUser/8633435\",\"_key\":\"8633435\",\"_rev\":\"_WWsxBBm---\",\"new\":{\"_key\":\"8633435\",\"_id\":\"InsertManyUser/8633435\",\"_rev\":\"_WWsxBBm---\",\"userName\":\"jdoe1\",\"passwd\":\"passcode1\",\"createdBy\":null,\"createdDateTime\":\"0001-01-01T00:00:00Z\",\"createdFunction\":null,\"updatedBy\":null,\"updatedDateTime\":\"0001-01-01T00:00:00Z\",\"updatedFunction\":null}},{\"_id\":\"InsertManyUser/8633439\",\"_key\":\"8633439\",\"_rev\":\"_WWsxBBm--_\",\"new\":{\"_key\":\"8633439\",\"_id\":\"InsertManyUser/8633439\",\"_rev\":\"_WWsxBBm--_\",\"userName\":\"jdoe2\",\"passwd\":\"passcode2\",\"createdBy\":null,\"createdDateTime\":\"0001-01-01T00:00:00Z\",\"createdFunction\":null,\"updatedBy\":null,\"updatedDateTime\":\"0001-01-01T00:00:00Z\",\"updatedFunction\":null}}]"); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/BorderEast.ArangoDB.ClientTest/MockData/User.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database.Meta; 2 | using BorderEast.ArangoDB.Client.Models; 3 | using Newtonsoft.Json; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace BorderEast.ArangoDB.ClientTest.MockData 9 | { 10 | public class User: ArangoBaseEntity { 11 | [JsonProperty(PropertyName = "userName", NullValueHandling = NullValueHandling.Ignore)] 12 | public string Username { get; set; } 13 | 14 | [JsonProperty(PropertyName = "passwd", NullValueHandling = NullValueHandling.Ignore)] 15 | public string Password { get; set; } 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/ConsoleTestApp/ConsoleTestApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\BorderEast.ArangoDB.Client\libs\Arango.VelocyPack.dll 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/ConsoleTestApp/Program.cs: -------------------------------------------------------------------------------- 1 | using Arango.VelocyPack; 2 | using BorderEast.ArangoDB.Client; 3 | using BorderEast.ArangoDB.Client.Database; 4 | using Newtonsoft.Json; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.IO; 9 | using Arango.VelocyPack.Segments; 10 | 11 | namespace ConsoleTestApp { 12 | class Program 13 | { 14 | static void Main(string[] args) 15 | { 16 | Console.WriteLine(Environment.GetEnvironmentVariable("USERNAME")); 17 | ArangoClient.Client().SetDefaultDatabase(new BorderEast.ArangoDB.Client.Database.ClientSettings() { 18 | DatabaseName = "_system", 19 | Protocol = BorderEast.ArangoDB.Client.Database.ProtocolType.HTTP, 20 | ServerAddress = "localhost", 21 | ServerPort = 8529, 22 | SystemCredential = new System.Net.NetworkCredential("root", Environment.GetEnvironmentVariable("USERNAME")), 23 | DatabaseCredential = new System.Net.NetworkCredential("root", Environment.GetEnvironmentVariable("USERNAME")), 24 | AutoCreate = true, 25 | HTTPClient = new System.Net.Http.HttpClient(), 26 | IsDebug = true 27 | }); 28 | 29 | var client = ArangoClient.Client(); 30 | 31 | 32 | VelocyStream vs = new VelocyStream(); 33 | vs.Connect("127.0.0.1", 8528); 34 | 35 | var stream = vs.Stream; 36 | byte[] bytes = System.Text.Encoding.UTF8.GetBytes("VST/1.0\r\n\r\n"); 37 | byte[] messageBytes = System.Text.Encoding.UTF8.GetBytes("[version: 1, type: 1, requestType 1, request: \"/_admin/echo\", parameter: {a: 1}]"); 38 | 39 | // Segment arraySegment = VPack.ToSegment(messageBytes); 40 | 41 | stream.Write(bytes, 0, bytes.Length); 42 | stream.Flush(); 43 | stream.Write(messageBytes, 0, messageBytes.Length); 44 | stream.Flush(); 45 | 46 | var data = new Byte[256]; 47 | String responseData = String.Empty; 48 | 49 | 50 | 51 | // Read the first batch of the TcpServer response bytes. 52 | var inbytes = stream.Read(data, 0, data.Length); 53 | responseData = System.Text.Encoding.UTF8.GetString(data, 0, inbytes); 54 | Console.WriteLine("Received: {0}", responseData); 55 | 56 | //Role r = new Role() 57 | //{ 58 | // Name = "sysadmin", 59 | // Permission = "RW" 60 | //}; 61 | //Role r2 = new Role() 62 | //{ 63 | // Name = "author", 64 | // Permission = "RW" 65 | //}; 66 | 67 | //var uR1 = client.DB().InsertAsync(r).Result; 68 | //var uR2 = client.DB().InsertAsync(r2).Result; 69 | 70 | 71 | 72 | 73 | //var juser = new User() 74 | //{ 75 | // Username = "andrew", 76 | // Password = "passcode", 77 | // Roles = new List() { } 78 | //}; 79 | 80 | 81 | //JsonSerializerSettings settings = new JsonSerializerSettings 82 | //{ 83 | // ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, 84 | // Formatting = Newtonsoft.Json.Formatting.Indented 85 | //}; 86 | 87 | //string json = JsonConvert.SerializeObject(juser); 88 | 89 | //var s = json; 90 | ////var u1 = client.DB().InsertAsync(r2).Result; 91 | //var users = client.DB().GetAllAsync(); 92 | 93 | //var u = client.DB().GetByKeyAsync(""); 94 | 95 | //var token = JsonConvert.SerializeObject(juser, Formatting.Indented, new ArangoJsonConverter(typeof(User))); 96 | 97 | //Dictionary databases = new Dictionary 98 | //{ 99 | // { "*", "rw" }, 100 | // { "temp", 2 } 101 | //}; 102 | //var json = JsonConvert.SerializeObject(databases); 103 | 104 | 105 | //var users = client.DB().GetAllAsync().Result; 106 | //var users2 = client.DB().GetAllKeysAsync().Result; 107 | 108 | //var result = client.DB().InsertAsync(juser); 109 | //var user = client.DB().Query("for u in User return u").ToList().Result.First(); 110 | //var user = client.DB().GetByKeyAsync("1312460").Result; 111 | //var q = client.DB().Query("", new { _key = 1235}); 112 | 113 | //var u = client.DB().Query("for r in User return r").ToList().Result; 114 | 115 | // var user = client.DB().GetByKeyAsync("1127162").Result; 116 | 117 | //Console.WriteLine("user = " + user.Username); 118 | 119 | ////user.Username = "andrew"; 120 | //var user = result.Result.New; 121 | //user.Password = "new"; 122 | //var updated = client.DB().UpdateAsync("1127162", user).Result; 123 | //var result2 = client.DB().DeleteAsync("1127162"); 124 | //user = updated.New; 125 | 126 | //Console.WriteLine("user = " + user.Username); 127 | 128 | Console.ReadLine(); 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/ConsoleTestApp/Role.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Models; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace ConsoleTestApp 8 | { 9 | public class Role : ArangoBaseEntity { 10 | 11 | [JsonProperty(PropertyName = "name", NullValueHandling = NullValueHandling.Ignore)] 12 | public string Name { get; set; } 13 | 14 | [JsonProperty(PropertyName = "permission", NullValueHandling = NullValueHandling.Ignore)] 15 | public string Permission { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/ConsoleTestApp/User.cs: -------------------------------------------------------------------------------- 1 | using BorderEast.ArangoDB.Client.Database; 2 | using BorderEast.ArangoDB.Client.Database.Meta; 3 | using BorderEast.ArangoDB.Client.Models; 4 | using Newtonsoft.Json; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace ConsoleTestApp 10 | { 11 | 12 | [Collection(HasForeignKey = true)] 13 | public class User : ArangoBaseEntity 14 | { 15 | [JsonProperty(PropertyName = "userName", NullValueHandling = NullValueHandling.Ignore)] 16 | public string Username { get; set; } 17 | 18 | [JsonProperty(PropertyName = "passwd", NullValueHandling = NullValueHandling.Ignore)] 19 | public string Password { get; set; } 20 | 21 | [ArangoField(ForeignKeyTo = "Role")] 22 | [JsonConverter(typeof(ForeignKeyConverter))] 23 | public List Roles { get; set; } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/BorderEast.ArangoDB.Client/ConsoleTestApp/VelocyStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Sockets; 4 | using System.Text; 5 | using System.Threading; 6 | 7 | namespace ConsoleTestApp 8 | { 9 | public class VelocyStream 10 | { 11 | private TcpClient _client; 12 | public NetworkStream Stream { get; private set; } 13 | private CancellationTokenSource _token; 14 | 15 | public VelocyStream() { 16 | _token = new CancellationTokenSource(); 17 | _client = new TcpClient(); 18 | } 19 | 20 | public void Connect(string host, int port) { 21 | Console.WriteLine("connecting..."); 22 | _client.ConnectAsync(host, port); 23 | Console.WriteLine("connected!"); 24 | 25 | while (!_client.Connected) { 26 | Thread.Sleep(20); 27 | } 28 | 29 | Console.WriteLine("getting stream..."); 30 | Stream = _client.GetStream(); // works because of Thread.Sleep above until the socket is connected 31 | Console.WriteLine("got stream!"); 32 | 33 | } 34 | } 35 | } 36 | --------------------------------------------------------------------------------