当前位置: 首页>>代码示例>>C#>>正文


C# Document.String方法代码示例

本文整理汇总了C#中Document.String方法的典型用法代码示例。如果您正苦于以下问题:C# Document.String方法的具体用法?C# Document.String怎么用?C# Document.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_create_and_check_for_document_existence

        public void Should_create_and_check_for_document_existence()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            var db = Database.GetTestDatabase();

            // create document object
            var document = new Document()
                .String("foo", "foo string value")
                .Int("bar", 12345);

            // save it to database collection
            db.Document.Create(Database.TestDocumentCollectionName, document);

            // check if the created document exists in database
            var exists = db.Document.Exists(document.String("_id"));

            Assert.AreEqual(true, exists);

            // delete document
            db.Document.Delete(document.String("_id"));

            // check if the document was deleted
            exists = db.Document.Exists(document.String("_id"));

            Assert.AreEqual(false, exists);
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:26,代码来源:ArangoDocumentTests.cs

示例2: Get

        internal Document Get(string id)
        {
            var request = new Request(RequestType.Edge, HttpMethod.Get);
            request.RelativeUri = string.Join("/", _apiUri, id);

            var response = _connection.Process(request);
            var edge = new Document();

            switch (response.StatusCode)
            {
                case HttpStatusCode.OK:
                    edge = response.Document;
                    break;
                case HttpStatusCode.NotModified:
                    edge.String("_rev", response.Headers.Get("etag").Replace("\"", ""));
                    break;
                case HttpStatusCode.NotFound:
                    edge = null;
                    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 edge;
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:34,代码来源:EdgeOperation.cs

示例3: Should_create_and_delete_document

        public void Should_create_and_delete_document()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            var db = Database.GetTestDatabase();

            // create document object
            var document = new Document()
                .String("foo", "foo string value")
                .Int("bar", 12345);

            // save it to database collection
            db.Document.Create(Database.TestDocumentCollectionName, document);

            // check if it contains data after creation
            Assert.AreEqual(false, document.IsNull("_id"));
            Assert.AreEqual(false, document.IsNull("_key"));
            Assert.AreEqual(false, document.IsNull("_rev"));
            Assert.AreEqual(false, document.IsNull("foo"));
            Assert.AreEqual(false, document.IsNull("bar"));

            Assert.AreEqual(true, document.Has("foo"));
            Assert.AreEqual(true, document.Has("bar"));

            // delete created document
            var isDeleted = db.Document.Delete(document.String("_id"));

            Assert.AreEqual(true, isDeleted);
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:28,代码来源:ArangoDocumentTests.cs

示例4: Should_create_and_check_for_edge_existence

        public void Should_create_and_check_for_edge_existence()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            Database.CreateTestCollection(Database.TestEdgeCollectionName, ArangoCollectionType.Edge);
            var db = Database.GetTestDatabase();

            // create test documents
            var doc1 = new Document()
                .String("foo", "foo string value 1")
                .Int("bar", 12345);

            var doc2 = new Document()
                .String("foo", "foo string value 2")
                .Int("bar", 54321);

            db.Document.Create(Database.TestDocumentCollectionName, doc1);
            db.Document.Create(Database.TestDocumentCollectionName, doc2);

            // create test edge
            var edge = new Document()
                .String("edgeFoo", "foo string value")
                .Int("edgeBar", 12345);

            edge.String("_from", doc1.String("_id"));
            edge.String("_to", doc2.String("_id"));

            db.Edge.Create(Database.TestEdgeCollectionName, edge);

            // check if the created edge exists in database
            var exists = db.Edge.Exists(edge.String("_id"));

            Assert.AreEqual(true, exists);

            // delete edge
            db.Edge.Delete(edge.String("_id"));

            // check if the edge was deleted
            exists = db.Edge.Exists(edge.String("_id"));

            Assert.AreEqual(false, exists);
        }
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:41,代码来源:ArangoEdgeTests.cs

示例5: Post

        internal void Post(string collection, Document edge, bool waitForSync, bool createCollection)
        {
            var request = new Request(RequestType.Document, HttpMethod.Post);
            request.RelativeUri = _apiUri;
            request.Body = edge.Except("_id", "_key", "_rev", "_from", "_to").Serialize();

            // set collection name where the document will be created
            request.QueryString.Add("collection", collection);

            // set from document handle
            request.QueryString.Add("from", edge.String("_from"));

            // set to document handle
            request.QueryString.Add("to", edge.String("_to"));

            // (optional)
            if (createCollection)
            {
                request.QueryString.Add("createCollection", "true");
            }

            // (optional)
            if (waitForSync)
            {
                request.QueryString.Add("waitForSync", "true");
            }

            var response = _connection.Process(request);

            switch (response.StatusCode)
            {
                case HttpStatusCode.Created:
                case HttpStatusCode.Accepted:
                    edge.String("_id", response.Document.String("_id"));
                    edge.String("_key", response.Document.String("_key"));
                    edge.String("_rev", response.Document.String("_rev"));
                    break;
                default:
                    if (response.IsException)
                    {
                        throw new ArangoException(
                            response.StatusCode,
                            response.Document.String("driverErrorMessage"),
                            response.Document.String("driverExceptionMessage"),
                            response.Document.Object<Exception>("driverInnerException")
                        );
                    }
                    break;
            }
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:50,代码来源:EdgeOperation.cs

示例6: Post

        internal void Post(ArangoCollection collection)
        {
            var request = new Request(RequestType.Collection, HttpMethod.Post);
            request.RelativeUri = _apiUri;

            var document = new Document();

            // set collection name
            document.String("name", collection.Name);

            // (optional, default: 2) set type
            if (collection.Type != 0)
            {
                document.Enum("type", collection.Type);
            }

            // (optional, default: false) set waitForSync
            if (collection.WaitForSync)
            {
                document.Bool("waitForSync", collection.WaitForSync);
            }

            // (optional, default: arangodb config) set journalSize
            if (collection.JournalSize > 0)
            {
                document.Int("journalSize", collection.JournalSize);
            }

            // (optional, default: false) set isSystem
            if (collection.IsSystem)
            {
                document.Bool("isSystem", collection.IsSystem);
            }

            // (optional, default: false) set isVolatile
            if (collection.IsVolatile)
            {
                document.Bool("isVolatile", collection.IsVolatile);
            }

            if (collection.NumberOfShards != null)
            {
                document.Int("numberOfShards", (int) collection.NumberOfShards);
            }

            if (collection.ShardKeys != null)
            {
                document.List("shardKeys", collection.ShardKeys);
            }

            // (optional) set keyOptions
            if (collection.KeyOptions != null)
            {
                if (collection.KeyOptions.GeneratorType != 0)
                {
                    document.String("keyOptions.type", collection.KeyOptions.GeneratorType.ToString().ToLower());

                    if (collection.KeyOptions.GeneratorType == ArangoKeyGeneratorType.Autoincrement)
                    {
                        if (collection.KeyOptions.Increment > 0)
                        {
                            document.Int("keyOptions.increment", collection.KeyOptions.Increment);
                        }

                        if (collection.KeyOptions.Offset > 0)
                        {
                            document.Int("keyOptions.offset", collection.KeyOptions.Offset);
                        }
                    }
                }

                if (collection.KeyOptions.AllowUserKeys)
                {
                    document.Bool("keyOptions.allowUserKeys", collection.KeyOptions.AllowUserKeys);
                }
            }

            request.Body = Document.Serialize(document);

            var response = _connection.Process(request);

            switch (response.StatusCode)
            {
                case HttpStatusCode.OK:
                    collection.Id = response.Document.String("id");
                    collection.Name = response.Document.String("name");
                    collection.Status = response.Document.Enum<ArangoCollectionStatus>("status");
                    collection.Type = response.Document.Enum<ArangoCollectionType>("type");
                    collection.WaitForSync = response.Document.Bool("waitForSync");
                    collection.IsVolatile = response.Document.Bool("isVolatile");
                    collection.IsSystem = response.Document.Bool("isSystem");
                    break;
                default:
                    if (response.IsException)
                    {
                        throw new ArangoException(
                            response.StatusCode,
                            response.Document.String("driverErrorMessage"),
                            response.Document.String("driverExceptionMessage"),
                            response.Document.Object<Exception>("driverInnerException")
//.........这里部分代码省略.........
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:101,代码来源:CollectionOperation.cs

示例7: Should_create_and_delete_edge

        public void Should_create_and_delete_edge()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            Database.CreateTestCollection(Database.TestEdgeCollectionName, ArangoCollectionType.Edge);
            var db = Database.GetTestDatabase();

            // create test documents
            var doc1 = new Document()
                .String("foo", "foo string value 1")
                .Int("bar", 12345);

            var doc2 = new Document()
                .String("foo", "foo string value 2")
                .Int("bar", 54321);

            db.Document.Create(Database.TestDocumentCollectionName, doc1);
            db.Document.Create(Database.TestDocumentCollectionName, doc2);

            // create test edge
            var edge = new Document()
                .String("edgeFoo", "foo string value")
                .Int("edgeBar", 12345);

            edge.String("_from", doc1.String("_id"));
            edge.String("_to", doc2.String("_id"));

            db.Edge.Create(Database.TestEdgeCollectionName, edge);

            // check if it contains data after creation
            Assert.AreEqual(false, edge.IsNull("_id"));
            Assert.AreEqual(false, edge.IsNull("_key"));
            Assert.AreEqual(false, edge.IsNull("_rev"));

            Assert.AreEqual(true, edge.Has("edgeFoo"));
            Assert.AreEqual(true, edge.Has("edgeBar"));

            // delete that document
            var isDeleted = db.Edge.Delete(edge.String("_id"));

            Assert.AreEqual(true, isDeleted);
        }
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:41,代码来源:ArangoEdgeTests.cs

示例8: Should_create_edge_without_fields_and_get_it_back

        public void Should_create_edge_without_fields_and_get_it_back()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            Database.CreateTestCollection(Database.TestEdgeCollectionName, ArangoCollectionType.Edge);
            var db = Database.GetTestDatabase();

            // create test documents
            var doc1 = new Document()
                .String("foo", "foo string value 1")
                .Int("bar", 12345);

            var doc2 = new Document()
                .String("foo", "foo string value 2")
                .Int("bar", 54321);

            db.Document.Create(Database.TestDocumentCollectionName, doc1);
            db.Document.Create(Database.TestDocumentCollectionName, doc2);

            // create test edge
            var edge = db.Edge.Create(Database.TestEdgeCollectionName, doc1.String("_id"), doc2.String("_id"));

            // get the very same edge from database
            var returnedEdge = db.Edge.Get(edge.String("_id"));

            // check if created and returned edge data are equal
            Assert.AreEqual(false, edge.IsNull("_id"));
            Assert.AreEqual(false, edge.IsNull("_key"));
            Assert.AreEqual(false, edge.IsNull("_rev"));
            Assert.AreEqual(false, edge.IsNull("_from"));
            Assert.AreEqual(false, edge.IsNull("_to"));
            Assert.AreEqual(false, returnedEdge.IsNull("_id"));
            Assert.AreEqual(false, returnedEdge.IsNull("_key"));
            Assert.AreEqual(false, returnedEdge.IsNull("_rev"));
            Assert.AreEqual(false, returnedEdge.IsNull("_from"));
            Assert.AreEqual(false, returnedEdge.IsNull("_to"));

            Assert.AreEqual(edge.String("_id"), returnedEdge.String("_id"));
            Assert.AreEqual(edge.String("_key"), returnedEdge.String("_key"));
            Assert.AreEqual(edge.String("_rev"), returnedEdge.String("_rev"));
            Assert.AreEqual(edge.String("_from"), returnedEdge.String("_from"));
            Assert.AreEqual(edge.String("_to"), returnedEdge.String("_to"));
        }
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:42,代码来源:ArangoEdgeTests.cs

示例9: Should_create_a_new_edge

 public void Should_create_a_new_edge()
 {
     Document vertex1 = new Document();
     vertex1.Add("name", "a");
     vertex1 = g.addVertex(fromCol1, vertex1, false);
     Document vertex2 = new Document();
     vertex2.Add("name", "b");
     vertex2 = g.addVertex(toCol1, vertex2, false);
     Document edge = new Document();
     edge.Add("_from", vertex1.String("_id"));
     edge.Add("_to", vertex2.String("_id"));
     edge.Add("relation", "myRelation");
     Document result = g.addEdge(edgeCol1, vertex1.String("_id"), vertex2.String("_id"), edge, false);
     Assert.True(result.Has("_id"));
     Assert.True(result.Has("_key"));
     Assert.True(result.Has("_rev"));
     Assert.True(result.Has("_from"));
     Assert.AreEqual(vertex1.String("_id"), result.String("_from"));
     Assert.True(result.Has("_to"));
     Assert.AreEqual(vertex2.String("_id"), result.String("_to"));
 }
开发者ID:jjchiw,项目名称:ArangoDB-NET,代码行数:21,代码来源:ArangoGraphTests.cs

示例10: Should_create_and_get_document

        public void Should_create_and_get_document()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            var db = Database.GetTestDatabase();

            var dateUtcNow = DateTime.UtcNow;
            var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            TimeSpan span = (dateUtcNow.ToUniversalTime() - unixEpoch);

            // create document object
            var document = new Document()
                .String("foo", "foo string value")
                .Int("bar", 12345)
                .DateTime("dateTime", dateUtcNow);

            // save it to database collection
            db.Document.Create(Database.TestDocumentCollectionName, document);

            // get the very same document from database
            var returnedDocument = db.Document.Get(document.String("_id"));

            // check if created and returned document data are equal

            Assert.AreEqual(false, document.IsNull("_id"));
            Assert.AreEqual(false, document.IsNull("_key"));
            Assert.AreEqual(false, document.IsNull("_rev"));
            Assert.AreEqual(false, document.IsNull("foo"));
            Assert.AreEqual(false, document.IsNull("bar"));
            Assert.AreEqual(false, document.IsNull("dateTime"));
            Assert.AreEqual(false, returnedDocument.IsNull("_id"));
            Assert.AreEqual(false, returnedDocument.IsNull("_key"));
            Assert.AreEqual(false, returnedDocument.IsNull("_rev"));
            Assert.AreEqual(false, returnedDocument.IsNull("foo"));
            Assert.AreEqual(false, returnedDocument.IsNull("bar"));
            Assert.AreEqual(false, returnedDocument.IsNull("dateTime"));

            Assert.AreEqual(document.String("_id"), returnedDocument.String("_id"));
            Assert.AreEqual(document.String("_key"), returnedDocument.String("_key"));
            Assert.AreEqual(document.String("_rev"), returnedDocument.String("_rev"));
            Assert.AreEqual(document.Has("foo"), returnedDocument.Has("foo"));
            Assert.AreEqual(document.String("foo"), returnedDocument.String("foo"));
            Assert.AreEqual(document.Has("bar"), returnedDocument.Has("bar"));
            Assert.AreEqual(document.Int("bar"), returnedDocument.Int("bar"));
            Assert.AreEqual(typeof(long), returnedDocument.Type("dateTime"));
            Assert.AreEqual(typeof(DateTime), returnedDocument.DateTime("dateTime").GetType());
            Assert.AreEqual((long)span.TotalSeconds, document.Long("dateTime"));
            Assert.AreEqual(dateUtcNow.ToString("yyyy-MM-dd HH:mm:ss"), document.DateTime("dateTime").ToString("yyyy-MM-dd HH:mm:ss"));
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:48,代码来源:ArangoDocumentTests.cs

示例11: Should_get_an_existing_edge_from_a_graph

 public void Should_get_an_existing_edge_from_a_graph()
 {
     Document vertex1 = new Document();
     vertex1.Add("name", "a");
     vertex1 = g.addVertex(fromCol1, vertex1, false);
     Document vertex2 = new Document();
     vertex2.Add("name", "b");
     vertex2 = g.addVertex(toCol1, vertex2, false);
     Document edge = new Document();
     edge.Add("_from", vertex1.String("_id"));
     edge.Add("_to", vertex2.String("_id"));
     edge.Add("relation", "myRelation");
     edge = g.addEdge(edgeCol1, vertex1.String("_id"), vertex2.String("_id"), edge, false);
     string key = edge.String("_key");
     Document result = g.getEdge(edgeCol1, key);
     Assert.True(result.Has("_from"));
     Assert.AreEqual(vertex1.String("_id"), result.String("_from"));
     Assert.True(result.Has("_to"));
     Assert.AreEqual(vertex2.String("_id"), result.String("_to"));
     Assert.True(result.Has("relation"));
     Assert.AreEqual("myRelation", result.String("relation"));
 }
开发者ID:jjchiw,项目名称:ArangoDB-NET,代码行数:22,代码来源:ArangoGraphTests.cs

示例12: Should_create_and_replace_and_get_document

        public void Should_create_and_replace_and_get_document()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            var db = Database.GetTestDatabase();

            // create document object
            var document = new Document()
                .String("foo", "foo string value")
                .Int("bar", 12345);

            // save it to database collection
            db.Document.Create(Database.TestDocumentCollectionName, document);

            // create new document object
            var newDocument = new Document()
                .String("_id", document.String("_id"))
                .String("baz.foo", "bar string value");

            // replace previously created document with new one
            var isReplaced = db.Document.Replace(newDocument);

            Assert.AreEqual(true, isReplaced);

            // get the very same document from database
            var returnedDocument = db.Document.Get(document.String("_id"));

            // check if the data of replaced and returned document are equal
            Assert.AreEqual(false, document.IsNull("_id"));
            Assert.AreEqual(false, document.IsNull("_key"));
            Assert.AreEqual(false, document.IsNull("_rev"));
            Assert.AreEqual(false, document.IsNull("foo"));
            Assert.AreEqual(false, document.IsNull("bar"));
            Assert.AreEqual(false, newDocument.IsNull("_id"));
            Assert.AreEqual(false, newDocument.IsNull("_key"));
            Assert.AreEqual(false, newDocument.IsNull("_rev"));
            Assert.AreEqual(false, newDocument.IsNull("baz.foo"));
            Assert.AreEqual(false, returnedDocument.IsNull("_id"));
            Assert.AreEqual(false, returnedDocument.IsNull("_key"));
            Assert.AreEqual(false, returnedDocument.IsNull("_rev"));
            Assert.AreEqual(false, returnedDocument.IsNull("baz.foo"));

            Assert.AreEqual(newDocument.String("_id"), returnedDocument.String("_id"));
            Assert.AreEqual(newDocument.String("_key"), returnedDocument.String("_key"));
            Assert.AreEqual(newDocument.String("_rev"), returnedDocument.String("_rev"));
            Assert.AreEqual(newDocument.Has("baz.foo"), returnedDocument.Has("baz.foo"));
            Assert.AreEqual(newDocument.String("baz.foo"), returnedDocument.String("baz.foo"));

            // check if the original data doesn't exist anymore
            Assert.AreEqual(false, newDocument.Has("foo"));
            Assert.AreEqual(false, newDocument.Has("bar"));
            Assert.AreEqual(false, returnedDocument.Has("foo"));
            Assert.AreEqual(false, returnedDocument.Has("bar"));
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:53,代码来源:ArangoDocumentTests.cs

示例13: Should_create_autoincrement_collection

        public void Should_create_autoincrement_collection()
        {
            var db = Database.GetTestDatabase();

            if (db.Server.Role().IsCluster())
            {
                // do not execute this test on a coordinator
                return;
            }

            Database.DeleteTestCollection(Database.TestDocumentCollectionName);

            // set collection data
            var collection = new ArangoCollection();
            collection.Name = Database.TestDocumentCollectionName;
            collection.KeyOptions = new ArangoCollectionKeyOptions();
            collection.KeyOptions.GeneratorType = ArangoKeyGeneratorType.Autoincrement;

            // create collection in database
            db.Collection.Create(collection);

            // create document
            var document1 = new Document()
                .String("foo", "foo string value");

            db.Document.Create(Database.TestDocumentCollectionName, document1);

            // check if the created document key starts with number 1
            Assert.AreEqual("1", document1.String("_key"));

            // create another document
            var document2 = new Document()
                .String("foo", "foo string value");

            db.Document.Create(Database.TestDocumentCollectionName, document2);

            // check if the created document key is autoincremented to 2
            Assert.AreEqual("2", document2.String("_key"));
        }
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:39,代码来源:ArangoCollectionTests.cs

示例14: documentToGraph

        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;
        }
开发者ID:jjchiw,项目名称:ArangoDB-NET,代码行数:24,代码来源:GraphGraphOperation.cs

示例15: GetDocument

        private Document GetDocument(string query, string urlPath)
        {
            var request = new Request(RequestType.Cursor, HttpMethod.Put);
            request.RelativeUri = _apiUri + urlPath;
            request.Body = query;

            var response = _connection.Process(request);
            var document = new Document();

            switch (response.StatusCode)
            {
                case HttpStatusCode.OK:
                    document = response.Document.Object("document");
                    break;
                case HttpStatusCode.NotModified:
                    document.String("_rev", response.Headers.Get("etag").Replace("\"", ""));
                    break;
                case HttpStatusCode.NotFound:
                    document = null;
                    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 document;
        }
开发者ID:jjchiw,项目名称:ArangoDB-NET,代码行数:35,代码来源:SimpleQueryOperation.cs


注:本文中的Document.String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。