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);
        }
Exemplo n.º 2
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 Comment AddCommentToSession(Session session, int id, Comment comment)
        {
            var client = new GraphClient(new Uri("http://localhost:7474/db/data"));

            client.Connect();

            var result = client.Cypher.Create("(c:Comment {comm})")
                         .WithParams(new { comm = comment })
                         .Return(c => c.Node <Comment>())
                         .Results
                         .Single();

            client.Connect();
            var userNode =
                client.Cypher.Match("(u:User)").Where((User u) => u.ProviderUserKey == id).Return(u => u.Node <User>())
                .Results.Single();

            client.CreateRelationship(result.Reference, new CreatedByRelationship(userNode.Reference));
            client.Connect();
            var sessionNode = client.Cypher.Start(new { s = string.Format("node({0})", session.Id) })
                              .Match("(s)")
                              .Return(s => s.Node <Session>()).Results.Single();

            client.CreateRelationship(result.Reference, new OnSession(sessionNode.Reference));
            result.Data.Id            = (int)result.Reference.Id;
            result.Data.MadeBy        = userNode.Data.AsType <UserInfo>();
            result.Data.MadeBy.NodeId = (int)result.Data.MadeBy.ProviderUserKey;
            return(result.Data);
        }
Exemplo n.º 4
0
        public void Visit(Node <Nodes.Database> databaseNode, TSqlObject view)
        {
            var viewNode = GetViewNode(databaseNode, view);

            foreach (var table in view.GetReferenced().Where(x => x.ObjectType == ModelSchema.Table))
            {
                try
                {
                    var tableNode = GetTableNode(databaseNode, table);

                    if ((viewNode == null) || (tableNode == null))
                    {
                        continue;
                    }

                    if (RelationshipExists(viewNode.Reference, tableNode.Reference))
                    {
                        continue;
                    }

                    Console.WriteLine("Creating dependency between view {0} and table {1}", viewNode.Data.Id, tableNode.Data.Id);
                    _graphClient.CreateRelationship(viewNode.Reference, new ViewReferencesTable(tableNode.Reference));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error analyzing {0}: {1}", view.Name.ToString(), ex);
                }
            }

            foreach (var column in view.GetReferenced().Where(x => x.ObjectType == ModelSchema.Column))
            {
                try
                {
                    var columnNode = GetColumnNode(databaseNode, column);

                    if ((viewNode == null) || (columnNode == null))
                    {
                        continue;
                    }

                    if (RelationshipExists(viewNode.Reference, columnNode.Reference))
                    {
                        continue;
                    }

                    Console.WriteLine("Creating dependency between stored procedure {0} and column {1}", viewNode.Data.Id, columnNode.Data.Id);
                    _graphClient.CreateRelationship(viewNode.Reference, new ViewReferencesColumn(columnNode.Reference));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error analyzing {0}: {1}", view.Name.ToString(), ex);
                }
            }
        }
        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();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var arguments = new Dictionary <string, string>();

            for (var index = 0; index < args.Length; index = index + 2)
            {
                arguments.Add(args[index].Substring(1), args[index + 1]);
            }

            GraphClient.Connect();

            if (arguments.ContainsKey("dacpac"))
            {
                var databaseVisitor    = new DatabaseVisitor(GraphClient);
                var databaseServerNode = GetDatabaseServerNode(arguments["server"]);

                GraphClient.CreateRelationship(databaseServerNode, new DatabaseServerContainsDatabase(databaseVisitor.Visit(arguments["dacpac"])));
            }
            else if (arguments.ContainsKey("dacpac-references"))
            {
                var storedProcedureDependencyVisitor = new StoredProcedureDependencyVisitor(GraphClient);
                storedProcedureDependencyVisitor.Visit(arguments["dacpac-references"]);

                var viewDependencyVisitor = new ViewDependencyVisitor(GraphClient);
                viewDependencyVisitor.Visit(arguments["dacpac-references"]);
            }
            else if (arguments.ContainsKey("assembly"))
            {
                var assemblyVisitor = new AssemblyVisitor(GraphClient);
                GraphClient.CreateRelationship(GraphClient.RootNode, new RootContainsAssembly(assemblyVisitor.Visit(arguments["assembly"])));
            }
            else if (arguments.ContainsKey("reports"))
            {
                var reportVisitor    = new ReportVisitor(GraphClient);
                var reportServerNode = GetReportServerNode(arguments["server"]);

                var directory = new DirectoryInfo(arguments["reports"]);
                foreach (var report in directory.EnumerateFiles("*.rdl"))
                {
                    GraphClient.CreateRelationship(reportServerNode, new ReportServerContainsReport(reportVisitor.Visit(report.FullName)));
                }
            }
            else if (arguments.ContainsKey("dotnet"))
            {
                var projectVisitor = new DotNetProjectVisitor(GraphClient);
                projectVisitor.Visit(arguments["dotnet"]);
            }
        }
Exemplo n.º 7
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();
 }
        private void CreateAssemblyReferencesAssemblyRelationship(Assembly source, AssemblyName target)
        {
            var sourceNode = GetAssemblyNode(source);
            var targetNode = GetAssemblyNode(target);

            if ((sourceNode != null) && (targetNode != null))
            {
                _graphClient.CreateRelationship(sourceNode.Reference, new AssemblyReferencesAssembly(targetNode.Reference));
            }
        }
        private void CreateMethodInvokesMethodRelationship(ISymbol source, ISymbol target)
        {
            var sourceNode = GetMethodNode(source);
            var targetNode = GetMethodNode(target);

            if ((sourceNode != null) && (targetNode != null))
            {
                Console.WriteLine("Discovered dependendency between {0} and {1}", sourceNode.Data.Id, targetNode.Data.Id);
                _graphClient.CreateRelationship(sourceNode.Reference, new MethodInvokesMethod(targetNode.Reference));
            }
        }
Exemplo n.º 10
0
        private void EnsureRelationshipInDb(Node <Actor> actor, Node <Character> character, GraphClient db)
        {
            var rel = actor
                      .Out <Character>(ActorPlayed.TypeKey, i => i.CharacterName == character.Data.CharacterName)
                      .InE()
                      .FirstOrDefault();

            if (rel == null)
            {
                db.CreateRelationship <Actor, ActorPlayed>(actor.Reference, new ActorPlayed(character.Reference));
            }
        }
Exemplo n.º 11
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);
        }
        private void CreateMethodInvokesStoredProcedureRelationship(ISymbol source, string target)
        {
            var sourceNode = GetMethodNode(source);
            var targetNode = GetStoredProcedureNode(target);

            if ((sourceNode == null) || (targetNode == null))
            {
                return;
            }

            Console.WriteLine("Discovered dependendency between {0} and {1}", sourceNode.Data.Id, targetNode.Data.Id);
            _graphClient.CreateRelationship(sourceNode.Reference, new MethodInvokesStoredProcedure(targetNode.Reference));
        }
Exemplo n.º 13
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);
        }
        public void LikeSession(Session session, int id)
        {
            var client = new GraphClient(new Uri("http://localhost:7474/db/data"));

            client.Connect();

            var createdSession = client.Cypher.Match("(s:Session)")
                                 .Where((Session s) => s.Id == session.Id).Return(s => s.Node <Session>())
                                 .Results.Single();

            client.Connect();
            var userNode =
                client.Cypher.Match("(u:User)").Where((User u) => u.ProviderUserKey == id).Return(u => u.Node <User>())
                .Results.Single();

            client.CreateRelationship(createdSession.Reference, new LikedBy(userNode.Reference));
        }
Exemplo n.º 15
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);
        }
        public void AddSession(Session s, long userKey)
        {
            var client = new GraphClient(new Uri("http://localhost:7474/db/data"));

            var sess = s;

            client.Connect();
            var createdSession = client.Cypher.Create("(session:Session {session})")
                                 .WithParams(new { session = sess })
                                 .Return(session => session.Node <Session>())
                                 .Results
                                 .Single();

            client.Connect();
            var userNode =
                client.Cypher.Match("(u:User)").Where((User u) => u.ProviderUserKey == userKey).Return(u => u.Node <User>())
                .Results.Single();

            client.CreateRelationship(createdSession.Reference, new CreatedByRelationship(userNode.Reference));
        }
Exemplo n.º 17
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);
        }
        public void ShouldThrowInvalidOperationExceptionIfNotConnected()
        {
            var client = new GraphClient(new Uri("http://foo"));

            client.CreateRelationship(new NodeReference <TestNode>(5), new TestRelationship(10));
        }
        public void ShouldThrowArgumentNullExceptionForNullNodeReference()
        {
            var client = new GraphClient(new Uri("http://foo"));

            client.CreateRelationship((NodeReference <TestNode>)null, new TestRelationship(10));
        }
Exemplo n.º 20
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));
        }
        public void Visit(Node <Nodes.Database> databaseNode, TSqlObject storedProcedure)
        {
            var storedProcedureNode = GetStoredProcedureNode(databaseNode, storedProcedure);

            foreach (var table in storedProcedure.GetReferenced().Where(x => x.ObjectType == ModelSchema.Table))
            {
                try
                {
                    var tableNode = GetTableNode(databaseNode, table);

                    if ((storedProcedureNode == null) || (tableNode == null))
                    {
                        continue;
                    }

                    if (RelationshipExists(storedProcedureNode.Reference, tableNode.Reference))
                    {
                        continue;
                    }

                    Console.WriteLine("Creating dependency between stored procedure {0} and table {1}", storedProcedureNode.Data.Id, tableNode.Data.Id);
                    _graphClient.CreateRelationship(storedProcedureNode.Reference, new StoredProcedureReferencesTable(tableNode.Reference));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error analyzing {0}: {1}", storedProcedure.Name.ToString(), ex);
                }
            }

            foreach (var column in storedProcedure.GetReferenced().Where(x => x.ObjectType == ModelSchema.Column))
            {
                try
                {
                    var columnNode = GetColumnNode(databaseNode, column);

                    if ((storedProcedureNode == null) || (columnNode == null))
                    {
                        continue;
                    }

                    if (RelationshipExists(storedProcedureNode.Reference, columnNode.Reference))
                    {
                        continue;
                    }

                    Console.WriteLine("Creating dependency between stored procedure {0} and column {1}", storedProcedureNode.Data.Id, columnNode.Data.Id);
                    _graphClient.CreateRelationship(storedProcedureNode.Reference, new StoredProcedureReferencesColumn(columnNode.Reference));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error analyzing {0}: {1}", storedProcedure.Name.ToString(), ex);
                }
            }

            // Check for dynamic SQL
            var script = storedProcedure.GetScript();

            if (!script.Contains("EXEC"))
            {
                return;
            }

            foreach (Match match in FromRegex.Matches(script))
            {
                try
                {
                    var tableNode = GetTableNode(databaseNode, string.Format("[dbo].[{0}]", match.Groups["table"].Value));

                    if ((storedProcedureNode == null) || (tableNode == null))
                    {
                        continue;
                    }

                    if (RelationshipExists(storedProcedureNode.Reference, tableNode.Reference))
                    {
                        continue;
                    }

                    Console.WriteLine("Creating dependency between stored procedure {0} and table {1} (dynamic SQL)", storedProcedureNode.Data.Id, tableNode.Data.Id);
                    _graphClient.CreateRelationship(storedProcedureNode.Reference, new StoredProcedureReferencesTable(tableNode.Reference));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error analyzing {0}: {1}", storedProcedure.Name.ToString(), ex);
                }
            }

            foreach (Match match in JoinRegex.Matches(script))
            {
                try
                {
                    var tableNode = GetTableNode(databaseNode, string.Format("[dbo].[{0}]", match.Groups["table"].Value));

                    if ((storedProcedureNode == null) || (tableNode == null))
                    {
                        continue;
                    }

                    if (RelationshipExists(storedProcedureNode.Reference, tableNode.Reference))
                    {
                        continue;
                    }

                    Console.WriteLine("Creating dependency between stored procedure {0} and table {1} (dynamic SQL)", storedProcedureNode.Data.Id, tableNode.Data.Id);
                    _graphClient.CreateRelationship(storedProcedureNode.Reference, new StoredProcedureReferencesTable(tableNode.Reference));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error analyzing {0}: {1}", storedProcedure.Name.ToString(), ex);
                }
            }
        }
Exemplo n.º 22
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));
        }