Exemplo n.º 1
0
        public async void MergeAsync(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = TogglClient.UserAgent)
        {
            var reportService    = new ReportServiceAsync(TogglSrv);
            var timeEntryService = new TimeEntryServiceAsync(TogglSrv);

            var reportParams = new DetailedReportParams
            {
                UserAgent   = userAgent,
                WorkspaceId = workspaceId,
                TaskIds     = string.Join(",", slaveTasksIds.Select(id => id.ToString())),
                Since       = DateTime.Now.AddYears(-1).ToIsoDateStr()
            };

            var result = await reportService.Detailed(reportParams).ConfigureAwait(false);

            if (result.TotalCount > result.PerPage)
            {
                result = await reportService.GetFullDetailedReportAsync(reportParams).ConfigureAwait(false);
            }

            foreach (var reportTimeEntry in result.Data ?? throw new FormatException("Data was unexpectedly null"))
            {
                if (reportTimeEntry.Id == null)
                {
                    continue;
                }
                var timeEntry = await timeEntryService
                                .GetAsync(reportTimeEntry.Id.Value)
                                .ConfigureAwait(false);

                timeEntry.TaskId = masterTaskId;
                var editedTimeEntry = await timeEntryService
                                      .UpdateAsync(timeEntry)
                                      .ConfigureAwait(false);

                if (editedTimeEntry == null)
                {
                    throw new ArgumentNullException(string.Format("Can't edit timeEntry #{0}", reportTimeEntry.Id));
                }
            }

            foreach (var slaveTaskId in slaveTasksIds)
            {
                if (!await DeleteAsync(slaveTaskId).ConfigureAwait(false))
                {
                    throw new InvalidOperationException(string.Format("Can't delete task #{0}", slaveTaskId));
                }
            }
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task MergeAsync(long masterTaskId, long slaveTaskId, long workspaceId, string userAgent = TogglClient.UserAgent)
        {
            var reportService    = new ReportServiceAsync(TogglSrv);
            var timeEntryService = new TimeEntryServiceAsync(TogglSrv);

            var reportParams = new DetailedReportParams
            {
                UserAgent   = userAgent,
                WorkspaceId = workspaceId,
                TaskIds     = slaveTaskId.ToString(),
                Since       = DateTime.Now.AddYears(-1).ToIsoDateStr()
            };

            var result = await reportService.Detailed(reportParams).ConfigureAwait(false);

            if (result.TotalCount > result.PerPage)
            {
                result = await reportService.GetFullDetailedReportAsync(reportParams).ConfigureAwait(false);
            }

            foreach (var reportTimeEntry in result.Data ?? throw new FormatException("Data was unexpectedly null"))
            {
                if (reportTimeEntry.Id == null)
                {
                    continue;
                }
                var timeEntry = await timeEntryService.GetAsync(reportTimeEntry.Id.Value).ConfigureAwait(false);

                timeEntry.TaskId = masterTaskId;
                try
                {
                    var _ = await timeEntryService.UpdateAsync(timeEntry).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    var _ = ex.Data;
                }
            }

            if (!await DeleteAsync(slaveTaskId).ConfigureAwait(false))
            {
                throw new InvalidOperationException(string.Format("Can't delete task #{0}", slaveTaskId));
            }
        }