public void ShouldCreateEdgeFromOEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    OVertex vertex1 = database
                                      .Create.Vertex <OVertex>()
                                      .Run();

                    OVertex vertex2 = database
                                      .Create.Vertex <OVertex>()
                                      .Run();

                    OEdge edge = new OEdge();
                    edge.SetField("Foo", "foo string value");
                    edge.SetField("Bar", 12345);

                    OEdge createdEdge = database
                                        .Create.Edge(edge)
                                        .From(vertex1)
                                        .To(vertex2)
                                        .Run();

                    Assert.IsTrue(!string.IsNullOrEmpty(createdEdge.ORID.ToString()));
                    Assert.AreEqual(createdEdge.Label, "E");
                    Assert.AreEqual(createdEdge.OClassName, "E");
                    Assert.AreEqual(createdEdge.InV, vertex2.ORID);
                    Assert.AreEqual(createdEdge.OutV, vertex1.ORID);
                    Assert.AreEqual(createdEdge.GetField <string>("Foo"), edge.GetField <string>("Foo"));
                    Assert.AreEqual(createdEdge.GetField <int>("Bar"), edge.GetField <int>("Bar"));
                }
            }
        }
        public void ShouldCreateEdgeFromOEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    OVertex vertex1 = database
                                      .Create.Vertex <OVertex>()
                                      .Run();

                    OVertex vertex2 = database
                                      .Create.Vertex <OVertex>()
                                      .Run();

                    OEdge edge = new OEdge();
                    edge.SetField("Foo", "foo string value");
                    edge.SetField("Bar", 12345);

                    OEdge createdEdge = database
                                        .Create.Edge(edge)
                                        .From(vertex1)
                                        .To(vertex2)
                                        .Run();

                    Assert.NotNull(createdEdge.ORID);
                    Assert.Equal("E", createdEdge.Label);
                    Assert.Equal("E", createdEdge.OClassName);
                    Assert.Equal(vertex2.ORID, createdEdge.InV);
                    Assert.Equal(vertex1.ORID, createdEdge.OutV);
                    Assert.Equal(edge.GetField <string>("Foo"), createdEdge.GetField <string>("Foo"));
                    Assert.Equal(edge.GetField <int>("Bar"), createdEdge.GetField <int>("Bar"));
                }
            }
        }
Exemplo n.º 3
0
        private async void PeriodicLinkData()
        {
            while (!_disposed)
            {
                Console.Clear();
                using (var db = new ODatabase("localhost", 2424, "txgraph", ODatabaseType.Graph, "admin", "admin"))
                {
                    var nodes = db.Query <OVertex>($"SELECT * FROM Transaction WHERE Unlinked = true LIMIT 100000");
                    foreach (var node in nodes)
                    {
                        var transaction = db.Transaction;
                        if (IsCoinbaseTx(node))
                        {
                            node.SetField("Unlinked", false);
                            transaction.AddOrUpdate(node);
                            transaction.Commit();
                            continue;
                        }
                        try
                        {
                            transaction.AddOrUpdate(node);
                            for (var i = 0; i < GetInputCount(node); i++)
                            {
                                var inputString = node.GetField <string>($"INPUT{i}");
                                var prevHash    = inputString.Split(':')[0];
                                var prevN       = Int64.Parse(inputString.Split(':')[1]);
                                var prevTx      = db.Query <OVertex>($"SELECT * FROM Transaction WHERE Hash = \"{prevHash}\"").FirstOrDefault();
                                if (prevTx != null)
                                {
                                    transaction.AddOrUpdate(prevTx);
                                    var prevOutString = prevTx.GetField <string>($"OUTPUT{prevN}");
                                    var prevOutN      = prevOutString?.Split(':')[0];
                                    var outAddr       = prevOutString?.Split(':')[1];
                                    var outAmount     = prevOutString != null?Int64.Parse(prevOutString?.Split(':')[2]) : 0;

                                    var edge = new OEdge()
                                    {
                                        OClassName = "Link"
                                    };
                                    edge.SetField("sTx", prevHash);
                                    edge.SetField("sN", prevN);
                                    edge.SetField("amount", outAmount);
                                    edge.SetField("tTx", node.GetField <string>("Hash"));
                                    edge.SetField("tAddr", outAddr ?? "");
                                    transaction.AddEdge(edge, prevTx, node);
                                }
                            }
                            node.SetField("Unlinked", false);
                            transaction.Update(node);
                            transaction.Commit();
                        }
                        catch (Exception e)
                        {
                            transaction.Reset();
                        }
                    }
                }
                await Task.Delay(60000);
            }
        }
Exemplo n.º 4
0
        public void AddEdge(OEdge edge, OVertex from, OVertex to)
        {
            this.Add(edge);
            edge.SetField("out", from.ORID);
            edge.SetField("in", to.ORID);

            appendOridToField(from, "out_" + edge.OClassName, edge.ORID);
            appendOridToField(to, "in_" + edge.OClassName, edge.ORID);

            if (!_records.ContainsKey(from.ORID))
            {
                Update(from);
            }

            if (!_records.ContainsKey(to.ORID))
            {
                Update(to);
            }
        }