/// <summary> /// Creates a new edge /// </summary> /// <param name="document">The edge document</param> /// <param name="waitForSync">Define if the request should wait until synced to disk</param> /// <param name="baseResult"></param> /// <returns>DocumentIdentifierResult</returns> public async Task <IDocumentIdentifierResult> InsertAsync(object document, bool?waitForSync = null, Action <BaseResult> baseResult = null) { waitForSync = waitForSync ?? db.Setting.WaitForSync; var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = HttpMethod.Post, Command = $"{graphName}/edge/{collection}", Query = new Dictionary <string, string>() }; command.Query.Add("waitForSync", waitForSync.ToString()); var result = await command.RequestMergedResult <InsertEdgeResult>(document).ConfigureAwait(false); if (result.BaseResult.HasError() == false) { if (db.Setting.DisableChangeTracking == false) { db.ChangeTracker.TrackChanges(document, result.Result.Edge); } db.SharedSetting.IdentifierModifier.Modify(document, result.Result.Edge); } if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Edge); }
/// <summary> /// Fetches an existing edge /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The document handle or key of document</param> /// <param name="baseResult"></param> /// <returns>T</returns> public async Task <T> GetAsync <T>(string id, string ifMatchRev = null, Action <BaseResult> baseResult = null) { var documentHandle = id.IndexOf("/") == -1 ? $"{collection}/{id}" : id; var command = new HttpCommand(this.db) { Api = CommandApi.Graph, Method = HttpMethod.Get, Command = $"{graphName}/edge/{documentHandle}", EnableChangeTracking = db.Setting.DisableChangeTracking == false, Headers = new Dictionary <string, string>() }; if (string.IsNullOrEmpty(ifMatchRev) == false) { command.Headers.Add("If-Match", ifMatchRev); } var result = await command.RequestGenericSingleResult <T, EdgeInheritedCommandResult <T> >(throwForServerErrors : false).ConfigureAwait(false); if (db.Setting.Document.ThrowIfDocumentDoesNotExists || (result.BaseResult.HasError() && result.BaseResult.ErrorNum != 1202)) { new BaseResultAnalyzer(db).Throw(result.BaseResult); } if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result); }
/// <summary> /// Partially updates the edge with no change tracking /// </summary> /// <param name="id">The document handle or key of document</param> /// <param name="document">Representation of the patch document</param> /// <param name="waitForSync">Define if the request should wait until synced to disk</param> /// <param name="keepNull">For remove any attributes from the existing document that are contained in the patch document with an attribute value of null</param> /// <param name="baseResult"></param> /// <returns></returns> public async Task <IDocumentIdentifierResult> UpdateByIdAsync(string id, object document , bool?waitForSync = null, bool?keepNull = null, string ifMatchRev = null, Action <BaseResult> baseResult = null) { var documentHandle = id.IndexOf("/") == -1 ? $"{collection}/{id}" : id; keepNull = keepNull ?? db.Setting.Document.KeepNullAttributesOnUpdate; waitForSync = waitForSync ?? db.Setting.WaitForSync; var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = new HttpMethod("PATCH"), Query = new Dictionary <string, string>(), Command = $"{graphName}/edge/{documentHandle}", Headers = new Dictionary <string, string>() }; if (string.IsNullOrEmpty(ifMatchRev) == false) { command.Headers.Add("If-Match", ifMatchRev); } command.Query.Add("keepNull", keepNull.ToString()); command.Query.Add("waitForSync", waitForSync.ToString()); var result = await command.RequestMergedResult <CrudEdgeResult>(document).ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Edge); }
/// <summary> /// Deletes the edge without change tracking /// </summary> /// <param name="id">The document handle or key of document</param> /// <param name="waitForSync">Wait until document has been synced to disk</param> /// <returns></returns> public async Task <bool> RemoveByIdAsync(string id, bool?waitForSync = null, string ifMatchRev = null, Action <BaseResult> baseResult = null) { var documentHandle = id.IndexOf("/") == -1 ? $"{collection}/{id}" : id; waitForSync = waitForSync ?? db.Setting.WaitForSync; var command = new HttpCommand(this.db) { Api = CommandApi.Graph, Method = HttpMethod.Delete, Query = new Dictionary <string, string>(), Command = $"{graphName}/edge/{documentHandle}", Headers = new Dictionary <string, string>() }; if (string.IsNullOrEmpty(ifMatchRev) == false) { command.Headers.Add("If-Match", ifMatchRev); } command.Query.Add("waitForSync", waitForSync.ToString()); var result = await command.RequestMergedResult <DropGraphResult>().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Removed); }
async Task MakeNextRequest() { HttpResponseMessage response; if (!initialized) { response = await initiateCommand.SendCommandAsync(data).ConfigureAwait(false); initialized = true; } else { HttpCommand command = new HttpCommand(db) { Api = CommandApi.Cursor, Command = CursorResult.Id, Method = HttpMethod.Put }; response = await command.SendCommandAsync().ConfigureAwait(false); } stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); streamReader = new StreamReader(stream); jsonTextReader = new ArangoJsonTextReader(streamReader); CursorResult.RequestCount++; }
/// <summary> /// Fetches an existing edge /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The document handle or key of document</param> /// <param name="baseResult"></param> /// <returns>T</returns> public async Task <T> GetAsync <T>(string id, Action <BaseResult> baseResult = null) { var documentHandle = id.IndexOf("/") == -1 ? $"{collection}/{id}" : id; var command = new HttpCommand(this.db) { Api = CommandApi.Graph, Method = HttpMethod.Get, Command = $"{graphName}/edge/{documentHandle}", EnableChangeTracking = !db.Setting.DisableChangeTracking }; var defaultThrowForServerErrors = db.Setting.ThrowForServerErrors; db.Setting.ThrowForServerErrors = false; var result = await command.RequestGenericSingleResult <T, EdgeInheritedCommandResult <T> >().ConfigureAwait(false); db.Setting.ThrowForServerErrors = defaultThrowForServerErrors; if (db.Setting.Document.ThrowIfDocumentDoesNotExists || (result.BaseResult.Error && result.BaseResult.ErrorNum != 1202)) { new BaseResultAnalyzer(db).Throw(result.BaseResult); } if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result); }
/// <summary> /// Replace an existing edge definition /// </summary> /// <param name="newCollection">The name of the edge collection to be used</param> /// <param name="from">One or many vertex collections that can contain source vertices</param> /// <param name="to">One or many edge collections that can contain target vertices</param> /// <param name="baseResult"></param> /// <returns></returns> public async Task <GraphIdentifierResult> EditDefinitionAsync(string newCollection, IList <string> from, IList <string> to, Action <BaseResult> baseResult = null) { var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = HttpMethod.Put, Command = $"{graphName}/edge/{collection}" }; EdgeDefinitionData data = new EdgeDefinitionData { Collection = newCollection, From = from, To = to }; var result = await command.RequestMergedResult <GraphResult>(data).ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Graph); }
public void cancelRequest(String szCallback) { if (szCallback == null || szCallback.length() == 0) { LOG.INFO("Cancel callback should not be empty. Use * for cancel all"); return; } lock (getCommandLock()) { HttpCommand pCmd = (HttpCommand)getCurCommand(); if (pCmd != null && (szCallback.compareTo("*") == 0 || pCmd.m_strCallback.compareTo(szCallback) == 0)) { pCmd.cancel(); } if (szCallback.compareTo("*") == 0) { getCommands().Clear(); } else { for (int i = getCommands().size() - 1; i >= 0; i--) { HttpCommand pCmd1 = (HttpCommand)getCommands().get(i); if (pCmd1 != null && pCmd1.m_strCallback.compareTo(szCallback) == 0) { getCommands().RemoveAt(i); } } } } }
public async Task DistinctResult() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.SingleResult); HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestDistinctResult <Person>(); Assert.Equal(result.BaseResult.Code, 200); Assert.Equal(result.BaseResult.Error, false); Assert.Equal(result.Result.Age, 27); Assert.Equal(result.Result.Fullname, "raoof hojat"); Assert.Equal(result.Result.Height, 172); var info = mockDB.Db.FindDocumentInfo(result.Result); Assert.Equal(info.Id, "Person/KEY"); Assert.Equal(info.Key, "KEY"); Assert.Equal(info.Rev, "REV"); Assert.True(JObject.DeepEquals(info.Document, JObject.Parse(JsonSample.SingleResult))); }
/// <summary> /// Create graph /// </summary> /// <param name="edgeDefinitions">If true then the data is synchronised to disk before returning from a document create, update, replace or removal operation</param> /// <param name="orphanCollection">Whether or not the collection will be compacted</param> /// <returns>GraphIdentifierResult</returns> public async Task <GraphIdentifierResult> CreateAsync(IList <EdgeDefinitionData> edgeDefinitions , IList <string> orphanCollections = null, Action <BaseResult> baseResult = null) { var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = HttpMethod.Post }; var data = new CreateGraphData { Name = graphName, EdgeDefinitions = edgeDefinitions, OrphanCollections = orphanCollections }; var result = await command.RequestMergedResult <GraphResult>(data).ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Graph); }
public async Task RequestGenericList_WithoutChangeTracking() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.ListResult); mockDB.Db.Setting.DisableChangeTracking = true; HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestGenericListResult <Person, DocumentInheritedCommandResult <List <Person> > >(); Assert.Equal(result.BaseResult.Code, 200); Assert.Equal(result.BaseResult.Error, false); Assert.Equal(result.Result.Count, 2); Assert.Equal(result.Result[0].Age, 27); Assert.Equal(result.Result[0].Fullname, "raoof hojat"); Assert.Equal(result.Result[0].Height, 172); Assert.Throws <Exception>(() => mockDB.Db.FindDocumentInfo(result.Result[0])); Assert.Equal(result.Result[1].Age, 7); Assert.Equal(result.Result[1].Fullname, "hojat raoof"); Assert.Equal(result.Result[1].Height, 721); Assert.Throws <Exception>(() => mockDB.Db.FindDocumentInfo(result.Result[1])); }
/// <summary> /// Creates a collection /// </summary> /// <param name="name">Name of the collection</param> /// <param name="waitForSync">If true then the data is synchronised to disk before returning from a document create, update, replace or removal operation</param> /// <param name="doCompact">Whether or not the collection will be compacted</param> /// <param name="journalSize"> The maximal size of a journal or datafile in bytes. The value must be at least 1048576 (1 MB).</param> /// <param name="isSystem"> If true, create a system collection. In this case collection-name should start with an underscore</param> /// <param name="isVolatile">If true then the collection data is kept in-memory only and not made persistent</param> /// <param name="type"> The type of the collection to create</param> /// <param name="numberOfShards">In a cluster, this value determines the number of shards to create for the collection</param> /// <param name="shardKeys">In a cluster, this attribute determines which document attributes are used to determine the target shard for documents</param> /// <returns>CreateCollectionResult</returns> public async Task <CreateCollectionResult> CreateCollectionAsync(string name, bool?waitForSync = null, bool?doCompact = null, decimal?journalSize = null, bool?isSystem = null, bool?isVolatile = null, CollectionType?type = null, int?numberOfShards = null , string shardKeys = null, Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Collection, Method = HttpMethod.Post }; var data = new CreateCollectionData { DoCompact = doCompact, IsSystem = isSystem, IsVolatile = isVolatile, Name = name, NumberOfShards = numberOfShards, ShardKeys = shardKeys, WaitForSync = waitForSync }; if (type.HasValue) { data.Type = (int)type.Value; } var result = await command.RequestMergedResult <CreateCollectionResult>(data).ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result); }
/// <summary> /// Completely updates the edge with no change tracking /// </summary> /// <param name="id">The document handle or key of document</param> /// <param name="document">Representation of the new document</param> /// <param name="waitForSync">Wait until document has been synced to disk</param> /// <returns>Document identifiers</returns> public async Task <IDocumentIdentifierResult> ReplaceByIdAsync(string id, object document, bool?waitForSync = null, Action <BaseResult> baseResult = null) { var documentHandle = id.IndexOf("/") == -1 ? $"{collection}/{id}" : id; waitForSync = waitForSync ?? db.Setting.WaitForSync; var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = HttpMethod.Put, Query = new Dictionary <string, string>(), Command = $"{graphName}/edge/{documentHandle}" }; command.Query.Add("waitForSync", waitForSync.ToString()); var result = await command.RequestMergedResult <CrudEdgeResult>(document).ConfigureAwait(false); if (!result.BaseResult.Error) { db.SharedSetting.IdentifierModifier.Modify(document, result.Result.Edge); } if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Edge); }
public async Task RequestGenericSingle() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.NestedSingleResult); HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestGenericSingleResult <Person, DocumentInheritedCommandResult <Person> >(); Assert.Equal(200, result.BaseResult.Code); Assert.False(result.BaseResult.Error); Assert.Equal(27, result.Result.Age); Assert.Equal("raoof hojat", result.Result.Fullname); Assert.Equal(172, result.Result.Height); var info = mockDB.Db.FindDocumentInfo(result.Result); Assert.Equal("Person/KEY", info.Id); Assert.Equal("KEY", info.Key); Assert.Equal("REV", info.Rev); Assert.True(JObject.DeepEquals(info.Document, JObject.Parse(JsonSample.SingleResult))); }
public string Authenticate(string userName, string password) { //API ENDPOINT HttpCommand.Setup(AppSettingsManager.Settings[Constants.BaseApiUrl]); _api.Setup(userName, password); var result = JsonConvert.DeserializeObject <TokenDTO>(_api.Execute(new GetCandidatesQuery())); return(result.Token); }
public CursorAsyncEnumerator(IArangoDatabase db, HttpCommand command, object data = null) { this.db = db; this.initiateCommand = command; this.CursorResult = new CursorResult { HasMore = true }; this.data = data; readerState = new ReaderState(); }
public async Task DistinctResult_BadRequest() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.Error, statusCode: HttpStatusCode.NotFound); HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; await Assert.ThrowsAsync<ArangoServerException>(() => command.RequestDistinctResult<Person>()); }
public async Task DistinctResult_BadRequest() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.Error, statusCode: HttpStatusCode.NotFound); HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; await Assert.ThrowsAsync <ArangoServerException>(() => command.RequestDistinctResult <Person>()); }
public async Task RequestGenericList_WithoutChangeTracking_BadRequest() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.Error, statusCode: HttpStatusCode.NotFound); mockDB.Db.Setting.DisableChangeTracking = true; HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; await Assert.ThrowsAsync <ArangoServerException>(() => command.RequestGenericListResult <Person, DocumentInheritedCommandResult <List <Person> > >()); }
/// <summary> /// List of accessible databases /// </summary> /// <returns>List of database names</returns> public async Task<List<string>> ListAccessibleDatabasesAsync(Action<BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Database, Method = HttpMethod.Get, Command = "user" }; var result = await command.RequestGenericListResult<string,InheritedCommandResult<List<string>>>().ConfigureAwait(false); if (baseResult != null) baseResult(result.BaseResult); return result.Result; }
/// <summary> /// Retrieves information about the current database /// </summary> /// <returns>DatabaseInformation</returns> public async Task<DatabaseInformation> CurrentDatabaseInformationAsync(Action<BaseResult> baseResult=null) { var command = new HttpCommand(this) { Api = CommandApi.Database, Method = HttpMethod.Get, Command = "current" }; var result = await command.RequestGenericSingleResult<DatabaseInformation, InheritedCommandResult<DatabaseInformation>>().ConfigureAwait(false); if(baseResult!=null) baseResult(result.BaseResult); return result.Result; }
public string Authenticate(string userName, string password) { //API ENDPOINT HttpCommand.Setup(Constants.APIEndpoint); HRApi.getApi().Setup(userName, password); var api = HRApi.getApi(); var command = new CandidateCommand(); var res = api.Execute(command); //var resultss = JsonConvert.DeserializeObject<IEnumerable<Candidate>>(res); var result = JsonConvert.DeserializeObject <TokenDTO>(res); return(result.Token); }
/// <summary> /// Creates an index /// </summary> /// <param name="collection">The collection name</param> /// <param name="data">Index details</param> /// <param name="baseResult"></param> /// <returns>EnsureIndexResult</returns> public async Task <EnsureIndexResult> EnsureIndexAsync(string collection, EnsureIndexData data, Action <BaseResult> baseResult = null) { var command = new HttpCommand(this.db) { Api = CommandApi.Index, Method = HttpMethod.Post, Query = new Dictionary <string, string>() }; command.Query.Add("collection", collection); var result = await command.RequestMergedResult <EnsureIndexResult>(data).ConfigureAwait(false); baseResult?.Invoke(result.BaseResult); return(result.Result); }
/// <summary> /// Lists all graphs /// </summary> /// <param name="baseResult"></param> /// <returns>List<GraphIdentifierResult></returns> public async Task <List <GraphIdentifierResult> > ListGraphsAsync(Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Graph, Method = HttpMethod.Get }; var result = await command.RequestMergedResult <GraphListResult>().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Graphs); }
/// <summary> /// Deletes a database /// </summary> /// <param name="name">Name of the database</param> /// <returns></returns> public async Task DropDatabaseAsync(string name, Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Database, Method = HttpMethod.Delete, IsSystemCommand = true, Command = name }; var result = await command.RequestGenericSingleResult <bool, InheritedCommandResult <bool> >().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } }
/// <summary> /// Retrieves information about the current database /// </summary> /// <returns>DatabaseInformation</returns> public async Task <DatabaseInformation> CurrentDatabaseInformationAsync(Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Database, Method = HttpMethod.Get, Command = "current" }; var result = await command.RequestGenericSingleResult <DatabaseInformation, InheritedCommandResult <DatabaseInformation> >().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result); }
/// <summary> /// Drops the collection identified by collection-name /// </summary> /// <param name="name">Name of the collection</param> /// <param name="baseResult"></param> /// <returns>DropCollectionResult</returns> public async Task <DropCollectionResult> DropCollectionAsync(string name, Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Collection, Method = HttpMethod.Delete, Command = name }; var result = await command.RequestMergedResult <DropCollectionResult>().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result); }
/// <summary> /// Lists all edge definitions /// </summary> /// <param name="baseResult"></param> /// <returns></returns> public async Task <List <string> > ListEdgeDefinitionsAsync(Action <BaseResult> baseResult = null) { var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = HttpMethod.Get, Command = $"{StringUtils.Encode(graphName)}/edge" }; var result = await command.RequestMergedResult <GraphCollectionResult>().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Collections); }
/// <summary> /// Get graph info /// </summary> /// <returns>GraphIdentifierResult</returns> public async Task <GraphIdentifierResult> InfoAsync(Action <BaseResult> baseResult = null) { var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = HttpMethod.Get, Command = StringUtils.Encode(graphName) }; var result = await command.RequestMergedResult <GraphResult>().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Graph); }
/// <summary> /// List of accessible databases /// </summary> /// <returns>List of database names</returns> public async Task <List <string> > ListAccessibleDatabasesAsync(Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Database, Method = HttpMethod.Get, Command = "user" }; var result = await command.RequestGenericListResult <string, InheritedCommandResult <List <string> > >().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result); }
/// <summary> /// Executes a server-side traversal /// </summary> /// <typeparam name="TVertex">Type of vertex</typeparam> /// <typeparam name="TEdge">Type of edge</typeparam> /// <param name="config">Configuration for the traversal</param> /// <param name="startVertex">Id of the startVertex</param> /// <param name="baseResult"></param> /// <returns>TraversalResult<TVertex, TEdge></returns> public async Task <TraversalResult <TVertex, TEdge> > TraverseAsync <TVertex, TEdge>(TraversalConfig config, string startVertex = null, Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Traversal, Method = HttpMethod.Post }; config.StartVertex = startVertex ?? config.StartVertex; var result = await command.RequestMergedResult <TraversalContainerResult <TVertex, TEdge> >(config).ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Result); }
/// <summary> /// Creates a new edge /// </summary> /// <param name="document">The edge document</param> /// <param name="waitForSync">Define if the request should wait until synced to disk</param> /// <param name="baseResult"></param> /// <returns>DocumentIdentifierResult</returns> public async Task <IDocumentIdentifierResult> InsertAsync(string from, string to, object document, bool?waitForSync = null, Action <BaseResult> baseResult = null) { waitForSync = waitForSync ?? db.Setting.WaitForSync; var command = new HttpCommand(db) { Api = CommandApi.Graph, Method = HttpMethod.Post, Command = $"{graphName}/edge/{collection}", Query = new Dictionary <string, string>() }; var jObject = new DocumentSerializer(db).FromObject(document); jObject.Add("_from", JToken.FromObject(from)); jObject.Add("_to", JToken.FromObject(to)); command.Query.Add("waitForSync", waitForSync.ToString()); var result = await command.RequestMergedResult <InsertEdgeResult>(jObject).ConfigureAwait(false); if (!result.BaseResult.Error) { if (!db.Setting.DisableChangeTracking) { var container = db.ChangeTracker.TrackChanges(document, result.Result.Edge); if (container != null) { container.From = from; container.To = to; } } db.SharedSetting.IdentifierModifier.Modify(document, result.Result.Edge, from, to); } if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result.Edge); }
/// <summary> /// List of collections /// </summary> /// <param name="excludeSystem">Exclude system collections</param> /// <param name="baseResult">Runs when base result is ready</param> /// <returns>List of collection properties</returns> public async Task <List <CreateCollectionResult> > ListCollectionsAsync(bool excludeSystem = true, Action <BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Collection, Method = HttpMethod.Get, Query = new Dictionary <string, string>() }; command.Query.Add("excludeSystem", excludeSystem.ToString()); var result = await command.RequestGenericListResult <CreateCollectionResult, CollectionsInheritedCommandResult <List <CreateCollectionResult> > >().ConfigureAwait(false); if (baseResult != null) { baseResult(result.BaseResult); } return(result.Result); }
public async Task DistinctResult_WithoutChangeTracking() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.SingleResult); mockDB.Db.Setting.DisableChangeTracking = true; HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestDistinctResult<Person>(); Assert.Equal(result.BaseResult.Code, 200); Assert.Equal(result.BaseResult.Error, false); Assert.Equal(result.Result.Age, 27); Assert.Equal(result.Result.Fullname, "raoof hojat"); Assert.Equal(result.Result.Height, 172); Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(result.Result)); }
public async Task DistinctResult() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.SingleResult); HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestDistinctResult<Person>(); Assert.Equal(result.BaseResult.Code, 200); Assert.Equal(result.BaseResult.Error, false); Assert.Equal(result.Result.Age, 27); Assert.Equal(result.Result.Fullname, "raoof hojat"); Assert.Equal(result.Result.Height, 172); var info = mockDB.Db.FindDocumentInfo(result.Result); Assert.Equal(info.Id, "Person/KEY"); Assert.Equal(info.Key, "KEY"); Assert.Equal(info.Rev, "REV"); Assert.True(JObject.DeepEquals(info.Document, JObject.Parse(JsonSample.SingleResult))); }
public async Task RequestGenericList() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.ListResult); HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestGenericListResult<Person, DocumentInheritedCommandResult<List<Person>>>(); Assert.Equal(result.BaseResult.Code, 200); Assert.Equal(result.BaseResult.Error, false); Assert.Equal(result.Result.Count, 2); Assert.Equal(result.Result[0].Age, 27); Assert.Equal(result.Result[0].Fullname, "raoof hojat"); Assert.Equal(result.Result[0].Height, 172); var info1 = mockDB.Db.FindDocumentInfo(result.Result[0]); Assert.Equal(info1.Id, "Person/KEY1"); Assert.Equal(info1.Key, "KEY1"); Assert.Equal(info1.Rev, "REV1"); Assert.Equal(result.Result[1].Age, 7); Assert.Equal(result.Result[1].Fullname, "hojat raoof"); Assert.Equal(result.Result[1].Height, 721); var info2 = mockDB.Db.FindDocumentInfo(result.Result[1]); Assert.NotNull(info2.Document); Assert.Equal(info2.Id, "Person/KEY2"); Assert.Equal(info2.Key, "KEY2"); Assert.Equal(info2.Rev, "REV2"); }
public async Task RequestGenericList_WithoutChangeTracking_BadRequest() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.Error, statusCode: HttpStatusCode.NotFound); mockDB.Db.Setting.DisableChangeTracking = true; HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; await Assert.ThrowsAsync<ArangoServerException>(() => command.RequestGenericListResult<Person, DocumentInheritedCommandResult<List<Person>>>()); }
public async Task RequestGenericList_WithoutChangeTracking() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.ListResult); mockDB.Db.Setting.DisableChangeTracking = true; HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestGenericListResult<Person, DocumentInheritedCommandResult<List<Person>>>(); Assert.Equal(result.BaseResult.Code, 200); Assert.Equal(result.BaseResult.Error, false); Assert.Equal(result.Result.Count, 2); Assert.Equal(result.Result[0].Age, 27); Assert.Equal(result.Result[0].Fullname, "raoof hojat"); Assert.Equal(result.Result[0].Height, 172); Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(result.Result[0])); Assert.Equal(result.Result[1].Age, 7); Assert.Equal(result.Result[1].Fullname, "hojat raoof"); Assert.Equal(result.Result[1].Height, 721); Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(result.Result[1])); }
/// <summary> /// Deletes a database /// </summary> /// <param name="name">Name of the database</param> /// <returns></returns> public async Task DropDatabaseAsync(string name, Action<BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Database, Method = HttpMethod.Delete, IsSystemCommand = true, Command = name }; var result = await command.RequestGenericSingleResult<bool, InheritedCommandResult<bool>>().ConfigureAwait(false); if (baseResult != null) baseResult(result.BaseResult); }
public async Task RequestMergedResult() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.MergeResult); HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking}; var result = await command.RequestMergedResult<Flight>(); Assert.Equal(result.BaseResult.Code, 202); Assert.Equal(result.BaseResult.Error, false); Assert.Equal(result.Result.Airline, "AIRLINE"); Assert.Equal(result.Result.FlightNumber, "10012314"); Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(result.Result)); }
void CreateRequestCursor(string json = null, IList<string> jsonList = null, bool? disableChangeTracking = false, bool? error = false, bool? throwOnError = true) { bool hasMore = string.IsNullOrEmpty(json); var mockDB = new ArangoDatabaseMock().WithChangeTracking(); if (!hasMore) mockDB.SendCommand(json, statusCode: error.Value ? HttpStatusCode.NotFound : HttpStatusCode.OK); else mockDB.SendCommandSequence(jsonList, statusCode: error.Value ? HttpStatusCode.NotFound : HttpStatusCode.OK); mockDB.Db.Setting.DisableChangeTracking = disableChangeTracking.Value; mockDB.Db.Setting.ThrowForServerErrors = throwOnError.Value; HttpCommand command = new HttpCommand(mockDB.Db); var cursor = command.CreateCursor<Person>(); if (error.Value) { if (throwOnError.Value) Assert.Throws<ArangoServerException>(() => cursor.ToList()); else { var persons = cursor.ToList(); Assert.Equal(persons.Count, 0); Assert.Equal(cursor.Statistics.Code, 400); Assert.Equal(cursor.Statistics.Error, true); Assert.Equal(cursor.Statistics.ErrorMessage, "ERROR"); } } else { var persons = cursor.ToList(); Assert.Equal(cursor.Statistics.Code, 201); Assert.Equal(cursor.Statistics.Count, 2); Assert.Equal(cursor.Statistics.Error, false); Assert.Equal(cursor.Statistics.Id, "26011191"); Assert.Equal(cursor.Statistics.RequestCount, hasMore ? 2 : 1); Assert.Equal(cursor.Statistics.HasMore, false); Assert.Equal(cursor.Statistics.Extra.Stats.FullCount, 6); Assert.Equal(cursor.Statistics.Extra.Stats.ScannedFull, 3); Assert.Equal(cursor.Statistics.Extra.Stats.ScannedIndex, 4); Assert.Equal(cursor.Statistics.Extra.Stats.WritesExecuted, 1); Assert.Equal(cursor.Statistics.Extra.Stats.WritesIgnored, 2); Assert.Equal(persons.Count, hasMore ? 4 : 2); int index = 0; if (hasMore) { Assert.Equal(persons[index].Age, 27); Assert.Equal(persons[index].Fullname, "raoof hojat2"); Assert.Equal(persons[index].Height, 172); if (disableChangeTracking.Value) Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(persons[index])); else { var info3 = mockDB.Db.FindDocumentInfo(persons[index]); Assert.Equal(info3.Id, "Person/KEY3"); Assert.Equal(info3.Key, "KEY3"); Assert.Equal(info3.Rev, "REV3"); } index++; Assert.Equal(persons[index].Age, 7); Assert.Equal(persons[index].Fullname, "hojat raoof2"); Assert.Equal(persons[index].Height, 721); if (disableChangeTracking.Value) Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(persons[index])); else { var info4 = mockDB.Db.FindDocumentInfo(persons[index]); Assert.NotNull(info4.Document); Assert.Equal(info4.Id, "Person/KEY4"); Assert.Equal(info4.Key, "KEY4"); Assert.Equal(info4.Rev, "REV4"); } index++; } Assert.Equal(persons[index].Age, 27); Assert.Equal(persons[index].Fullname, "raoof hojat"); Assert.Equal(persons[index].Height, 172); if (disableChangeTracking.Value) Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(persons[index])); else { var info1 = mockDB.Db.FindDocumentInfo(persons[index]); Assert.Equal(info1.Id, "Person/KEY1"); Assert.Equal(info1.Key, "KEY1"); Assert.Equal(info1.Rev, "REV1"); } index++; Assert.Equal(persons[index].Age, 7); Assert.Equal(persons[index].Fullname, "hojat raoof"); Assert.Equal(persons[index].Height, 721); if (disableChangeTracking.Value) Assert.Throws<Exception>(() => mockDB.Db.FindDocumentInfo(persons[index])); else { var info2 = mockDB.Db.FindDocumentInfo(persons[index]); Assert.NotNull(info2.Document); Assert.Equal(info2.Id, "Person/KEY2"); Assert.Equal(info2.Key, "KEY2"); Assert.Equal(info2.Rev, "REV2"); } } }
public async Task DistinctResult_BadRequest_DontThrow() { var mockDB = new ArangoDatabaseMock().WithChangeTracking(); mockDB.SendCommand(JsonSample.Error, statusCode: HttpStatusCode.NotFound); mockDB.Db.Setting.ThrowForServerErrors = false; HttpCommand command = new HttpCommand(mockDB.Db) { EnableChangeTracking = !mockDB.Db.Setting.DisableChangeTracking }; var result = await command.RequestDistinctResult<Person>(); Assert.Null(result.Result); Assert.Equal(result.BaseResult.Code, 400); Assert.Equal(result.BaseResult.Error, true); Assert.Equal(result.BaseResult.ErrorMessage, "ERROR"); }
/// <summary> /// Creates a collection /// </summary> /// <param name="name">Name of the collection</param> /// <param name="waitForSync">If true then the data is synchronised to disk before returning from a document create, update, replace or removal operation</param> /// <param name="doCompact">Whether or not the collection will be compacted</param> /// <param name="journalSize"> The maximal size of a journal or datafile in bytes. The value must be at least 1048576 (1 MB).</param> /// <param name="isSystem"> If true, create a system collection. In this case collection-name should start with an underscore</param> /// <param name="isVolatile">If true then the collection data is kept in-memory only and not made persistent</param> /// <param name="type"> The type of the collection to create</param> /// <param name="numberOfShards">In a cluster, this value determines the number of shards to create for the collection</param> /// <param name="shardKeys">In a cluster, this attribute determines which document attributes are used to determine the target shard for documents</param> /// <returns>CreateCollectionResult</returns> public async Task<CreateCollectionResult> CreateCollectionAsync(string name, bool? waitForSync = null, bool? doCompact = null, decimal? journalSize=null, bool? isSystem = null, bool? isVolatile = null, CollectionType? type = null, int? numberOfShards=null , string shardKeys = null, Action<BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Collection, Method = HttpMethod.Post }; var data = new CreateCollectionData { DoCompact=doCompact, IsSystem=isSystem, IsVolatile=isVolatile, Name=name, NumberOfShards=numberOfShards, ShardKeys=shardKeys, WaitForSync=waitForSync }; if (type.HasValue) data.Type = (int)type.Value; var result = await command.RequestMergedResult<CreateCollectionResult>(data).ConfigureAwait(false); if (baseResult != null) baseResult(result.BaseResult); return result.Result; }
/// <summary> /// Creates a database /// </summary> /// <param name="name">Name of the database</param> /// <param name="users">list of database user</param> /// <returns></returns> public async Task CreateDatabaseAsync(string name, List<DatabaseUser> users = null, Action<BaseResult> baseResult = null) { var command = new HttpCommand(this) { Api = CommandApi.Database, Method = HttpMethod.Post, IsSystemCommand = true }; var data = new CreateDatabaseData { Name = name, Users = users }; var result = await command.RequestGenericSingleResult<bool, InheritedCommandResult<bool>>(data).ConfigureAwait(false); if (baseResult != null) baseResult(result.BaseResult); }
public MutableString addHttpCommand(HttpCommand pCmd) { pCmd.setLog(LOG); pCmd.setInternal(m_bInternal); if (!m_bInternal && pCmd.m_strCallback.length() == 0) { processCommandBase(pCmd); return pCmd.getRetValue(); } else { if (m_bInternal) { lock (getCommandLock()) { if (getCommands().isEmpty()) addQueueCommand(pCmd); else { HttpCommand cmd = getCommands().get(0) as HttpCommand; MutableString rString = cmd.m_params.findHashParam("body") as MutableString; MutableString rString2 = pCmd.m_params.findHashParam("body") as MutableString; rString.Append(rString2); } } }else addQueueCommand(pCmd); start(epLow); return pCmd.getRetValue(); } }