示例#1
0
        public async void GetRepoUsers(string projectDir)
        {
            if (projectDir == null || projectDir.Equals(""))
            {
                return;
            }

            IDictionary <string, string> resourceInfo = this.GetResourceInfo(projectDir);

            if (resourceInfo != null && resourceInfo.ContainsKey("identifier"))
            {
                string identifier = "";
                resourceInfo.TryGetValue("identifier", out identifier);
                if (identifier != null && !identifier.Equals(""))
                {
                    string tag = "";
                    resourceInfo.TryGetValue("tag", out tag);
                    string branch = "";
                    resourceInfo.TryGetValue("branch", out branch);

                    string gitLogData = SoftwareCoUtil.RunCommand("git log --pretty=%an,%ae | sort", projectDir);

                    IDictionary <string, string> memberMap = new Dictionary <string, string>();

                    List <RepoMember> repoMembers = new List <RepoMember>();
                    if (gitLogData != null && !gitLogData.Equals(""))
                    {
                        string[] lines = gitLogData.Split(
                            new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                        if (lines != null && lines.Length > 0)
                        {
                            for (int i = 0; i < lines.Length; i++)
                            {
                                string   line        = lines[i];
                                string[] memberInfos = line.Split(',');
                                if (memberInfos != null && memberInfos.Length > 1)
                                {
                                    string name  = memberInfos[0].Trim();
                                    string email = memberInfos[1].Trim();
                                    if (!memberMap.ContainsKey(email))
                                    {
                                        memberMap.Add(email, name);
                                        repoMembers.Add(new RepoMember(name, email));
                                    }
                                }
                            }
                        }
                    }

                    if (memberMap.Count > 0)
                    {
                        RepoData repoData    = new RepoData(identifier, tag, branch, repoMembers);
                        string   jsonContent = SimpleJson.SerializeObject(repoData);
                        // send the members
                        HttpResponseMessage response = await SoftwareHttpManager.SendRequestAsync(
                            HttpMethod.Post, "/repo/members", jsonContent);

                        if (!SoftwareHttpManager.IsOk(response))
                        {
                            Logger.Error(response.ToString());
                        }
                    }
                }
            }
        }
        private static async Task FetchCodeTimeDashboardAsync(SessionSummary _sessionSummary)
        {
            string summaryContent  = "";
            string summaryInfoFile = SoftwareCoUtil.getSessionSummaryInfoFile();

            bool online = await SoftwareUserSession.IsOnlineAsync();

            long diff = SoftwareCoUtil.getNowInSeconds() - lastDashboardFetchTime;

            if (lastDashboardFetchTime == 0 || diff >= day_in_sec || !online)
            {
                if (!online)
                {
                    lastDashboardFetchTime = 0;
                }
                else
                {
                    lastDashboardFetchTime = SoftwareCoUtil.getNowInSeconds();
                }

                HttpResponseMessage resp =
                    await SoftwareHttpManager.SendDashboardRequestAsync(HttpMethod.Get, "/dashboard?showMusic=false&showGit=false&showRank=false&showToday=false");

                if (SoftwareHttpManager.IsOk(resp))
                {
                    summaryContent += await resp.Content.ReadAsStringAsync();
                }
                else
                {
                    summaryContent = NO_DATA;
                }


                if (File.Exists(summaryInfoFile))
                {
                    File.SetAttributes(summaryInfoFile, FileAttributes.Normal);
                }

                try
                {
                    File.WriteAllText(summaryInfoFile, summaryContent);
                    File.SetAttributes(summaryInfoFile, FileAttributes.ReadOnly);
                }
                catch (Exception e)
                {
                }
            }
            string dashboardFile    = SoftwareCoUtil.getDashboardFile();
            string dashboardContent = "";
            string suffix           = SoftwareCoUtil.CreateDateSuffix(DateTime.Now);
            string formattedDate    = DateTime.Now.ToString("ddd, MMM ") + suffix + DateTime.Now.ToString(" h:mm tt");

            dashboardContent  = "CODE TIME          " + "(Last updated on " + formattedDate + " )";
            dashboardContent += "\n\n";

            string todayDate  = DateTime.Now.ToString("ddd, MMM ") + suffix;
            string today_date = "Today " + "(" + todayDate + ")";

            dashboardContent += SoftwareCoUtil.getSectionHeader(today_date);

            if (_sessionSummary != null)
            {
                string averageTime     = SoftwareCoUtil.HumanizeMinutes(_sessionSummary.averageDailyMinutes);
                string hoursCodedToday = SoftwareCoUtil.HumanizeMinutes(_sessionSummary.currentDayMinutes);
                String liveshareTime   = "";
                //if (_sessionSummary.liveshareMinutes != 0)
                //{
                //    liveshareTime = SoftwareCoUtil.HumanizeMinutes(_sessionSummary.liveshareMinutes);
                //}
                dashboardContent += SoftwareCoUtil.getDashboardRow("Hours Coded", hoursCodedToday);
                dashboardContent += SoftwareCoUtil.getDashboardRow("90-day avg", averageTime);
                //if (liveshareTime != "0")
                //{
                //    dashboardContent += SoftwareCoUtil.getDashboardRow("Live Share", liveshareTime);
                //}
                dashboardContent += "\n";
            }

            if (SoftwareCoUtil.SessionSummaryInfoFileExists())
            {
                string SummaryData = SoftwareCoUtil.getSessionSummaryInfoFileData();
                dashboardContent += SummaryData;
            }


            if (File.Exists(dashboardFile))
            {
                File.SetAttributes(dashboardFile, FileAttributes.Normal);
            }
            try
            {
                //SoftwareCoUtil.WriteToFileThreadSafe(dashboardContent, dashboardFile);
                File.WriteAllText(dashboardFile, dashboardContent);
                File.SetAttributes(dashboardFile, FileAttributes.ReadOnly);
            }
            catch (Exception e)
            {
            }
        }