Inheritance: INotifyPropertyChanged
Beispiel #1
0
        public void StartTimer(Guid uniqueId)
        {
            var timerForInteration = GetTimer(uniqueId);

            if (timerForInteration.DateStarted.Date != DateTime.Now.Date)
            {
                if (timerForInteration.TempTimer)
                {
                    uniqueId           = AddTempTimer(timerForInteration.JiraName, DateTime.Now, new TimeSpan(), false);
                    timerForInteration = GetTimer(uniqueId);
                }
                else
                {
                    timerForInteration = new JiraTimer(timerForInteration, DateTime.Now, true);
                    AddTimer(timerForInteration);
                    uniqueId = timerForInteration.UniqueId;
                }
            }

            var runningTimerId = GetRunningTimerId();

            if (runningTimerId.HasValue && runningTimerId.Value != uniqueId)
            {
                GetTimer(runningTimerId.Value).StopTimer();
            }

            timerForInteration.StartTimer();

            SaveTimers();
        }
        public AdjustTimerWindow(IBackend gallifrey, Guid timerGuid)
        {
            this.gallifrey = gallifrey;
            timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid);
            InitializeComponent();

            txtJiraRef.Text = timerToShow.JiraReference;
        }
 public TimerDisplayModel(JiraTimer jiraTimer)
 {
     Timer = jiraTimer;
     Reference = jiraTimer.JiraReference;
     Description = jiraTimer.JiraName;
     ParentReference = jiraTimer.JiraParentReference;
     ParentDescription = jiraTimer.JiraParentName;
     HasParent = jiraTimer.HasParent;
 }
        public void AddTimer(Issue jiraIssue, DateTime startDate, TimeSpan seedTime, bool startNow)
        {
            var newTimer = new JiraTimer(jiraIssue, startDate, seedTime);

            AddTimer(newTimer);
            if (startNow)
            {
                StartTimer(newTimer.UniqueId);
            }
        }
        private void AddTimer(JiraTimer newTimer)
        {
            if (timerList.Any(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date))
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!");
            }

            timerList.Add(newTimer);
            SaveTimers();
        }
        public RenameTimerWindow(IBackend gallifrey, Guid timerGuid)
        {
            this.gallifrey = gallifrey;
            timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid);
            InitializeComponent();

            txtJiraRef.Text = timerToShow.JiraReference;
            calStartDate.Value = timerToShow.DateStarted.Date;
            txtJiraRef.Enabled = timerToShow.HasExportedTime();
        }
Beispiel #7
0
 public JiraTimer(JiraTimer previousTimer, DateTime dateStarted)
 {
     JiraReference      = previousTimer.JiraReference;
     JiraProjectName    = previousTimer.JiraProjectName;
     JiraName           = previousTimer.JiraName;
     DateStarted        = dateStarted;
     CurrentTime        = new TimeSpan();
     ExportedTime       = new TimeSpan();
     UniqueId           = Guid.NewGuid();
     IsRunning          = false;
     currentRunningTime = new Stopwatch();
 }
Beispiel #8
0
 public JiraTimer(JiraTimer previousTimer, DateTime dateStarted)
 {
     JiraReference = previousTimer.JiraReference;
     JiraProjectName = previousTimer.JiraProjectName;
     JiraName = previousTimer.JiraName;
     DateStarted = dateStarted;
     CurrentTime = new TimeSpan();
     ExportedTime = new TimeSpan();
     UniqueId = Guid.NewGuid();
     IsRunning = false;
     currentRunningTime = new Stopwatch();
 }
Beispiel #9
0
        private void AddTimer(JiraTimer newTimer)
        {
            var timerSearch = timerList.FirstOrDefault(timer => string.Equals(timer.JiraReference, newTimer.JiraReference, StringComparison.InvariantCultureIgnoreCase) && timer.DateStarted.Date == newTimer.DateStarted.Date);

            if (timerSearch != null)
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId);
            }

            trackUsage.TrackAppUsage(TrackingType.TimerAdded);
            timerList.Add(newTimer);
            SaveTimers();
        }
Beispiel #10
0
        private void AddTimer(JiraTimer newTimer)
        {
            var timerSearch = timerList.FirstOrDefault(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date);

            if (timerSearch != null)
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId);
            }

            trackUsage.TrackAppUsage(TrackingType.TimerAdded);
            timerList.Add(newTimer);
            SaveTimers();
        }
Beispiel #11
0
 public JiraTimer(JiraTimer previousTimer, DateTime dateStarted, bool resetTimes)
 {
     JiraReference = previousTimer.JiraReference;
     JiraProjectName = previousTimer.JiraProjectName;
     JiraName = previousTimer.JiraName;
     JiraParentReference = previousTimer.JiraParentReference;
     JiraParentName = previousTimer.JiraParentName;
     DateStarted = dateStarted;
     CurrentTime = resetTimes ? new TimeSpan() : previousTimer.CurrentTime;
     ExportedTime = resetTimes ? new TimeSpan() : previousTimer.ExportedTime;
     UniqueId = Guid.NewGuid();
     IsRunning = false;
     currentRunningTime = new Stopwatch();
     runningWatcher = new Timer(100);
     runningWatcher.Elapsed += runningWatcherElapsed;
 }
Beispiel #12
0
 public JiraTimer(JiraTimer previousTimer, DateTime dateStarted, bool resetTimes)
 {
     JiraReference           = previousTimer.JiraReference;
     JiraProjectName         = previousTimer.JiraProjectName;
     JiraName                = previousTimer.JiraName;
     JiraParentReference     = previousTimer.JiraParentReference;
     JiraParentName          = previousTimer.JiraParentName;
     DateStarted             = dateStarted;
     CurrentTime             = resetTimes ? new TimeSpan() : previousTimer.CurrentTime;
     ExportedTime            = resetTimes ? new TimeSpan() : previousTimer.ExportedTime;
     UniqueId                = Guid.NewGuid();
     IsRunning               = false;
     currentRunningTime      = new Stopwatch();
     runningWatcher          = new Timer(100);
     runningWatcher.Elapsed += runningWatcherElapsed;
 }
        public EditTimerWindow(IBackend gallifrey, Guid timerGuid)
        {
            this.gallifrey = gallifrey;
            timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid);
            InitializeComponent();

            txtJiraRef.AutoCompleteCustomSource.AddRange(gallifrey.JiraConnection.GetJiraProjects().Select(x => x.ToString()).ToArray());
            showingJiras = false;
            txtJiraRef.Text = timerToShow.JiraReference;

            calStartDate.Value = timerToShow.DateStarted.Date;

            txtJiraRef.Enabled = timerToShow.HasExportedTime();
            calStartDate.Enabled = timerToShow.HasExportedTime();

            TopMost = gallifrey.Settings.UiSettings.AlwaysOnTop;
        }
        public Guid AddTimer(Issue jiraIssue, DateTime startDate, TimeSpan seedTime, bool startNow)
        {
            var newTimer = new JiraTimer(jiraIssue, startDate, seedTime);

            AddTimer(newTimer);
            if (startNow)
            {
                StartTimer(newTimer.UniqueId);
            }
            else
            {
                if (exportSettings.ExportPrompt != null && exportSettings.ExportPrompt.OnCreatePreloaded && !newTimer.FullyExported)
                {
                    exportPrompt.Invoke(this, new ExportPromptDetail(newTimer.UniqueId, seedTime));
                }
            }
            return(newTimer.UniqueId);
        }
        public void RenameTimer(Guid timerGuid, Issue newIssue)
        {
            var currentTimer = GetTimer(timerGuid);

            if (currentTimer.IsRunning)
            {
                currentTimer.StopTimer();
            }
            var newTimer = new JiraTimer(newIssue, currentTimer.DateStarted, currentTimer.ExactCurrentTime);

            if (timerList.Any(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date && timer.UniqueId != timerGuid))
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!");
            }

            RemoveTimer(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
        }
        public ExportTimerWindow(IBackend gallifrey, Guid timerGuid)
        {
            this.gallifrey = gallifrey;
            timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid);
            InitializeComponent();

            jiraIssue = gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference);
            var loggedTime = new TimeSpan();
            foreach (var worklog in jiraIssue.GetWorklogs())
            {
                if (worklog.StartDate.HasValue && worklog.StartDate.Value.Date == timerToShow.DateStarted.Date && worklog.Author.ToLower() == gallifrey.JiraConnectionSettings.JiraUsername.ToLower())
                {
                    loggedTime = loggedTime.Add(new TimeSpan(0, 0, (int)worklog.TimeSpentInSeconds));
                }
            }
            gallifrey.JiraTimerCollection.SetJiraExportedTime(timerGuid, loggedTime);

            timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid);

            if (timerToShow.TimeToExport.TotalMinutes <= 0)
            {
                MessageBox.Show("There Is No Time To Export", "Nothing To Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DisplayForm = false;
            }

            txtJiraRef.Text = timerToShow.JiraReference;
            txtDescription.Text = timerToShow.JiraName;
            txtTotalHours.Text = timerToShow.ExactCurrentTime.Hours.ToString();
            txtTotalMinutes.Text = timerToShow.ExactCurrentTime.Minutes.ToString();
            txtExportedHours.Text = timerToShow.ExportedTime.Hours.ToString();
            txtExportedMins.Text = timerToShow.ExportedTime.Minutes.ToString();
            txtExportHours.Text = timerToShow.TimeToExport.Hours.ToString();
            txtExportMins.Text = timerToShow.TimeToExport.Minutes.ToString();

            if (timerToShow.DateStarted.Date != DateTime.Now.Date)
            {
                calExportDate.Value = timerToShow.DateStarted.Date.AddHours(12);
            }
            else
            {
                calExportDate.Value = DateTime.Now;
            }
        }
Beispiel #17
0
        public Guid ChangeTimerDate(Guid timerGuid, DateTime newStartDate)
        {
            var currentTimer = GetTimer(timerGuid);

            if (currentTimer.IsRunning)
            {
                currentTimer.StopTimer();
            }

            JiraTimer newTimer;

            if (currentTimer.TempTimer)
            {
                var foundValid          = false;
                var nextTempTimerNumber = 0;
                var currentLocalTimers  = GetTimersForADate(newStartDate.Date).Where(x => x.TempTimer).ToList();
                while (!foundValid)
                {
                    nextTempTimerNumber++;
                    if (!currentLocalTimers.Any(x => x.JiraReference.EndsWith($"-{nextTempTimerNumber}")))
                    {
                        foundValid = true;
                    }
                }
                newTimer = new JiraTimer(nextTempTimerNumber, currentTimer.JiraName, newStartDate.Date, currentTimer.ExactCurrentTime);
            }
            else
            {
                newTimer = new JiraTimer(currentTimer, newStartDate.Date, false);

                var timerSearch = timerList.FirstOrDefault(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date);

                if (timerSearch != null)
                {
                    throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId);
                }
            }

            RemoveTimerInternal(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
            return(newTimer.UniqueId);
        }
        public Guid ChangeTimerDate(Guid timerGuid, DateTime newStartDate)
        {
            var currentTimer = GetTimer(timerGuid);

            if (currentTimer.IsRunning)
            {
                currentTimer.StopTimer();
            }
            var newTimer = new JiraTimer(currentTimer, newStartDate.Date, false);

            if (timerList.Any(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date && timer.UniqueId != timerGuid))
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!");
            }

            RemoveTimer(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
            return(newTimer.UniqueId);
        }
Beispiel #19
0
        public ExportModel(JiraTimer timer, TimeSpan? exportTime, IExportSettings exportSettings)
        {
            UpdateTimer(timer, exportTime);

            ExportDate = timer.DateStarted.Date != DateTime.Now.Date ? timer.DateStarted.Date.AddHours(12) : DateTime.Now;

            switch (exportSettings.DefaultRemainingValue)
            {
                case DefaultRemaining.Auto:
                    WorkLogStrategy = WorkLogStrategy.Automatic;
                    break;
                case DefaultRemaining.Leave:
                    WorkLogStrategy = WorkLogStrategy.LeaveRemaining;
                    break;
                case DefaultRemaining.Set:
                    WorkLogStrategy = WorkLogStrategy.SetValue;
                    break;
            }

            DefaultComment = exportSettings.EmptyExportComment;
        }
        public void StartTimer(Guid uniqueId)
        {
            var timerForInteration = GetTimer(uniqueId);

            if (timerForInteration.DateStarted.Date != DateTime.Now.Date)
            {
                timerForInteration = new JiraTimer(timerForInteration, DateTime.Now, true);
                AddTimer(timerForInteration);
                uniqueId = timerForInteration.UniqueId;
            }

            var runningTimerId = GetRunningTimerId();

            if (runningTimerId.HasValue && runningTimerId.Value != uniqueId)
            {
                GetTimer(runningTimerId.Value).StopTimer();
            }

            timerForInteration.StartTimer();

            SaveTimers();
        }
Beispiel #21
0
        public Guid RenameTimer(Guid timerGuid, Issue newIssue)
        {
            var currentTimer = GetTimer(timerGuid);

            if (currentTimer.IsRunning)
            {
                currentTimer.StopTimer();
            }
            var newTimer = new JiraTimer(newIssue, currentTimer.DateStarted, currentTimer.ExactCurrentTime);

            var timerSearch = timerList.FirstOrDefault(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date);

            if (timerSearch != null)
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId);
            }

            RemoveTimerInternal(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
            return(newTimer.UniqueId);
        }
Beispiel #22
0
        public Guid AddTempTimer(string tempTimerDescription, DateTime startDate, TimeSpan seedTime, bool startNow)
        {
            var foundValid          = false;
            var nextTempTimerNumber = 0;
            var currentLocalTimers  = GetTimersForADate(startDate.Date).Where(x => x.TempTimer).ToList();

            while (!foundValid)
            {
                nextTempTimerNumber++;
                if (!currentLocalTimers.Any(x => x.JiraReference.EndsWith($"-{nextTempTimerNumber}")))
                {
                    foundValid = true;
                }
            }

            var newTimer = new JiraTimer(nextTempTimerNumber, tempTimerDescription, startDate, seedTime);

            AddTimer(newTimer);
            if (startNow)
            {
                StartTimer(newTimer.UniqueId);
            }
            return(newTimer.UniqueId);
        }
Beispiel #23
0
 private ContextMenu BuildTimerListContextMenu(JiraTimer jiraTimerSelected)
 {
     if (jiraTimerSelected != null)
     {
         return BuildSelectedTimerContext(jiraTimerSelected);
     }
     else
     {
         return BuildNoTimerContext();
     }
 }
Beispiel #24
0
        private ContextMenu BuildSelectedTimerContext(JiraTimer jiraTimer)
        {
            var menuItems = new List<MenuItem>();

            var dateMenuItems = new List<MenuItem>();

            var dateList = gallifrey.JiraTimerCollection.GetValidTimerDates().OrderByDescending(x => x.Date);

            if (dateList.All(x => x.Date != DateTime.Now.Date))
            {
                dateMenuItems.Add(new MenuItem(DateTime.Now.ToString("ddd, dd MMM"), ListContextDateClicked));
            }

            foreach (var timerlistValue in dateList)
            {
                if (timerlistValue.Date != jiraTimer.DateStarted.Date)
                {
                    dateMenuItems.Add(new MenuItem(timerlistValue.ToString("ddd, dd MMM"), ListContextDateClicked));
                }
            }

            menuItems.Add(new MenuItem("Add To Date", dateMenuItems.ToArray()));
            menuItems.Add(new MenuItem("Move Time To New Timer", ListContextSplitClicked));
            menuItems.Add(new MenuItem("Delete Timer", btnRemoveTimer_Click));
            menuItems.Add(new MenuItem("Adjust Timer Time", btnTimeEdit_Click));
            menuItems.Add(new MenuItem("Change Jira Ref/Date", btnRename_Click));
            menuItems.Add(new MenuItem("Export Timer", btnExport_Click));
            if (jiraTimer.IsRunning)
            {
                menuItems.Add(new MenuItem("Stop Timer", ListBoxDoubleClick));
            }
            else
            {
                menuItems.Add(new MenuItem("Start Timer", ListBoxDoubleClick));
            }

            return new ContextMenu(menuItems.ToArray());
        }
        private void UpdateTimer(JiraTimer timer)
        {
            Timer = timer;

            toExportMaxTime = new TimeSpan(timer.TimeToExport.Hours, timer.TimeToExport.Minutes, 0);
            ToExportHours = toExportMaxTime.Hours;
            ToExportMinutes = toExportMaxTime.Minutes;

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

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HasParent"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentRef"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentDesc"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraRef"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraDesc"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedHours"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedMinutes"));
        }
Beispiel #26
0
 public JiraTimer(JiraTimer previousTimer, DateTime dateStarted, bool resetTimes) :
     this(previousTimer.JiraReference, previousTimer.JiraProjectName, previousTimer.JiraName, dateStarted, resetTimes ? new TimeSpan() : previousTimer.CurrentTime, resetTimes ? new TimeSpan() : previousTimer.ExportedTime, Guid.NewGuid(), previousTimer.JiraParentReference, previousTimer.JiraParentName, null, previousTimer.LocalTimer)
 {
 }
        public Guid AddLocalTimer(string localTimerDescription, DateTime startDate, TimeSpan seedTime, bool startNow)
        {
            var foundValid = false;
            var nextLocalTimerNumber = 0;
            var currentLocalTimers = GetTimersForADate(startDate.Date).Where(x => x.LocalTimer).ToList();
            while (!foundValid)
            {
                nextLocalTimerNumber++;
                if (!currentLocalTimers.Any(x => x.JiraReference.EndsWith($"-{nextLocalTimerNumber}")))
                {
                    foundValid = true;
                }
            }

            var newTimer = new JiraTimer(nextLocalTimerNumber, localTimerDescription, startDate, seedTime);

            AddTimer(newTimer);
            if (startNow)
            {
                StartTimer(newTimer.UniqueId);
            }
            return newTimer.UniqueId;
        }
        private void AddTimer(JiraTimer newTimer)
        {
            var timerSearch = timerList.FirstOrDefault(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date);

            if (timerSearch != null)
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId);
            }

            trackUsage.TrackAppUsage(TrackingType.TimerAdded);
            timerList.Add(newTimer);
            SaveTimers();
        }
        public Guid ChangeTimerDate(Guid timerGuid, DateTime newStartDate)
        {
            var currentTimer = GetTimer(timerGuid);
            if (currentTimer.IsRunning) currentTimer.StopTimer();

            JiraTimer newTimer;
            if (currentTimer.LocalTimer)
            {
                var foundValid = false;
                var nextLocalTimerNumber = 0;
                var currentLocalTimers = GetTimersForADate(newStartDate.Date).Where(x => x.LocalTimer).ToList();
                while (!foundValid)
                {
                    nextLocalTimerNumber++;
                    if (!currentLocalTimers.Any(x => x.JiraReference.EndsWith($"-{nextLocalTimerNumber}")))
                    {
                        foundValid = true;
                    }
                }
                newTimer = new JiraTimer(nextLocalTimerNumber, currentTimer.JiraName, newStartDate.Date, currentTimer.ExactCurrentTime);
            }
            else
            {
                newTimer = new JiraTimer(currentTimer, newStartDate.Date, false);

                var timerSearch = timerList.FirstOrDefault(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date);

                if (timerSearch != null)
                {
                    throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId);
                }
            }

            RemoveTimerInternal(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
            return newTimer.UniqueId;
        }
Beispiel #30
0
        private void UpdateTimer(JiraTimer timer, TimeSpan? exportTime)
        {
            Timer = timer;

            if (exportTime.HasValue && exportTime.Value < timer.TimeToExport)
            {
                ToExportMaxTime = exportTime.Value;
            }
            else
            {
                ToExportMaxTime = new TimeSpan(timer.TimeToExport.Hours, timer.TimeToExport.Minutes, 0);
            }

            ToExportHours = ToExportMaxTime.Hours;
            ToExportMinutes = ToExportMaxTime.Minutes;

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HasParent"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentRef"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraParentDesc"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraRef"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("JiraDesc"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedHours"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExportedMinutes"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToExportHours"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToExportMinutes"));
        }
Beispiel #31
0
        public void UpdateTimer(JiraTimer timer, Issue jiraIssue)
        {
            UpdateTimer(timer, ToExportMaxTime);

            OriginalRemaining = jiraIssue.fields.timetracking != null ? TimeSpan.FromSeconds(jiraIssue.fields.timetracking.remainingEstimateSeconds) : new TimeSpan();

            SetRemaining();
        }
 public void AddTimer(Issue jiraIssue, DateTime startDate, TimeSpan seedTime, bool startNow)
 {
     var newTimer = new JiraTimer(jiraIssue, startDate, seedTime);
     AddTimer(newTimer);
     if (startNow)
     {
         StartTimer(newTimer.UniqueId);
     }
 }
        public Guid RenameTimer(Guid timerGuid, Issue newIssue)
        {
            var currentTimer = GetTimer(timerGuid);
            if (currentTimer.IsRunning) currentTimer.StopTimer();
            var newTimer = new JiraTimer(newIssue, currentTimer.DateStarted, currentTimer.ExactCurrentTime);

            var timerSearch = timerList.FirstOrDefault(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date);

            if (timerSearch != null)
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId);
            }

            RemoveTimerInternal(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
            return newTimer.UniqueId;
        }
        public void StartTimer(Guid uniqueId)
        {
            var timerForInteration = GetTimer(uniqueId);
            if (timerForInteration.DateStarted.Date != DateTime.Now.Date)
            {
                if (timerForInteration.LocalTimer)
                {
                    uniqueId = AddLocalTimer(timerForInteration.JiraName, DateTime.Now, new TimeSpan(), false);
                    timerForInteration = GetTimer(uniqueId);
                }
                else
                {
                    timerForInteration = new JiraTimer(timerForInteration, DateTime.Now, true);
                    AddTimer(timerForInteration);
                    uniqueId = timerForInteration.UniqueId;
                }
            }

            var runningTimerId = GetRunningTimerId();
            if (runningTimerId.HasValue && runningTimerId.Value != uniqueId)
            {
                GetTimer(runningTimerId.Value).StopTimer();
            }

            timerForInteration.StartTimer();

            SaveTimers();
        }
 public Guid AddTimer(Issue jiraIssue, DateTime startDate, TimeSpan seedTime, bool startNow)
 {
     var newTimer = new JiraTimer(jiraIssue, startDate, seedTime);
     AddTimer(newTimer);
     if (startNow)
     {
         StartTimer(newTimer.UniqueId);
     }
     else
     {
         if (exportSettings.ExportPrompt != null && exportSettings.ExportPrompt.OnCreatePreloaded && !newTimer.FullyExported && !newTimer.LocalTimer)
         {
             exportPrompt?.Invoke(this, new ExportPromptDetail(newTimer.UniqueId, seedTime));
         }
     }
     return newTimer.UniqueId;
 }
        public ExportTimerWindow(IBackend gallifrey, Guid timerGuid)
        {
            DisplayForm = true;
            this.gallifrey = gallifrey;
            timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid);
            InitializeComponent();

            try
            {
                jiraIssue = gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference, true);
            }
            catch (NoResultsFoundException)
            {
                MessageBox.Show(string.Format("Unable To Locate Jira {0}!\nCannot Export Time\nPlease Verify/Correct Jira Reference", timerToShow.JiraReference), "Unable To Locate Jira", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DisplayForm = false;
            }

            gallifrey.JiraTimerCollection.RefreshFromJira(timerGuid, jiraIssue, gallifrey.JiraConnection.CurrentUser);

            timerToShow = gallifrey.JiraTimerCollection.GetTimer(timerGuid);

            if (timerToShow.FullyExported)
            {
                MessageBox.Show("There Is No Time To Export", "Nothing To Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DisplayForm = false;
            }

            txtJiraRef.Text = timerToShow.JiraReference;
            txtDescription.Text = timerToShow.JiraName;
            if (timerToShow.HasParent)
            {
                txtParentRef.Text = timerToShow.JiraParentReference;
                txtParentDesc.Text = timerToShow.JiraParentName;
            }
            else
            {
                txtParentRef.Visible = false;
                txtParentDesc.Visible = false;
                lblParentRef.Visible = false;
                lblParentDesc.Visible = false;
            }

            txtTotalHours.Text = timerToShow.ExactCurrentTime.Hours.ToString();
            txtTotalMinutes.Text = timerToShow.ExactCurrentTime.Minutes.ToString();
            txtExportedHours.Text = timerToShow.ExportedTime.Hours.ToString();
            txtExportedMins.Text = timerToShow.ExportedTime.Minutes.ToString();
            txtExportHours.Text = timerToShow.TimeToExport.Hours.ToString();
            txtExportMins.Text = timerToShow.TimeToExport.Minutes.ToString();

            if (jiraIssue.fields.timetracking == null)
            {
                txtRemainingHours.Text = "N/A";
                txtRemainingMinutes.Text = "N/A";
            }
            else
            {
                var remainingTime = jiraIssue.fields.timetracking != null ? TimeSpan.FromSeconds(jiraIssue.fields.timetracking.remainingEstimateSeconds) : new TimeSpan();
                var hours = (remainingTime.Days * 24) + remainingTime.Hours;
                txtRemainingHours.Text = hours.ToString();
                txtRemainingMinutes.Text = remainingTime.Minutes.ToString();
            }

            if (timerToShow.DateStarted.Date != DateTime.Now.Date)
            {
                calExportDate.Value = timerToShow.DateStarted.Date.AddHours(12);
            }
            else
            {
                calExportDate.Value = DateTime.Now;
            }

            radAutoAdjust.Checked = gallifrey.Settings.ExportSettings.DefaultRemainingValue == DefaultRemaining.Auto;
            radLeaveRemaining.Checked = gallifrey.Settings.ExportSettings.DefaultRemainingValue == DefaultRemaining.Leave;
            radSetValue.Checked = gallifrey.Settings.ExportSettings.DefaultRemainingValue == DefaultRemaining.Set;
            radSetValue_CheckedChanged(this, null);

            TopMost = gallifrey.Settings.UiSettings.AlwaysOnTop;

            txtComment.AltEnterEvent += btnOK_Click;
        }
Beispiel #37
0
 public TimerModel(JiraTimer timer)
 {
     JiraTimer = timer;
     JiraTimer.PropertyChanged += JiraTimerOnPropertyChanged;
 }
        public void StartTimer(Guid uniqueId)
        {
            var timerForInteration = GetTimer(uniqueId);
            if (timerForInteration.DateStarted.Date != DateTime.Now.Date)
            {
                timerForInteration = new JiraTimer(timerForInteration, DateTime.Now);
                AddTimer(timerForInteration);
                uniqueId = timerForInteration.UniqueId;
            }

            timerForInteration.StartTimer();

            var runningTimerId = GetRunningTimerId();
            if (runningTimerId.HasValue && runningTimerId.Value != uniqueId)
            {
                GetTimer(runningTimerId.Value).StopTimer();
            }

            SaveTimers();
        }
        private void AddTimer(JiraTimer newTimer)
        {
            if (timerList.Any(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date))
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!");
            }

            timerList.Add(newTimer);
            SaveTimers();
        }
Beispiel #40
0
        private async void SetupContext(JiraTimer timerToShow, TimeSpan? exportTime, bool skipJiraCheck)
        {
            await Task.Delay(50);
            modelHelpers.HideFlyout(this);
            if (timerToShow.LocalTimer)
            {
                await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Local Timer", "You Cannot Export A Local Timer!");
                modelHelpers.CloseFlyout(this);
                return;
            }

            DataContext = new ExportModel(timerToShow, exportTime, modelHelpers.Gallifrey.Settings.ExportSettings);

            if (!skipJiraCheck)
            {
                Issue jiraIssue = null;
                var requireRefresh = !timerToShow.LastJiraTimeCheck.HasValue || timerToShow.LastJiraTimeCheck < DateTime.UtcNow.AddMinutes(-15);
                var showError = false;
                try
                {
                    var jiraDownloadResult = await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference, requireRefresh), "Downloading Jira Work Logs To Ensure Accurate Export", true, false);

                    switch (jiraDownloadResult.Status)
                    {
                        case ProgressResult.JiraHelperStatus.Cancelled:
                            modelHelpers.CloseFlyout(this);
                            return;
                        case ProgressResult.JiraHelperStatus.Errored:
                            showError = true;
                            break;
                        case ProgressResult.JiraHelperStatus.Success:
                            jiraIssue = jiraDownloadResult.RetVal;
                            break;
                    }
                }
                catch (Exception)
                {
                    showError = true;
                }

                if (showError)
                {
                    await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Unable To Locate Jira", $"Unable To Locate Jira {timerToShow.JiraReference}!\nCannot Export Time\nPlease Verify/Correct Jira Reference");
                    modelHelpers.CloseFlyout(this);
                    return;
                }

                if (requireRefresh)
                {
                    modelHelpers.Gallifrey.JiraTimerCollection.RefreshFromJira(timerToShow.UniqueId, jiraIssue, modelHelpers.Gallifrey.JiraConnection.CurrentUser);
                    timerToShow = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(timerToShow.UniqueId);
                }

                DataModel.UpdateTimer(timerToShow, jiraIssue);
            }

            if (timerToShow.FullyExported)
            {
                await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Nothing To Export", "There Is No Time To Export");
                modelHelpers.CloseFlyout(this);
                return;
            }

            if (timerToShow.IsRunning)
            {
                await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Timer Is Running", "You Cannot Export A Timer While It Is Running");
                modelHelpers.CloseFlyout(this);
                return;
            }

            await modelHelpers.OpenFlyout(this);
        }
        public Guid ChangeTimerDate(Guid timerGuid, DateTime newStartDate)
        {
            var currentTimer = GetTimer(timerGuid);
            if (currentTimer.IsRunning) currentTimer.StopTimer();
            var newTimer = new JiraTimer(currentTimer, newStartDate.Date, false);

            if (timerList.Any(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date && timer.UniqueId != timerGuid))
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!");
            }

            RemoveTimer(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
            return newTimer.UniqueId;
        }
        public void RenameTimer(Guid timerGuid, Issue newIssue)
        {
            var currentTimer = GetTimer(timerGuid);
            if (currentTimer.IsRunning) currentTimer.StopTimer();
            var newTimer = new JiraTimer(newIssue, currentTimer.DateStarted, currentTimer.ExactCurrentTime);

            if (timerList.Any(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date && timer.UniqueId != timerGuid))
            {
                throw new DuplicateTimerException("Already have a timer for this task on this day!");
            }

            RemoveTimer(timerGuid);
            AddTimer(newTimer);
            SaveTimers();
        }
Beispiel #43
0
 public JiraTimer(JiraTimer previousTimer, DateTime dateStarted, bool resetTimes)
     : this(previousTimer.JiraReference, previousTimer.JiraProjectName, previousTimer.JiraName, dateStarted, resetTimes ? new TimeSpan() : previousTimer.CurrentTime, resetTimes ? new TimeSpan() : previousTimer.ExportedTime, Guid.NewGuid(), previousTimer.JiraParentReference, previousTimer.JiraParentName, null, previousTimer.LocalTimer)
 {
 }