private static Node<PO.Workers> AddWorkersRootNode(GraphClient client, Node<PO.Root> rootNode) { var nodeRef = client.Create(PO.Workers.Create("Workers"), null, new[]{ new IndexEntry{ Name=NameIndexName, KeyValues=new[]{ new KeyValuePair<string,object>("Name", "Workers") } } }); client.CreateRelationship<PO.Root, Relationships.RelatedToRelationship>(rootNode.Reference, new Relationships.RelatedToRelationship(nodeRef)); var ret = client.Get<PO.Workers>(nodeRef.Id); client.Update<PO.Workers>(ret.Reference, node => { node.SetID(ret.Reference.Id); }); ret = client.Get<PO.Workers>(nodeRef.Id); Debug.Assert(ret.Reference.Id == ret.Data.ID); Debug.Assert(ret.Reference.Id == nodeRef.Id); Debug.Assert(ret.Reference.Id == GetWorkersRootNode(client, rootNode).Reference.Id); return ret; }
private static void Fill(GraphClient graphClient) { using (var context = new AdventureWorks2012Context()) { foreach (var product in context.Products) { graphClient.Create(new Product {ProductId = product.ProductID}); } } }
public NodeWrapper CreateIfExists(string FBid, GraphClient client, string firstName, string lastName, Graph<Person> peopleGraph) { //firstName = client.RootNode. //var nodePerson = client.RootNode.StartCypher("n").Where("n.FacebookId = {" + FBid + "}").Return<Person>("n").Results; //firstName = nodePerson.FirstName; //lastName = nodePerson.LastName; //client.ExecuteGetCypherResults<Person>("start n=node(*) where n.FacebookId = {" + FBid + "} return n")); NodeReference<Person> node = null; if (nodes.TryGetValue(FBid, out node)) { // Node exists. //// Get node in Neo4J //Neo4jClient.Node<Person> myNode = client.Get<Person>(node.Id); //// Get the first and last name //if (firstName != null && lastName != null) //{ // myNode.Data.FirstName = firstName; // myNode.Data.LastName = lastName; // newGraphNode.Value.FirstName = firstName; // newGraphNode.Value.LastName = lastName; //} // Fetch node in graph GraphNode<Person> newGraphNode = peopleGraph.Nodes.First(x => x.Value.FacebookId == FBid); Console.WriteLine("Found node for {0} {1}. Returning",newGraphNode.Value.FirstName,newGraphNode.Value.LastName); return new NodeWrapper(){GraphNode = newGraphNode,NodeReference = node}; } // It doesn't exist yet, so first create the new person Person person = new Person(); person.FirstName = firstName; person.LastName = lastName; person.FacebookId = FBid; // Create them in Neo4J! nodes[FBid] = client.Create<Person>(person, null, null); // Create them in graph GraphNode<Person> newNode = new GraphNode<Person>(person); peopleGraph.AddNode(newNode); // You created a node! Console.WriteLine("Created node for " + firstName + " " + lastName + ". Returning."); return new NodeWrapper() { GraphNode = newNode, NodeReference = nodes[FBid] }; }
private static Node<PO.Root> AddRootNode( GraphClient client) { var nodeRef = client.Create(PO.Root.Create(), null, new[]{ new IndexEntry{ Name=NameIndexName, KeyValues=new[]{ new KeyValuePair<string,object>("Name", "Root") } } }); var ret = client.Get<PO.Root>(nodeRef.Id); client.Update<PO.Root>(ret.Reference, node => { node.SetID(ret.Reference.Id); }); ret = client.Get<PO.Root>(nodeRef.Id); return ret; }
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; }
public Scaffolding() { client = new GraphClient(new Uri("http://localhost:7474/db/data")); client.Connect(); client.CreateIndex("User", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.exact }, IndexFor.Node); // full text node index client.CreateIndex("Module", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node); // exact node index //client.CreateIndex("Genre", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node); // full text node index // Create Entities // Movies /* Movie swI = new Movie() { Name = "Star Wars: Episode I - The Phantom Menace", Description = "Begins the story of Anakin Skywalker" }; var starWarsEpisodeI = client.Create(swI, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", swI.Name }, { "Description", swI.Description }, { "Id", swI.Id.ToString() } } }); Movie swIV = new Movie() { Name = "Star Wars: Episode IV - A New Hope", Description = "First Starwars movie to debut on the big screen" }; var starWarsEpisodeIV = client.Create(swIV, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", swIV.Name }, { "Description", swIV.Description }, { "Id", swIV.Id.ToString() } } }); Movie indy = new Movie() { Name = "Indiana Jones and the Temple of Doom", Description = "Second movie in the original Indiana Jones trilogy" }; var indianaJonesTempleOfDoom = client.Create(indy, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", indy.Name }, { "Description", indy.Description }, { "Id", indy.Id.ToString() } } }); Movie jp = new Movie() { Name = "Jurassic Park", Description = "First Jurassic park movie" }; var jurassicPark = client.Create(jp, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", jp.Name }, { "Description", jp.Description }, { "Id", jp.Id.ToString() } } }); Movie et = new Movie() { Name = "ET", Description = "ET phone home" }; var ET = client.Create(et, new IRelationshipAllowingParticipantNode<Movie>[0], new[] { new IndexEntry("Movie") { { "Name", et.Name }, { "Description", et.Description }, { "Id", et.Id.ToString() } } }); */ // Directors User lucas = new User() { UserName = "******", Email_ID ="Lucas", Password ="******" }; var georgeLucas = client.Create(lucas, new IRelationshipAllowingParticipantNode<User>[0], new[] { new IndexEntry("User") { { "Name", lucas.UserName }, { "Id", lucas.UserID.ToString() } } }); User spielberg = new User() { UserName = "******", Email_ID = "Lucas", Password = "******" }; var stevenSpielberg = client.Create(spielberg, new IRelationshipAllowingParticipantNode<User>[0], new[] { new IndexEntry("User") { { "Name", spielberg.UserName }, { "Id", spielberg.UserID.ToString() } } }); Module module1 = new Module() { ModuleName = "Module 1" }; var modModule1 = client.Create(module1, new IRelationshipAllowingParticipantNode<Module>[0], new[] { new IndexEntry("Module") { { "Name", module1.ModuleName }, { "Id", module1.ModuleId.ToString() } } }); Module module2 = new Module() { ModuleName = "Module 2" }; var modModule2 = client.Create(module2, new IRelationshipAllowingParticipantNode<Module>[0], new[] { new IndexEntry("Module") { { "Name", module2.ModuleName }, { "Id", module2.ModuleId.ToString() } } }); /* // Genres Genre sf = new Genre() { Name = "Science Fiction" }; var sciFi = client.Create(sf, new IRelationshipAllowingParticipantNode<Genre>[0], new[] { new IndexEntry("Genre") { { "Name", sf.Name }, { "Id", sf.Id.ToString() } } }); Genre adv = new Genre() { Name = "Adventure" }; var adventure = client.Create(adv, new IRelationshipAllowingParticipantNode<Genre>[0], new[] { new IndexEntry("Genre") { { "Name", adv.Name }, { "Id", adv.Id.ToString() } } }); */ // Create Relationships client.CreateRelationship(stevenSpielberg, new HasCompletedRelation(modModule1)); client.CreateRelationship(stevenSpielberg, new HasCompletedRelation(modModule2)); client.CreateRelationship(georgeLucas, new HasCompletedRelation(modModule2)); /* client.CreateRelationship(starWarsEpisodeIV, new PartOf(sciFi)); client.CreateRelationship(indianaJonesTempleOfDoom, new PartOf(adventure)); client.CreateRelationship(jurassicPark, new PartOf(sciFi)); client.CreateRelationship(jurassicPark, new PartOf(adventure)); client.CreateRelationship(ET, new PartOf(sciFi)); client.CreateRelationship(georgeLucas, new Directed(starWarsEpisodeI, new Models.Payloads.Payload() { Comment = "George Lucas' second Star Wars trilogy" })); client.CreateRelationship(georgeLucas, new Directed(starWarsEpisodeIV, new Models.Payloads.Payload() { Comment = "First Starwars movie that George Lucas directed" })); client.CreateRelationship(georgeLucas, new Directed(indianaJonesTempleOfDoom, new Models.Payloads.Payload() { Comment = "Lucas collaborated with Spielberg while filming" })); client.CreateRelationship(stevenSpielberg, new Directed(jurassicPark, new Models.Payloads.Payload() { Comment = "Huge box office success" })); client.CreateRelationship(stevenSpielberg, new Directed(ET, new Models.Payloads.Payload() { Comment = "One of Spielberg's most successful movies" })); */ /* var refA = client.Create(new User() { UserName = "******" }); var refB = client.Create(new Module() { ModuleName = "Module A" }); var refC = client.Create(new Module() { ModuleName = "Module B" }); var refD = client.Create(new User() { UserName = "******" }); // Create relationships client.CreateRelationship(refA, new HasCompletedRelation(refB)); client.CreateRelationship(refA, new HasCompletedRelation(refC)); client.CreateRelationship(refD, new HasCompletedRelation(refC)); //client.CreateRelationship(refC, new HasCompletedRelation(refD) { Reason = "Don't know why : )" }); client.CreateRelationship(refD, new HasCompletedRelation(refA)); */ }
private static Node<PO.Worker> AddWorker(string name, GraphClient Client, Node<PO.Workers>WorkersRootNode) { var workerNodeRef = Client.Create( PO.Worker.Create(name), null, new[] { new IndexEntry { Name = "my_index", KeyValues = new[] { /* new KeyValuePair<string, object>("key", "value"), new KeyValuePair<string, object>("key2", ""), */ new KeyValuePair<string, object>("key3", "value3") } } } ); Client.Update<PO.Worker>(workerNodeRef, node => { node.SetID(workerNodeRef.Id); }); var workersRootNode = WorkersRootNode; var rel = Client.CreateRelationship<PO.Workers, Relationships.HasItemRelationship>( workersRootNode.Reference, new Relationships.HasItemRelationship(workerNodeRef) ); var workerNode = Get(workerNodeRef.Id, Client); return workerNode; }