コード例 #1
0
ファイル: BugzillaRestClient.cs プロジェクト: nodia/gollum
        public async Task <BugzillaBug> GetBugInformationAsync(BugzillaArguments arguments, CancellationTokenSource tokenSource)
        {
            tokenSource.Token.ThrowIfCancellationRequested();

            await Login(arguments).ConfigureAwait(false);

            tokenSource.Token.ThrowIfCancellationRequested();
            tokenSource.CancelAfter(DefaultTimeout);

            var xml = new XmlRequest
            {
                Method     = "Bug.get",
                Parameters =
                {
                    new XmlParameter {
                        Name = "ids", Value = new[]{ arguments.UpdateToken                }
                    }
                }
            };

            var request = new RestRequest {
                Method = Method.POST, RequestFormat = DataFormat.Xml
            };

            request.AddParameter("text/xml", xml.ToString(), ParameterType.RequestBody);

            var response = await ExecuteAsync(request, tokenSource.Token).ConfigureAwait(false);

            CheckResponse(response);
            return(new BugzillaBug(response.Content));
        }
コード例 #2
0
ファイル: BugzillaRestClient.cs プロジェクト: nodia/gollum
        public async Task PostToBugzillaAsync(BugzillaArguments arguments)
        {
            await Login(arguments).ConfigureAwait(false);

            var updateStatus = new XmlRequest
            {
                Method     = "Bug.update",
                Parameters =
                {
                    new XmlParameter {
                        Name = "ids", Value = new[]{ arguments.BugId                }
                    },
                    new XmlParameter {
                        Name = "status", Value = arguments.Status
                    },
                    new XmlParameter {
                        Name = "resolution", Value = arguments.Resolution
                    }
                }
            };

            using (var tokenSource = new CancellationTokenSource())
            {
                var statusRequest = new RestRequest {
                    Method = Method.POST, RequestFormat = DataFormat.Xml
                };
                statusRequest.AddParameter("text/xml", updateStatus.ToString(), ParameterType.RequestBody);

                tokenSource.CancelAfter(DefaultTimeout);
                var statusResponse = await ExecuteAsync(statusRequest, tokenSource.Token).ConfigureAwait(false);

                CheckResponse(statusResponse);

                var addComment = new XmlRequest
                {
                    Method     = "Bug.add_comment",
                    Parameters =
                    {
                        new XmlParameter {
                            Name = "id", Value = arguments.BugId
                        },
                        new XmlParameter {
                            Name = "comment", Value = arguments.Comment
                        }
                    }
                };

                var commentRequest = new RestRequest {
                    Method = Method.POST, RequestFormat = DataFormat.Xml
                };
                commentRequest.AddParameter("text/xml", addComment.ToString(), ParameterType.RequestBody);

                var commentResponse = await ExecuteAsync(commentRequest, tokenSource.Token).ConfigureAwait(false);

                CheckResponse(commentResponse);
            }
        }
コード例 #3
0
ファイル: BugzillaRestClient.cs プロジェクト: space035/gollum
        private async Task Login(BugzillaArguments arguments)
        {
            if (ReadCookies())
            {
                return;
            }

            if (arguments.CredentialCallback == null)
            {
                throw new BugzillaAuthenticationException();
            }
            var credentials = arguments.CredentialCallback("Bugzilla login");
            await SendLoginRequestAsync(credentials.Username, credentials.Password).ConfigureAwait(false);
        }
コード例 #4
0
ファイル: BugzillaRestClient.cs プロジェクト: nodia/gollum
        private async Task Login(BugzillaArguments arguments)
        {
            if (ReadCookies())
            {
                return;
            }

            if (arguments.CredentialCallback == null)
            {
                throw new BugzillaAuthenticationException();
            }
            var credentials = arguments.CredentialCallback("Bugzilla login");

            await SendLoginRequestAsync(credentials.Username, credentials.Password).ConfigureAwait(false);
        }
コード例 #5
0
ファイル: BugzillaRestClient.cs プロジェクト: space035/gollum
        public async Task PostToBugzillaAsync(BugzillaArguments arguments)
        {
            await Login(arguments).ConfigureAwait(false);

            var updateStatus = new XmlRequest
            {
                Method = "Bug.update",
                Parameters =
                {
                    new XmlParameter {Name = "ids", Value = new[] { arguments.BugId  }},
                    new XmlParameter {Name = "status", Value = arguments.Status},
                    new XmlParameter {Name = "resolution", Value = arguments.Resolution}
                }
            };

            using (var tokenSource = new CancellationTokenSource())
            {
                var statusRequest = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Xml };
                statusRequest.AddParameter("text/xml", updateStatus.ToString(), ParameterType.RequestBody);

                tokenSource.CancelAfter(DefaultTimeout);
                var statusResponse = await ExecuteAsync(statusRequest, tokenSource.Token).ConfigureAwait(false);
                CheckResponse(statusResponse);

                var addComment = new XmlRequest
                {
                    Method = "Bug.add_comment",
                    Parameters =
                    {
                        new XmlParameter { Name = "id", Value = arguments.BugId },
                        new XmlParameter { Name = "comment", Value = arguments.Comment }
                    }
                };

                var commentRequest = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Xml };
                commentRequest.AddParameter("text/xml", addComment.ToString(), ParameterType.RequestBody);

                var commentResponse = await ExecuteAsync(commentRequest, tokenSource.Token).ConfigureAwait(false);
                CheckResponse(commentResponse);
            }
        }
コード例 #6
0
 public async Task PostToBugzillaAsync(BugzillaArguments arguments)
 {
     await Task.Delay(3000).ConfigureAwait(false);
 }
コード例 #7
0
 public async Task<BugzillaBug> GetBugInformationAsync(BugzillaArguments arguments, CancellationTokenSource tokenSource)
 {
     tokenSource.CancelAfter(TimeSpan.FromSeconds(4));
     await Task.Delay(3000, tokenSource.Token).ConfigureAwait(false);
     return new BugzillaBug("<bug></bug>");
 }
コード例 #8
0
ファイル: BugzillaRestClient.cs プロジェクト: space035/gollum
        public async Task<BugzillaBug> GetBugInformationAsync(BugzillaArguments arguments, CancellationTokenSource tokenSource)
        {
            tokenSource.Token.ThrowIfCancellationRequested();

            await Login(arguments).ConfigureAwait(false);
            
            tokenSource.Token.ThrowIfCancellationRequested();
            tokenSource.CancelAfter(DefaultTimeout);

            var xml = new XmlRequest
            {
                Method = "Bug.get",
                Parameters =
                {
                    new XmlParameter {Name = "ids", Value = new[] { arguments.UpdateToken }}
                }
            };

            var request = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Xml };
            request.AddParameter("text/xml", xml.ToString(), ParameterType.RequestBody);

            var response = await ExecuteAsync(request, tokenSource.Token).ConfigureAwait(false);
            CheckResponse(response);
            return new BugzillaBug(response.Content);
        }