/// <summary> /// Syncs the Jira entry with the work entry /// </summary> /// <param name="jEntry">Jira entry to update</param> /// <param name="wEntry">Work entry to update Jira with</param> /// <returns>True if updated successfully</returns> public bool SyncWorkEntry(JiraWorkEntry jEntry, WorkEntry wEntry) { jEntry.TimeSpent = wEntry.TimeSpent; jEntry.TimeSpentSeconds = 0; Logger.DebugFormat("Syncronizing {0} in {1}", wEntry.TogglId, wEntry.IssueId); try { using (IHttpResponse response = GetResponse(() => GetWorkEntryRequest(jEntry, jEntry.Self, "PUT"))) { if (response.StatusCode == HttpStatusCode.OK) { EncounteredError = false; WorkEntryUpdated?.Invoke(wEntry); return(true); } else { EncounteredError = true; WorkEntryUpdateFailed?.Invoke(wEntry); Logger.WarnFormat("Didn't get the expected status code back when syncing a work entry for {0}. Got {1}", wEntry.IssueId, response.StatusCode); } } } catch (WebException we) { EncounteredError = true; WorkEntryUpdateFailed?.Invoke(wEntry); Logger.Error("Unable to sync web entry", we); } return(false); }
private HttpWebRequest GetWorkEntryRequest(JiraWorkEntry jEntry, string url, string method) { HttpWebRequest request = GetRequest(url, false); request.ContentType = "application/json;charset=UTF-8"; request.Method = method; WriteWorkEntry(jEntry, request); return(request); }
/// <summary> /// Writes the Jira entry to the request stream /// </summary> /// <param name="jEntry">Entry to write</param> /// <param name="request">Request to write to</param> private static void WriteWorkEntry(JiraWorkEntry jEntry, HttpWebRequest request) { using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) using (MemoryStream memStream = new MemoryStream()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(JiraWorkEntry)); serializer.WriteObject(memStream, jEntry); string jsonData = Encoding.UTF8.GetString(memStream.ToArray()); writer.Write(jsonData); Logger.Debug("Work entry written to stream"); } }
/// <summary> /// Adds the gived entry to the worklog of its issue /// </summary> /// <param name="wEntry">Worklog entry to add</param> /// <returns>True if added successfully</returns> public bool AddWorkEntry(WorkEntry wEntry) { JiraWorkEntry jEntry = new JiraWorkEntry { Started = GetStartTime(wEntry), Comment = wEntry.CommentWithMarker, TimeSpent = wEntry.TimeSpent }; Logger.DebugFormat("Creating a entry for {0} corresponding to {1}.", wEntry.IssueId, wEntry.TogglId); HttpWebRequest request = GetRequest(string.Format(GetWorklogUrl, wEntry.IssueId), true); request.ContentType = "application/json;charset=UTF-8"; request.Method = "POST"; try { WriteWorkEntry(jEntry, request); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { if (response.StatusCode == HttpStatusCode.Created) { Logger.DebugFormat("Work entry created for issue {0}", wEntry.IssueId); EncounteredError = false; WorkEntryCreated?.Invoke(wEntry); return(true); } else { WorkEntryCreationFailed?.Invoke(wEntry); Logger.WarnFormat("Didn't get the expected status code back when creating a work entry for {0}. Got {1}", wEntry.IssueId, response.StatusCode); } } } catch (WebException we) { WorkEntryCreationFailed?.Invoke(wEntry); Logger.Error("Unable add work entry", we); } EncounteredError = true; return(false); }
/// <summary> /// Syncs the Jira entry with the work entry /// </summary> /// <param name="jEntry">Jira entry to update</param> /// <param name="wEntry">Work entry to update Jira with</param> /// <returns>True if updated successfully</returns> public bool SyncWorkEntry(JiraWorkEntry jEntry, WorkEntry wEntry) { jEntry.TimeSpent = wEntry.TimeSpent; jEntry.TimeSpentSeconds = 0; Logger.DebugFormat("Syncronizing {0} in {1}", wEntry.TogglId, wEntry.IssueId); HttpWebRequest request = GetRequest(jEntry.Self, false); request.ContentType = "application/json;charset=UTF-8"; request.Method = "PUT"; try { WriteWorkEntry(jEntry, request); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { if (response.StatusCode == HttpStatusCode.OK) { EncounteredError = false; WorkEntryUpdated?.Invoke(wEntry); return(true); } else { EncounteredError = true; WorkEntryUpdateFailed?.Invoke(wEntry); Logger.WarnFormat("Didn't get the expected status code back when syncing a work entry for {0}. Got {1}", wEntry.IssueId, response.StatusCode); } } } catch (WebException we) { EncounteredError = true; WorkEntryUpdateFailed?.Invoke(wEntry); Logger.Error("Unable to sync web entry", we); } return(false); }
/// <summary> /// Adds the gived entry to the worklog of its issue /// </summary> /// <param name="wEntry">Worklog entry to add</param> /// <returns>True if added successfully</returns> public bool AddWorkEntry(WorkEntry wEntry) { JiraWorkEntry jEntry = new JiraWorkEntry { Started = GetStartTime(wEntry), Comment = wEntry.CommentWithMarker, TimeSpent = wEntry.TimeSpent }; Logger.DebugFormat("Creating a entry for {0} corresponding to {1}.", wEntry.IssueId, wEntry.TogglId); try { using (IHttpResponse response = GetResponse(() => GetWorkEntryRequest(jEntry, ServerUrl + string.Format(GetWorklogUrl, wEntry.IssueId), "POST"))) { if (response.StatusCode == HttpStatusCode.Created) { Logger.DebugFormat("Work entry created for issue {0}", wEntry.IssueId); EncounteredError = false; WorkEntryCreated?.Invoke(wEntry); return(true); } else { WorkEntryCreationFailed?.Invoke(wEntry); Logger.WarnFormat("Didn't get the expected status code back when creating a work entry for {0}. Got {1}", wEntry.IssueId, response.StatusCode); } } } catch (WebException we) { WorkEntryCreationFailed?.Invoke(wEntry); Logger.Error("Unable add work entry", we); } EncounteredError = true; return(false); }