public void ShouldCreateDocumentClassSet()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";
                    document
                        .SetField("foo", "foo string value")
                        .SetField("bar", 12345);

                    ODocument createdDocument = database
                        .Create.Document("TestClass")
                        .Set(document)
                        .Run();

                    Assert.NotNull(createdDocument.ORID);
                    Assert.Equal("TestClass", createdDocument.OClassName);
                    Assert.Equal(document.GetField<string>("foo"), createdDocument.GetField<string>("foo"));
                    Assert.Equal(document.GetField<int>("bar"), createdDocument.GetField<int>("bar"));
                }
            }
        }
        internal static ODocument Deserialize(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord)
        {
            ODocument document = new ODocument();
            document.ORID = orid;
            document.OVersion = version;
            document.OType = type;
            document.OClassId = classId;

            string recordString = BinarySerializer.ToString(rawRecord).Trim();

            int atIndex = recordString.IndexOf('@');
            int colonIndex = recordString.IndexOf(':');
            int index = 0;

            // parse class name
            if ((atIndex != -1) && (atIndex < colonIndex))
            {
                document.OClassName = recordString.Substring(0, atIndex);
                index = atIndex + 1;
            }

            // start document parsing with first field name
            do
            {
                index = ParseFieldName(index, recordString, document);
            }
            while (index < recordString.Length);

            return document;
        }
        public override ODocument Response(Response response)
        {
            Dictionary<ORID, int> entries = new Dictionary<ORID, int>();

            ODocument document = new ODocument();
            if (response == null)
            {
                return document;
            }

            var reader = response.Reader;
            if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
                ReadToken(reader);

            // (count:int)[(key:binary)(value:binary)]
            var bytesLength = reader.ReadInt32EndianAware();
            var count = reader.ReadInt32EndianAware();
            for (int i = 0; i < count; i++)
            {
                // key
                short clusterId = reader.ReadInt16EndianAware();
                long clusterPosition = reader.ReadInt64EndianAware();
                var rid = new ORID(clusterId, clusterPosition);

                // value
                var value = reader.ReadInt32EndianAware();

                entries.Add(rid, value);
            }
            document.SetField<Dictionary<ORID, int>>("entries", entries);
            return document;
        }
Esempio n. 4
0
        public override ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return document;
            }

            var reader = response.Reader;

            if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
                ReadToken(reader);

            short len = reader.ReadInt16EndianAware();
            Dictionary<string, string> configList = new Dictionary<string, string>();
            for (int i = 0; i < len; i++)
            {
                string key = reader.ReadInt32PrefixedString();
                string value = reader.ReadInt32PrefixedString();
                configList.Add(key, value);
            }
            document.SetField<Dictionary<string, string>>("config", configList);
            return document;
        }
        public void ShouldInsertDocumentInto()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document = new ODocument()
                        .SetField("foo", "foo string value")
                        .SetField("bar", 12345);

                    ODocument insertedDocument = database
                        .Insert(document)
                        .Into("TestClass")
                        .Run();

                    Assert.IsTrue(insertedDocument.ORID != null);
                    Assert.AreEqual(insertedDocument.OClassName, "TestClass");
                    Assert.AreEqual(insertedDocument.GetField<string>("foo"), document.GetField<string>("foo"));
                    Assert.AreEqual(insertedDocument.GetField<int>("bar"), document.GetField<int>("bar"));


                }
            }
        }
        private static string SerializeDocument(ODocument document)
        {
            string serializedString = "";

            if (document.Keys.Count > 0)
            {
                int iteration = 0;

                foreach (KeyValuePair<string, object> field in document)
                {
                    // serialize only fields which doesn't start with @ character
                    if ((field.Key.Length > 0) && (field.Key[0] != '@'))
                    {
                        serializedString += field.Key + ":";
                        serializedString += SerializeValue(field.Value);
                    }

                    iteration++;

                    if (iteration < document.Keys.Count)
                    {
                        if ((field.Key.Length > 0) && (field.Key[0] != '@'))
                        {
                            serializedString += ",";
                        }
                    }
                }
            }

            return serializedString;
        }
Esempio n. 7
0
        public override ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return document;
            }

            var reader = response.Reader;
            if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
                ReadToken(reader);

            // operation specific fields
            byte existByte = reader.ReadByte();

            if (existByte == 0)
            {
                document.SetField("Exists", false);
            }
            else
            {
                document.SetField("Exists", true);
            }

            return document;
        }
        public void ShouldDeleteDocumentFromDocumentOClassName()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    database
                        .Create.Document("TestClass")
                        .Set("foo", "foo string value1")
                        .Set("bar", 12345)
                        .Run();

                    database
                        .Create.Document("TestClass")
                        .Set("foo", "foo string value2")
                        .Set("bar", 54321)
                        .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";

                    int documentsDeleted = database
                        .Delete.Document(document)
                        .Run();

                    Assert.AreEqual(documentsDeleted, 2);
                }
            }
        }
        public void ShouldFetchLinkedDocumentsFromSimpleQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                database.Create.Class("Owner").Extends("V").Run();
                database.Create.Class("Computer").Extends("V").Run();
                var owner = new ODocument { OClassName = "Owner" };

                owner.SetField<String>("name", "Shawn");

                owner = database.Create.Vertex(owner).Run();

                var computer = new ODocument { OClassName = "Computer" };

                computer.SetField<ORID>("owner", owner.ORID);
                database.Create.Vertex(computer).Run();

                computer = database.Query("SELECT FROM Computer", "*:-1").FirstOrDefault();

                Assert.That(database.ClientCache.ContainsKey(computer.GetField<ORID>("owner")));

                var document = database.ClientCache[computer.GetField<ORID>("owner")];
                Assert.That(document.GetField<string>("name"), Is.EqualTo("Shawn"));
            }
        }
Esempio n. 10
0
        public ODocument Response(Response response)
        {
            // start from this position since standard fields (status, session ID) has been already parsed
            int offset = 5;
            ODocument document = new ODocument();

            if (response == null)
            {
                return document;
            }

            // operation specific fields
            byte existByte = BinarySerializer.ToByte(response.Data.Skip(offset).Take(1).ToArray());
            offset += 1;

            if (existByte == 0)
            {
                document.SetField("Exists", false);
            }
            else
            {
                document.SetField("Exists", true);
            }

            return document;
        }
        public void ShouldSerializeNumbers()
        {
            string recordString = "TestClass@ByteNumber:123b,ShortNumber:1234s,IntNumber:123456,LongNumber:12345678901l,FloatNumber:3.14f,DoubleNumber:3.14d,DecimalNumber:1234567.8901c,embedded:(ByteNumber:123b,ShortNumber:1234s,IntNumber:123456,LongNumber:12345678901l,FloatNumber:3.14f,DoubleNumber:3.14d,DecimalNumber:1234567.8901c)";

            ODocument document = new ODocument()
                .SetField("@ClassName", "TestClass")
                .SetField("ByteNumber", byte.Parse("123"))
                .SetField("ShortNumber", short.Parse("1234"))
                .SetField("IntNumber", 123456)
                .SetField("LongNumber", 12345678901)
                .SetField("FloatNumber", 3.14f)
                .SetField("DoubleNumber", 3.14)
                .SetField("DecimalNumber", new Decimal(1234567.8901))
                .SetField("embedded.ByteNumber", byte.Parse("123"))
                .SetField("embedded.ShortNumber", short.Parse("1234"))
                .SetField("embedded.IntNumber", 123456)
                .SetField("embedded.LongNumber", 12345678901)
                .SetField("embedded.FloatNumber", 3.14f)
                .SetField("embedded.DoubleNumber", 3.14)
                .SetField("embedded.DecimalNumber", new Decimal(1234567.8901));

            string serializedRecord = document.Serialize();

            Assert.AreEqual(serializedRecord, recordString);
        }
        public void TestLoadWithFetchPlanNoLinks()
        {
            using (var testContext = new TestDatabaseContext())
            using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                // prerequisites
                database
                    .Create.Class("TestClass")
                    .Run();

                ODocument document = new ODocument()
                    .SetField("foo", "foo string value")
                    .SetField("bar", 12345);

                ODocument insertedDocument = database
                    .Insert(document)
                    .Into("TestClass")
                    .Run();
                var loaded = database.Load.ORID(insertedDocument.ORID).FetchPlan("*:1").Run();
                Assert.AreEqual("TestClass", loaded.OClassName);
                Assert.AreEqual(document.GetField<string>("foo"), loaded.GetField<string>("foo"));
                Assert.AreEqual(document.GetField<int>("bar"), loaded.GetField<int>("bar"));
                Assert.AreEqual(insertedDocument.ORID, loaded.ORID);

            }
        }
        //[Fact]
        public void ShouldDeserializeWholeStructure()
        {
            /*
                The whole record is structured in three main segments
                +---------------+------------------+---------------+-------------+
                | version:byte   | className:string | header:byte[] | data:byte[]  |
                +---------------+------------------+---------------+-------------+
             */


            //byte version = 0;
            byte[] className = Encoding.UTF8.GetBytes("TestClass");
            byte[] header = new byte[0];
            byte[] data = new byte[0];

            //string serString = "ABJUZXN0Q2xhc3MpAAAAEQDI/wE=";
            string serString1 = "AAxQZXJzb24EaWQAAABEBwhuYW1lAAAAaQcOc3VybmFtZQAAAHAHEGJpcnRoZGF5AAAAdwYQY2hpbGRyZW4AAAB9AQBIZjk1M2VjNmMtNGYyMC00NDlhLWE2ODQtYjQ2ODkxNmU4NmM3DEJpbGx5MQxNYXllczGUlfWVo1IC/wE=";

            var document = new ODocument();
            document.OClassName = "TestClass";
            document.SetField<DateTime>("_date", DateTime.Now);

            var createdDocument = database
                .Create
                .Document(document)
                .Run();

            Assert.Equal(document.GetField<DateTime>("_date").Date, createdDocument.GetField<DateTime>("eeee"));
            var serBytes1 = Convert.FromBase64String(serString1);
            var doc = serializer.Deserialize(serBytes1, new ODocument());
        }
        public void ShouldGenerateCreateEdgeObjectFromDocumentToDocumentQuery()
        {
            TestProfileClass profile = new TestProfileClass();
            profile.Name = "Johny";
            profile.Surname = "Bravo";

            ODocument vertexFrom = new ODocument();
            vertexFrom.ORID = new ORID(8, 0);

            ODocument vertexTo = new ODocument();
            vertexTo.ORID = new ORID(8, 1);

            string generatedQuery = new OSqlCreateEdge()
                .Edge(profile)
                .From(vertexFrom)
                .To(vertexTo)
                .ToString();

            string query =
                "CREATE EDGE TestProfileClass " +
                "FROM #8:0 TO #8:1 " +
                "SET Name = 'Johny', " +
                "Surname = 'Bravo'";

            Assert.AreEqual(generatedQuery, query);
        }
        public void ShouldRetrieveRecordMetadata()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    database
                        .Create
                        .Class("TestClass")
                        .Run();

                    var document = new ODocument();
                    document.OClassName = "TestClass";
                    document.SetField("bar", 12345);
                    document.SetField("foo", "foo value 345");

                    var createdDocument = database
                        .Create
                        .Document(document)
                        .Run();

                    var metadata = database
                        .Metadata
                        .ORID(createdDocument.ORID)
                        .Run();
                    Assert.IsNotNull(metadata);
                    Assert.AreEqual(createdDocument.ORID, metadata.ORID);
                    Assert.AreEqual(createdDocument.OVersion, metadata.OVersion);

                }
            }
        }
Esempio n. 16
0
 public RecordCreate(ODocument document, ODatabase database)
     : base(database)
 {
     _document = document;
     _database = database;
     _operationType = OperationType.RECORD_CREATE;
 }
        public void ShouldCreateVertexFromDocument()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestVertexClass")
                        .Extends<OVertex>()
                        .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestVertexClass";
                    document
                        .SetField("foo", "foo string value")
                        .SetField("bar", 12345);

                    OVertex createdVertex = database
                        .Create.Vertex(document)
                        .Run();

                    Assert.IsNotNull(createdVertex.ORID);
                    Assert.AreEqual("TestVertexClass", createdVertex.OClassName);
                    Assert.AreEqual(document.GetField<string>("foo"), createdVertex.GetField<string>("foo"));
                    Assert.AreEqual(document.GetField<int>("bar"), createdVertex.GetField<int>("bar"));
                }
            }
        }
        private OCommandResult RunInternal()
        {
            try
            {
                if (_parameters == null)
                    throw new ArgumentNullException("_parameters");

                var paramsDocument = new ODocument();
                paramsDocument.OClassName = "";
                paramsDocument.SetField(OClient.ProtocolVersion < 22 ? "params" : "parameters", _parameters);

                var serializer = RecordSerializerFactory.GetSerializer(_connection.Database);


                CommandPayloadCommand payload = new CommandPayloadCommand();
                payload.Text = ToString();
                payload.SimpleParams = serializer.Serialize(paramsDocument);

                Command operation = new Command(_connection.Database);
                operation.OperationMode = OperationMode.Synchronous;
                operation.CommandPayload = payload;

                ODocument document = _connection.ExecuteOperation(operation);

                return new OCommandResult(document);
            }
            finally
            {
                _parameters = null;
            }
        }
Esempio n. 19
0
        public ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return document;
            }

            var reader = response.Reader;

            // operation specific fields
            byte existByte = reader.ReadByte();

            if (existByte == 0)
            {
                document.SetField("Exists", false);
            }
            else
            {
                document.SetField("Exists", true);
            }

            return document;
        }
Esempio n. 20
0
        public ODocument Response(Response response)
        {
            // start from this position since standard fields (status, session ID) has been already parsed
            int offset = 5;
            ODocument document = new ODocument();

            if (response == null)
            {
                return document;
            }

            // operation specific fields
            document.SetField("SessionId", BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray()));
            offset += 4;
            short clusterCount = BinarySerializer.ToShort(response.Data.Skip(offset).Take(2).ToArray());
            document.SetField("ClusterCount", clusterCount);
            offset += 2;

            if (clusterCount > 0)
            {
                List<OCluster> clusters = new List<OCluster>();

                for (int i = 1; i <= clusterCount; i++)
                {
                    OCluster cluster = new OCluster();

                    int clusterNameLength = BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray());
                    offset += 4;

                    cluster.Name = BinarySerializer.ToString(response.Data.Skip(offset).Take(clusterNameLength).ToArray());
                    offset += clusterNameLength;

                    cluster.Id = BinarySerializer.ToShort(response.Data.Skip(offset).Take(2).ToArray());
                    offset += 2;

                    int clusterTypeLength = BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray());
                    offset += 4;

                    string clusterName = BinarySerializer.ToString(response.Data.Skip(offset).Take(clusterTypeLength).ToArray());
                    cluster.Type = (OClusterType)Enum.Parse(typeof(OClusterType), clusterName, true);
                    offset += clusterTypeLength;

                    cluster.DataSegmentID = BinarySerializer.ToShort(response.Data.Skip(offset).Take(2).ToArray());
                    offset += 2;

                    clusters.Add(cluster);
                }

                document.SetField("Clusters", clusters);
            }

            int clusterConfigLength = BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray());
            offset += 4;

            document.SetField("ClusterConfig", response.Data.Skip(offset).Take(clusterConfigLength).ToArray());
            offset += clusterConfigLength;

            return document;
        }
        public ODocument Deserialize(byte[] recordString, ODocument document)
        {
            using (var stream = new MemoryStream(recordString))
            using (var reader = new BinaryReader(stream))
            {

                return Deserialize(reader, document);
            }
        }
        //[Fact]
        public void ShouldSerializeDocumnet()
        {
            //string serString = "ABJUZXN0Q2xhc3MpAAAAEQDI/wE=";
            ODocument document = new ODocument();
            document.OClassName = "TestClass";
            document.SetField<DateTime>("eeee", new DateTime(635487552000000000));

            var str = Convert.ToBase64String(serializer.Serialize(document));
        }
        private ODocument Deserialize(BinaryReader reader, ODocument document)
        {
            var serializerVersion = reader.ReadByte();
            var classNameLength = readAsInteger(reader);
            var className = Encoding.UTF8.GetString(reader.ReadBytesRequired(classNameLength));
            document.OClassName = className;

            return parseDocument(reader, document);
        }
        public byte[] Serialize(ODocument document)
        {
            if (!document.HasField("@OClassName"))
            {
                throw new OException(OExceptionType.Serialization, "Document doesn't contain @OClassName field which is required for serialization.");
            }

            return Encoding.UTF8.GetBytes(document.GetField<string>("@OClassName") + "@" + SerializeDocument(document));
        }
        internal static string Serialize(ODocument document)
        {
            if (!document.HasField("@ClassName"))
            {
                throw new OException(OExceptionType.Serialization, "Document doesn't contain @ClassName field which is required for serialization.");
            }

            return document.GetField<string>("@ClassName") + "@" + SerializeDocument(document);
        }
        public void ShouldUpdateClassFromDocument()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";
                    document
                        .SetField("foo", "foo string value")
                        .SetField("bar", 12345);

                    database
                        .Insert(document)
                        .Run();

                    database
                        .Insert(document)
                        .Run();

                    document
                        .SetField("bar", 54321)
                        .SetField("baz", "new baz value");

                    int documentsUpdated = database
                        .Update(document)
                        .Run();

                    Assert.AreEqual(documentsUpdated, 2);

                    List<ODocument> documents = database
                        .Select()
                        .From("TestClass")
                        .ToList();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, document.OClassName);
                        Assert.AreEqual(documents[i].GetField<string>("foo"), document.GetField<string>("foo"));
                        Assert.AreEqual(documents[i].GetField<int>("bar"), document.GetField<int>("bar"));
                        Assert.AreEqual(documents[i].GetField<string>("baz"), document.GetField<string>("baz"));
                    }
                }
            }
        }
        internal static ODocument Deserialize(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord)
        {
            ODocument document = new ODocument();
            document.ORID = orid;
            document.OVersion = version;
            document.OType = type;
            document.OClassId = classId;

            string recordString = BinarySerializer.ToString(rawRecord).Trim();

            return Deserialize(recordString, document);
        }
Esempio n. 28
0
 public ODocument Response(Response response)
 {
     ODocument document = new ODocument();
     if (response == null)
     {
         return document;
     }
     var reader = response.Reader;
     int recordLength = reader.ReadInt32EndianAware();
     byte[] rawRecord = reader.ReadBytes(recordLength);
     document = RecordSerializer.Deserialize(BinarySerializer.ToString(rawRecord).Trim(), document);
     return document;
 }
        public void ShouldSerializeNull()
        {
            string recordString = "TestClass@null:,embedded:(null:)";

            ODocument document = new ODocument()
                .SetField("@OClassName", "TestClass")
                .SetField<object>("null", null)
                .SetField<object>("embedded.null", null);

            string serializedRecord = Encoding.UTF8.GetString(serializer.Serialize(document));

            Assert.Equal(serializedRecord, recordString);
        }
        public void ShouldSerializeNull()
        {
            string recordString = "TestClass@null:,embedded:(null:)";

            ODocument document = new ODocument()
                .SetField("@ClassName", "TestClass")
                .SetField<object>("null", null)
                .SetField<object>("embedded.null", null);

            string serializedRecord = document.Serialize();

            Assert.AreEqual(serializedRecord, recordString);
        }
        public override ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return(document);
            }

            var reader       = response.Reader;
            var b            = reader.ReadByte();
            var removeLocaly = b == 1 ? true : false;

            document.SetField <bool>("remove_localy", removeLocaly);
            return(document);
        }
        public ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return(document);
            }

            var reader = response.Reader;

            document.ORID     = ReadORID(reader);
            document.OVersion = reader.ReadInt32EndianAware();

            return(document);
        }
        public IOCreateEdge Set <T>(T obj)
        {
            var document = obj is ODocument ? obj as ODocument : ODocument.ToDocument(obj);

            // TODO: go also through embedded fields
            foreach (KeyValuePair <string, object> field in document)
            {
                // set only fields which doesn't start with @ character
                if ((field.Key.Length > 0) && (field.Key[0] != '@'))
                {
                    Set(field.Key, field.Value);
                }
            }

            return(this);
        }
        public void TestDeserializeSubObject()
        {
            string recordString = "TheThing:(Value:17,Text:\"blah\")";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            TypeMapper <TestHasAThing> tm = TypeMapper <TestHasAThing> .Instance;
            var t = new TestHasAThing();

            tm.ToObject(document, t);

            Assert.NotNull(t.TheThing);
            Assert.Equal(17, t.TheThing.Value);
            Assert.Equal("blah", t.TheThing.Text);
        }
Esempio n. 35
0
        public override ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return(document);
            }

            var reader    = response.Reader;
            var clusterid = reader.ReadInt16EndianAware();

            document.SetField <short>("clusterid", clusterid);

            return(document);
        }
        public void TestDeserializeList()
        {
            string recordString = "values:[1,2,3,4,5]";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            TypeMapper <TestList> tm = TypeMapper <TestList> .Instance;
            var t = new TestList();

            tm.ToObject(document, t);

            Assert.NotNull(t.values);
            Assert.Equal(5, t.values.Count);
            Assert.Equal(3, t.values[2]);
        }
Esempio n. 37
0
        public override ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return(document);
            }

            var reader = response.Reader;
            var size   = reader.ReadInt64EndianAware();

            document.SetField <long>("size", size);

            return(document);
        }
Esempio n. 38
0
        public void TestDeserializeList()
        {
            string recordString = "values:[1,2,3,4,5]";

            ODocument document = ODocument.Deserialize(recordString);


            TypeMapper <TestList> tm = TypeMapper <TestList> .Instance;
            var t = new TestList();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.values);
            Assert.AreEqual(5, t.values.Count);
            Assert.AreEqual(3, t.values[2]);
        }
Esempio n. 39
0
        public ODocument Response(Response response)
        {
            ODocument document = new ODocument();

            if (response == null)
            {
                return(document);
            }

            var reader = response.Reader;

            // operation specific fields
            document.SetField("SessionId", reader.ReadInt32EndianAware());

            return(document);
        }
Esempio n. 40
0
        public void ShouldDeserializeSingleItemToOneElementList()
        {
            string recordString = "single:#10:12345,list:[#11:123,#22:1234,#33:1234567]";

            ODocument document = ODocument.Deserialize(recordString);

            // check for fields existence
            Assert.AreEqual(document.HasField("single"), true);
            Assert.AreEqual(document.HasField("list"), true);

            // check for fields values
            List <ORID> collection = document.GetField <List <ORID> >("single");

            Assert.AreEqual(collection.Count, 1);
            Assert.AreEqual(collection[0], new ORID(10, 12345));
        }
        public override ODocument Response(Response response)
        {
            ODocument responseDocument = new ODocument();

            if (response == null)
            {
                return(responseDocument);
            }

            var reader = response.Reader;

            if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
            {
                ReadToken(reader);
            }

            while (true)
            {
                PayloadStatus payload_status = (PayloadStatus)reader.ReadByte();

                bool done = false;
                switch (payload_status)
                {
                case PayloadStatus.NoRemainingRecords:
                    done = true;
                    break;

                case PayloadStatus.ResultSet:
                    ReadPrimaryResult(responseDocument, reader);
                    break;

                case PayloadStatus.PreFetched:
                    ReadAssociatedResult(reader);
                    break;

                default:
                    throw new InvalidOperationException();
                }

                if (done)
                {
                    break;
                }
            }

            return(responseDocument);
        }
Esempio n. 42
0
        public void ShouldUpdateRemoveFieldQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument document1 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value1")
                                          .Set("bar", 11111)
                                          .Run();

                    ODocument document2 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value2")
                                          .Set("bar", 12345)
                                          .Run();

                    int documentsUpdated = database
                                           .Update(document2)
                                           .Remove("bar")
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("TestClass")
                                                 .Where("foo").Equals("foo string value2")
                                                 .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);
                    Assert.AreEqual(documents[0].GetField <string>("foo"), document2.GetField <string>("foo"));
                    Assert.IsFalse(documents[0].HasField("bar"));
                }
            }
        }
Esempio n. 43
0
        public void TestDeserializeSubObjectList()
        {
            string recordString = "TheThings:[(Value:17,Text:\"blah\"),(Value:18,Text:\"foo\")]";

            ODocument document = ODocument.Deserialize(recordString);


            TypeMapper <TestHasListThings> tm = TypeMapper <TestHasListThings> .Instance;
            var t = new TestHasListThings();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.TheThings);
            Assert.AreEqual(2, t.TheThings.Count);
            Assert.AreEqual(18, t.TheThings[1].Value);
            Assert.AreEqual("foo", t.TheThings[1].Text);
        }
Esempio n. 44
0
        public void TestDeserializeSingleSubObjectArray()
        {
            string recordString = "TheThings:[(Value:18,Text:\"foo\")]";

            ODocument document = ODocument.Deserialize(recordString);


            TypeMapper <TestHasThings> tm = TypeMapper <TestHasThings> .Instance;
            var t = new TestHasThings();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.TheThings);
            Assert.AreEqual(1, t.TheThings.Length);
            Assert.AreEqual(18, t.TheThings[0].Value);
            Assert.AreEqual("foo", t.TheThings[0].Text);
        }
Esempio n. 45
0
        public void ShouldDeserializeSimpleEmbeddedrecordsArray()
        {
            string recordString = "array:[(joe1:\"js1\"),(joe2:\"js2\"),(joe3:\"js3\")]";

            ODocument document = ODocument.Deserialize(recordString);

            // check for fields existence
            Assert.AreEqual(document.HasField("array"), true);

            // check for fields values
            List <ODocument> array = document.GetField <List <ODocument> >("array");

            Assert.AreEqual(array.Count, 3);
            Assert.AreEqual(array[0].GetField <string>("joe1"), "js1");
            Assert.AreEqual(array[1].GetField <string>("joe2"), "js2");
            Assert.AreEqual(array[2].GetField <string>("joe3"), "js3");
        }
Esempio n. 46
0
        public void ShouldGenerateSelectFromDocumentOClassNameQuery()
        {
            ODocument document = new ODocument();

            document.OClassName = "TestClass";

            string generatedQuery = new OSqlSelect()
                                    .Select("foo", "bar")
                                    .From(document)
                                    .ToString();

            string query =
                "SELECT foo, bar " +
                "FROM TestClass";

            Assert.Equal(generatedQuery, query);
        }
Esempio n. 47
0
        public void ShouldGenerateSelectFromDocumentOridQuery()
        {
            ODocument document = new ODocument();

            document.ORID = new ORID(8, 0);

            string generatedQuery = new OSqlSelect()
                                    .Select("foo", "bar")
                                    .From(document)
                                    .ToString();

            string query =
                "SELECT foo, bar " +
                "FROM #8:0";

            Assert.Equal(generatedQuery, query);
        }
        public void ShouldGenerateDeleteDocumentFromDocumentOridQuery()
        {
            ODocument document = new ODocument();

            document.OClassName = "TestVertexClass";
            document.ORID       = new ORID(8, 0);

            string generatedQuery = new OSqlDeleteDocument()
                                    .Delete(document)
                                    .ToString();

            string query =
                "DELETE FROM TestVertexClass " +
                "WHERE @rid = #8:0";

            Assert.AreEqual(generatedQuery, query);
        }
Esempio n. 49
0
        public ODocument Response(Response response)
        {
            ODocument responseDocument = _document;


            if (response == null)
            {
                return(responseDocument);
            }

            var reader = response.Reader;

            _document.ORID.ClusterPosition = reader.ReadInt64EndianAware();
            _document.OVersion             = reader.ReadInt32EndianAware();

            return(responseDocument);
        }
        public override ODocument Response(Response response)
        {
            ODocument responseDocument = _document;


            if (response == null)
            {
                return(responseDocument);
            }

            var reader = response.Reader;

            if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
            {
                ReadToken(reader);
            }

            if (OClient.ProtocolVersion > 25)
            {
                _document.ORID.ClusterId = reader.ReadInt16EndianAware();
            }

            _document.ORID.ClusterPosition = reader.ReadInt64EndianAware();

            if (OClient.ProtocolVersion >= 11)
            {
                _document.OVersion = reader.ReadInt32EndianAware();
            }

            // Work around differents in storage type < version 2.0
            if (_database.ProtocolVersion >= 28 || (_database.ProtocolVersion >= 20 && _database.ProtocolVersion <= 27 && !EndOfStream(reader)))
            {
                int collectionChangesCount = reader.ReadInt32EndianAware();
                if (collectionChangesCount > 0)
                //for (var i = 0; i < collectionChangesCount; i++)
                {
                    throw new NotImplementedException("Collection changes not yet handled - failing rather than ignoring potentially significant information");
                    //var mostSigBits = reader.ReadInt64EndianAware();
                    //var leastSigBits = reader.ReadInt64EndianAware();
                    //var updatedFileId = reader.ReadInt64EndianAware();
                    //var updatedPageIndex = reader.ReadInt64EndianAware();
                    //var updatedPageOffset = reader.ReadInt32EndianAware();
                }
            }
            return(responseDocument);
        }
Esempio n. 51
0
        public ODocument Response(Response response)
        {
            // start from this position since standard fields (status, session ID) has been already parsed
            int       offset   = 5;
            ODocument document = new ODocument();

            if (response == null)
            {
                return(document);
            }

            // operation specific fields
            document.SetField("SessionId", BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray()));
            offset += 4;

            return(document);
        }
        public void ShouldSerializeByteArray()
        {
            string recordString = "TestClass@data:_AQIDBAU=_";

            ODocument document = new ODocument()
                                 .SetField("@OClassName", "TestClass")
                                 .SetField("data", new byte[] { 1, 2, 3, 4, 5 });

            string serializedString = Encoding.UTF8.GetString(serializer.Serialize(document));

            Assert.Equal(serializedString, recordString);

            var deserialized = serializer.Deserialize(Encoding.UTF8.GetBytes(serializedString), new ODocument());

            byte[] data = deserialized.GetField <byte[]>("data");
            Assert.True(data.SequenceEqual(new byte[] { 1, 2, 3, 4, 5 }));
        }
        private int ParseSet(int i, string recordString, ODocument document, string fieldName)
        {
            // move to the first element of this set
            i++;

            if (document[fieldName] == null)
            {
                document[fieldName] = new HashSet <object>();
            }

            while (recordString[i] != '>')
            {
                // check what follows after parsed field name and start parsing underlying type
                switch (recordString[i])
                {
                case '"':
                    i = ParseString(i, recordString, document, fieldName);
                    break;

                case '#':
                    i = ParseRecordID(i, recordString, document, fieldName);
                    break;

                case '(':
                    i = ParseEmbeddedDocument(i, recordString, document, fieldName);
                    break;

                case '{':
                    i = ParseMap(i, recordString, document, fieldName);
                    break;

                case ',':
                    i++;
                    break;

                default:
                    i = ParseValue(i, recordString, document, fieldName);
                    break;
                }
            }

            // move past closing bracket of this set
            i++;

            return(i);
        }
        public void TestDeserializeSubObjectList()
        {
            string recordString = "TheThings:[(Value:17,Text:\"blah\"),(Value:18,Text:\"foo\")]";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            TypeMapper <TestHasListThings> tm = TypeMapper <TestHasListThings> .Instance;
            var t = new TestHasListThings();

            tm.ToObject(document, t);

            Assert.NotNull(t.TheThings);
            Assert.Equal(2, t.TheThings.Count);
            Assert.Equal(18, t.TheThings[1].Value);
            Assert.Equal("foo", t.TheThings[1].Text);
        }
Esempio n. 55
0
        private IEnumerable <ODocument> Run()
        {
            CommandPayloadQuery payload = new CommandPayloadQuery();

            payload.Text         = query;
            payload.NonTextLimit = -1;
            payload.FetchPlan    = "*:0";

            Command operation = new Command(_connection.Database);

            operation.OperationMode  = OperationMode.Asynchronous;
            operation.CommandPayload = payload;

            ODocument document = _connection.ExecuteOperation(operation);

            return(document.GetField <List <ODocument> >("Content"));
        }
        public static List <ODocument> FindServerConnections(String name, String LanMacAddress)
        {
            ODatabase database = InitDB();
            string    query    = String.Format("SELECT * FROM Server WHERE name=\"" + name + "\" AND LanMacAddress=\""
                                               + LanMacAddress + "\"");
            List <ODocument> result = database.Query(query).ToList();

            ODocument o = result[0];
            ORID      z = o.GetField <ORID>("@ORID");


            String           querry    = "TRAVERSE * FROM " + z + " WHILE $depth<=2";
            List <ODocument> resultset = database.Query(querry).ToList <ODocument>();

            database.Close();
            return(resultset);
        }
        public void ShouldDeleteEdgeFromDocumentOrid()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestVertexClass")
                    .Extends <OVertex>()
                    .Run();

                    database
                    .Create.Class("TestEdgeClass")
                    .Extends <OEdge>()
                    .Run();

                    ODocument vertex1 = database
                                        .Create.Vertex("TestVertexClass")
                                        .Set("foo", "foo string value1")
                                        .Set("bar", 12345)
                                        .Run();

                    ODocument vertex2 = database
                                        .Create.Vertex("TestVertexClass")
                                        .Set("foo", "foo string value2")
                                        .Set("bar", 54321)
                                        .Run();

                    ODocument edge1 = database
                                      .Create.Edge("TestEdgeClass")
                                      .From(vertex1)
                                      .To(vertex2)
                                      .Set("foo", "foo string value2")
                                      .Set("bar", 54321)
                                      .Run();

                    int documentsDeleted = database
                                           .Delete.Edge(edge1)
                                           .Run();

                    Assert.AreEqual(documentsDeleted, 1);
                }
            }
        }
Esempio n. 58
0
            /// <summary>
            /// Populate model object(s)
            /// </summary>
            /// <typeparam name="T">Type of model to return</typeparam>
            /// <returns>A collection of model objects which appear in the traversal.</returns>
            public IEnumerable <T> ToModel <T>() where T : ABaseModel, new()
            {
                if (documents.Count() == 0)
                {
                    return(null);
                }
                IDictionary <ORID, ABaseModel> models = new Dictionary <ORID, ABaseModel>();

                foreach (OEdge e in edges)
                {
                    ODocument outDoc = documentMap[e.OutV];
                    ODocument inDoc = documentMap[e.InV];
                    dynamic   outModel, inModel;
                    bool      containsOutId = models.ContainsKey(outDoc.ORID);
                    bool      containsInId  = models.ContainsKey(inDoc.ORID);
                    // Set the value for the models that edge is pointing into/out of
                    if (containsOutId)
                    {
                        outModel = models[outDoc.ORID];
                    }
                    else
                    {
                        outModel = GetNewPropertyModel(typeof(T).Namespace, outDoc.OClassName);
                        MapProperties(outDoc, outModel);
                        models.Add(outModel.ORID, outModel);
                    }
                    if (containsInId)
                    {
                        inModel = models[inDoc.ORID];
                    }
                    else
                    {
                        inModel = GetNewPropertyModel(typeof(T).Namespace, inDoc.OClassName);
                        MapProperties(inDoc, inModel);
                        models.Add(inDoc.ORID, inModel);
                    }
                    // Set the property values for outModel to inModel if they exist
                    setPropertiesHelper(outModel, inModel, e.OClassName);
                    setPropertiesHelper(inModel, outModel, e.OClassName);
                }
                // Return models of type T
                IEnumerable <T> result = models.Select(kvp => kvp.Value).Where(model => model.OClassName.Equals(typeof(T).Name)).Cast <T>();

                return(result);
            }
Esempio n. 59
0
        public void ShouldSelectFromDocumentOClassNameQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument document1 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value1")
                                          .Set("bar", 12345)
                                          .Run();

                    ODocument document2 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value2")
                                          .Set("bar", 54321)
                                          .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From(document)
                                                 .ToList();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, document.OClassName);
                        Assert.IsTrue(documents[i].HasField("foo"));
                        Assert.IsTrue(documents[i].HasField("bar"));
                    }
                }
            }
        }
        public void ShouldSerializeBoolean()
        {
            string recordString = "TestClass@isTrue:true,isFalse:false,embedded:(isTrue:true,isFalse:false),array:[true,false]";

            ODocument document = new ODocument()
                                 .SetField("@OClassName", "TestClass")
                                 .SetField("isTrue", true)
                                 .SetField("isFalse", false)
                                 .SetField("embedded.isTrue", true)
                                 .SetField("embedded.isFalse", false)
                                 .SetField <List <bool> >("array", new List <bool> {
                true, false
            });

            string serializedRecord = Encoding.UTF8.GetString(serializer.Serialize(document));

            Assert.Equal(serializedRecord, recordString);
        }