private ArangoGraph documentToGraph(Document doc)
        {
            string graphName;

            if (doc.ContainsKey("name"))
            {
                graphName = doc.String("name");
            }
            else
            {
                graphName = doc.String("_key");
            }
            ArangoGraph graph = new ArangoGraph(_connection, graphName);

            graph.orphanCollections = doc.List <String>("orphanCollections");
            List <Object> eDs = doc.List <Object>("edgeDefinitions");
            List <ArangoGraphEdgeDefinition> edgeDefinitions = new List <ArangoGraphEdgeDefinition>();

            foreach (Document eD in eDs)
            {
                ArangoGraphEdgeDefinition edgeDefinition = new ArangoGraphEdgeDefinition(
                    eD.String("collection"),
                    eD.List <String>("from"),
                    eD.List <String>("to")
                    );
                edgeDefinitions.Add(edgeDefinition);
            }
            graph.edgeDefinitions = edgeDefinitions;

            return(graph);
        }
 public async Task CreateAsync(ArangoHandle database, ArangoGraph request,
                               CancellationToken cancellationToken = default)
 {
     await SendAsync <JObject>(HttpMethod.Post,
                               ApiPath(database, "gharial"),
                               JsonConvert.SerializeObject(request), cancellationToken : cancellationToken);
 }
        /// <summary>
        /// Adds a vertex collection to the graph.
        /// </summary>
        internal ArangoGraph addVertexCollection(string colName)
        {
            var request = new Request(RequestType.Collection, HttpMethod.Post);

            request.RelativeUri = string.Join("/", _apiUri, "vertex");
            Document body = new Document();

            body.Add("collection", colName);
            request.Body = body.Serialize();

            var response = _connection.Process(request);

            ArangoGraph result = new ArangoGraph(_connection, _graphName);

            switch (response.StatusCode)
            {
            case HttpStatusCode.Created:
                result = this.responseToGraph(response);
                break;

            default:
                if (response.IsException)
                {
                    throw new ArangoException(
                              response.StatusCode,
                              response.Document.String("driverErrorMessage"),
                              response.Document.String("driverExceptionMessage"),
                              response.Document.Object <Exception>("driverInnerException")
                              );
                }
                break;
            }

            return(result);
        }
 public async Task CreateGraphAsync(ArangoHandle database, ArangoGraph request,
                                    CancellationToken cancellationToken = default)
 {
     await SendAsync <JObject>(HttpMethod.Post,
                               $"{Server}/_db/{DbName(database)}/_api/gharial",
                               JsonConvert.SerializeObject(request), cancellationToken : cancellationToken);
 }
示例#5
0
        [SetUp()] public void Init()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);
            db = Database.GetTestDatabase();
            List <ArangoGraphEdgeDefinition> eds = new List <ArangoGraphEdgeDefinition>();

            ed1 = new ArangoGraphEdgeDefinition(
                edgeCol1,
                new List <String> {
                fromCol1, fromCol2
            },
                new List <String> {
                toCol1, toCol2
            }
                );
            eds.Add(ed1);
            ed2 = new ArangoGraphEdgeDefinition(
                edgeCol2,
                new List <String> {
                fromCol2, fromCol3
            },
                new List <String> {
                toCol2, toCol3
            }
                );
            eds.Add(ed2);
            List <String> vertexCollections = new List <String>();

            vertexCollections.Add(vertexCol1);
            vertexCollections.Add(vertexCol2);
            vertexCollections.Add(vertexCol3);
            g = db.Graph.Create(graphName, eds, vertexCollections);
        }
示例#6
0
 public async Task CreateAsync(ArangoHandle database, ArangoGraph request,
                               CancellationToken cancellationToken = default)
 {
     await SendAsync <ArangoVoid>(HttpMethod.Post,
                                  ApiPath(database, "gharial"),
                                  request, cancellationToken : cancellationToken);
 }
示例#7
0
        public void Should_get_graph_by_name()
        {
            List <String> vertexCollections = new List <String>();

            vertexCollections.Add("vc1");
            vertexCollections.Add("vc2");
            vertexCollections.Add("t1");

            List <ArangoGraphEdgeDefinition> eds = new List <ArangoGraphEdgeDefinition>();
            ArangoGraphEdgeDefinition        ed1 = new ArangoGraphEdgeDefinition(
                "ed1",
                new List <String> {
                "f1", "f2"
            },
                new List <String> {
                "t1", "t2"
            }
                );

            eds.Add(ed1);
            string name = "UnitTestGraph";

            db.Graph.Create(name, eds, vertexCollections);
            ArangoGraph graph = db.Graph.Get(name);

            Assert.AreEqual(graph.Name, name);
            Assert.AreEqual(graph.edgeDefinitions.First().collection, ed1.collection);
            Assert.AreEqual(graph.edgeDefinitions.First().from, ed1.from);
            Assert.AreEqual(graph.edgeDefinitions.First().to, ed1.to);
            Assert.AreEqual(6, graph.vertexCollections().Count);
        }
示例#8
0
 public void Should_delete_a_vertex_collection_error()
 {
     try {
         ArangoGraph graph = g.deleteVertexCollection("blub");
     } catch (ArangoException e) {
         Assert.NotNull(e);
     }
 }
示例#9
0
        public void Should_create_and_get_empty_graph()
        {
            string name = "UnitTestGraph";

            db.Graph.Create(name);
            ArangoGraph graph = db.Graph.Get(name);

            Assert.AreEqual(name, graph.Name);
            Assert.AreEqual(0, graph.edgeDefinitions.Count);
            Assert.AreEqual(0, graph.orphanCollections.Count);
        }
示例#10
0
        public void Should_create_and_get_graph_with_orphanage()
        {
            List <string> orphanage = new List <string> {
                "v1"
            };
            string name = "UnitTestGraph";

            db.Graph.Create(name, orphanage);
            ArangoGraph graph = db.Graph.Get(name);

            Assert.AreEqual(name, graph.Name);
            Assert.AreEqual(0, graph.edgeDefinitions.Count);
            Assert.AreEqual(1, graph.orphanCollections.Count);
        }
示例#11
0
        public void Should_add_a_vertex_collection_already_exists()
        {
            string        name   = "UnitTestNewVertexCollection";
            List <string> result = g.vertexCollections();

            Assert.False(result.Contains(name));
            g.addVertexCollection(name);
            result = g.vertexCollections();
            Assert.True(result.Contains(name));
            try {
                ArangoGraph resultGraph = g.addVertexCollection(name);
            } catch (ArangoException e) {
                Assert.NotNull(e);
            }
        }
示例#12
0
        /// <summary>
        /// Update an existing edge definition.
        /// </summary>
        internal ArangoGraph updateEdgeDefinition(ArangoGraphEdgeDefinition edgeDefinition)
        {
            var request = new Request(RequestType.Collection, HttpMethod.Put);

            request.RelativeUri = string.Join("/", _apiUri, "edge", edgeDefinition.collection);

            Document body = new Document();

            body.Add("collection", edgeDefinition.collection);
            body.Add("from", edgeDefinition.from);
            body.Add("to", edgeDefinition.to);
            request.Body = body.Serialize();

            var response = _connection.Process(request);

            ArangoGraph result = new ArangoGraph(_connection, _graphName);

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                result = this.responseToGraph(response);
                break;

            default:
                if (response.IsException)
                {
                    throw new ArangoException(
                              response.StatusCode,
                              response.Document.String("driverErrorMessage"),
                              response.Document.String("driverExceptionMessage"),
                              response.Document.Object <Exception>("driverInnerException")
                              );
                }
                break;
            }

            return(result);
        }
示例#13
0
        /// <summary>
        /// Delete an existing edge definition.
        /// </summary>
        internal ArangoGraph deleteEdgeDefinition(string collectionName, bool dropCollections)
        {
            string drop = "dropCollection=false";

            if (dropCollections)
            {
                drop = "dropCollection=true";
            }
            var    request = new Request(RequestType.Collection, HttpMethod.Delete);
            string uri     = string.Join("/", _apiUri, "edge", collectionName);

            request.RelativeUri = string.Join("?", uri, drop);

            var response = _connection.Process(request);

            ArangoGraph result = new ArangoGraph(_connection, _graphName);

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                result = this.responseToGraph(response);
                break;

            default:
                if (response.IsException)
                {
                    throw new ArangoException(
                              response.StatusCode,
                              response.Document.String("driverErrorMessage"),
                              response.Document.String("driverExceptionMessage"),
                              response.Document.Object <Exception>("driverInnerException")
                              );
                }
                break;
            }

            return(result);
        }
示例#14
0
        public void Should_create_and_get_graph_with_edge_definition()
        {
            ArangoGraphEdgeDefinition ed = new ArangoGraphEdgeDefinition(
                "unitTestEdge",
                new List <string> {
                "unitTestFrom"
            },
                new List <string> {
                "unitTestTo"
            }
                );
            List <ArangoGraphEdgeDefinition> edgeDefinitions = new List <ArangoGraphEdgeDefinition> {
                ed
            };
            string name = "UnitTestGraph";

            db.Graph.Create(name, edgeDefinitions);
            ArangoGraph graph = db.Graph.Get(name);

            Assert.AreEqual(name, graph.Name);
            Assert.AreEqual(1, graph.edgeDefinitions.Count);
            Assert.AreEqual(0, graph.orphanCollections.Count);
        }
示例#15
0
        /// <summary>
        /// Gets the list of all edge collections.
        /// </summary>
        internal ArangoGraph addEdgeDefinition(ArangoGraphEdgeDefinition edgeDefinition)
        {
            var request = new Request(RequestType.Collection, HttpMethod.Post);
            request.RelativeUri = string.Join("/", _apiUri, "edge");

            Document body = new Document();
            body.Add("collection", edgeDefinition.collection);
            body.Add("from", edgeDefinition.from);
            body.Add("to", edgeDefinition.to);
            request.Body = body.Serialize();

            var response = _connection.Process(request);

            ArangoGraph result = new ArangoGraph(_connection, _graphName);

            switch (response.StatusCode)
            {
                case HttpStatusCode.Created:
                    result = this.responseToGraph(response);
                    break;
                default:
                    if (response.IsException)
                    {
                        throw new ArangoException(
                            response.StatusCode,
                            response.Document.String("driverErrorMessage"),
                            response.Document.String("driverExceptionMessage"),
                            response.Document.Object<Exception>("driverInnerException")
                        );
                    }
                    break;
            }

            return result;
        }
示例#16
0
        private ArangoGraph documentToGraph(Document doc)
        {
            string graphName;
            if (doc.ContainsKey("name")) {
                graphName = doc.String("name");
            } else {
                graphName = doc.String("_key");
            }
            ArangoGraph graph = new ArangoGraph(_connection, graphName);
            graph.orphanCollections = doc.List<String>("orphanCollections");
            List<Object> eDs = doc.List<Object>("edgeDefinitions");
            List<ArangoGraphEdgeDefinition> edgeDefinitions = new List<ArangoGraphEdgeDefinition>();
            foreach(Document eD in eDs) {
                ArangoGraphEdgeDefinition edgeDefinition = new ArangoGraphEdgeDefinition(
                   eD.String("collection"),
                   eD.List<String>("from"),
                   eD.List<String>("to")
                   );
                edgeDefinitions.Add(edgeDefinition);
            }
            graph.edgeDefinitions = edgeDefinitions;

            return graph;
        }
示例#17
0
        /// <summary>
        /// Removes a vertex collection from this graph. If this collection is used in one ore
        /// more edge definitions it will not be dropped, if this option is set 
        /// </summary>
        internal ArangoGraph deleteVertexCollection(string colName, bool dropCollection)
        {
            string drop = "dropCollection=false";
            if (dropCollection) {
                drop = "dropCollection=true";
            }
            var request = new Request(RequestType.Collection, HttpMethod.Delete);
            string uri = string.Join("/", _apiUri, "vertex", colName);
            request.RelativeUri = string.Join("?", uri, drop);

            var response = _connection.Process(request);

            ArangoGraph result = new ArangoGraph(_connection, _graphName);

            switch (response.StatusCode)
            {
                case HttpStatusCode.OK:
                    result = this.responseToGraph(response);
                    break;
                default:
                    if (response.IsException)
                    {
                        throw new ArangoException(
                            response.StatusCode,
                            response.Document.String("driverErrorMessage"),
                            response.Document.String("driverExceptionMessage"),
                            response.Document.Object<Exception>("driverInnerException")
                        );
                    }
                    break;
            }

            return result;
        }