Esempio n. 1
0
        public CrumbGetCommand(IJenkinsContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Url      = NetPath.Combine(context.BaseUrl, "crumbIssuer/api/xml");
            UserName = context.UserName;
            Password = context.Password;

            OnWrite = request => {
                request.Method = "GET";
            };

            OnRead = response => {
                using (var stream = response.GetResponseStream()) {
                    if (stream == null)
                    {
                        return;
                    }

                    var document = XDocument.Load(stream);
                    if (document.Root == null)
                    {
                        throw new ApplicationException("An empty response was returned!");
                    }

                    Result = new JenkinsCrumb(document.Root);
                }
            };
        }
Esempio n. 2
0
        public JenkinsCrumb TryGetCrumb()
        {
            if (crumb == null)
            {
                lock (locker)
                {
                    if (crumb == null)
                    {
                        crumb = GetCrumb().Result;
                    }
                }
            }

            return(crumb);
        }
        public async Task <JenkinsCrumb> CrumbGet()
        {
            using (var response = await _httpClient.GetAsync("crumbIssuer/api/xml"))
            {
                using (var stream = await response.Content.ReadAsStreamAsync())
                {
                    var document = XDocument.Load(stream);
                    if (document.Root == null)
                    {
                        throw new ApplicationException("An empty response was returned!");
                    }

                    var crumb = new JenkinsCrumb(document.Root);

                    if (crumb != null)
                    {
                        _httpClient.DefaultRequestHeaders.Add(crumb.CrumbRequestField, crumb.Crumb);
                    }

                    return(crumb);
                }
            }
        }
Esempio n. 4
0
 public static bool IsValid(this JenkinsCrumb crumb)
 {
     return crumb != null && !string.IsNullOrEmpty(crumb.Crumb) && !string.IsNullOrEmpty(crumb.CrumbRequestField);
 }