Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
 public async Task PostToBugzillaAsync(BugzillaArguments arguments)
 {
     await Task.Delay(3000).ConfigureAwait(false);
 }
Exemplo n.º 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>");
 }
Exemplo n.º 8
0
        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);
        }