Example #1
0
        public void ShouldUpdateCluster()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    database
                    .Create.Cluster("TestCluster", OClusterType.Physical)
                    .Run();

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

                    database
                    .Insert(document)
                    .Cluster("TestCluster")
                    .Run();

                    database
                    .Insert(document)
                    .Cluster("TestCluster")
                    .Run();

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

                    int documentsUpdated = database
                                           .Update(document)
                                           .Cluster("TestCluster")
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 2);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("cluster:TestCluster")
                                                 .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"));
                    }
                }
            }
        }
Example #2
0
        public void ShouldUpdateClass()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    database
                    .Insert(document)
                    .Into("TestClass")
                    .Run();

                    database
                    .Insert(document)
                    .Into("TestClass")
                    .Run();

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

                    int documentsUpdated = database
                                           .Update(document)
                                           .Class("TestClass")
                                           .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, "TestClass");
                        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"));
                    }
                }
            }
        }
Example #3
0
        public void ShouldUpdateOridSet()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    ODocument document1 = database
                                          .Insert(document)
                                          .Run();

                    ODocument document2 = database
                                          .Insert(document)
                                          .Run();

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

                    int documentsUpdated = database
                                           .Update(document2.ORID)
                                           .Set(document2)
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 1);

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

                    Assert.AreEqual(documents.Count, 1);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.AreEqual(documents[i].ORID, document2.ORID);
                        Assert.AreEqual(documents[i].OClassName, document2.OClassName);
                        Assert.AreEqual(documents[i].GetField <string>("foo"), document2.GetField <string>("foo"));
                        Assert.AreEqual(documents[i].GetField <int>("bar"), document2.GetField <int>("bar"));
                        Assert.AreEqual(documents[i].GetField <string>("baz"), document2.GetField <string>("baz"));
                    }
                }
            }
        }
        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"));
                    }
                }
            }
        }
Example #5
0
        public void ShouldUpdateRecord()
        {
            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 document1 = database
                                          .Insert(document)
                                          .Run();

                    ODocument document2 = database
                                          .Insert(document)
                                          .Run();

                    ODocument docToUpdate = new ODocument()
                                            .SetField("bar", 54321)
                                            .SetField("baz", "new baz value");

                    int documentsUpdated = database
                                           .Update(docToUpdate)
                                           .Record(document2.ORID)
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("TestClass")
                                                 .Where("bar").Equals(54321)
                                                 .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.AreEqual(documents[0].GetField <int>("bar"), docToUpdate.GetField <int>("bar"));
                    Assert.AreEqual(documents[0].GetField <string>("baz"), docToUpdate.GetField <string>("baz"));
                }
            }
        }
        public void ShouldUpdateRecord()
        {
            using (var testContext = new TestDatabaseContext())
            using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                // prerequisites
                database
                    .Create.Class("TestClass")
                    .Run();

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

                var cd = database.Create.Document(document).Run();
                cd.SetField("bar", 54321);

                var ud = database.Update(cd).Run();
                cd.SetField("bar", 9876);
                var ud1 = database.Update(cd).Run();
            }
        }
        public static void UpdateDesktop(String name, String OS, String LanMacAddress, String nameOld, String LanMacAddressOld)
        {
            ODatabase database = InitDB();

            string query = String.Format("SELECT * FROM Desktop WHERE name=\"" + nameOld + "\" AND LanMacAddress=\""
                                         + LanMacAddressOld + "\"");
            List <ODocument> result = database.Query(query).ToList();

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

            database.Update(z).Set("name", name).Set("OS", OS).Set("LanMacAddress", LanMacAddress).Run();
        }
Example #8
0
        public void ShouldUpdateRecord()
        {
            using (var testContext = new TestDatabaseContext())
                using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    var cd = database.Create.Document(document).Run();
                    cd.SetField("bar", 54321);

                    var ud = database.Update(cd).Run();
                    cd.SetField("bar", 9876);
                    var ud1 = database.Update(cd).Run();
                }
        }
Example #9
0
        public void ShouldUpdateClassFromObject()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class <TestProfileClass>()
                    .Run();

                    TestProfileClass profile = new TestProfileClass();
                    profile.Name = "Johny";

                    database
                    .Insert(profile)
                    .Run();

                    database
                    .Insert(profile)
                    .Run();

                    profile.Name    = "Julia";
                    profile.Surname = "Bravo";

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

                    Assert.AreEqual(documentsUpdated, 2);

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

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, typeof(TestProfileClass).Name);
                        Assert.AreEqual(documents[i].Name, profile.Name);
                        Assert.AreEqual(documents[i].Surname, profile.Surname);
                    }
                }
            }
        }
        public void ShouldUpdateRecordUsingMerge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument record1 = database.Insert("TestClass")
                                        .Content(TestConstants.CreateJson)
                                        .Run();

                    ODocument record2 = database.Insert("TestClass")
                                        .Content(TestConstants.CreateJson)
                                        .Run();

                    var recordsMerged = database.Update(record1.ORID)
                                        .Merge(TestConstants.MergeJson)
                                        .Run();

                    Assert.AreEqual(1, recordsMerged);

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

                    Assert.AreEqual(2, documents.Count);

                    documents = database
                                .Select()
                                .From("TestClass")
                                .Where("embeddedObject.newProperty").Equals("NewValue")
                                .ToList();

                    Assert.AreEqual(1, documents.Count);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        checkMergedContentAssertions(documents[i]);
                    }
                }
            }
        }
Example #11
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"));
                }
            }
        }
        public static void UpdateRouter(String name, String OS, String SerialNumber, String Manufacturer,
                                        int NumberOfPorts, int NumberOfTakenPorts, String WiFiNetworkName,
                                        List <String> MacAddressList, String RouterNameOld, String SerialNumberOld)
        {
            ODatabase database = InitDB();

            string query = String.Format("SELECT * FROM Router WHERE name=\"" + RouterNameOld + "\" AND SerialNumber=\""
                                         + SerialNumberOld + "\"");
            List <ODocument> result = database.Query(query).ToList();

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

            database.Update(z).Set("name", name).Set("OS", OS).Set("SerialNumber", SerialNumber)
            .Set("Manufacturer", Manufacturer).Set("NumberOfPorts", NumberOfPorts)
            .Set("NumberOfTakenPorts", NumberOfTakenPorts).Set("WiFiNetworkName", WiFiNetworkName)
            .Set("MacAddressList", MacAddressList).Run();
        }
        public void ShouldUpdateClassFromObject()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class<TestProfileClass>()
                        .Run();

                    TestProfileClass profile = new TestProfileClass();
                    profile.Name = "Johny";

                    database
                        .Insert(profile)
                        .Run();

                    database
                        .Insert(profile)
                        .Run();

                    profile.Name = "Julia";
                    profile.Surname = "Bravo";

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

                    Assert.AreEqual(documentsUpdated, 2);

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

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, typeof(TestProfileClass).Name);
                        Assert.AreEqual(documents[i].Name, profile.Name);
                        Assert.AreEqual(documents[i].Surname, profile.Surname);
                    }
                }
            }
        }
        public void ShouldUpdateRemoveFieldQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // 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"));
                }
            }
        }
        public void ShouldUpdateRemoveCollectionItem()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document1 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", new List<string>() { "foo1", "foo2" })
                        .Set("bar", 11111)
                        .Run();

                    ODocument document2 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", new List<string>() { "foo1", "foo2" })
                        .Set("bar", 12345)
                        .Run();

                    int documentsUpdated = database
                        .Update(document2)
                        .Remove("foo", "foo2")
                        .Run();

                    Assert.AreEqual(documentsUpdated, 1);

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

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);

                    List<string> foos = new List<string>() { "foo1" };

                    Assert.AreEqual(documents[0].GetField<List<string>>("foo").Count, foos.Count);
                    Assert.AreEqual(documents[0].GetField<List<string>>("foo")[0], foos[0]);

                    Assert.AreEqual(documents[0].GetField<int>("bar"), document2.GetField<int>("bar"));
                }
            }
        }
        public void ShouldUpdateRecordSet()
        {
            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 document1 = database
                        .Insert(document)
                        .Run();

                    ODocument document2 = database
                        .Insert(document)
                        .Run();

                    int documentsUpdated = database
                        .Update(document2.ORID)
                        .Set("bar", 54321)
                        .Set("baz", "new baz value")
                        .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List<ODocument> documents = database
                        .Select()
                        .From("TestClass")
                        .Where("bar").Equals(54321)
                        .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.AreEqual(documents[0].GetField<int>("bar"), 54321);
                    Assert.AreEqual(documents[0].GetField<string>("baz"), "new baz value");
                }
            }
        }
        public static void CreateEdgeCable(ORID o1, ORID o2, String firstNodeType, String secondNodeType,
                                           String connectionTypeValue, String CableTypeValue,
                                           LanCable lanCable, OpticCable opticCable)
        {
            ODatabase database = InitDB();

            if ((firstNodeType == "Desktop" || firstNodeType == "Laptop" || firstNodeType == "Server") &&
                (secondNodeType == "Router" || secondNodeType == "Switch"))
            {
                String               query     = "SELECT * FROM Computer WHERE @rid=" + o1.RID.ToString();
                List <ODocument>     resultset = database.Query(query).ToList();
                JavaScriptSerializer converter = new JavaScriptSerializer();

                List <Computer> AllComputers = new List <Computer>();
                String          macAddress1  = null;
                foreach (ODocument doc in resultset)
                {
                    var      json = converter.Serialize(doc);
                    String   a    = json.ToString();
                    Computer d    = converter.Deserialize <Computer>(a);
                    AllComputers.Add(d);
                }

                Computer computer = null;
                if (AllComputers != null)
                {
                    computer = AllComputers[0];
                }

                macAddress1 = computer.LanMacAddress;

                String           query1     = "SELECT * FROM Node WHERE @rid=" + o2.RID.ToString();
                List <ODocument> resultset1 = database.Query(query1).ToList();

                List <Node> AllNodes = new List <Node>();

                foreach (ODocument doc in resultset1)
                {
                    var    json = converter.Serialize(doc);
                    String a    = json.ToString();
                    Node   d    = converter.Deserialize <Node>(a);
                    AllNodes.Add(d);
                }

                Node node = null;
                if (AllNodes != null)
                {
                    node = AllNodes[0];
                }

                String macAddress2 = null;
                if (node != null)
                {
                    if (node.NumberOfPorts != node.NumberOfTakenPorts)
                    {
                        node.NumberOfTakenPorts++;
                        macAddress2 = node.MacAddressList.ElementAt(node.NumberOfTakenPorts - 1);
                    }
                }

                if (connectionTypeValue == "Cable")
                {
                    if (CableTypeValue == "Lan")
                    {
                        lanCable.End1 = macAddress1;
                        lanCable.End2 = macAddress2;
                        lanCable.Type = "Lan";

                        String addCableQuerry = "CREATE EDGE LanCable FROM " + o1.RID.ToString() + " TO " + o2.RID.ToString() +
                                                " SET End1 = \"" + lanCable.End1 + "\", End2 = \"" + lanCable.End2 + "\", Type=\"" + lanCable.Type
                                                + "\", Manufacturer=\"" + lanCable.Manufacturer + "\", Category=\"" + lanCable.Category + "\"";

                        database.Command(addCableQuerry);

                        if (node != null)
                        {
                            database.Update(o2)
                            .Set("NumberOfPorts", node.NumberOfPorts)
                            .Set("NumberOfTakenPorts", node.NumberOfTakenPorts)
                            .Set("MacAddressList", node.MacAddressList).Run();
                        }
                        return;
                    }
                }
                else
                if (connectionTypeValue == "WiFi")
                {
                    if (firstNodeType == "Laptop")
                    {
                        String           queryL     = "SELECT * FROM Laptop WHERE @rid=" + o1.RID.ToString();
                        List <ODocument> resultsetL = database.Query(queryL).ToList();

                        List <Laptop> AllLaptops = new List <Laptop>();
                        foreach (ODocument doc in resultset)
                        {
                            var    json = converter.Serialize(doc);
                            String a    = json.ToString();
                            Laptop d    = converter.Deserialize <Laptop>(a);
                            AllLaptops.Add(d);
                        }

                        Laptop laptop = null;
                        if (AllLaptops != null)
                        {
                            laptop = AllLaptops[0];
                        }

                        macAddress1 = laptop.WifiMacAddress;
                    }

                    String           query2     = "SELECT * FROM Router WHERE @rid=" + o2.RID.ToString();
                    List <ODocument> resultset2 = database.Query(query1).ToList();

                    List <Router> AllRouters = new List <Router>();

                    foreach (ODocument doc in resultset2)
                    {
                        var    json = converter.Serialize(doc);
                        String a    = json.ToString();
                        Router d    = converter.Deserialize <Router>(a);
                        AllRouters.Add(d);
                    }

                    Router router = null;
                    if (AllRouters != null)
                    {
                        router = AllRouters[0];
                    }

                    if (router != null)
                    {
                        macAddress2 = router.WiFiMacAddress;
                    }

                    WiFiConnection wificonnection = new WiFiConnection();
                    wificonnection.ClientMacAddress = macAddress1;
                    wificonnection.HostMacAddress   = macAddress2;
                    wificonnection.WiFiNetworkName  = router.WiFiNetworkName;

                    String addWifiQuerry = "CREATE EDGE WiFiConnection FROM " + o1.RID.ToString() + " TO " + o2.RID.ToString() +
                                           " SET WiFiNetworkName = \"" + wificonnection.WiFiNetworkName
                                           + "\", HostMacAddress = \"" + wificonnection.HostMacAddress
                                           + "\", ClientMacAddress=\"" + wificonnection.ClientMacAddress + "\"";
                    database.Command(addWifiQuerry);
                }
            }
            else
            if ((secondNodeType == "Desktop" || secondNodeType == "Laptop" || secondNodeType == "Server") &&
                (firstNodeType == "Router" || firstNodeType == "Switch"))
            {
                String               query     = "SELECT * FROM Computer WHERE @rid=" + o2.RID.ToString();
                List <ODocument>     resultset = database.Query(query).ToList();
                JavaScriptSerializer converter = new JavaScriptSerializer();

                List <Computer> AllComputers = new List <Computer>();
                String          macAddress1  = null;
                foreach (ODocument doc in resultset)
                {
                    var      json = converter.Serialize(doc);
                    String   a    = json.ToString();
                    Computer d    = converter.Deserialize <Computer>(a);
                    AllComputers.Add(d);
                }

                Computer computer = null;
                if (AllComputers != null)
                {
                    computer = AllComputers[0];
                }

                macAddress1 = computer.LanMacAddress;

                String           query1     = "SELECT * FROM Node WHERE @rid=" + o1.RID.ToString();
                List <ODocument> resultset1 = database.Query(query1).ToList();

                List <Node> AllNodes = new List <Node>();

                foreach (ODocument doc in resultset1)
                {
                    var    json = converter.Serialize(doc);
                    String a    = json.ToString();
                    Node   d    = converter.Deserialize <Node>(a);
                    AllNodes.Add(d);
                }

                Node node = null;
                if (AllNodes != null)
                {
                    node = AllNodes[0];
                }

                String macAddress2 = null;
                if (node != null)
                {
                    if (node.NumberOfPorts != node.NumberOfTakenPorts)
                    {
                        node.NumberOfTakenPorts++;
                        macAddress2 = node.MacAddressList.ElementAt(node.NumberOfTakenPorts - 1);
                    }
                }

                if (connectionTypeValue == "Cable")
                {
                    if (CableTypeValue == "Lan")
                    {
                        lanCable.End1 = macAddress1;
                        lanCable.End2 = macAddress2;
                        lanCable.Type = "Lan";

                        String addCableQuerry = "CREATE EDGE LanCable FROM " + o2.RID.ToString() + " TO " + o1.RID.ToString() +
                                                " SET End1 = \"" + lanCable.End1 + "\", End2 = \"" + lanCable.End2 + "\", Type=\"" + lanCable.Type
                                                + "\", Manufacturer=\"" + lanCable.Manufacturer + "\", Category=\"" + lanCable.Category + "\"";

                        database.Command(addCableQuerry);

                        if (node != null)
                        {
                            database.Update(o1)
                            .Set("NumberOfPorts", node.NumberOfPorts)
                            .Set("NumberOfTakenPorts", node.NumberOfTakenPorts)
                            .Set("MacAddressList", node.MacAddressList).Run();
                        }
                        return;
                    }
                }
                if (connectionTypeValue == "WiFi")
                {
                    if (secondNodeType == "Laptop")
                    {
                        String           queryL     = "SELECT * FROM Laptop WHERE @rid=" + o2.RID.ToString();
                        List <ODocument> resultsetL = database.Query(queryL).ToList();

                        List <Laptop> AllLaptops = new List <Laptop>();
                        foreach (ODocument doc in resultset)
                        {
                            var    json = converter.Serialize(doc);
                            String a    = json.ToString();
                            Laptop d    = converter.Deserialize <Laptop>(a);
                            AllLaptops.Add(d);
                        }

                        Laptop laptop = null;
                        if (AllLaptops != null)
                        {
                            laptop = AllLaptops[0];
                        }

                        macAddress1 = laptop.WifiMacAddress;
                    }

                    String           query2     = "SELECT * FROM Router WHERE @rid=" + o1.RID.ToString();
                    List <ODocument> resultset2 = database.Query(query1).ToList();

                    List <Router> AllRouters = new List <Router>();

                    foreach (ODocument doc in resultset2)
                    {
                        var    json = converter.Serialize(doc);
                        String a    = json.ToString();
                        Router d    = converter.Deserialize <Router>(a);
                        AllRouters.Add(d);
                    }

                    Router router = null;
                    if (AllRouters != null)
                    {
                        router = AllRouters[0];
                    }

                    if (router != null)
                    {
                        macAddress2 = router.WiFiMacAddress;
                    }

                    WiFiConnection wificonnection = new WiFiConnection();
                    wificonnection.ClientMacAddress = macAddress1;
                    wificonnection.HostMacAddress   = macAddress2;
                    wificonnection.WiFiNetworkName  = router.WiFiNetworkName;

                    String addWifiQuerry = "CREATE EDGE WiFiConnection FROM " + o2.RID.ToString() + " TO " + o1.RID.ToString() +
                                           " SET WiFiNetworkName = \"" + wificonnection.WiFiNetworkName
                                           + "\", HostMacAddress = \"" + wificonnection.HostMacAddress
                                           + "\", ClientMacAddress=\"" + wificonnection.ClientMacAddress + "\"";
                    database.Command(addWifiQuerry);
                }
            }
            else
            if ((firstNodeType == "Desktop" || firstNodeType == "Laptop" || firstNodeType == "Server") &&
                (secondNodeType == "Desktop" || secondNodeType == "Laptop" || secondNodeType == "Server"))
            {
                String               query     = "SELECT * FROM Computer WHERE @rid=" + o1.RID.ToString();
                List <ODocument>     resultset = database.Query(query).ToList();
                JavaScriptSerializer converter = new JavaScriptSerializer();

                List <Computer> AllComputers = new List <Computer>();
                String          macAddress1  = null;
                foreach (ODocument doc in resultset)
                {
                    var      json = converter.Serialize(doc);
                    String   a    = json.ToString();
                    Computer d    = converter.Deserialize <Computer>(a);
                    AllComputers.Add(d);
                }

                Computer computer = null;
                if (AllComputers != null)
                {
                    computer = AllComputers[0];
                }

                macAddress1 = computer.LanMacAddress;

                String           query1     = "SELECT * FROM Computer WHERE @rid=" + o2.RID.ToString();
                List <ODocument> resultset1 = database.Query(query1).ToList();

                List <Computer> AllComputers1 = new List <Computer>();
                String          macAddress2   = null;
                foreach (ODocument doc in resultset1)
                {
                    var      json = converter.Serialize(doc);
                    String   a    = json.ToString();
                    Computer d    = converter.Deserialize <Computer>(a);
                    AllComputers1.Add(d);
                }

                Computer computer1 = null;
                if (AllComputers1 != null)
                {
                    computer1 = AllComputers1[0];
                }

                macAddress2 = computer1.LanMacAddress;

                if (connectionTypeValue == "Cable")
                {
                    if (CableTypeValue == "Lan")
                    {
                        lanCable.End1 = macAddress1;
                        lanCable.End2 = macAddress2;
                        lanCable.Type = "Lan";

                        String addCableQuerry = "CREATE EDGE LanCable FROM " + o1.RID.ToString() + " TO " + o2.RID.ToString() +
                                                " SET End1 = \"" + lanCable.End1 + "\", End2 = \"" + lanCable.End2 + "\", Type=\"" + lanCable.Type
                                                + "\", Manufacturer=\"" + lanCable.Manufacturer + "\", Category=\"" + lanCable.Category + "\"";

                        database.Command(addCableQuerry);

                        return;
                    }
                }
            }
            else
            if ((firstNodeType == "Router" || firstNodeType == "Switch") &&
                (secondNodeType == "Router" || secondNodeType == "Switch"))
            {
                String query = "SELECT * FROM Node WHERE @rid=" + o1.RID.ToString();
                JavaScriptSerializer converter = new JavaScriptSerializer();
                List <ODocument>     resultset = database.Query(query).ToList();

                List <Node> AllNodes = new List <Node>();

                foreach (ODocument doc in resultset)
                {
                    var    json = converter.Serialize(doc);
                    String a    = json.ToString();
                    Node   d    = converter.Deserialize <Node>(a);
                    AllNodes.Add(d);
                }

                Node node = null;
                if (AllNodes != null)
                {
                    node = AllNodes[0];
                }

                String macAddress1 = null;
                if (node != null)
                {
                    if (node.NumberOfPorts != node.NumberOfTakenPorts)
                    {
                        node.NumberOfTakenPorts++;
                        macAddress1 = node.MacAddressList.ElementAt(node.NumberOfTakenPorts - 1);
                    }
                }

                String           query1     = "SELECT * FROM Node WHERE @rid=" + o2.RID.ToString();
                List <ODocument> resultset1 = database.Query(query1).ToList();

                List <Node> AllNodes1 = new List <Node>();

                foreach (ODocument doc in resultset1)
                {
                    var    json = converter.Serialize(doc);
                    String a    = json.ToString();
                    Node   d    = converter.Deserialize <Node>(a);
                    AllNodes1.Add(d);
                }

                Node node1 = null;
                if (AllNodes1 != null)
                {
                    node1 = AllNodes1[0];
                }

                String macAddress2 = null;
                if (node1 != null)
                {
                    if (node1.NumberOfPorts != node1.NumberOfTakenPorts)
                    {
                        node1.NumberOfTakenPorts++;
                        macAddress2 = node1.MacAddressList.ElementAt(node1.NumberOfTakenPorts - 1);
                    }
                }

                if (connectionTypeValue == "Cable")
                {
                    if (CableTypeValue == "Lan")
                    {
                        lanCable.End1 = macAddress1;
                        lanCable.End2 = macAddress2;
                        lanCable.Type = "Lan";

                        String addCableQuerry = "CREATE EDGE LanCable FROM " + o1.RID.ToString() + " TO " + o2.RID.ToString() +
                                                " SET End1 = \"" + lanCable.End1 + "\", End2 = \"" + lanCable.End2 + "\", Type=\"" + lanCable.Type
                                                + "\", Manufacturer=\"" + lanCable.Manufacturer + "\", Category=\"" + lanCable.Category + "\"";

                        database.Command(addCableQuerry);

                        if (node != null)
                        {
                            database.Update(o1)
                            .Set("NumberOfPorts", node.NumberOfPorts)
                            .Set("NumberOfTakenPorts", node.NumberOfTakenPorts)
                            .Set("MacAddressList", node.MacAddressList).Run();
                        }

                        if (node1 != null)
                        {
                            database.Update(o2)
                            .Set("NumberOfPorts", node1.NumberOfPorts)
                            .Set("NumberOfTakenPorts", node1.NumberOfTakenPorts)
                            .Set("MacAddressList", node1.MacAddressList).Run();
                        }
                        return;
                    }
                }
            }
        }
Example #18
0
        public void ShouldUpdateRemoveCollectionItem()
        {
            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", new List <string>()
                    {
                        "foo1", "foo2"
                    })
                                          .Set("bar", 11111)
                                          .Run();

                    ODocument document2 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", new List <string>()
                    {
                        "foo1", "foo2"
                    })
                                          .Set("bar", 12345)
                                          .Run();

                    int documentsUpdated = database
                                           .Update(document2)
                                           .Remove("foo", "foo2")
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 1);

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

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);

                    List <string> foos = new List <string>()
                    {
                        "foo1"
                    };

                    Assert.AreEqual(documents[0].GetField <List <string> >("foo").Count, foos.Count);
                    Assert.AreEqual(documents[0].GetField <List <string> >("foo")[0], foos[0]);

                    Assert.AreEqual(documents[0].GetField <int>("bar"), document2.GetField <int>("bar"));
                }
            }
        }
Example #19
0
 static void Main(string[] args)
 {
     _server = new OServer(_hostname, _port, _rootUserName, _rootUserPassword);
     if (!_server.DatabaseExist(_DBname, OStorageType.PLocal))
     {
         _server.CreateDatabase(_DBname, ODatabaseType.Graph, OStorageType.PLocal);
         Console.WriteLine("Database " + _DBname + " created");
         //Connect to the DB
         OClient.CreateDatabasePool(
             _hostname,
             _port,
             _DBname,
             ODatabaseType.Graph,
             _username,
             _password,
             10,
             _aliasDB
             );
         Console.WriteLine("Connected to the DB " + _DBname);
         using (ODatabase database = new ODatabase(_aliasDB))
         {
             //Classes and properties creation
             database
             .Create
             .Class("Users")
             .Extends <OVertex>()
             .Run();
             database
             .Create
             .Property("userID", OType.Integer)
             .Class("users")
             .Run();
             //Populate the DB
             OVertex vertexUser = new OVertex();
             vertexUser.OClassName = "Users";
             vertexUser
             .SetField("userID", 1);
             OVertex createVertexUser = database
                                        .Create.Vertex(vertexUser)
                                        .Run();
             Console.WriteLine("Created vertex " + createVertexUser.OClassName + " with @rid " + createVertexUser.ORID + " and userID " + createVertexUser.GetField <int>("userID"));
         }
     }
     else
     {
         //Connection
         OClient.CreateDatabasePool(
             _hostname,
             _port,
             _DBname,
             ODatabaseType.Graph,
             _username,
             _password,
             10,
             _aliasDB
             );
         Console.WriteLine("Connected to the DB " + _DBname);
         using (ODatabase database = new ODatabase(_aliasDB))
         {
             database
             .Update()
             .Class("Users")
             .Set("userID", 2)
             .Upsert()
             .Where("userID")
             .Equals(2)
             .Run();
             Console.WriteLine("Operation executed");
         }
     }
 }