예제 #1
0
        private void AddAstGraphToGraph(AstGraph parsedGraph, File rootFile)
        {
            foreach (var n in parsedGraph.Nodes)
            {
                n.Id        = this.neo4jwrapp.NextNodeId();
                n.FilePath  = rootFile.Path;
                n.CommitSha = rootFile.Commit;
                this.neo4jwrapp.WriteNode(n);
            }

            BaseNode root = parsedGraph.GetRoot();

            if (root != null)
            {
                this.neo4jwrapp.WriteEdge(rootFile, root, new AstOfFile(this.neo4jwrapp));

                var deleteNode = new AstElementDeleted(this.neo4jwrapp)
                {
                    CommitSha = rootFile.Commit, FilePath = rootFile.Path
                };
                this.neo4jwrapp.WriteNode(deleteNode);
                this.neo4jwrapp.WriteEdge(rootFile, deleteNode, new AstSpecialNode(this.neo4jwrapp));
            }

            foreach (var e in parsedGraph.Edges)
            {
                var from = this.neo4jwrapp.Find(new AstElement()
                {
                    AstId = e.From, FilePath = rootFile.Path, CommitSha = rootFile.Commit
                }).FirstOrDefault();
                var to = this.neo4jwrapp.Find(new AstElement()
                {
                    AstId = e.To, FilePath = rootFile.Path, CommitSha = rootFile.Commit
                }).FirstOrDefault();

                if ((from != null) && (to != null))
                {
                    this.neo4jwrapp.WriteEdge(from, to, new AstAbove(this.neo4jwrapp));
                }
            }
        }
        public static ICypherFluentQuery MatchQuerry(this ICypherFluentQuery cypher, string varialbeName, AstElementDeleted node)
        {
            string matchClause = "(" + varialbeName + ":" + node.GetType().Name + ")";

            var wherClause = new List <String>();

            if (!String.IsNullOrWhiteSpace(node.FilePath))
            {
                wherClause.Add(varialbeName + "." + nameof(node.FilePath) + "=\"" + node.FilePath + "\"");
            }

            if (!String.IsNullOrWhiteSpace(node.CommitSha))
            {
                wherClause.Add(varialbeName + "." + nameof(node.CommitSha) + "=\"" + node.CommitSha + "\"");
            }
            return(cypher.Match(matchClause).Where(String.Join(" and ", wherClause)));
        }