Example #1
0
        public async Task DisplayProjectContributorSummaryDashboard()
        {
            string        file = FileManager.GetContributorDashboardFile();
            StringBuilder sb   = new StringBuilder();

            // fetch the git stats
            string projectDir = DocEventManager._solutionDirectory;

            RepoResourceInfo resourceInfo = GitUtilManager.GetResourceInfo(projectDir, false);
            string           identifier   = resourceInfo != null && resourceInfo.identifier != null ? resourceInfo.identifier : "Untitled";

            NowTime           nowTime              = SoftwareCoUtil.GetNowTime();
            string            email                = GitUtilManager.GetUsersEmail(projectDir);
            CommitChangeStats usersTodaysCommits   = GitUtilManager.GetTodaysCommits(projectDir, email);
            CommitChangeStats contribTodaysCommits = GitUtilManager.GetTodaysCommits(projectDir, null);

            CommitChangeStats usersYesterdaysCommits   = GitUtilManager.GetYesterdayCommits(projectDir, email);
            CommitChangeStats contribYesterdaysCommits = GitUtilManager.GetYesterdayCommits(projectDir, null);

            CommitChangeStats usersThisWeeksCommits   = GitUtilManager.GetThisWeeksCommits(projectDir, email);
            CommitChangeStats contribThisWeeksCommits = GitUtilManager.GetThisWeeksCommits(projectDir, null);


            string lastUpdatedStr = DateTime.Now.ToString("dddd, MMM d h:mm tt");

            sb.Append(getTableHeader("PROJECT SUMMARY", " (Last updated on " + lastUpdatedStr + ")", true));
            sb.Append("\n\n Project: ").Append(identifier).Append("\n\n");

            // TODAY
            String projectDate = DateTime.Now.ToString("MMM d, yyyy");

            sb.Append(getRightAlignedTableHeader("Today (" + projectDate + ")"));
            sb.Append(getColumnHeaders(new List <string>()
            {
                "Metric", "You", "All Contributors"
            }));
            sb.Append(getRowNumberData("Commits", usersTodaysCommits.commitCount, contribTodaysCommits.commitCount));
            sb.Append(getRowNumberData("Files changed", usersTodaysCommits.fileCount, contribTodaysCommits.fileCount));
            sb.Append(getRowNumberData("Insertions", usersTodaysCommits.insertions, contribTodaysCommits.insertions));
            sb.Append(getRowNumberData("Deletions", usersTodaysCommits.deletions, contribTodaysCommits.deletions));
            sb.Append("\n");

            // YESTERDAY
            String yesterday = nowTime.start_of_yesterday_dt.ToString("MMM d, yyyy");

            sb.Append(getRightAlignedTableHeader("Yesterday (" + yesterday + ")"));
            sb.Append(getColumnHeaders(new List <string>()
            {
                "Metric", "You", "All Contributors"
            }));
            sb.Append(getRowNumberData("Commits", usersYesterdaysCommits.commitCount, contribYesterdaysCommits.commitCount));
            sb.Append(getRowNumberData("Files changed", usersYesterdaysCommits.fileCount, contribYesterdaysCommits.fileCount));
            sb.Append(getRowNumberData("Insertions", usersYesterdaysCommits.insertions, contribYesterdaysCommits.insertions));
            sb.Append(getRowNumberData("Deletions", usersYesterdaysCommits.deletions, contribYesterdaysCommits.deletions));
            sb.Append("\n");

            // THIS WEEK
            String startOfWeek = nowTime.start_of_week_dt.ToString("MMM d, yyyy");

            sb.Append(getRightAlignedTableHeader("This week (" + startOfWeek + " to " + projectDate + ")"));
            sb.Append(getColumnHeaders(new List <string>()
            {
                "Metric", "You", "All Contributors"
            }));
            sb.Append(getRowNumberData("Commits", usersThisWeeksCommits.commitCount, contribThisWeeksCommits.commitCount));
            sb.Append(getRowNumberData("Files changed", usersThisWeeksCommits.fileCount, contribThisWeeksCommits.fileCount));
            sb.Append(getRowNumberData("Insertions", usersThisWeeksCommits.insertions, contribThisWeeksCommits.insertions));
            sb.Append(getRowNumberData("Deletions", usersThisWeeksCommits.deletions, contribThisWeeksCommits.deletions));
            sb.Append("\n");


            if (File.Exists(file))
            {
                File.SetAttributes(file, FileAttributes.Normal);
            }
            try
            {
                File.WriteAllText(file, sb.ToString(), System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
            }

            try
            {
                if (File.Exists(file))
                {
                    SoftwareCoPackage.ObjDte.ItemOperations.OpenFile(file);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("LaunchCodeTimeDashboardAsync, error : " + ex.Message, ex);
            }
        }
        public async Task RebuildGitMetricsAsync()
        {
            string dir = DocEventManager._solutionDirectory;

            if ((dir == null || dir.Equals("")) && SoftwareCoPackage.PLUGIN_READY)
            {
                dir = await DocEventManager.GetSolutionDirectory();
            }

            // if (dir == null || dir.Equals(""))
            // {
            // Uncommitted.Visibility = Visibility.Hidden;
            // CommittedToday.Visibility = Visibility.Hidden;
            // return;
            // } else
            // {
            // Uncommitted.Visibility = Visibility.Visible;
            // CommittedToday.Visibility = Visibility.Visible;
            // }

            string name = "";

            try
            {
                FileInfo fi = new FileInfo(dir);
                name = fi.Name;
            } catch (Exception e)
            {
                //
            }

            CommitChangeStats uncommited            = GitUtilManager.GetUncommitedChanges(dir);
            string            uncommittedInsertions = "Insertion(s): " + uncommited.insertions;
            string            uncommittedDeletions  = "Deletion(s): " + uncommited.deletions;

            if (Uncommitted.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(Uncommitted, "uncommitted");

                UpdateNodeValue(parentItem, "uncommittedinsertions", uncommittedInsertions, "insertion.png");
                UpdateNodeValue(parentItem, "uncommitteddeletions", uncommittedDeletions, "deletion.png");
            }
            else
            {
                List <TreeViewItem> uncommitedChilren = new List <TreeViewItem>();
                uncommitedChilren.Add(BuildMetricNode("uncommittedinsertions", uncommittedInsertions, "insertion.png"));
                uncommitedChilren.Add(BuildMetricNode("uncommitteddeletions", uncommittedDeletions, "deletion.png"));
                TreeViewItem uncommittedParent = BuildMetricNodes("uncommitted", "Open changes", uncommitedChilren);
                Uncommitted.Items.Add(uncommittedParent);
            }

            string            email               = GitUtilManager.GetUsersEmail(dir);
            CommitChangeStats todaysStats         = GitUtilManager.GetTodaysCommits(dir, email);
            string            committedInsertions = "Insertion(s): " + todaysStats.insertions;
            string            committedDeletions  = "Deletion(s): " + todaysStats.deletions;
            string            committedCount      = "Commit(s): " + todaysStats.commitCount;
            string            committedFilecount  = "Files changed: " + todaysStats.fileCount;

            if (CommittedToday.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(CommittedToday, "committed");

                UpdateNodeValue(parentItem, "committedinsertions", committedInsertions, "insertion.png");
                UpdateNodeValue(parentItem, "committeddeletions", committedDeletions, "deletion.png");
                UpdateNodeValue(parentItem, "committedcount", committedCount, "commit.png");
                UpdateNodeValue(parentItem, "committedfilecount", committedFilecount, "files.png");
            }
            else
            {
                List <TreeViewItem> committedChilren = new List <TreeViewItem>();
                committedChilren.Add(BuildMetricNode("committedinsertions", committedInsertions, "insertion.png"));
                committedChilren.Add(BuildMetricNode("committeddeletions", committedDeletions, "deletion.png"));
                committedChilren.Add(BuildMetricNode("committedcount", committedCount, "commit.png"));
                committedChilren.Add(BuildMetricNode("committedfilecount", committedFilecount, "files.png"));
                TreeViewItem committedParent = BuildMetricNodes("committed", "Committed today", committedChilren);
                CommittedToday.Items.Add(committedParent);
            }
        }