public HttpClient(
     IWebResponseExtractor webResponseExtractor,
     IWebRequestBuilder webRequestBuilder)
 {
     _webResponseExtractor = webResponseExtractor;
     _webRequestBuilder    = webRequestBuilder;
 }
Ejemplo n.º 2
0
        public MultiPartDownload(
            Uri url,
            int bufferSize,
            int numberOfParts,
            IDownloadBuilder downloadBuilder,
            IWebRequestBuilder requestBuilder,
            IDownloadChecker downloadChecker,
            List<DownloadRange> alreadyDownloadedRanges)
            : base(url, bufferSize, null, null, requestBuilder, downloadChecker)
        {
            if (numberOfParts <= 0)
                throw new ArgumentException("numberOfParts <= 0");

            if (downloadBuilder == null)
                throw new ArgumentNullException("downloadBuilder");

            this.numberOfParts = numberOfParts;
            this.downloadBuilder = downloadBuilder;
            this.AlreadyDownloadedRanges = alreadyDownloadedRanges ?? new List<DownloadRange>();

            if (System.Net.ServicePointManager.DefaultConnectionLimit < numberOfParts)
            {
                System.Net.ServicePointManager.DefaultConnectionLimit = numberOfParts;
            }
        }
Ejemplo n.º 3
0
        public MultiPartDownload(
            Uri url,
            int bufferSize,
            int numberOfParts,
            IDownloadBuilder downloadBuilder,
            IWebRequestBuilder requestBuilder,
            IDownloadChecker downloadChecker,
            List <DownloadRange> alreadyDownloadedRanges)
            : base(url, bufferSize, null, null, requestBuilder, downloadChecker)
        {
            if (numberOfParts <= 0)
            {
                throw new ArgumentException("numberOfParts <= 0");
            }

            if (downloadBuilder == null)
            {
                throw new ArgumentNullException("downloadBuilder");
            }

            this.numberOfParts           = numberOfParts;
            this.downloadBuilder         = downloadBuilder;
            this.AlreadyDownloadedRanges = alreadyDownloadedRanges ?? new List <DownloadRange>();

            if (System.Net.ServicePointManager.DefaultConnectionLimit < numberOfParts)
            {
                System.Net.ServicePointManager.DefaultConnectionLimit = numberOfParts;
            }
        }
Ejemplo n.º 4
0
        public AbstractDownload(Uri url, int bufferSize, long?offset, long?maxReadBytes, IWebRequestBuilder requestBuilder, IDownloadChecker downloadChecker)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            if (bufferSize < 0)
            {
                throw new ArgumentException("bufferSize < 0");
            }

            if (offset.HasValue && offset.Value < 0)
            {
                throw new ArgumentException("offset < 0");
            }

            if (maxReadBytes.HasValue && maxReadBytes.Value < 0)
            {
                throw new ArgumentException("maxReadBytes < 0");
            }

            this.url             = url;
            this.bufferSize      = bufferSize;
            this.offset          = offset;
            this.maxReadBytes    = maxReadBytes;
            this.requestBuilder  = requestBuilder;
            this.downloadChecker = downloadChecker;

            this.state = DownloadState.Initialized;
        }
Ejemplo n.º 5
0
        public MultiPartDownloadBuilder(
            int numberOfParts,
            IDownloadBuilder downloadBuilder,
            IWebRequestBuilder requestBuilder,
            IDownloadChecker downloadChecker,
            List<DownloadRange> alreadyDownloadedRanges)
        {
            if (numberOfParts <= 0)
                throw new ArgumentException("numberOfParts <= 0");

            if (downloadBuilder == null)
                throw new ArgumentNullException("downloadBuilder");

            if (requestBuilder == null)
                throw new ArgumentNullException("requestBuilder");

            if (downloadChecker == null)
                throw new ArgumentNullException("downloadChecker");

            this.numberOfParts = numberOfParts;
            this.downloadBuilder = downloadBuilder;
            this.requestBuilder = requestBuilder;
            this.downloadChecker = downloadChecker;
            this.alreadyDownloadedRanges = alreadyDownloadedRanges ?? new List<DownloadRange>();
        }
 public HttpClient(
     IWebResponseExtractor webResponseExtractor,
     IWebRequestBuilder webRequestBuilder)
 {
     _webResponseExtractor = webResponseExtractor;
     _webRequestBuilder = webRequestBuilder;
 }
Ejemplo n.º 7
0
        public static async Task<Session> LoginAsync(string email, string password, IWebRequestBuilder requestBuilder)
        {
            const string urlLogin = "******";

            var session = new Session(requestBuilder);
            var csrfToken = ConstructCsrfToken();
            var data = string.Format("email={0}&password={1}", Uri.EscapeDataString(email), Uri.EscapeDataString(password));
            var headers = CommonHeaders();
            headers.Add("Origin", "https://accounts.coursera.org");
            headers.Add("X-CSRFToken", csrfToken);
            headers.Add("Host", "accounts.coursera.org");
            headers.Add("Referer", "https://accounts.coursera.org/signin");

            using (var request = requestBuilder.Build(urlLogin, headers, session.CookieJar))
            {
                request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";
                session.CookieJar.Add(request.RequestUri, new Cookie("csrftoken", csrfToken));

                await request.SetContentAsync(data);

                using (var response = await request.GetResponseAsync().ConfigureAwait(false))
                {
                    using (var sr = new StreamReader(await response.GetResponseStreamAsync()))
                    {
                        var userJson = sr.ReadToEnd();
                        session._user = JsonConvert.DeserializeObject<User>(userJson);
                    }
                }
            }

            return session;
        }
Ejemplo n.º 8
0
        public DownloadCheckResult CheckDownload(Uri url, IWebRequestBuilder requestBuilder)
        {
            try
            {
                var request = requestBuilder.CreateRequest(url, null);

                using (var response = request.GetResponse())
                {
                    return(CheckDownload(response));
                }
            }
            catch (WebException ex)
            {
                return(new DownloadCheckResult()
                {
                    Exception = ex, StatusCode = (int)(ex.Response as HttpWebResponse).StatusCode
                });
            }
            catch (Exception ex)
            {
                return(new DownloadCheckResult()
                {
                    Exception = ex
                });
            }
        }
Ejemplo n.º 9
0
        public MultiPartDownloadBuilder(
            int numberOfParts,
            IDownloadBuilder downloadBuilder,
            IWebRequestBuilder requestBuilder,
            IDownloadChecker downloadChecker,
            List <DownloadRange> alreadyDownloadedRanges)
        {
            if (numberOfParts <= 0)
            {
                throw new ArgumentException("numberOfParts <= 0");
            }

            if (downloadBuilder == null)
            {
                throw new ArgumentNullException("downloadBuilder");
            }

            if (requestBuilder == null)
            {
                throw new ArgumentNullException("requestBuilder");
            }

            if (downloadChecker == null)
            {
                throw new ArgumentNullException("downloadChecker");
            }

            this.numberOfParts           = numberOfParts;
            this.downloadBuilder         = downloadBuilder;
            this.requestBuilder          = requestBuilder;
            this.downloadChecker         = downloadChecker;
            this.alreadyDownloadedRanges = alreadyDownloadedRanges ?? new List <DownloadRange>();
        }
Ejemplo n.º 10
0
        public SimpleDownloadBuilder(IWebRequestBuilder requestBuilder, IDownloadChecker downloadChecker)
        {
            if (requestBuilder == null)
                throw new ArgumentNullException("requestBuilder");

            if (downloadChecker == null)
                throw new ArgumentNullException("downloadChecker");

            this.requestBuilder = requestBuilder;
            this.downloadChecker = downloadChecker;
        }
        private static void AddHeadersOnWebResponseBuilder(
            IEnumerable<KeyValuePair<string, string>> requestHeaders,
            IWebRequestBuilder webRequestBuilder)
        {
            if (requestHeaders == null)
            {
                return;
            }

            requestHeaders
                    .ToList()
                    .ForEach(header => webRequestBuilder.InsertHeader(header.Key, header.Value));
        }
        private static void AddHeadersOnWebResponseBuilder(
            IEnumerable <KeyValuePair <string, string> > requestHeaders,
            IWebRequestBuilder webRequestBuilder)
        {
            if (requestHeaders == null)
            {
                return;
            }

            requestHeaders
            .ToList()
            .ForEach(header => webRequestBuilder.InsertHeader(header.Key, header.Value));
        }
        public SimpleDownloadBuilder(IWebRequestBuilder requestBuilder, IDownloadChecker downloadChecker)
        {
            if (requestBuilder == null)
            {
                throw new ArgumentNullException("requestBuilder");
            }

            if (downloadChecker == null)
            {
                throw new ArgumentNullException("downloadChecker");
            }

            this.requestBuilder  = requestBuilder;
            this.downloadChecker = downloadChecker;
        }
Ejemplo n.º 14
0
        public DownloadCheckResult CheckDownload(Uri url, IWebRequestBuilder requestBuilder)
        {
            try
            {
                var request = requestBuilder.CreateRequest(url, null);

                using (var response = request.GetResponse())
                {
                    return CheckDownload(response);
                }
            }
            catch (Exception ex)
            {
                return new DownloadCheckResult() { Exception = ex };
            }
        }
Ejemplo n.º 15
0
        public AbstractDownload(Uri url, int bufferSize, int? offset, int? maxReadBytes, IWebRequestBuilder requestBuilder, IDownloadChecker downloadChecker)
        {
            if (url == null)
                throw new ArgumentNullException("url");

            if (bufferSize < 0)
                throw new ArgumentException("bufferSize < 0");

            if (offset.HasValue && offset.Value < 0)
                throw new ArgumentException("offset < 0");

            if (maxReadBytes.HasValue && maxReadBytes.Value < 0)
                throw new ArgumentException("maxReadBytes < 0");

            this.url = url;
            this.bufferSize = bufferSize;
            this.offset = offset;
            this.maxReadBytes = maxReadBytes;
            this.requestBuilder = requestBuilder;
            this.downloadChecker = downloadChecker;

            this.state = DownloadState.Initialized;
        }
Ejemplo n.º 16
0
 public DownloadCheckResult CheckDownload(Uri url, IWebRequestBuilder requestBuilder)
 {
     return this.CheckDownload(null);
 }
Ejemplo n.º 17
0
 private Session(IWebRequestBuilder requestBuilder)
 {
     CookieJar = new CookieContainer();
     RequestBuilder = requestBuilder;
     IsAuthRedirected = false;
 }
Ejemplo n.º 18
0
 public SimpleDownload(Uri url, int bufferSize, long?offset, long?maxReadBytes, IWebRequestBuilder requestBuilder, IDownloadChecker downloadChecker)
     : base(url, bufferSize, offset, maxReadBytes, requestBuilder, downloadChecker)
 {
 }
 public DownloadCheckResult CheckDownload(Uri url, IWebRequestBuilder requestBuilder)
 {
     return(this.CheckDownload(null));
 }
Ejemplo n.º 20
0
 public SearchService(IWebRequestBuilder builder)
 {
     Builder = builder;
 }
Ejemplo n.º 21
0
 public SimpleDownload(Uri url, int bufferSize, int? offset, int? maxReadBytes, IWebRequestBuilder requestBuilder, IDownloadChecker downloadChecker)
     : base(url, bufferSize, offset, maxReadBytes, requestBuilder, downloadChecker)
 {
 }