public void Merge(int masterTaskId, int slaveTaskId, int workspaceId, string userAgent = "TogglAPI.Net") { var reportService = new ReportService(this.ToggleSrv); var timeEntryService = new TimeEntryService(this.ToggleSrv); var reportParams = new DetailedReportParams() { UserAgent = userAgent, WorkspaceId = workspaceId, TaskIds = slaveTaskId.ToString(), Since = DateTime.Now.AddYears(-1).ToIsoDateStr() }; var result = reportService.Detailed(reportParams); if (result.TotalCount > result.PerPage) result = reportService.FullDetailedReport(reportParams); foreach (var reportTimeEntry in result.Data) { var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value); timeEntry.TaskId = masterTaskId; try { var editedTimeEntry = timeEntryService.Edit(timeEntry); } catch (Exception ex) { var res = ex.Data; } } if (!Delete(slaveTaskId)) throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId)); }
public void Merge(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = "TogglAPI.Net") { var reportService = new ReportService(this.ToggleSrv); var timeEntryService = new TimeEntryService(this.ToggleSrv); var reportParams = new DetailedReportParams() { UserAgent = userAgent, WorkspaceId = workspaceId, TaskIds = string.Join(",", slaveTasksIds.Select(id => id.ToString())), Since = DateTime.Now.AddYears(-1).ToIsoDateStr() }; var result = reportService.Detailed(reportParams); if (result.TotalCount > result.PerPage) result = reportService.FullDetailedReport(reportParams); foreach (var reportTimeEntry in result.Data) { var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value); timeEntry.TaskId = masterTaskId; var editedTimeEntry = timeEntryService.Edit(timeEntry); if (editedTimeEntry == null) throw new ArgumentNullException(string.Format("Can't edit timeEntry #{0}", reportTimeEntry.Id)); } foreach (var slaveTaskId in slaveTasksIds) { if (!Delete(slaveTaskId)) throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId)); } }
public void Merge(int masterTaskId, int[] slaveTasksIds, int workspaceId, string userAgent = "TogglAPI.Net") { var reportService = new ReportService(this.ToggleSrv); var timeEntryService = new TimeEntryService(this.ToggleSrv); var reportParams = new DetailedReportParams() { UserAgent = userAgent, WorkspaceId = workspaceId, TaskIds = string.Join(",", slaveTasksIds.Select(id => id.ToString())), Since = DateTime.Now.AddYears(-1).ToIsoDateStr() }; var result = reportService.Detailed(reportParams); if (result.TotalCount > result.PerPage) result = reportService.FullDetailedReport(reportParams); foreach (var reportTimeEntry in result.Data) { var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value); timeEntry.TaskId = masterTaskId; var editedTimeEntry = timeEntryService.Edit(timeEntry); if (editedTimeEntry == null) throw new ArgumentNullException(string.Format("Can't edit timeEntry #{0}", reportTimeEntry.Id)); } foreach (var slaveTaskId in slaveTasksIds) { if (!Delete(slaveTaskId)) throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId)); } }
public void Merge(int masterTaskId, int slaveTaskId, int workspaceId, string userAgent = "TogglAPI.Net") { var reportService = new ReportService(this.ToggleSrv); var timeEntryService = new TimeEntryService(this.ToggleSrv); var reportParams = new DetailedReportParams() { UserAgent = userAgent, WorkspaceId = workspaceId, TaskIds = slaveTaskId.ToString(), Since = DateTime.Now.AddYears(-1).ToIsoDateStr() }; var result = reportService.Detailed(reportParams); if (result.TotalCount > result.PerPage) result = reportService.FullDetailedReport(reportParams); foreach (var reportTimeEntry in result.Data) { var timeEntry = timeEntryService.Get(reportTimeEntry.Id.Value); timeEntry.TaskId = masterTaskId; try { var editedTimeEntry = timeEntryService.Edit(timeEntry); } catch (Exception ex) { var res = ex.Data; } } if (!Delete(slaveTaskId)) throw new InvalidOperationException(string.Format("Can't delte task #{0}", slaveTaskId)); }
public Task PushTime(AppSetting settings, DateTime startDate, DateTime endDate) { //tra-74 if (settings == null) throw new Exception("No Jira or Toggl credentials provided."); this.VerifySetting(settings.JiraLogin, "JIRA login"); this.VerifySetting(settings.JiraPassword, "JIRA password"); this.VerifySetting(settings.JiraUrl, "JIRA URL"); this.VerifySetting(settings.TogglApiKey, "Toggl API Key"); var jira = new Jira(settings.JiraUrl, settings.JiraLogin, settings.JiraPassword); var toggl = new Toggl.Toggl(settings.TogglApiKey); return Task.Run(() => { var timeService = new TimeEntryService(settings.TogglApiKey); var timeParams = new TimeEntryParams(); timeParams.StartDate = startDate.Date; timeParams.EndDate = endDate.Date; foreach (var te in timeService.List(timeParams).Where(w => (w.TagNames == null || !w.TagNames.Contains(POSTED_TAG)) && !string.IsNullOrEmpty(w.Description))) { KeyValuePair<string, string> description = this.ParseDescription(te.Description); if (string.IsNullOrEmpty(description.Key)) continue; var issue = jira.GetIssue(description.Key); issue.AddWorklog(new Worklog(this.GetMinutes(te.Duration.GetValueOrDefault()), DateTime.Parse(te.Start), description.Value)); if (te.TagNames == null) te.TagNames = new List<string>(); te.TagNames.Add(POSTED_TAG); timeService.Edit(te); } }); //return Task.Run(() => // { // //Atlassian.Jira.Jira aa = new Atlassian.Jira.Jira("urlhere", "loginhere", "passwordhere"); // //var issue = aa.GetIssue("FLW6-2247"); // //issue.AddWorklog(new Atlassian.Jira.Worklog) // //var apiKey = "apikeyhere"; // //var t = new Toggl.Toggl(apiKey); // //var c = t.User.GetCurrent(); // //var timeSrv = new Toggl.Services.TimeEntryService(apiKey); // //var prams = new Toggl.QueryObjects.TimeEntryParams(); // //// there is an issue with the date ranges have // //// to step out of the range on the end. // //// To capture the end of the billing range day + 1 // //prams.StartDate = DateTime.Now.AddMonths(-1); // //prams.EndDate = DateTime.Now.AddMonths(1); // //var hours = timeSrv.List(prams) // // .Where(w => !string.IsNullOrEmpty(w.Description)).ToList(); // }); }