示例#1
0
        public void SaveTimerEntry()
        {
            TimerEntry entry;

            var getTask = service.GetTimerEntryAsync();

            getTask.Wait();
            entry = getTask.Result;

            if (entry == null)
            {
                entry = new TimerEntry {
                    Date = DateTime.Now.AddHours(-1)
                };
            }

            try {
                var task = service.SaveTimerEntryAsync(entry, CancellationToken.None);

                task.Wait();

                Assert.That(task.Result, Is.EqualTo(1));
            } finally {
                var deleteTask = service.DeleteTimerEntryAsync(entry, CancellationToken.None);

                deleteTask.Wait();
            }
        }
        /// <summary>
        /// Pauses timer
        /// </summary>
        public Task PauseAsync()
        {
            if (activeAssignment == null || timerEntry == null)
            {
                return(Task.Factory.StartNew(delegate { }));
            }

            IsBusy    = true;
            Recording = false;

            var labor = new Labor {
                Type         = LaborType.Hourly,
                AssignmentId = activeAssignment.Id,
                Description  = "Time entered automatically at: " + DateTime.Now.ToShortTimeString(),
                Hours        = (DateTime.Now - timerEntry.Date),
            };

            return(service
                   .SaveLaborAsync(labor)
                   .ContinueWith(service.DeleteTimerEntryAsync(timerEntry))
                   .ContinueOnCurrentThread(_ => {
                CurrentHours = TimeSpan.Zero;
                IsBusy = false;
            }));
        }