Exemple #1
0
        private async Task FetchCodeTimeDashboardAsync()
        {
            string summaryContent  = "";
            string summaryInfoFile = FileManager.getSessionSummaryInfoFile();

            bool online = await SoftwareUserSession.IsOnlineAsync();


            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, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
            }

            string dashboardFile    = FileManager.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);

            SessionSummary  _sessionSummary = SessionSummaryManager.Instance.GetSessionSummayData();
            CodeTimeSummary ctSummary       = TimeDataManager.Instance.GetCodeTimeSummary();

            string codeTimeMinutes = SoftwareCoUtil.HumanizeMinutes(ctSummary.codeTimeMinutes);

            dashboardContent += SoftwareCoUtil.getDashboardRow("Code time today", codeTimeMinutes);
            string activeCodeTimeMinutes = SoftwareCoUtil.HumanizeMinutes(ctSummary.activeCodeTimeMinutes);

            dashboardContent += SoftwareCoUtil.getDashboardRow("Active code time today", activeCodeTimeMinutes);
            if (_sessionSummary != null)
            {
                string averageTime = SoftwareCoUtil.HumanizeMinutes(_sessionSummary.averageDailyMinutes);

                String liveshareTime = "";
                //if (_sessionSummary.liveshareMinutes != 0)
                //{
                //    liveshareTime = SoftwareCoUtil.HumanizeMinutes(_sessionSummary.liveshareMinutes);
                //}

                dashboardContent += SoftwareCoUtil.getDashboardRow("90-day avg", averageTime);
                //if (liveshareTime != "0")
                //{
                //    dashboardContent += SoftwareCoUtil.getDashboardRow("Live Share", liveshareTime);
                //}
                dashboardContent += "\n";
            }

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


            if (File.Exists(dashboardFile))
            {
                File.SetAttributes(dashboardFile, FileAttributes.Normal);
            }
            try
            {
                File.WriteAllText(dashboardFile, dashboardContent, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
            }
        }
        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)
            {
            }
        }