public async Task RebuildContributorMetricsAsync()
        {
            string dir = DocEventManager._solutionDirectory;

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

            RepoResourceInfo resourceInfo = GitUtilManager.GetResourceInfo(dir, true);

            // clear the children
            ContributorsMetricsPanel.Children.Clear();

            if (resourceInfo != null && resourceInfo.identifier != null)
            {
                StackPanel identifierPanel = BuildClickLabel("IdentifierPanel", "github.png", resourceInfo.identifier, RepoIdentifierClickHandler);
                ContributorsMetricsPanel.Children.Add(identifierPanel);

                // build the repo contributors
                //
            }



            // < TreeView x: Name = "TopCodeTimeFiles" Background = "Transparent" BorderBrush = "Transparent" Width = "auto" Height = "auto" ScrollViewer.VerticalScrollBarVisibility = "Auto" ScrollViewer.HorizontalScrollBarVisibility = "Disabled" >

            // < TreeView.Resources >

            // < SolidColorBrush x: Key = "{x:Static SystemColors.HighlightBrushKey}"
            // Color = "Transparent" />
            // < SolidColorBrush x: Key = "{x:Static SystemColors.HighlightTextBrushKey}"
            // Color = "Transparent" />
            // < SolidColorBrush x: Key = "{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
            // Color = "Transparent" />
            // < SolidColorBrush x: Key = "{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}"
            // Color = "Transparent" />
            //  </ TreeView.Resources >
            // </ TreeView >
        }
        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);
            }
        }
Exemple #3
0
        public async Task <string> CompletePayloadAndReturnJsonString()
        {
            RepoResourceInfo resourceInfo = null;

            // make sure we have a valid project and identifier if possible
            if (this.project == null || this.project.directory == null || this.project.directory.Equals("Untitled"))
            {
                // try to get a valid project
                string projectDir = await DocEventManager.GetSolutionDirectory();

                if (projectDir != null && !projectDir.Equals(""))
                {
                    FileInfo fi = new FileInfo(projectDir);
                    project      = new PluginDataProject(fi.Name, projectDir);
                    resourceInfo = GitUtilManager.GetResourceInfo(projectDir, false);
                }
            }
            else
            {
                resourceInfo = GitUtilManager.GetResourceInfo(this.project.directory, false);
            }

            if (resourceInfo != null && resourceInfo.identifier != null && !resourceInfo.identifier.Equals(""))
            {
                project.identifier = resourceInfo.identifier;
            }

            SessionSummaryManager summaryMgr = SessionSummaryManager.Instance;
            TimeGapData           eTimeInfo  = summaryMgr.GetTimeBetweenLastPayload();
            NowTime nowTime = SoftwareCoUtil.GetNowTime();

            this.end       = nowTime.now;
            this.local_end = nowTime.local_now;

            // get the TimeData for this project dir
            await ValidateAndUpdateCumulativeDataAsync(eTimeInfo.session_seconds);

            this.elapsed_seconds = eTimeInfo.elapsed_seconds;

            // make sure all of the end times are set
            foreach (PluginDataFileInfo pdFileInfo in this.source)
            {
                pdFileInfo.EndFileInfoTime(nowTime);
            }

            double offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalMinutes;

            this.offset = Math.Abs((int)offset);
            if (TimeZone.CurrentTimeZone.DaylightName != null &&
                TimeZone.CurrentTimeZone.DaylightName != TimeZone.CurrentTimeZone.StandardName)
            {
                this.timezone = TimeZone.CurrentTimeZone.DaylightName;
            }
            else
            {
                this.timezone = TimeZone.CurrentTimeZone.StandardName;
            }

            // update the file metrics used in the tree
            List <FileInfoSummary> fileInfoList = this.GetSourceFileInfoList();
            KeystrokeAggregates    aggregates   = new KeystrokeAggregates();

            aggregates.directory = this.project.directory;

            foreach (FileInfoSummary fileInfo in fileInfoList)
            {
                aggregates.Aggregate(fileInfo);

                FileChangeInfo fileChangeInfo = FileChangeInfoDataManager.Instance.GetFileChangeInfo(fileInfo.fsPath);
                if (fileChangeInfo == null)
                {
                    // create a new entry
                    fileChangeInfo = new FileChangeInfo();
                }
                fileChangeInfo.UpdateFromFileInfo(fileInfo);
                FileChangeInfoDataManager.Instance.SaveFileChangeInfoDataSummaryToDisk(fileChangeInfo);
            }

            // increment the session summary minutes and other metrics
            summaryMgr.IncrementSessionSummaryData(aggregates, eTimeInfo);

            // create the json payload
            JsonObject jsonObj = new JsonObject();

            jsonObj.Add("start", this.start);
            jsonObj.Add("local_start", this.local_start);
            jsonObj.Add("pluginId", this.pluginId);
            jsonObj.Add("type", this.type);
            jsonObj.Add("keystrokes", this.keystrokes);
            jsonObj.Add("project", this.project.GetAsJson());
            jsonObj.Add("timezone", this.timezone);
            jsonObj.Add("offset", this.offset);
            jsonObj.Add("version", this.version);
            jsonObj.Add("os", this.os);
            jsonObj.Add("end", this.end);
            jsonObj.Add("local_end", this.local_end);
            jsonObj.Add("cumulative_editor_seconds", this.cumulative_editor_seconds);
            jsonObj.Add("cumulative_session_seconds", this.cumulative_session_seconds);
            jsonObj.Add("elapsed_seconds", this.elapsed_seconds);
            jsonObj.Add("workspace_name", this.workspace_name);
            jsonObj.Add("hostname", this.hostname);
            jsonObj.Add("project_null_error", this.project_null_error);

            // get the source as json
            jsonObj.Add("source", BuildSourceJson());

            return(jsonObj.ToString());
        }
        public async void SolutionEventOpenedAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (!PLUGIN_READY)
            {
                string solutionDir = await GetSolutionDirectory();

                if (solutionDir == null || solutionDir.Equals(""))
                {
                    Task.Delay(3000).ContinueWith((task) =>
                    {
                        SolutionEventOpenedAsync();
                    });
                    return;
                }
                // init the doc event mgr and inject ObjDte
                docEventMgr            = DocEventManager.Instance;
                DocEventManager.ObjDte = ObjDte;

                // init the session summary mgr
                sessionSummaryMgr = SessionSummaryManager.Instance;
                sessionSummaryMgr.InjectAsyncPackage(this);

                // init the event manager and inject this
                EventManager.Instance.InjectAsyncPackage(this);

                // update the latestPayloadTimestampEndUtc
                NowTime nowTime = SoftwareCoUtil.GetNowTime();
                FileManager.setNumericItem("latestPayloadTimestampEndUtc", nowTime.now);

                // init the wallclock
                WallclockManager wallclockMgr = WallclockManager.Instance;
                wallclockMgr.InjectAsyncPackage(this, ObjDte);

                // setup event handlers
                _textDocKeyEvent.AfterKeyPress += docEventMgr.AfterKeyPressedAsync;
                _docEvents.DocumentOpened      += docEventMgr.DocEventsOnDocumentOpenedAsync;
                _docEvents.DocumentClosing     += docEventMgr.DocEventsOnDocumentClosedAsync;
                _docEvents.DocumentSaved       += docEventMgr.DocEventsOnDocumentSaved;
                _docEvents.DocumentOpening     += docEventMgr.DocEventsOnDocumentOpeningAsync;

                // init the code metrics tree mgr
                CodeMetricsTreeManager.Instance.InjectAsyncPackage(this);

                // initialize the menu commands
                await SoftwareLaunchCommand.InitializeAsync(this);

                await SoftwareDashboardLaunchCommand.InitializeAsync(this);

                await SoftwareTopFortyCommand.InitializeAsync(this);

                await SoftwareLoginCommand.InitializeAsync(this);

                await SoftwareToggleStatusInfoCommand.InitializeAsync(this);

                await SoftwareOpenCodeMetricsTreeCommand.InitializeAsync(this);

                if (_softwareRepoUtil == null)
                {
                    _softwareRepoUtil = new SoftwareRepoManager();
                }

                // Create an AutoResetEvent to signal the timeout threshold in the
                // timer callback has been reached.
                var autoEvent = new AutoResetEvent(false);

                offlineDataTimer = new System.Threading.Timer(
                    SendOfflineData,
                    null,
                    ONE_MINUTE,
                    ONE_MINUTE * 15);

                repoCommitsTimer = new System.Threading.Timer(
                    ProcessRepoJobs,
                    autoEvent,
                    ONE_MINUTE * 5,
                    ONE_MINUTE * 20);

                keystrokeTimer = new System.Threading.Timer(
                    ProcessKeystrokePayload,
                    autoEvent,
                    ONE_MINUTE,
                    ONE_MINUTE);

                // initialize the status bar before we fetch the summary data
                InitializeStatusBar();

                // make sure the last payload is in memory
                FileManager.GetLastSavedKeystrokeStats();

                // check if we've shown the readme or not
                bool initializedVisualStudioPlugin = FileManager.getItemAsBool("visualstudio_CtInit");
                if (!initializedVisualStudioPlugin)
                {
                    DashboardManager.Instance.LaunchReadmeFileAsync();
                    FileManager.setBoolItem("visualstudio_CtInit", true);

                    // launch the tree view
                    CodeMetricsTreeManager.Instance.OpenCodeMetricsPaneAsync();
                }

                Task.Delay(3000).ContinueWith((task) =>
                {
                    EventManager.Instance.CreateCodeTimeEvent("resource", "load", "EditorActivate");
                });

                string PluginVersion = GetVersion();
                Logger.Info(string.Format("Initialized Code Time v{0}", PluginVersion));

                PLUGIN_READY = true;
            }
        }
Exemple #5
0
        public static async Task <PluginDataProject> GetPluginProject()
        {
            string projectDir = await DocEventManager.GetSolutionDirectory();

            return(GetPluginProjectUsingDir(projectDir));
        }