コード例 #1
0
ファイル: SaveListener.cs プロジェクト: chrisparnin/ganji
        private void HandleSave(string name)
        {
            try
            {
                using (var db = new HistoryContext())
                {
                    var now = DateTime.Now;
                    // add file to commit!
                    provider.CopyFileToCache(name);
                    // commit to git...
                    var commitId = provider.Commit();

                    var doc = db.Documents.Where(d => d.CurrentFullName == name).SingleOrDefault();
                    if (doc == null)
                    {
                        doc = new Document() { CurrentFullName = name };
                        db.Documents.Add(doc);
                    }

                    var commit = new Commit()
                    {
                        Document = doc,
                        RepositoryId = commitId,
                        Timestamp = now,
                    };

                    db.Commits.Add(commit);

                    // Build tokens, code members, and code classes
                    //Parser(name, db, doc, commit); // test

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #2
0
ファイル: SaveListener.cs プロジェクト: chrisparnin/ganji
        private static void Parser(string name, HistoryContext db, Document doc, Commit commit)
        {
            //var parser = new Tokenizing.TokenParser();
            //var tokens = parser.Parse(name);

            //// initial pass on class declarations...
            //var classTokens = tokens.Where(t => t.Kind == "ClassDeclaration");
            //Dictionary<string, CodeClass> classCache = new Dictionary<string, CodeClass>();
            //Dictionary<string, CodeMember> methodCache = new Dictionary<string, CodeMember>();

            //foreach (var cToken in classTokens)
            //{
            //    var klass = db.CodeClass.Where(c => c.Signature == cToken.Value).SingleOrDefault();
            //    if (klass == null)
            //    {
            //        klass = new CodeClass()
            //        {
            //            Document = doc,
            //            Name = cToken.Name,
            //            Signature = cToken.Value,
            //            Namespace =  parser.GetNamespace(cToken.Node),
            //            Parent = null
            //        };
            //        db.CodeClass.Add(klass);
            //    }
            //    classCache.Add(klass.Signature, klass);
            //}

            //// setting parents of class declarations (inner classes)
            //foreach (var cToken in classTokens)
            //{
            //    var klass = classCache[cToken.Value];
            //    if (!string.IsNullOrEmpty(cToken.ParentSignature))
            //    {
            //        klass.Parent = classCache[cToken.ParentSignature];
            //    }
            //}

            //// setting code members
            //var methodTokens = tokens.Where(t => t.Kind == "MethodDeclaration");
            //foreach (var methodToken in methodTokens)
            //{
            //    if( string.IsNullOrEmpty( methodToken.ParentSignature ) )
            //        continue;

            //    var member = db.CodeMember.Where(m => m.Signature == methodToken.Value).SingleOrDefault();
            //    var parent = classCache[methodToken.ParentSignature];
            //    if (member == null)
            //    {
            //        member = new CodeMember() { ShortName = methodToken.Name, Signature = methodToken.Value, Parent = parent };
            //        db.CodeMember.Add(member);
            //    }
            //    if (member.Parent.Signature != member.Parent.Signature)
            //    {
            //        // might happen if class renamed or method moved within same file...
            //        member.Parent = parent;
            //    }

            //    methodCache.Add(methodToken.Value, member);

            //    // build method boundaries
            //    var methodBoundary = new CodeToken()
            //    {
            //        LineStart = methodToken.LineStart,
            //        LineEnd = methodToken.LineEnd,
            //        Commit = commit,
            //        Document = doc,
            //        Parent = member,
            //        Kind = methodToken.Kind,
            //        Value = methodToken.Value,
            //        Name = methodToken.Name,
            //        Path = methodToken.ParentSignature
            //    };
            //    db.CodeTokens.Add(methodBoundary);
            //}

            //var invocations = tokens.Where(t => t.Kind == "Invocation");
            //foreach (var invoke in invocations)
            //{
            //    if (!string.IsNullOrEmpty(invoke.ParentSignature) &&
            //        methodCache.ContainsKey(invoke.ParentSignature))
            //    {
            //        var member = methodCache[invoke.ParentSignature];
            //        var token = new CodeToken()
            //        {
            //            LineStart = invoke.LineStart,
            //            LineEnd = invoke.LineEnd,
            //            Commit = commit,
            //            Document = doc,
            //            Parent = member,
            //            IsSystem = invoke.IsSystem,
            //            Kind = invoke.Kind,
            //            Value = invoke.Value,
            //            Name = invoke.Name,
            //            Path = invoke.ParentSignature
            //        };
            //        db.CodeTokens.Add(token);
            //    }
            //}
        }