Example #1
0
        private List <CodeDoc> GetDocumentsFromCommit(GitHubUser user, Repository repo, GitHubCommit commit)
        {
            List <CodeDoc> cd = new List <CodeDoc>();

            var associated_files = user.GitHubClient.Repository.Commit.Get(repo.Id, commit.Sha).Result;

            foreach (var file in associated_files.Files)
            {
                string ext = Path.GetExtension(file.Filename);
                if (!SrcML.supportedExtensions.ContainsKey(ext))
                {
                    Console.WriteLine("Skipping {0} ({1}): not supported by SrcML", file.Filename, file.Sha);
                    continue;
                }

                if (file.Additions == 0 || String.Equals(file.Status, "removed"))
                {
                    Console.WriteLine("Skipping {0} ({1}): file was deleted", file.Filename, file.Sha);
                    continue;
                }

                // pulls out relevant information for later searching
                string parsedPatch = FullyParsePatch(file.Filename, file.RawUrl, file.Patch);

                if (String.IsNullOrEmpty(parsedPatch))
                {
                    Console.WriteLine("Discarding {0} ({1}): no relevant terms found in parsed patch", file.Filename, file.Sha);
                    continue;
                }

                CodeDoc doc = new CodeDoc
                {
                    Id                 = file.Sha,
                    Sha                = file.Sha,
                    Author_Date        = commit.Commit.Author.Date.Date,
                    Author_Name        = commit.Commit.Author.Name,
                    Channel            = user.ChannelID,
                    Committer_Name     = user.UserID,
                    Accesstoken        = user.GitHubAccessToken,
                    Filename           = file.Filename,
                    Previous_File_Name = file.PreviousFileName,
                    Raw_Url            = file.RawUrl,
                    Blob_Url           = file.BlobUrl,
                    Unindexed_Patch    = parsedPatch,
                    Patch              = parsedPatch,
                    Repo               = repo.Name,
                    Html_Url           = commit.HtmlUrl,
                    Message            = commit.Commit.Message,
                    Prog_Language      = SrcML.supportedExtensions[ext]
                };

                cd.Add(doc);
                Console.WriteLine("Adding {0} ({1}) to Solr", doc.Filename, doc.Sha);
            }

            return(cd);
        }
 public void CreateInstance(Form main)
 {
     if (main is Main)
     {
         Main form = (Main)main;
         if (form.databasetree == null)
         {
             form.databasetree = new DataBasesTree();
             form.databasetree.DocHandler += new EventHandler<DocumentEventArgs>((object sender, DocumentEventArgs e) =>
             {
                 if (e.Sender is string)
                 {
                     form.CreateDocument(e.Tag, () =>
                     {
                         string msg = (string)e.Sender;
                         CodeDoc dummyDoc = new CodeDoc();
                         dummyDoc.SetMessage(msg, LauguaageType.mssql);
                         return dummyDoc;
                     });
                 }
                 else if (e.sender is TableEntity)
                 {
                     var obj=LCW.Framework.Common.Driver.DBDriverProvice.GetInstance;
                     TableEntity table = (TableEntity)e.sender;
                     form.CreateDocument(table.Name, () =>
                     {
                         IDictionary<string, object> dic = new Dictionary<string, object>();
                         dic.Add("table", table.Name);
                         dic.Add("columns", table.Columns);
                         string msg = VelocityWrapper.CreateCode(new GeneralCode().Execute(),dic);
                         CodeDoc dummyDoc = new CodeDoc();
                         dummyDoc.SetMessage(msg, LauguaageType.cs);
                         return dummyDoc;
                     });
                 }
             });
         }
         form.databasetree.Show(form.DockPanel);
     }
 }