public void Create()
		{
			var doc = new JObject
			{
				{ "Name", "ZEK" },
				{ "Capacity", 999 }
			};

			doc.SetKey("ZEK");

			var created = Database.Document.Create(doc, "Station", true);

			created.AssertRevision();
		}
		public void Update()
		{
			Create();

			var doc = new JObject
			{
				{ "Name", "ZEK" },
				{ "Capacity", 523 }
			};

			doc.SetKey("ZEK");

			var updated = Database.Document.Update("Station/ZEK", doc);

			updated.AssertSuccess();
		}
Пример #3
0
		public void Create()
		{
			var station = new JObject
			{
				{"Name", "SOC"},
				{"Capacity", 200}
			};

			station.SetKey("SOC");

			var line1 = new JObject
			{
				{"Name", "SOC1"},
				{"MainLine", true}
			};

			line1.SetKey("SOC1");

			var line2 = new JObject
			{
				{"Name", "SOC2"},
				{"MainLine", false}
			};

			line2.SetKey("SOC2");

			var stationCreated = Database.Document.Create(station, "Station", true);
			var line1Created = Database.Document.Create(line1, "Line", true);
			var line2Created = Database.Document.Create(line2, "Line", true);

			var collectionCreated = Database.Collection.Create("Station-Line", CollectionType.Edge);

			var stationLine1EdgeCreated = Database.Edge.Create("Station-Line", "Station/SOC", "Line/SOC1", "SOC-SOC1");

			var stationLine2EdgeCreated = Database.Edge.Create("Station-Line", "Station/SOC", "Line/SOC2", "SOC-SOC2");

			stationCreated.AssertRevision();
			line1Created.AssertRevision();
			line2Created.AssertRevision();
			collectionCreated.AssertSuccess();
			stationLine1EdgeCreated.AssertRevision();
			stationLine2EdgeCreated.AssertRevision();
		}
Пример #4
0
		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");
			}
		}