Exemple #1
0
 public IEnumerable <Guid> GetSelectedTimerIds()
 {
     foreach (var timerDateModel in TimerDates.Where(x => x.DateIsSelected))
     {
         foreach (var timerModel in timerDateModel.Timers.Where(timerModel => timerModel.TimerIsSelected))
         {
             yield return(timerModel.JiraTimer.UniqueId);
         }
     }
 }
Exemple #2
0
        public Guid?GetSelectedTimerId()
        {
            foreach (var timerDateModel in TimerDates.Where(x => x.IsSelected))
            {
                foreach (var timerModel in timerDateModel.Timers.Where(timerModel => timerModel.IsSelected))
                {
                    return(timerModel.JiraTimer.UniqueId);
                }
            }

            return(null);
        }
Exemple #3
0
        public void RefreshModel()
        {
            var validTimerDates = Gallifrey.JiraTimerCollection.GetValidTimerDates().ToList();

            foreach (var timerDate in validTimerDates)
            {
                var dateModel = TimerDates.FirstOrDefault(x => x.TimerDate.Date == timerDate.Date);

                if (dateModel == null)
                {
                    dateModel = new TimerDateModel(timerDate, Gallifrey.JiraTimerCollection);
                    TimerDates.Add(dateModel);
                }

                var dateTimers = Gallifrey.JiraTimerCollection.GetTimersForADate(timerDate);

                foreach (var timer in dateTimers)
                {
                    if (!dateModel.Timers.Any(x => x.JiraTimer.UniqueId == timer.UniqueId))
                    {
                        dateModel.AddTimerModel(new TimerModel(timer));
                    }
                }

                var removeTimers = dateModel.Timers.Where(timerModel => !dateTimers.Any(x => x.UniqueId == timerModel.JiraTimer.UniqueId)).ToList();

                foreach (var removeTimer in removeTimers)
                {
                    dateModel.RemoveTimerModel(removeTimer);
                }
            }

            var orderedCollection = TimerDates.Where(x => validTimerDates.Contains(x.TimerDate)).OrderByDescending(x => x.TimerDate).ToList();

            for (int i = 0; i < TimerDates.Count; i++)
            {
                var main    = TimerDates[i];
                var ordered = orderedCollection[i];

                if (main.TimerDate != ordered.TimerDate)
                {
                    TimerDates = new ObservableCollection <TimerDateModel>(orderedCollection);
                    break;
                }
            }

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("TimerDates"));
            }

            runningWatcherElapsed(this, null);
        }
Exemple #4
0
        private void RefreshModel()
        {
            var workingDays     = ModelHelpers.Gallifrey.Settings.AppSettings.ExportDays.ToList();
            var workingDate     = DateTime.Now.AddDays((ModelHelpers.Gallifrey.Settings.AppSettings.KeepTimersForDays - 1) * -1).Date;
            var validTimerDates = new List <DateTime>();
            var jiraCache       = new List <Issue>();

            while (workingDate.Date <= DateTime.Now.Date)
            {
                if (workingDays.Contains(workingDate.DayOfWeek))
                {
                    validTimerDates.Add(workingDate.Date);
                }
                workingDate = workingDate.AddDays(1);
            }

            foreach (var timerDate in ModelHelpers.Gallifrey.JiraTimerCollection.GetValidTimerDates())
            {
                if (!validTimerDates.Contains(timerDate))
                {
                    validTimerDates.Add(timerDate.Date);
                }
            }

            foreach (var timerDate in validTimerDates.OrderBy(x => x.Date))
            {
                var dateModel = TimerDates.FirstOrDefault(x => x.TimerDate.Date == timerDate.Date);

                if (dateModel == null)
                {
                    dateModel = new TimerDateModel(timerDate, ModelHelpers.Gallifrey.JiraTimerCollection);
                    TimerDates.Add(dateModel);
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TimerDates)));
                }

                var dateTimers = ModelHelpers.Gallifrey.JiraTimerCollection.GetTimersForADate(timerDate.Date).ToList();

                foreach (var timer in dateTimers)
                {
                    if (dateModel.Timers.All(x => x.JiraTimer.UniqueId != timer.UniqueId))
                    {
                        timer.PropertyChanged += (sender, args) => TimerChanged();
                        dateModel.AddTimerModel(new TimerModel(timer));
                    }
                }

                foreach (var removeTimer in dateModel.Timers.Where(timerModel => dateTimers.All(x => x.UniqueId != timerModel.JiraTimer.UniqueId)).ToList())
                {
                    dateModel.RemoveTimerModel(removeTimer);
                }

                if (dateModel.TimerDate.Date <= DateTime.Now.Date)
                {
                    var defaultTimers = (ModelHelpers.Gallifrey.Settings.AppSettings.DefaultTimers ?? new List <string>()).Select(x => x.ToUpper().Trim()).Distinct();
                    foreach (var defaultJira in defaultTimers)
                    {
                        if (!dateModel.Timers.Any(x => string.Equals(x.JiraTimer.JiraReference, defaultJira, StringComparison.InvariantCultureIgnoreCase) && x.JiraTimer.DateStarted.Date == dateModel.TimerDate.Date))
                        {
                            try
                            {
                                var jira = jiraCache.FirstOrDefault(x => string.Equals(x.key, defaultJira, StringComparison.InvariantCultureIgnoreCase));
                                if (jira == null && ModelHelpers.Gallifrey.JiraConnection.IsConnected)
                                {
                                    if (ModelHelpers.Gallifrey.JiraConnection.DoesJiraExist(defaultJira))
                                    {
                                        jira = ModelHelpers.Gallifrey.JiraConnection.GetJiraIssue(defaultJira);
                                        jiraCache.Add(jira);
                                    }
                                }

                                if (jira != null && string.Equals(jira.key, defaultJira, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    var timerId = ModelHelpers.Gallifrey.JiraTimerCollection.AddTimer(jira, dateModel.TimerDate.Date, TimeSpan.Zero, false);
                                    var timer   = ModelHelpers.Gallifrey.JiraTimerCollection.GetTimer(timerId);
                                    if (timer != null)
                                    {
                                        timer.PropertyChanged += (sender, args) => TimerChanged();
                                        dateModel.AddTimerModel(new TimerModel(timer));
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                ExceptionlessClient.Default.CreateEvent().SetException(ex).AddTags("Hidden").Submit();
                            }
                        }
                    }
                }
            }

            //see if the order would be different now, and if so, recreate the TimerDates
            var orderedCollection = TimerDates.Where(x => validTimerDates.Contains(x.TimerDate)).OrderByDescending(x => x.TimerDate).ToList();

            if (orderedCollection.Count != TimerDates.Count)
            {
                TimerDates = new ObservableCollection <TimerDateModel>(orderedCollection);
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TimerDates)));
            }
            else
            {
                for (var i = 0; i < TimerDates.Count; i++)
                {
                    var main    = TimerDates[i];
                    var ordered = orderedCollection[i];

                    if (main.TimerDate != ordered.TimerDate)
                    {
                        TimerDates = new ObservableCollection <TimerDateModel>(orderedCollection);
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TimerDates)));
                        break;
                    }
                }
            }

            SetTrackingOnlyInModel();
            targetBarValues.Update();
        }
Exemple #5
0
        private void RefreshModel()
        {
            var workingDays     = ModelHelpers.Gallifrey.Settings.AppSettings.ExportDays.ToList();
            var workingDate     = DateTime.Now.AddDays((ModelHelpers.Gallifrey.Settings.AppSettings.KeepTimersForDays - 1) * -1).Date;
            var validTimerDates = new List <DateTime>();
            var jiraCache       = new List <Issue>();

            while (workingDate.Date <= DateTime.Now.Date)
            {
                if (workingDays.Contains(workingDate.DayOfWeek))
                {
                    validTimerDates.Add(workingDate.Date);
                }
                workingDate = workingDate.AddDays(1);
            }

            foreach (var timerDate in ModelHelpers.Gallifrey.JiraTimerCollection.GetValidTimerDates())
            {
                if (!validTimerDates.Contains(timerDate))
                {
                    validTimerDates.Add(timerDate.Date);
                }
            }

            foreach (var timerDate in validTimerDates.OrderBy(x => x.Date))
            {
                var dateModel = TimerDates.FirstOrDefault(x => x.TimerDate.Date == timerDate.Date);

                if (dateModel == null)
                {
                    dateModel = new TimerDateModel(timerDate, ModelHelpers.Gallifrey.JiraTimerCollection);
                    TimerDates.Add(dateModel);
                }

                var dateTimers = ModelHelpers.Gallifrey.JiraTimerCollection.GetTimersForADate(timerDate).ToList();

                foreach (var timer in dateTimers)
                {
                    if (!dateModel.Timers.Any(x => x.JiraTimer.UniqueId == timer.UniqueId))
                    {
                        timer.PropertyChanged += (sender, args) => TimerChanged();
                        dateModel.AddTimerModel(new TimerModel(timer));
                    }
                }

                foreach (var removeTimer in dateModel.Timers.Where(timerModel => !dateTimers.Any(x => x.UniqueId == timerModel.JiraTimer.UniqueId)).ToList())
                {
                    dateModel.RemoveTimerModel(removeTimer);
                }

                foreach (var defaultJira in ModelHelpers.Gallifrey.Settings.AppSettings.DefaultTimers ?? new List <string>())
                {
                    if (!dateModel.Timers.Any(x => x.JiraTimer.JiraReference == defaultJira) && dateModel.TimerDate.Date <= DateTime.Now.Date)
                    {
                        try
                        {
                            var jira = jiraCache.FirstOrDefault(x => x.key == defaultJira);
                            if (jira == null && ModelHelpers.Gallifrey.JiraConnection.IsConnected)
                            {
                                jira = ModelHelpers.Gallifrey.JiraConnection.GetJiraIssue(defaultJira);
                                jiraCache.Add(jira);
                            }

                            if (jira != null)
                            {
                                var timerId = ModelHelpers.Gallifrey.JiraTimerCollection.AddTimer(jira, timerDate.Date, TimeSpan.Zero, false);
                                var timer   = ModelHelpers.Gallifrey.JiraTimerCollection.GetTimer(timerId);
                                timer.PropertyChanged += (sender, args) => TimerChanged();
                                dateModel.AddTimerModel(new TimerModel(timer));
                            }
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
            }

            //see if the order would be different now, and if so, recreate the TimerDates
            var orderedCollection = TimerDates.Where(x => validTimerDates.Contains(x.TimerDate)).OrderByDescending(x => x.TimerDate).ToList();

            if (orderedCollection.Count != TimerDates.Count)
            {
                TimerDates = new ObservableCollection <TimerDateModel>(orderedCollection);
            }
            else
            {
                for (var i = 0; i < TimerDates.Count; i++)
                {
                    var main    = TimerDates[i];
                    var ordered = orderedCollection[i];

                    if (main.TimerDate != ordered.TimerDate)
                    {
                        TimerDates = new ObservableCollection <TimerDateModel>(orderedCollection);
                        break;
                    }
                }
            }
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TimerDates"));

            SetTrackingOnlyInModel();
            targetBarValues.Update();
        }
        private void RefreshModel()
        {
            var workingDays     = ModelHelpers.Gallifrey.Settings.AppSettings.ExportDays.ToList();
            var workingDate     = DateTime.Now.AddDays((ModelHelpers.Gallifrey.Settings.AppSettings.KeepTimersForDays - 1) * -1).Date;
            var validTimerDates = new List <DateTime>();

            while (workingDate.Date <= DateTime.Now.Date)
            {
                if (workingDays.Contains(workingDate.DayOfWeek))
                {
                    validTimerDates.Add(workingDate.Date);
                }
                workingDate = workingDate.AddDays(1);
            }

            foreach (var timerDate in ModelHelpers.Gallifrey.JiraTimerCollection.GetValidTimerDates())
            {
                if (!validTimerDates.Contains(timerDate))
                {
                    validTimerDates.Add(timerDate.Date);
                }
            }

            foreach (var timerDate in validTimerDates.OrderBy(x => x.Date))
            {
                var dateModel = TimerDates.FirstOrDefault(x => x.TimerDate.Date == timerDate.Date);

                if (dateModel == null)
                {
                    dateModel = new TimerDateModel(timerDate, ModelHelpers.Gallifrey.JiraTimerCollection);
                    TimerDates.Add(dateModel);
                }

                var dateTimers = ModelHelpers.Gallifrey.JiraTimerCollection.GetTimersForADate(timerDate).ToList();

                foreach (var timer in dateTimers)
                {
                    if (!dateModel.Timers.Any(x => x.JiraTimer.UniqueId == timer.UniqueId))
                    {
                        dateModel.AddTimerModel(new TimerModel(timer));
                    }
                }

                var removeTimers = dateModel.Timers.Where(timerModel => !dateTimers.Any(x => x.UniqueId == timerModel.JiraTimer.UniqueId)).ToList();

                foreach (var removeTimer in removeTimers)
                {
                    dateModel.RemoveTimerModel(removeTimer);
                }
            }

            //see if the order would be different now, and if so, recreate the TimerDates
            var orderedCollection = TimerDates.Where(x => validTimerDates.Contains(x.TimerDate)).OrderByDescending(x => x.TimerDate).ToList();

            if (orderedCollection.Count != TimerDates.Count)
            {
                TimerDates = new ObservableCollection <TimerDateModel>(orderedCollection);
            }
            else
            {
                for (var i = 0; i < TimerDates.Count; i++)
                {
                    var main    = TimerDates[i];
                    var ordered = orderedCollection[i];

                    if (main.TimerDate != ordered.TimerDate)
                    {
                        TimerDates = new ObservableCollection <TimerDateModel>(orderedCollection);
                        break;
                    }
                }
            }

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TimerDates"));

            runningWatcherElapsed(this, null);
        }