protected DownloadCompletedEventArgs(object userArgs, Response <T> resp, SettingsBase settings) : base(userArgs) { mResponse = resp; mSettings = settings; }
protected override System.IO.Stream ConvertResult(ConnectionInfo connInfo, System.IO.Stream stream, SettingsBase settings) { return(MyHelper.CopyStream(stream)); }
protected abstract T ConvertResult(ConnectionInfo connInfo, System.IO.Stream stream, SettingsBase settings);
protected void SetSettings(SettingsBase value) { mSettings = value; }
internal StreamDownloadSettings(SettingsBase settings) { mUserSettings = settings; }
public Response <System.IO.Stream> Download(SettingsBase userSettings) { if (!mDisposedValue) { StreamDownloadSettings <T> ss = new StreamDownloadSettings <T>(userSettings); DateTime startTime = System.DateTime.Now; HttpWebRequest wr = this.GetWebRequest(ss); byte[] postDataBytes = null; if (userSettings.PostDataInternal != string.Empty) { postDataBytes = System.Text.Encoding.ASCII.GetBytes(userSettings.PostDataInternal); wr.ContentLength = postDataBytes.Length; } mActualDownload = wr; System.IO.MemoryStream memStream = null; System.Net.WebException dlException = null; int size = 0; var headers = new List <KeyValuePair <string, string> >(); DateTime endTime = System.DateTime.Now; try { if (postDataBytes != null) { using (System.IO.Stream s = wr.GetRequestStream()) { s.Write(postDataBytes, 0, postDataBytes.Length); } } using (HttpWebResponse resp = (HttpWebResponse)wr.GetResponse()) { foreach (string header in resp.Headers.Keys) { headers.Add(new KeyValuePair <string, string> (header, resp.Headers[header]));// //headers.Add(header, resp.Headers[header]);//new KeyValuePair<HttpResponseHeader, string>());// } if (userSettings.DownloadResponseStreamInternal) { System.IO.Stream s = resp.GetResponseStream(); endTime = System.DateTime.Now; memStream = MyHelper.CopyStream(s); s.Dispose(); } } if (memStream != null && memStream.CanSeek) { int.TryParse(memStream.Length.ToString(), out size); } } catch (Exception ex) { dlException = this.GetOrCreateWebException(ex, null); } finally { mActualDownload = null; } return(new DefaultResponse <System.IO.Stream>(new ConnectionInfo(dlException, this.Timeout, size, startTime, endTime, headers.ToArray()), memStream)); } else { return(null); } }