Esempio n. 1
0
        public void PrettyPrintIgnoresTime()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            // The timespan is not a whole day, nevertheless it should be yesterday
            Assert.AreEqual("yesterday", timeAgo.PrettyPrint(new DateTime(2011, 11, 11, 11, 11, 11), new DateTime(2011, 11, 12, 01, 01, 01)));
        }
Esempio n. 2
0
        public override void OnMenuWillOpen(NSMenu _)
        {
            if (_lastExecutionResult != null && _lastExecutionResult.Success)
            {
                if (_lastExecutionResult.Success)
                {
                    foreach (var record in _lastExecutionResult.Items.Skip(1))
                    {
                        AddItemsToMenu(record, Menu);
                    }
                }

                Menu.AddItem(new NSMenuItem("LastUpdated")
                {
                    Title = $"Updated {TimeAgo.Format(_lastExecutionResult.LastExecution.ToLocalTime())}",
                });
            }
            else
            {
                Menu.AddItem(new NSMenuItem("Execution")
                {
                    Title = Plugin.IsExecuting ? "Still Executing" : "Finished Executing",
                });
            }

            Menu.AddItem(new DefaultSubMenuSection
            {
                OnRefreshClicked     = OnRefresh,
                OnRefreshAllClicked  = OnRefreshAll,
                OnPreferencesClicked = OnOpenPreferences,
                OnQuitClicked        = OnExit
            });
        }
Esempio n. 3
0
        public void PrettyPrintCalculatesCorrectWeeksAtLeapYear()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            // The timespan is not a whole day, nevertheless it should be yesterday
            Assert.AreEqual("3 weeks", timeAgo.PrettyPrint(new DateTime(2000, 02, 09), new DateTime(2000, 03, 01)));
            Assert.AreEqual("2 weeks", timeAgo.PrettyPrint(new DateTime(2000, 02, 10), new DateTime(2000, 03, 01)));
        }
        protected virtual string GetString(TimeAgo timeAgo, int value)
        {
            if (timeAgo == TimeAgo.Now)
            {
                return("Just Now");
            }

            return(String.Format("{0} {1} ago", value, timeAgo.ToString().ToLower()));
        }
Esempio n. 5
0
        public void AgeInMonthsIgnoresTime()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            Assert.AreEqual(0, timeAgo.AgeInMonths(new DateTime(2011, 11, 11, 11, 11, 11), new DateTime(2011, 11, 11, 11, 11, 11)));
            Assert.AreEqual(0, timeAgo.AgeInMonths(new DateTime(2011, 11, 11, 11, 11, 11), new DateTime(2011, 11, 11, 23, 11, 11)));
            Assert.AreEqual(0, timeAgo.AgeInMonths(new DateTime(2011, 11, 11, 11, 11, 11), new DateTime(2011, 11, 11, 01, 11, 11)));

            Assert.AreEqual(1, timeAgo.AgeInMonths(new DateTime(2011, 11, 11, 11, 11, 11), new DateTime(2011, 12, 11, 01, 01, 01)));
        }
Esempio n. 6
0
        public void AgeInYearsReturnsCorrectNumberOfYears()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            Assert.AreEqual(0, timeAgo.AgeInYears(new DateTime(2011, 11, 11), new DateTime(2012, 11, 10)));
            Assert.AreEqual(1, timeAgo.AgeInYears(new DateTime(2011, 11, 11), new DateTime(2012, 11, 11)));
            Assert.AreEqual(1, timeAgo.AgeInYears(new DateTime(2011, 11, 11), new DateTime(2012, 11, 12)));

            Assert.AreEqual(100, timeAgo.AgeInYears(new DateTime(1911, 11, 11), new DateTime(2011, 11, 11)));
        }
Esempio n. 7
0
        public void AgeInWeeksRoundsCorrectly()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            Assert.AreEqual(0, timeAgo.AgeInWeeks(0.0));
            Assert.AreEqual(0, timeAgo.AgeInWeeks(6.999999));
            Assert.AreEqual(1, timeAgo.AgeInWeeks(7.0));
            Assert.AreEqual(1, timeAgo.AgeInWeeks(7.000001));
            Assert.AreEqual(1, timeAgo.AgeInWeeks(13.999999));
            Assert.AreEqual(2, timeAgo.AgeInWeeks(14.000));
            Assert.AreEqual(2, timeAgo.AgeInWeeks(14.000001));
        }
Esempio n. 8
0
        public void AgeInMonthsHandlesIrregularMonths()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            Assert.AreEqual(1, timeAgo.AgeInMonths(new DateTime(2000, 01, 27), new DateTime(2000, 02, 28)));
            Assert.AreEqual(1, timeAgo.AgeInMonths(new DateTime(2000, 01, 28), new DateTime(2000, 02, 28)));
            Assert.AreEqual(0, timeAgo.AgeInMonths(new DateTime(2000, 01, 29), new DateTime(2000, 02, 28)));

            Assert.AreEqual(0, timeAgo.AgeInMonths(new DateTime(2000, 02, 28), new DateTime(2000, 03, 27)));
            Assert.AreEqual(1, timeAgo.AgeInMonths(new DateTime(2000, 02, 28), new DateTime(2000, 03, 28)));
            Assert.AreEqual(1, timeAgo.AgeInMonths(new DateTime(2000, 02, 28), new DateTime(2000, 03, 29)));
        }
Esempio n. 9
0
 private TimeAgo GetOrCreateTimeAgo()
 {
     if (_timeAgo == null)
     {
         var localization = new TimeAgo.Localization
         {
             Today             = Language.LoadText("today"),
             Yesterday         = Language.LoadText("yesterday"),
             NumberOfDaysAgo   = Language.LoadText("days_ago"),
             NumberOfWeeksAgo  = Language.LoadText("weeks_ago"),
             NumberOfMonthsAgo = Language.LoadText("months_ago"),
             NumberOfYearsAgo  = Language.LoadText("years_ago"),
         };
         _timeAgo = new TimeAgo(localization);
     }
     return(_timeAgo);
 }
Esempio n. 10
0
        public void Execute(IJobExecutionContext context)
        {
            DashBoardViewModelDTO dashBoardViewModelDTO = new DashBoardViewModelDTO();
            DashBoardWidgetDTO    dashBoardWidgetDTO    = new DashBoardWidgetDTO();

            DashBoardWidgetViewModel dashBoardWidgetViewModel = new DashBoardWidgetViewModel();
            DashBoardWidget          dashBoardWidget          = new DashBoardWidget();

            dashBoardWidgetDTO = this._IDashBoardOrchestrator.GetDashBoardWidgetDetails();

            Mapper.Map(dashBoardWidgetDTO, dashBoardViewModelDTO);

            dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoUsers          = GlobalCachingProvider.Instance.GetAllUsersAccountsFromCache().Count;
            dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoActiveUsers    = ActiveConnections.ActiveUsers.Where(x => x != "").ToList().Distinct().ToList().Count;
            dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoActiveSessions = ActiveConnections.ActiveSessions.Count;

            dashBoardViewModelDTO.DashBoardWidgetDetails.ApplicationCachesTotal       = GlobalCachingProvider.Instance.GetItem("TotalCaches") as string;
            dashBoardViewModelDTO.DashBoardWidgetDetails.ApplicationCachesLastUpdated = GlobalCachingProvider.Instance.GetItem("LastCachedOn") as string;

            //dashBoardViewModelDTO.DashBoardWidgetViewModel = dashBoardWidgetViewModel;

            var context1 = GlobalHost.ConnectionManager.GetHubContext <DashBoardHub>();



            context1.Clients.All.broadCastDashBoardWidget(dashBoardViewModelDTO.DashBoardWidgetDetails.TotalFileEncrypted,
                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.FileEncryptedToday,

                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.NoOfServersUp,
                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.NoOfServersDown,
                                                          TimeAgo.GetTimeAgo(
                                                              dashBoardViewModelDTO.DashBoardWidgetDetails.StatusRanOn
                                                              ),

                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoUsers,
                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoActiveUsers,
                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoActiveSessions,
                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.FileUploadChartLables,
                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.FileUploadChartData
                                                          , dashBoardViewModelDTO.DashBoardWidgetDetails.ApplicationCachesTotal,
                                                          dashBoardViewModelDTO.DashBoardWidgetDetails.ApplicationCachesLastUpdated
                                                          );
        }
        //private readonly IConnectionManager _connectionManager;
        //public DashBoardController(IConnectionManager iConnectionManager)
        //{
        //    _connectionManager = iConnectionManager;
        //}

        public ActionResult Index()
        {
            DashBoardViewModelDTO dashBoardViewModelDTO = new DashBoardViewModelDTO();
            DashBoardWidgetDTO    dashBoardWidgetDTO    = new DashBoardWidgetDTO();

            DashBoardWidgetViewModel dashBoardWidgetViewModel = new DashBoardWidgetViewModel();
            DashBoardWidget          dashBoardWidget          = new DashBoardWidget();

            dashBoardWidgetDTO = this._IDashBoardOrchestrator.GetDashBoardWidgetDetails();

            Mapper.Map(dashBoardWidgetDTO, dashBoardViewModelDTO);
            dashBoardViewModelDTO.DashBoardWidgetDetails.StatusRanOnText = TimeAgo.GetTimeAgo(
                dashBoardViewModelDTO.DashBoardWidgetDetails.StatusRanOn
                );

            dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoUsers          = GlobalCachingProvider.Instance.GetAllUsersAccountsFromCache().Count;
            dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoActiveUsers    = ActiveConnections.ActiveUsers.Where(x => x != "").ToList().Distinct().ToList().Count;
            dashBoardViewModelDTO.DashBoardWidgetDetails.TotalNoActiveSessions = ActiveConnections.ActiveSessions.Count;

            dashBoardViewModelDTO.DashBoardWidgetDetails.ApplicationCachesTotal       = GlobalCachingProvider.Instance.GetItem("TotalCaches") as string;
            dashBoardViewModelDTO.DashBoardWidgetDetails.ApplicationCachesLastUpdated = GlobalCachingProvider.Instance.GetItem("LastCachedOn") as string;

            //dashBoardViewModelDTO.DashBoardWidgetViewModel = dashBoardWidgetViewModel;

            ViewBag.FileUploadChartData = dashBoardViewModelDTO.DashBoardWidgetDetails.FileUploadChartData;
            //ViewBag.FileUploadChartLables = dashBoardViewModelDTO.DashBoardWidgetDetails.FileUploadChartLables;
            ViewBag.FileUploadChartLables = dashBoardViewModelDTO.DashBoardWidgetDetails.FileUploadChartLables;


            //var context1 = GlobalHost.ConnectionManager.GetHubContext<DashBoardHub>();

            //context1.Clients.All.broadCastDashBoardWidget(dashBoardWidgetViewModel.TotalFileEncrypted, dashBoardWidgetViewModel.FileEncryptedToday,
            //                                               dashBoardWidgetViewModel.TotalNoUsers, dashBoardWidgetViewModel.TotalNoActiveUsers
            //                                               , dashBoardWidgetViewModel.TotalNoActiveSessions
            //                                               , dashBoardWidgetViewModel.FileUplaodChartLables
            //                                               , dashBoardWidgetViewModel.FileUplaodChartData
            //                                           , dashBoardWidgetViewModel.ApplicationCachesTotal
            //                                           , dashBoardWidgetViewModel.ApplicationCachesLastUpdated
            //                                               );

            return(View("~/Areas/DashBoard/Views/DashBoard/Index.cshtml", dashBoardViewModelDTO));
        }
Esempio n. 12
0
        public void PrettyPrintStepsAtCorrectThresholds()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            Assert.AreEqual("today", timeAgo.PrettyPrint(new DateTime(2011, 11, 11, 11, 11, 11), new DateTime(2011, 11, 11, 11, 11, 11)));
            Assert.AreEqual("today", timeAgo.PrettyPrint(new DateTime(2011, 11, 11, 00, 00, 00), new DateTime(2011, 11, 11, 23, 59, 59)));
            Assert.AreEqual("yesterday", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2011, 10, 02)));
            Assert.AreEqual("yesterday", timeAgo.PrettyPrint(new DateTime(2011, 10, 31), new DateTime(2011, 11, 01)));
            Assert.AreEqual("2 days", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2011, 10, 03)));
            Assert.AreEqual("2 days", timeAgo.PrettyPrint(new DateTime(2011, 10, 31), new DateTime(2011, 11, 02)));

            Assert.AreEqual("13 days", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2011, 10, 14)));
            Assert.AreEqual("2 weeks", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2011, 10, 15)));
            Assert.AreEqual("2 weeks", timeAgo.PrettyPrint(new DateTime(2011, 10, 31), new DateTime(2011, 11, 14)));

            Assert.AreEqual("8 weeks", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2011, 11, 30)));
            Assert.AreEqual("2 months", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2011, 12, 01)));
            Assert.AreEqual("2 months", timeAgo.PrettyPrint(new DateTime(2011, 10, 31), new DateTime(2011, 12, 31)));

            Assert.AreEqual("23 months", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2013, 09, 30)));
            Assert.AreEqual("23 months", timeAgo.PrettyPrint(new DateTime(2011, 10, 11), new DateTime(2013, 10, 10)));
            Assert.AreEqual("2 years", timeAgo.PrettyPrint(new DateTime(2011, 10, 01), new DateTime(2013, 10, 01)));
            Assert.AreEqual("27 years", timeAgo.PrettyPrint(new DateTime(1984, 10, 01), new DateTime(2011, 10, 01)));
        }
Esempio n. 13
0
 protected virtual string GetString(TimeAgo timeAgo, int time)
 {
     return(timeAgo == TimeAgo.Now
         ? "Just Now"
         : String.Format("{0} {1} ago", time, timeAgo.ToString().ToLower()));
 }
 void UpdateTimeAgo()
 {
     m_TimeAgo.text = TimeAgo.GetString(m_TimeStamp);
 }
        public CollabHistoryItem(RevisionData data)
        {
            m_RevisionId  = data.id;
            m_TimeStamp   = data.timeStamp;
            name          = "HistoryItem";
            m_ActionsTray = new VisualElement {
                name = "HistoryItemActionsTray"
            };
            m_ProgressSpinner = new HistoryProgressSpinner();
            m_Details         = new VisualElement {
                name = "HistoryDetail"
            };
            var author = new Label(data.authorName)
            {
                name = "Author"
            };

            m_TimeAgo         = new Label(TimeAgo.GetString(m_TimeStamp));
            m_FullDescription = data.comment;
            var shouldTruncate = ShouldTruncateDescription(m_FullDescription);

            if (shouldTruncate)
            {
                m_Description = new Label(GetTruncatedDescription(m_FullDescription));
            }
            else
            {
                m_Description = new Label(m_FullDescription);
            }
            m_Description.name = "RevisionDescription";
            var dropdown = new CollabHistoryDropDown(data.changes, data.changesTotal, data.changesTruncated, data.id);

            if (data.current)
            {
                m_Button = new Button(Restore)
                {
                    name = "ActionButton", text = "Restore"
                };
            }
            else if (data.obtained)
            {
                m_Button = new Button(GoBackTo)
                {
                    name = "ActionButton", text = "Go back to..."
                };
            }
            else
            {
                m_Button = new Button(UpdateTo)
                {
                    name = "ActionButton", text = "Update"
                };
            }
            m_Button.SetEnabled(data.enabled);
            m_ProgressSpinner.ProgressEnabled = data.inProgress;

            m_ActionsTray.Add(m_ProgressSpinner);
            m_ActionsTray.Add(m_Button);

            m_Details.Add(author);
            m_Details.Add(m_TimeAgo);
            m_Details.Add(m_Description);

            if (shouldTruncate)
            {
                m_ExpandCollapseButton = new Button(ToggleDescription)
                {
                    name = "ToggleDescription", text = "Show More"
                };
                m_Details.Add(m_ExpandCollapseButton);
            }

            if (data.buildState != BuildState.None)
            {
                BuildStatusButton buildButton;
                if (data.buildState == BuildState.Configure)
                {
                    buildButton = new BuildStatusButton(ShowServicePage);
                }
                else
                {
                    buildButton = new BuildStatusButton(ShowBuildForCommit, data.buildState, data.buildFailures);
                }

                m_Details.Add(buildButton);
            }

            m_Details.Add(m_ActionsTray);
            m_Details.Add(dropdown);

            Add(m_Details);

            this.schedule.Execute(UpdateTimeAgo).Every(1000 * 20);
        }
Esempio n. 16
0
        public CollabHistoryItem(RevisionData data)
        {
            this.m_RevisionId  = data.id;
            this.m_TimeStamp   = data.timeStamp;
            base.name          = "HistoryItem";
            this.m_ActionsTray = new VisualContainer
            {
                name = "HistoryItemActionsTray"
            };
            this.m_ProgressSpinner = new HistoryProgressSpinner();
            this.m_Details         = new VisualElement
            {
                name = "HistoryDetail"
            };
            Label child = new Label(data.authorName)
            {
                name = "Author"
            };

            this.m_TimeAgo         = new Label(TimeAgo.GetString(this.m_TimeStamp));
            this.m_FullDescription = data.comment;
            bool flag = this.ShouldTruncateDescription(this.m_FullDescription);

            if (flag)
            {
                this.m_Description = new Label(this.GetTruncatedDescription(this.m_FullDescription));
            }
            else
            {
                this.m_Description = new Label(this.m_FullDescription);
            }
            this.m_Description.name = "RevisionDescription";
            CollabHistoryDropDown child2 = new CollabHistoryDropDown(data.changes, data.changesTotal, data.changesTruncated);

            if (data.current)
            {
                this.m_Button = new Button(new Action(this.Restore))
                {
                    name = "ActionButton",
                    text = "Restore"
                };
            }
            else if (data.obtained)
            {
                this.m_Button = new Button(new Action(this.GoBackTo))
                {
                    name = "ActionButton",
                    text = "Go back to..."
                };
            }
            else
            {
                this.m_Button = new Button(new Action(this.UpdateTo))
                {
                    name = "ActionButton",
                    text = "Update"
                };
            }
            this.m_Button.SetEnabled(data.enabled);
            this.m_ProgressSpinner.ProgressEnabled = data.inProgress;
            this.m_ActionsTray.Add(this.m_ProgressSpinner);
            this.m_ActionsTray.Add(this.m_Button);
            this.m_Details.Add(child);
            this.m_Details.Add(this.m_TimeAgo);
            this.m_Details.Add(this.m_Description);
            if (flag)
            {
                this.m_ExpandCollapseButton = new Button(new Action(this.ToggleDescription))
                {
                    name = "ToggleDescription",
                    text = "Show More"
                };
                this.m_Details.Add(this.m_ExpandCollapseButton);
            }
            if (data.buildState != BuildState.None)
            {
                BuildStatusButton child3;
                if (data.buildState == BuildState.Configure)
                {
                    child3 = new BuildStatusButton(new Action(this.ShowServicePage));
                }
                else
                {
                    child3 = new BuildStatusButton(new Action(this.ShowBuildForCommit), data.buildState, data.buildFailures);
                }
                this.m_Details.Add(child3);
            }
            this.m_Details.Add(this.m_ActionsTray);
            this.m_Details.Add(child2);
            base.Add(this.m_Details);
            base.schedule.Execute(new Action(this.UpdateTimeAgo)).Every(20000L);
        }
Esempio n. 17
0
 private void UpdateTimeAgo()
 {
     this.m_TimeAgo.text = TimeAgo.GetString(this.m_TimeStamp);
 }
Esempio n. 18
0
        public void AgeInMonthsIsNeverNegative()
        {
            TimeAgo timeAgo = new TimeAgo(CreateTestLocalization());

            Assert.AreEqual(0, timeAgo.AgeInMonths(new DateTime(2011, 11, 11), new DateTime(2011, 10, 11)));
        }
        public override int GetHashCode()
        {
            int hash = UserId.GetHashCode() + TimeAgo.GetHashCode() + ProfileId.GetHashCode();

            return(hash);
        }
 protected virtual string GetString(TimeAgo timeAgo, int time) {
     return timeAgo == TimeAgo.Now
         ? "Just Now"
         : String.Format("{0} {1} ago", time, timeAgo.ToString().ToLower());
 }