コード例 #1
0
 private void SetProxy(TimeoutWebClient <T> wc)
 {
     if (mProxy != null)
     {
         wc.Proxy = mProxy;
     }
 }
コード例 #2
0
        protected void DownloadAsync(SettingsBase settings, object userArgs)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings", "The settings for downloading with " + this.GetType().Name + " are null.");
            }
            TimeoutWebClient <T> wc = new TimeoutWebClient <T>(mTimeout);

            wc.AsyncDownloadCompleted += this.AsyncDownload_Completed;
            mWebClients.Add(wc);
            wc.DownloadAsync(settings, userArgs);
        }
コード例 #3
0
 protected Response<T> Download(SettingsBase settings)
 {
     if (settings == null) { throw new ArgumentNullException("Settings", "The settings for downloading with " + this.GetType().Name + " are null."); }
     using (TimeoutWebClient<T> wc = new TimeoutWebClient<T>(mTimeout))
     {
         if (mProxy != null)
             wc.Proxy = mProxy;
         Response<System.IO.Stream> sr = wc.Download(settings);
         Response<T> result = this.ConvertResponse(new DefaultResponse<T>(sr.Connection, this.ConvertResult(sr.Connection, sr.Result, settings)));
         if (sr.Result != null) { sr.Result.Dispose(); }
         return result;
     }
 }
コード例 #4
0
 private void AsyncDownload_Completed(TimeoutWebClient <T> sender, StreamDownloadCompletedEventArgs <T> e)
 {
     using (TimeoutWebClient <T> snd = sender)
     {
         snd.AsyncDownloadCompleted -= this.AsyncDownload_Completed;
         if (mWebClients.Contains(sender))
         {
             mWebClients.Remove(sender);
         }
         using (System.IO.Stream stream = (e.Response.Result != null ? e.Response.Result : new System.IO.MemoryStream()))
         {
             ConnectionInfo conn = e.Response.Connection;
             T result            = default(T);
             try
             {
                 result = this.ConvertResult(e.Response.Connection, stream, e.UserSettings);
             }
             catch (Exception ex)
             {
                 conn = new ConnectionInfo(new ConversionException("An exception was thrown during result conversion process. See InnerException for more details.", ex), conn.Timeout, conn.SizeInBytes, conn.StartTime, conn.EndTime);
             }
             finally
             {
                 Response <T> resp = this.ConvertResponse(new DefaultResponse <T>(conn, result));
                 DownloadCompletedEventArgs <T> args = this.ConvertDownloadCompletedEventArgs(new DefaultDownloadCompletedEventArgs <T>(e.UserArgs, resp, e.UserSettings));
                 if (args != null && (AsyncDownloadCompleted != null || AsyncDownloadCompletedEvent != null))
                 {
                     AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(this);
                     if (AsyncDownloadCompleted != null)
                     {
                         asyncOp.Post(new SendOrPostCallback(delegate(object obj) { AsyncDownloadCompleted(this, (DownloadCompletedEventArgs <T>)obj); }), args);
                     }
                     if (AsyncDownloadCompletedEvent != null)
                     {
                         asyncOp.Post(new SendOrPostCallback(delegate(object obj) { AsyncDownloadCompletedEvent(this, (IDownloadCompletedEventArgs)obj); }), args);
                     }
                 }
             }
         }
     }
 }