示例#1
0
        /// <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);
        }
示例#2
0
文件: JiraClient.cs 项目: setias/TJI
        /// <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);
        }