Exemple #1
0
        public XlsxRequest SetWebRequestCreator(
            WebRequestCreator webRequestCreator)
        {
            var clone = new XlsxRequest(this);

            clone.webRequestCreator = webRequestCreator;
            return(clone);
        }
Exemple #2
0
        public static XlsxRequest[] SetDefaultWebRequestCreator(
            this XlsxRequest[] src, WebRequestCreator webRequestCreator)
        {
            if (src == null)
            {
                throw new System.ArgumentNullException("src");
            }
            var dst = new XlsxRequest[src.Length];

            for (var n = 0; n < dst.Length; ++n)
            {
                dst[n] = src[n];
                if (dst[n].webRequestCreator == null)
                {
                    dst[n] = dst[n].SetWebRequestCreator(webRequestCreator);
                }
            }
            return(dst);
        }
        private HttpWebResponse SendRequest(WebRequestCreator wrc)
        {
            HttpWebRequest wr = wrc();

            if (_authHeader != null)
            {
                wr.Headers["Authorization"] = _authHeader;
            }

            try
            {
                return((HttpWebResponse)wr.GetResponse());
            }
            catch (WebException we)
            {
                HttpWebResponse wresp = (HttpWebResponse)we.Response;

                if (wresp.StatusCode == HttpStatusCode.Unauthorized)
                {
                    string authMethod;
                    Dictionary <string, string> authParams = ParseAuthenticationHeader(wresp.Headers["WWW-Authenticate"], out authMethod);

                    if (authMethod != "Digest")
                    {
                        throw;
                    }

                    string resp = CalcDigestResponse(authParams["nonce"], wr.RequestUri.AbsolutePath, wr.Method, authParams["realm"]);

                    _authHeader = "Digest username=\"" + _userName + "\", realm=\"ODS\", nonce=\"" + authParams["nonce"] + "\", uri=\"" + wr.RequestUri.AbsolutePath + "\", response=\"" + resp + "\"";

                    wresp.Close();

                    wr = wrc();
                    wr.Headers["Authorization"] = _authHeader;

                    return((HttpWebResponse)wr.GetResponse());
                }

                throw;
            }
        }
Exemple #4
0
        private static IEnumerator _LoadFromWebRequest(
            XlsxRequest request, _LoadingResult result)
        {
            WebRequestCreator createWebRequest = (uri) => {
                WebRequest webReq = null;
                if (request.webRequestCreator != null)
                {
                    webReq = request.webRequestCreator(uri);
                }
                if (webReq == null)
                {
                    webReq = new WebRequest(uri);
                }
                if (webReq.downloadHandler == null)
                {
                    webReq.downloadHandler = new DownloadHandlerBuffer();
                }
                return(webReq);
            };

            using (var webReq = createWebRequest(request.uri)) {
                webReq.SendWebRequest();
                while (!webReq.isDone)
                {
                    result.progress = Mathf.Clamp(
                        webReq.downloadProgress, result.progress, 0.99F
                        );
                    yield return(null);
                }
                if (webReq.isNetworkError || webReq.isHttpError)
                {
                    result.error = webReq.error;
                }
                else
                {
                    var bytes = webReq.downloadHandler.data;
                    result.stream = new MemoryStream(bytes);
                }
            }
            result.progress = 1;
        }
        private HttpWebResponse SendRequest(WebRequestCreator wrc)
        {
            HttpWebRequest wr = wrc();
            if (_authHeader != null)
            {
                wr.Headers["Authorization"] = _authHeader;
            }

            try
            {
                return (HttpWebResponse)wr.GetResponse();
            }
            catch (WebException we)
            {
                HttpWebResponse wresp = (HttpWebResponse)we.Response;

                if (wresp.StatusCode == HttpStatusCode.Unauthorized)
                {
                    string authMethod;
                    Dictionary<string, string> authParams = ParseAuthenticationHeader(wresp.Headers["WWW-Authenticate"], out authMethod);

                    if (authMethod != "Digest")
                    {
                        throw;
                    }

                    string resp = CalcDigestResponse(authParams["nonce"], wr.RequestUri.AbsolutePath, wr.Method, authParams["realm"]);

                    _authHeader = "Digest username=\"" + _userName + "\", realm=\"ODS\", nonce=\"" + authParams["nonce"] + "\", uri=\"" + wr.RequestUri.AbsolutePath + "\", response=\"" + resp + "\"";

                    wresp.Close();

                    wr = wrc();
                    wr.Headers["Authorization"] = _authHeader;

                    return (HttpWebResponse)wr.GetResponse();
                }

                throw;
            }
        }
Exemple #6
0
 public static XlsxRequest SetWebRequestCreator(
     this string uri, WebRequestCreator webRequestCreator)
 {
     return(new XlsxRequest(uri).SetWebRequestCreator(webRequestCreator));
 }