Example #1
0
     static void Main(string[] args)
     {
     try{
         GraphClient client = new GraphClient(new Uri("http://localhost:7474/db/data"));
         client.Connect();
         Us us = new Us { Name = "We are Us" };
         NodeReference<Us> usRef = client.Create(us);
         Console.WriteLine("us node.id: {0}", usRef.Id);
         var queryUs = client.Cypher.Start("n", "node(" + usRef.Id + ")").Return<Node<Us>>("n");
         Console.WriteLine("Us node name: {0}\n", queryUs.Results.AsEnumerable<Node<Us>>().First().Data);
         AllYourBase allYourBase = new AllYourBase { Name = "We are all your base" };
         NodeReference<AllYourBase> allYourBaseRef = client.Create(allYourBase);
         Console.WriteLine("AllYourBase node.id: {0}",allYourBaseRef.Id);
         var queryAllYourBase = client.Cypher.Start("n", "node(" + allYourBaseRef.Id + ")").Return<Node<AllYourBase>>("n");
         Console.WriteLine("AllYourBase node name: {0}\n", queryAllYourBase.Results.AsEnumerable<Node<AllYourBase>>().First().Data);
         RelationshipReference areBelongToRef = client.CreateRelationship(allYourBaseRef, new AreBelongTo(usRef));
         var query = client.Cypher.Start("allyourbase", "node(" + allYourBaseRef.Id + ")").Match("allyourbase-[:ARE_BELONG_TO]->us").Return<Node<AllYourBase>>("allyourbase");
         query.ExecuteWithoutResults();
         Console.WriteLine("Result of querying for all your base that belongs to us: {0}", query.Results.AsEnumerable<Node<AllYourBase>>().First().Data.Name);
     }
     catch(Exception ex)
     {
         Console.WriteLine("{0}", ex.Message);
         Console.WriteLine("{0}", ex.InnerException);
     }
     Console.ReadKey();
 }
Example #2
0
        static NodeReference <DatabaseServer> GetDatabaseServerNode(string serverName)
        {
            var query = GraphClient.Cypher
                        .Start(new { root = GraphClient.RootNode })
                        .Match("root-[:ROOT_CONTAINS_DATABASESERVER]->databaseserver")
                        .Where(string.Format("databaseserver.Id='{0}'", serverName))
                        .Return <Node <DatabaseServer> >("databaseserver");

            var results = query.Results.ToList();

            if (results.Count() == 1)
            {
                return(results.First().Reference);
            }

            var databaseServerNode = GraphClient.Create(new DatabaseServer
            {
                Id   = serverName,
                Name = serverName
            });

            GraphClient.CreateRelationship(GraphClient.RootNode, new RootContainsDatabaseServer(databaseServerNode));

            return(databaseServerNode);
        }
        static void Main(string[] args)
        {
            try
            {
                GraphClient client = new GraphClient(new Uri("http://localhost:7474/db/data"));
                client.Connect();

                // Create nodes and relationship
                MyNode node1 = new MyNode()
                {
                    Name = "Test 1"
                };
                MyNode node2 = new MyNode()
                {
                    Name = "Test 2"
                };

                NodeReference <MyNode> node1ref = client.Create <MyNode>(node1);
                NodeReference <MyNode> node2ref = client.Create <MyNode>(node2);

                MyRelationShip rel12 = new MyRelationShip(node2ref);

                var Rel1 = client.CreateRelationship <MyNode, MyRelationShip>(node1ref, rel12);

                MyNode node3 = new MyNode()
                {
                    Name = "Test 3"
                };
                NodeReference <MyNode> node3ref = client.Create <MyNode>(node3);

                MyRelationShip rel13 = new MyRelationShip(node3ref);
                var            Rel13 = client.CreateRelationship <MyNode, MyRelationShip>(node1ref, rel13);

                var query = client.Cypher.Start(new { n1 = node1ref })
                            .Match("n1-[:MYRELATIONSHIP]->targetnode")
                            .Return <MyNode>(targetnode => targetnode.As <MyNode>());
                var res = query.Results;

                int i = 0;
                foreach (MyNode n in res)
                {
                    i++;
                    Console.WriteLine(i + ". Name: '" + n.Name + "'");
                }
            }
            catch (NeoException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.ReadKey();
        }
Example #4
0
        public NodeReference Visit(Type type)
        {
            const BindingFlags bindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;

            Console.WriteLine("Discovered class {0}", type.FullName);

            var classNode = _graphClient.Create(new Nodes.Class
            {
                Id   = type.FullName,
                Name = type.FullName
            });

            var propertyVisitor = new PropertyVisitor(_graphClient);

            foreach (var propertyNode in type.GetProperties(bindingFlags).Select(propertyVisitor.Visit))
            {
                _graphClient.CreateRelationship(classNode, new ClassContainsProperty(propertyNode));
            }

            var fieldVisitor = new FieldVisitor(_graphClient);

            foreach (var fieldNode in type.GetFields(bindingFlags).Select(fieldVisitor.Visit))
            {
                _graphClient.CreateRelationship(classNode, new ClassContainsField(fieldNode));
            }

            var methodVisitor = new MethodVisitor(_graphClient);

            foreach (var methodNode in type.GetMethods(bindingFlags).Select(methodVisitor.Visit))
            {
                _graphClient.CreateRelationship(classNode, new ClassContainsMethod(methodNode));
            }

            return(classNode);
        }
        public void ShouldThrowArgumentExceptionForPreemptivelyWrappedNode()
        {
            var graphClient = new GraphClient(new Uri("http://foo/db/data"), null);
            var ex          = Assert.Throws <ArgumentException>(() => graphClient.Create((Node <TestNode>)null));

            ex.Message.Should().Be("You're trying to pass in a Node<TestNode> instance. Just pass the TestNode instance instead.\r\nParameter name: node");
        }
        public NodeReference Visit(Type type)
        {
            const BindingFlags bindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;

            var classNode = _graphClient.Create(new Nodes.Interface
            {
                Id   = type.Name,
                Name = type.Name
            });

            var propertyVisitor = new PropertyVisitor(_graphClient);

            foreach (var propertyNode in type.GetProperties(bindingFlags).Select(propertyVisitor.Visit))
            {
                _graphClient.CreateRelationship(classNode, new InterfaceContainsProperty(propertyNode));
            }

            var methodVisitor = new MethodVisitor(_graphClient);

            foreach (var methodNode in type.GetMethods(bindingFlags).Select(methodVisitor.Visit))
            {
                _graphClient.CreateRelationship(classNode, new InterfaceContainsMethod(methodNode));
            }

            return(classNode);
        }
 public NodeReference Visit(FieldInfo field)
 {
     return(_graphClient.Create(new Nodes.Field
     {
         Id = field.Name,
         Name = field.Name
     }));
 }
        public void ShouldThrowValidationExceptionForInvalidNodes()
        {
            var graphClient = new GraphClient(new Uri("http://foo/db/data"), null);

            var testNode = new TestNode {
                Foo = "text is too long", Bar = null, Baz = "123"
            };

            Assert.Throws <ValidationException>(() => graphClient.Create(testNode));
        }
Example #9
0
        public NodeReference Visit(TSqlObject column)
        {
            var columnNode = _graphClient.Create(new Nodes.Column
            {
                Id   = column.Name.ToString(),
                Name = column.Name.ToString()
            });

            return(columnNode);
        }
        public NodeReference Visit(TSqlObject storedProcedure)
        {
            Console.WriteLine("Discovered stored procedure {0}", storedProcedure.Name);

            var storedProcedureNode = _graphClient.Create(new Nodes.StoredProcedure
            {
                Id   = storedProcedure.Name.ToString(),
                Name = storedProcedure.Name.ToString()
            });

            return(storedProcedureNode);
        }
Example #11
0
 private static void Fill(GraphClient graphClient)
 {
     using (var context = new AdventureWorks2012Context())
     {
         foreach (var product in context.Products)
         {
             graphClient.Create(new Product {
                 ProductId = product.ProductID
             });
         }
     }
 }
Example #12
0
        public NodeReference Visit(TSqlObject view)
        {
            Console.WriteLine("Discovered view {0}", view.Name);

            var viewNode = _graphClient.Create(new Nodes.View
            {
                Id   = view.Name.ToString(),
                Name = view.Name.ToString()
            });

            return(viewNode);
        }
Example #13
0
        public NodeReference Visit(TSqlObject userDefinedFunction)
        {
            Console.WriteLine("Discovered user defined function {0}", userDefinedFunction.Name);

            var userDefinedFunctionNode = _graphClient.Create(new Nodes.UserDefinedFunction
            {
                Id   = userDefinedFunction.Name.ToString(),
                Name = userDefinedFunction.Name.ToString()
            });

            return(userDefinedFunctionNode);
        }
        public NodeReference Visit(MethodInfo method)
        {
            if (method.DeclaringType != null)
            {
                Console.WriteLine("Discovered method {0}.{1}", method.DeclaringType.Name, method.Name);
            }

            return(_graphClient.Create(new Nodes.Method
            {
                Id = method.Name,
                Name = method.Name
            }));
        }
Example #15
0
        public void Create(Field field, Row row, Herbicide herbicide)
        {
            try
            {
                Connect();
                var temp1 = client.Create(field);
                var temp2 = client.Create(row);
                var tmep3 = client.Create(herbicide);

                //client.CreateRelationship(field,new FieldRelationship(temp2) { flightNumber = "2" });
                client.Cypher
                .Match("p(Simon")
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Disconnect();
            }
        }
        public NodeReference Visit(PropertyInfo property)
        {
            if (property.DeclaringType != null)
            {
                Console.WriteLine("Discovered property {0}.{1}", property.DeclaringType.Name, property.Name);
            }

            return(_graphClient.Create(new Nodes.Property
            {
                Id = property.Name,
                Name = property.Name
            }));
        }
Example #17
0
        void Foo()
        {
            IGraphClient graph = new GraphClient(new Uri(""));

            // Based on http://wiki.neo4j.org/content/Image:Warehouse.png

            // Can create nodes from POCOs
            var frameStore = graph.Create(
                new StorageLocation { Name = "Frame Store" });
            var mainStore = graph.Create(
                new StorageLocation { Name = "Main Store" });

            // Can create a node with outgoing relationships
            var frame = graph.Create(
                new Part { Name = "Frame" },
                new StoredIn(frameStore));

            // Can create multiple outgoing relationships and relationships with payloads
            graph.Create(
                new Product { Name = "Trike", Weight = 2 },
                new StoredIn(mainStore),
                new Requires(frame, new Requires.Payload { Count = 1 }));

            // Can create relationships in both directions
            graph.Create(
                new Part { Name = "Pedal" },
                new StoredIn(frameStore),
                new Requires(frame, new Requires.Payload { Count = 2 })
                    { Direction = RelationshipDirection.Incoming });

            var wheel = graph.Create(
                 new Part { Name = "Wheel" },
                 new Requires(frame, new Requires.Payload { Count = 2 })
                    { Direction = RelationshipDirection.Incoming });

            // Can create implicit incoming relationships
            graph.Create(
                new StorageLocation { Name = "Wheel Store" },
                new StoredIn(wheel));

            // Can create relationships against the root node
            graph.Create(
                new StorageLocation {Name = "Auxillary Store"},
                new StoredIn(wheel),
                new OwnedBy(graph.RootNode));
        }
Example #18
0
        public NodeReference Visit(TSqlObject table)
        {
            Console.WriteLine("Discovered table {0}", table.Name);

            var tableNode = _graphClient.Create(new Nodes.Table
            {
                Id   = table.Name.ToString(),
                Name = table.Name.ToString()
            });

            var columnVisitor = new ColumnVisitor(_graphClient);

            foreach (var columnNode in table.GetChildren().Where(x => x.ObjectType == ModelSchema.Column).Select(columnVisitor.Visit))
            {
                _graphClient.CreateRelationship(tableNode, new TableContainsColumn(columnNode));
            }

            return(tableNode);
        }
Example #19
0
        private void Btn_Start_Click(object sender, EventArgs e)
        {
            btn_Start.Enabled = false;
            try
            {
                var jsonFiles = Directory.GetFiles(tb_JsonDir.Text.Trim());
                graphClient = new GraphClient(new Uri(tb_Addr.Text.Trim()), tb_User.Text.Trim(), tb_Password.Text.Trim());
                if (!graphClient.IsConnected)
                {
                    graphClient.Connect();
                }
                #region 進度條
                progressBar.Maximum = jsonFiles.Count();
                progressBar.Value   = 0;
                progressBar.Step    = 1;
                #endregion

                foreach (var jsonPath in jsonFiles)
                {
                    progressBar.PerformStep();
                    var json = File.ReadAllText(jsonPath);
                    var jdg  = ConvertToDTO(json);
                    if (jdg == null)
                    {
                        continue;
                    }
                    graphClient.Create <JDG>(jdg);
                    Application.DoEvents();
                    this.Invoke(new Action(() => { lb_Count.Text = $"{progressBar.Value} / {progressBar.Maximum}"; }));
                }
                MessageBox.Show("Finished");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"發生錯誤: {ex.Message}");
            }
            finally
            {
                progressBar.Maximum = 0;
                progressBar.Value   = 0;
                btn_Start.Enabled   = true;
            }
        }
Example #20
0
        public NodeReference Visit(string databasePackagePath)
        {
            var databaseNode = _graphClient.Create(new Nodes.Database
            {
                Id   = Path.GetFileNameWithoutExtension(databasePackagePath),
                Name = Path.GetFileNameWithoutExtension(databasePackagePath)
            });

            var model = new TSqlModel(databasePackagePath);

            var tableVisitor = new TableVisitor(_graphClient);

            foreach (var tableNode in model.GetObjects(DacQueryScopes.All, ModelSchema.Table).Select(tableVisitor.Visit))
            {
                _graphClient.CreateRelationship(databaseNode, new DatabaseContainsTable(tableNode));
            }

            var storedProcedureVisitor = new StoredProcedureVisitor(_graphClient);

            foreach (var storedProcedureNode in model.GetObjects(DacQueryScopes.All, ModelSchema.Procedure).Select(storedProcedureVisitor.Visit))
            {
                _graphClient.CreateRelationship(databaseNode, new DatabaseContainsStoredProcedure(storedProcedureNode));
            }

            var viewVisitor = new ViewVisitor(_graphClient);

            foreach (var viewNode in model.GetObjects(DacQueryScopes.All, ModelSchema.View).Select(viewVisitor.Visit))
            {
                _graphClient.CreateRelationship(databaseNode, new DatabaseContainsView(viewNode));
            }

            var userDefinedFunctionVisitor = new UserDefinedFunctionVisitor(_graphClient);

            foreach (var userDefinedFunctionNode in model.GetObjects(DacQueryScopes.All, ModelSchema.TableValuedFunction, ModelSchema.ScalarFunction).Select(userDefinedFunctionVisitor.Visit))
            {
                _graphClient.CreateRelationship(databaseNode, new DatabaseContainsUserDefinedFunction(userDefinedFunctionNode));
            }

            return(databaseNode);
        }
Example #21
0
        private Node <Actor> EnsureActorIsInDb(GraphClient db)
        {
            if (!db.CheckIndexExists("Actors", IndexFor.Node))
            {
                db.CreateIndex("Actors",
                               new IndexConfiguration {
                    Provider = IndexProvider.lucene, Type = IndexType.exact
                },
                               IndexFor.Node);
            }

            var actor = db.RootNode
                        .Out <Actor>(ObjectBelongsTo.TypeKey, i => i.ActorName == this.ActorName)
                        .FirstOrDefault();

            if (actor == null)
            {
                var actorRef = db.Create <Actor>(this, new ObjectBelongsTo(db.RootNode));
                actor = db.Get <Actor>(actorRef);
            }

            return(actor);
        }
Example #22
0
        public NodeReference Visit(Assembly assembly)
        {
            Console.WriteLine("Discovered assembly {0}", assembly.FullName);

            var assemblyNode = _graphClient.Create(new Nodes.Assembly
            {
                Id   = assembly.FullName,
                Name = assembly.GetName().Name
            });


            Type[] types;
            try
            {
                types = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException ex)
            {
                types = ex.Types;
            }

            var classVisitor = new ClassVisitor(_graphClient);

            foreach (var classNode in types.Where(x => x != null && x.IsClass).Select(classVisitor.Visit))
            {
                _graphClient.CreateRelationship(assemblyNode, new AssemblyContainsClass(classNode));
            }

            var interfaceVisitor = new InterfaceVisitor(_graphClient);

            foreach (var interfaceNode in types.Where(x => x != null && x.IsInterface).Select(interfaceVisitor.Visit))
            {
                _graphClient.CreateRelationship(assemblyNode, new AssemblyContainsInterface(interfaceNode));
            }

            return(assemblyNode);
        }
Example #23
0
        public NodeReference Visit(string path)
        {
            var reportNode = _graphClient.Create(new Report
            {
                Id   = Path.GetFileNameWithoutExtension(path),
                Name = Path.GetFileNameWithoutExtension(path)
            });

            var root = XDocument.Load(path);

            var storedProcedureNames = root
                                       .Descendants("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Query")
                                       .Where(x => (string)x.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}CommandType") == "StoredProcedure")
                                       .Select(x => (string)x.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}CommandText"));


            foreach (var storedProcedureName in storedProcedureNames)
            {
                var fullyQualifiedStoredProcedureName = string.Format("[dbo].[{0}]", storedProcedureName);

                var storedProcedureQuery = _graphClient.Cypher
                                           .Start(new { root = _graphClient.RootNode })
                                           .Match("root-[:ROOT_CONTAINS_DATABASESERVER]->databaseServer-[:DATABASESERVER_CONTAINS_DATABASE]->database-[:DATABASE_CONTAINS_STOREDPROCEDURE]->storedprocedure")
                                           .Where((StoredProcedure storedprocedure) => storedprocedure.Id == fullyQualifiedStoredProcedureName)
                                           .Return <Node <StoredProcedure> >("storedprocedure");

                var results = storedProcedureQuery.Results.ToList();

                if (results.Count == 1)
                {
                    _graphClient.CreateRelationship(reportNode, new ReportInvokesStoredProcedure(results.First().Reference));
                }
            }

            return(reportNode);
        }
Example #24
0
        void createGraph(GraphOfNodes graphNodes, Dictionary <int, int> SubjectIdLevelMapping, GraphClient client)
        {
            List <GraphNode> lst_graphNodes = graphNodes.GraphNodes;

            Dictionary <GraphNode, List <GraphNode> > lst_relationships = graphNodes.ParentToChildrenMap;

            if (lst_graphNodes == null || lst_relationships == null)
            {
                return;
            }


            Dictionary <TermNode, NodeReference <Neo4jTermNode> >   m_term_nodes  = new Dictionary <TermNode, NodeReference <Neo4jTermNode> >();
            Dictionary <CoverNode, NodeReference <Neo4jCoverNode> > m_cover_nodes = new Dictionary <CoverNode, NodeReference <Neo4jCoverNode> >();


            //Add Nodes
            foreach (GraphNode node in lst_graphNodes)
            {
                if (node is TermNode)
                {
                    TermNode term_node = (TermNode)node;

                    //term_node.ded;
                    int           id = node.Subject.ID;
                    Neo4jTermNode tn = new Neo4jTermNode();
                    tn.NodeID            = id;
                    tn.NumberOfBuildings = term_node.PrimarySubject.Schedule.ActNumOfBldgs;
                    tn.IsPerRisk         = term_node.IsPerRisk;
                    tn.Level             = SubjectIdLevelMapping[id];

                    if (term_node.Deductibles.GetDedList() != null && term_node.Deductibles.GetDedList().Count != 0)
                    {
                        tn.Deductible = term_node.Deductibles.GetDedList().First().Amount;
                    }

                    if (term_node.Limits.GetLimList() != null && term_node.Limits.GetLimList().Count != 0)
                    {
                        tn.Limit = term_node.Limits.GetLimList().First().Amount;
                    }

                    var ref1 = client.Create(tn);
                    m_term_nodes.Add(term_node, (NodeReference <Neo4jTermNode>)ref1);
                }
                else if (node is CoverNode)
                {
                    CoverNode cover_node = (CoverNode)node;
                    //term_node.ded;
                    string         coverName = cover_node.CoverName;
                    Neo4jCoverNode cn        = new Neo4jCoverNode();
                    cn.Name      = coverName;
                    cn.IsPerRisk = cover_node.IsPerRisk;
                    cn.Level     = SubjectIdLevelMapping[cover_node.Subject.ID];

                    var ref1 = client.Create(cn);
                    m_cover_nodes.Add(cover_node, (NodeReference <Neo4jCoverNode>)ref1);
                }
            }

            //Add relationships
            foreach (KeyValuePair <GraphNode, List <GraphNode> > rel in lst_relationships)
            {
                //Parent is  term Node
                if (rel.Key is TermNode)
                {
                    NodeReference <Neo4jTermNode> parentTermNode;
                    m_term_nodes.TryGetValue(rel.Key as TermNode, out parentTermNode);
                    List <GraphNode> lst_childnodes = rel.Value;
                    foreach (GraphNode child in lst_childnodes)
                    {
                        NodeReference <Neo4jTermNode> childGraphTermNode;
                        m_term_nodes.TryGetValue(child as TermNode, out childGraphTermNode);

                        if (child != null)
                        {
                            client.CreateRelationship <Neo4jTermNode, TermChildRelationship>(parentTermNode, new TermChildRelationship(childGraphTermNode));
                        }
                    }
                }

                //Parent is  Cover Node
                else if (rel.Key is CoverNode)
                {
                    NodeReference <Neo4jCoverNode> parentTermNode;
                    m_cover_nodes.TryGetValue(rel.Key as CoverNode, out parentTermNode);
                    List <GraphNode> lst_childnodes = rel.Value;
                    foreach (GraphNode child in lst_childnodes)
                    {
                        if (child is TermNode)
                        {
                            NodeReference <Neo4jTermNode> childGraphTermNode;
                            m_term_nodes.TryGetValue(child as TermNode, out childGraphTermNode);

                            if (child != null)
                            {
                                client.CreateRelationship <Neo4jCoverNode, CoverChildRelationship>(parentTermNode, new CoverChildRelationship(childGraphTermNode));
                            }
                        }

                        else if (child is CoverNode)
                        {
                            NodeReference <Neo4jCoverNode> childGraphCoverNode;
                            m_cover_nodes.TryGetValue(child as CoverNode, out childGraphCoverNode);

                            if (child != null)
                            {
                                client.CreateRelationship <Neo4jCoverNode, DerivedCoverChildRelationship>(parentTermNode, new DerivedCoverChildRelationship(childGraphCoverNode));
                            }
                        }
                        else
                        {
                            throw new NotSupportedException("Can only handle nodes of type term and cover");
                        }
                    }
                }
            }
            // Create entities
            //var refA = client.Create(new Person() { Name = "Person A" });
            //var refB = client.Create(new Person() { Name = "Person B" });
            //var refC = client.Create(new Person() { Name = "Person C" });
            //var refD = client.Create(new Person() { Name = "Person D" });

            //// Create relationships
            //client.CreateRelationship(refA, new KnowsRelationship(refB));
            //client.CreateRelationship(refB, new KnowsRelationship(refC));
            //client.CreateRelationship(refB, new HatesRelationship(refD), new HatesData("Crazy guy")));
            //client.CreateRelationship(refC, new HatesRelationship(refD), new HatesData("Don't know why...")));
            //client.CreateRelationship(refD, new KnowsRelationship(refA));
        }
        public void ShouldThrowInvalidOperationExceptionIfNotConnected()
        {
            var client = new GraphClient(new Uri("http://foo"));

            Assert.Throws <InvalidOperationException>(() => client.Create(new object()));
        }
        public void ShouldThrowArgumentNullExceptionForNullNode()
        {
            var client = new GraphClient(new Uri("http://foo"));

            Assert.Throws <ArgumentNullException>(() => client.Create <object>(null));
        }
Example #27
0
        private static void CreateSampleDataShunLan()
        {
            // Create entities
            var ShunLan = client.Create(new Person()
            {
                Name = "ShunLan"
            });
            var BillyHub = client.Create(new Person()
            {
                Name = "BillyHub"
            });
            var BobbySon = client.Create(new Person()
            {
                Name = "BobbySon"
            });

            var autoPolicyA = client.Create(new Policy()
            {
                PolicyNumber = "AutoPolicy A"
            });
            // var cyclePolicyA = client.Create(new Policy() { PolicyNumber = "Cycle Policy B" });
            var homePolicyA = client.Create(new Policy()
            {
                PolicyNumber = "Home Policy A"
            });

            var veh1 = client.Create(new Vehicle()
            {
                MakeModel = "Honda 1", Id = "111"
            });
            var veh2 = client.Create(new Vehicle()
            {
                MakeModel = "Subaru 2", Id = "222"
            });
            var veh3 = client.Create(new Vehicle()
            {
                MakeModel = "MG 3", Id = "333"
            });

            var home = client.Create(new Home()
            {
                HomeAddress = "1 GEICO Plaza", Id = "12345"
            });


            // ShunLan is Spouse of BillyHub
            client.CreateRelationship(ShunLan, new IsSpouseRelationship(BillyHub));

            // BobbySon child of ShunLan
            client.CreateRelationship(BobbySon, new IsChildRelationship(ShunLan));

            // BobbySon child of BillyHub
            client.CreateRelationship(BobbySon, new IsChildRelationship(BillyHub));

            // ShunLan is NIN on Auto Policy A
            client.CreateRelationship(ShunLan, new NamedInsuredRelationship(autoPolicyA, new NamedInsuredData("Named Insured Data")));

            // BillyHub is SIN on Auto Policy A
            client.CreateRelationship(BillyHub, new SecondaryInsuredRelationship(autoPolicyA));

            //PolicyA has 3 Operators.  THis doesn't mean they actually drive all the cars.
            client.CreateRelationship(ShunLan, new OperatorRelationship(autoPolicyA));
            client.CreateRelationship(BillyHub, new OperatorRelationship(autoPolicyA));
            client.CreateRelationship(BobbySon, new OperatorRelationship(autoPolicyA));

            //BillyHub  Owns Veh 1 and Veh 3
            client.CreateRelationship(BillyHub, new OwnerRelationship(veh1));
            client.CreateRelationship(BillyHub, new OwnerRelationship(veh3));

            //ShunLan Owns Veh 2
            client.CreateRelationship(ShunLan, new OwnerRelationship(veh2));

            //BillyHub Drives Vehicle 1
            client.CreateRelationship(BillyHub, new PolicyDriverRelationship(veh1));

            //ShunLan Drives Veh 2
            client.CreateRelationship(ShunLan, new PolicyDriverRelationship(veh2));

            //BobbySon Drives Veh 3
            client.CreateRelationship(BobbySon, new PolicyDriverRelationship(veh3));

            //ShunLan Owns Home
            client.CreateRelationship(ShunLan, new OwnerRelationship(home));

            //BillyHub Owns Home as well
            client.CreateRelationship(BillyHub, new OwnerRelationship(home));

            // ShunLan Has a home Policy
            client.CreateRelationship(ShunLan, new NamedInsuredRelationship(homePolicyA, new NamedInsuredData("sdajklf")));

            // PolicyA insures Veh1, Veh2, and Veh3
            client.CreateRelationship(autoPolicyA, new InsuresRelationship(veh1));
            client.CreateRelationship(autoPolicyA, new InsuresRelationship(veh2));
            client.CreateRelationship(autoPolicyA, new InsuresRelationship(veh3));

            // HomePolicy insures Home
            client.CreateRelationship(homePolicyA, new InsuresRelationship(home));
        }
Example #28
0
        void Foo()
        {
            IGraphClient graph = new GraphClient(new Uri(""));

            // Based on http://wiki.neo4j.org/content/Image:Warehouse.png

            // Can create nodes from POCOs
            var frameStore = graph.Create(
                new StorageLocation {
                Name = "Frame Store"
            });
            var mainStore = graph.Create(
                new StorageLocation {
                Name = "Main Store"
            });

            // Can create a node with outgoing relationships
            var frame = graph.Create(
                new Part {
                Name = "Frame"
            },
                new StoredIn(frameStore));

            // Can create multiple outgoing relationships and relationships with payloads
            graph.Create(
                new Product {
                Name = "Trike", Weight = 2
            },
                new StoredIn(mainStore),
                new Requires(frame, new Requires.Payload {
                Count = 1
            }));

            // Can create relationships in both directions
            graph.Create(
                new Part {
                Name = "Pedal"
            },
                new StoredIn(frameStore),
                new Requires(frame, new Requires.Payload {
                Count = 2
            })
            {
                Direction = RelationshipDirection.Incoming
            });

            var wheel = graph.Create(
                new Part {
                Name = "Wheel"
            },
                new Requires(frame, new Requires.Payload {
                Count = 2
            })
            {
                Direction = RelationshipDirection.Incoming
            });

            // Can create implicit incoming relationships
            graph.Create(
                new StorageLocation {
                Name = "Wheel Store"
            },
                new StoredIn(wheel));

            // Can create relationships against the root node
            graph.Create(
                new StorageLocation {
                Name = "Auxillary Store"
            },
                new StoredIn(wheel),
                new OwnedBy(graph.RootNode));
        }
        private async Task <T> Get <T>(T db)
        {
            await _cluster.WaitForFollowers();

            return(_cluster.CurrentLeader == _cluster.Self ? db : GraphClient.Create <T>(_cluster.CurrentLeader));
        }
Example #30
0
        public void ShouldThrowArgumentExceptionForPreemptivelyWrappedNode()
        {
            var graphClient = new GraphClient(new Uri("http://foo/db/data"), null);

            graphClient.Create((Node <TestNode>)null);
        }