Example #1
0
        public void ClaimBuild(Project project, BuildDetails buildDetails, string reason, bool sticky)
        {
            string url     = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/claim/claim");
            var    request = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // we don't want to follow redirections
            request.AllowAutoRedirect = false;

            var credentials = project.Server.Credentials;

            if (credentials != null)
            {
                request.Credentials = new NetworkCredential(credentials.Username, credentials.Password);
            }

            using (Stream postStream = request.GetRequestStream())
            {
                var claim = new ClaimDetailsDto
                {
                    Reason = reason,
                    Sticky = sticky
                };

                var stream     = new MemoryStream();
                var serializer = new DataContractJsonSerializer(typeof(ClaimDetailsDto));
                serializer.WriteObject(stream, claim);
                string json = Encoding.UTF8.GetString(stream.ToArray());

                string postData = "json=" + HttpUtility.UrlEncode(json, Encoding.UTF8);
                using (var writer = new StreamWriter(postStream))
                {
                    writer.Write(postData);
                }
            }

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.Found && response.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception("Received response code " + response.StatusCode);
                }
            }

            string buildUrl = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/api/xml");

            JenkinsService.RemoveFromCache(buildUrl);
        }
        public void ClaimBuild(Project project, BuildDetails buildDetails, string reason, bool sticky)
        {
            string url = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/claim/claim");
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // we don't want to follow redirections
            request.AllowAutoRedirect = false;

            var credentials = project.Server.Credentials;
            if (credentials != null)
                request.Credentials = new NetworkCredential(credentials.Username, credentials.Password);

            using (Stream postStream = request.GetRequestStream())
            {
                var claim = new ClaimDetailsDto
                {
                    Reason = reason,
                    Sticky = sticky
                };

                var stream = new MemoryStream();
                var serializer = new DataContractJsonSerializer(typeof(ClaimDetailsDto));
                serializer.WriteObject(stream, claim);
                string json = Encoding.UTF8.GetString(stream.ToArray());

                string postData = "json=" + HttpUtility.UrlEncode(json, Encoding.UTF8);
                using (var writer = new StreamWriter(postStream))
                {
                    writer.Write(postData);
                }
            }

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.Found && response.StatusCode != HttpStatusCode.OK)
                    throw new Exception("Received response code " + response.StatusCode);
            }

            string buildUrl = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/api/xml", HudsonService.buildDetailsFilter);
            HudsonService.RemoveFromCache(buildUrl);
        }
Example #3
0
        public void ClaimBuild(Project project, BuildDetails buildDetails, string reason, bool sticky)
        {
            string url = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/claim/claim");
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // we don't want to follow redirections
            request.AllowAutoRedirect = false;

            // currently supporting assigning to self
            string assignee = string.Empty;

            var credentials = project.Server.Credentials;
            if (credentials != null)
            {
                // claim plugin requests uses the username from the session cookie but not from request credentials
                request.Credentials = new NetworkCredential(credentials.Username, credentials.Password);
                assignee = credentials.Username;
            }

            try
            {
                using (Stream postStream = request.GetRequestStream())
                {
                    var claim = new ClaimDetailsDto
                    {
                        Assignee = assignee,
                        Reason = reason,
                        Sticky = sticky
                    };

                    var stream = new MemoryStream();
                    var serializer = new DataContractJsonSerializer(typeof(ClaimDetailsDto));
                    serializer.WriteObject(stream, claim);
                    string json = Encoding.UTF8.GetString(stream.ToArray());

                    string postData = "json=" + HttpUtility.UrlEncode(json, Encoding.UTF8);
                    using (var writer = new StreamWriter(postStream))
                    {
                        writer.Write(postData);
                    }
                }

                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    if (response.StatusCode != HttpStatusCode.Found && response.StatusCode != HttpStatusCode.OK)
                        throw new Exception("Received response code " + response.StatusCode);
                }
            }
            catch (WebException webEx)
            {
                MessageBox.Show(webEx.Message, "Claim failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LoggingHelper.LogError(logger, webEx);
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(logger, ex);
            }
            string buildUrl = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/api/xml");
            JenkinsService.RemoveFromCache(buildUrl);
        }
Example #4
0
        public void ClaimBuild(Project project, BuildDetails buildDetails, string reason, bool sticky)
        {
            var url     = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/claim/claim");
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // we don't want to follow redirections
            request.AllowAutoRedirect = false;

            // currently supporting assigning to self
            var assignee = string.Empty;

            var credentials = project.Server.Credentials;

            if (credentials != null)
            {
                // claim plugin requests uses the username from the session cookie but not from request credentials
                request.Credentials = new NetworkCredential(credentials.Username, credentials.Password);
                assignee            = credentials.Username;
            }

            try
            {
                using (var postStream = request.GetRequestStream())
                {
                    var claim = new ClaimDetailsDto
                    {
                        Assignee = assignee,
                        Reason   = reason,
                        Sticky   = sticky
                    };

                    var stream     = new MemoryStream();
                    var serializer = new DataContractJsonSerializer(typeof(ClaimDetailsDto));
                    serializer.WriteObject(stream, claim);
                    var json = Encoding.UTF8.GetString(stream.ToArray());

                    var postData = "json=" + HttpUtility.UrlEncode(json, Encoding.UTF8);
                    using (var writer = new StreamWriter(postStream))
                    {
                        writer.Write(postData);
                    }
                }

                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    if (response.StatusCode != HttpStatusCode.Found && response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception("Received response code " + response.StatusCode);
                    }
                }
            }
            catch (WebException webEx)
            {
                MessageBox.Show(webEx.Message, "Claim failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LoggingHelper.LogError(logger, webEx);
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(logger, ex);
            }
            var buildUrl = NetUtils.ConcatUrls(project.Url, buildDetails.Number.ToString(), "/api/xml");

            JenkinsService.RemoveFromCache(buildUrl);
        }