Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }