public FileToDownloadStatusCodes DownloadFile(IFileToDownload myfile) { string str = Path.Combine(this.string_0, myfile.Filename); MyWebClient myWebClient = new MyWebClient(); FileToDownloadStatusCodes downloadStatusCodes = FileToDownloadStatusCodes.OK; try { myWebClient.AllowAutoRedirect = true; myWebClient.DownloadFile(myfile.Url, str); } catch (WebException ex) { HttpWebResponse httpWebResponse = (HttpWebResponse)ex.Response; downloadStatusCodes = httpWebResponse != null ? (FileToDownloadStatusCodes)httpWebResponse.StatusCode : FileToDownloadStatusCodes.UnknownError; } catch (Exception ex) { downloadStatusCodes = FileToDownloadStatusCodes.UnknownError; } if (downloadStatusCodes == FileToDownloadStatusCodes.OK) { if (!System.IO.File.Exists(str)) { return(FileToDownloadStatusCodes.FileNotDownloaded); } try { if (new FileInfo(str).Length < 1L) { downloadStatusCodes = FileToDownloadStatusCodes.FileDownloadedButEmpty; } } catch (Exception ex) { downloadStatusCodes = FileToDownloadStatusCodes.FileUnknownError; } WebHeaderCollection responseHeaders = myWebClient.ResponseHeaders; DateTime creationTime = DateTime.Now; for (int index = 0; index < responseHeaders.Count; ++index) { if (responseHeaders.GetKey(index).Equals("Last-Modified")) { creationTime = DateTime.Parse(responseHeaders.Get(index)); } } try { System.IO.File.SetCreationTime(str, creationTime); } catch (Exception ex) { } } if (myWebClient != null) { myWebClient.Dispose(); } return(downloadStatusCodes); }
public FileToDownloadFailed(IFileToDownload ifileToDownload_0, FileToDownloadStatusCodes fileToDownloadStatusCodes_0) : base(ifileToDownload_0.Url, ifileToDownload_0.Filename, ifileToDownload_0.Key) { this.ErrorCode = fileToDownloadStatusCodes_0; }