public ArangoResponse <T> Send <T>(IOperationThatReturns <T> operation) { string typeName = operation.GetType().Name; try { _logger.Trace("Sending {0} operation", typeName); DateTime begin = DateTime.UtcNow; ArangoResponse <T> arangoResponse = _restDispatcher.Send(operation); DateTime end = DateTime.UtcNow; arangoResponse.Status.TotalDuration = end - begin; _logger.Trace("Operation {0} completed successfully in {1}ms", typeName, arangoResponse.Status.TotalDuration.TotalMilliseconds); if (_settings.ThrowExceptions) { arangoResponse.ThrowIfError(); } return(arangoResponse); } catch (Exception e) { _logger.TraceException(string.Format("Operation {0} fail", typeName), e); throw; } }
public void SimpleUsage() { using (var client = new ArangoClient()) { // Init the client, is possible to define settings like host/port client.Init(); // Create new database client.Database.Create("ApiTests"); // Scope to the recently created database using (var db = client.UseDatabase("ApiTests")) { // Create Station document collection db.Collection.Create("Station"); // Create a station with key ZEK var stationZEK = new JObject { { "_key", "ZEK" }, { "Name", "ZEK" }, { "Capacity", 2 } }; // All operations return ArangoResponse generic type ArangoResponse <JObject> createResult = db.Document.Create(stationZEK, "Station"); // By default, this API doesn't throws a Exception if an operation fail, // always is good check the Status.Error property. // This behavior can be configured in ArangoClientSettings.ThrowExceptions if (createResult.Status.Error) { throw new Exception(createResult.Status.ErrorMessage); } // Or just call the ThrowIfError() method createResult.ThrowIfError(); // Status has other details // https://www.arangodb.org/manuals/current/ImplementorManualArangoErrors.html int errorNum = createResult.Status.ErrorNum; int code = createResult.Status.Code; HttpStatusCode httpStatusCode = createResult.Status.StatusCode; TimeSpan totalDuration = createResult.Status.TotalDuration; TimeSpan serverDuration = createResult.Status.ServerDuration; // Each operation have a type of result JObject resultOfOperation = createResult.Result; // Create the main line of ZEK station var lineZEK1 = new JObject { { "Name", "ZEK1" }, { "MainLine", true } }; // Is possible to use the SetKey extension method to set the _key lineZEK1.SetKey("ZEK1"); // Are possible to create collections on the fly db.Document.Create(lineZEK1, "Line", createCollection: true); // Now, we create the edge collection to link Station with Lines db.Collection.Create("Station-Line", CollectionType.Edge); // Create the edge to link ZEK station with ZEK1 line db.Edge.Create("Station-Line", "Station/ZEK", "Line/ZEK1", "ZEK-ZEK1"); } // To finalize the test, drop the database client.Database.Drop("ApiTests"); } }