示例#1
0
        private bool CheckSyncDigest(HttpClient httpClient, string resource, EndPointInfo endpoint)
        {
            string tmpUrl = endpoint.GetResourceUri(resource).ToString();

            tmpUrl = string.Format("{0}/{1}?runName={2}&runStamp={3}", tmpUrl, "$syncDigest", "testDigest", this.RunStamp.ToUniversalTime());
            HttpResponseMessage respMsg = httpClient.Get(tmpUrl);

            respMsg.Content.LoadIntoBuffer();

            if (respMsg.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }

            this.Logger.Write(string.Format("The Resource {0} is not accessable", resource), Severity.Error);
            this.Logger.Write(string.Format("on following root url {0}", endpoint.UrlString), Severity.Error);
            return(false);
        }
示例#2
0
        private HttpClient GetHttpClient(EndPointInfo endpoint, ProxyInfo proxy, string resource)
        {
            HttpClient result = new HttpClient();

            result.BaseAddress = endpoint.GetResourceUri(resource);
            if ((endpoint.Credentials != null) && (!String.IsNullOrEmpty(endpoint.Credentials.User)))
            {
                result.TransportSettings.Credentials = new NetworkCredential(endpoint.Credentials.User, endpoint.Credentials.Password);
            }
            if ((proxy != null) && (!String.IsNullOrEmpty(proxy.Host)))
            {
                WebProxy webProxy = new WebProxy(proxy.Host, proxy.Port);
                if ((proxy.Credentials != null) && (!String.IsNullOrEmpty(proxy.Credentials.User)))
                {
                    webProxy.Credentials = new NetworkCredential(proxy.Credentials.User, proxy.Credentials.Password);
                }
                result.TransportSettings.Proxy = webProxy;
            }
            result.TransportSettings.ConnectionTimeout = new TimeSpan(0, 5, 0);
            return(result);
        }