Exemplo n.º 1
0
 public void DownloadFile(File file)
 {
     file.DownloadCompleted  = false;
     file.DownloadInprogress = true;
     DownloadInprogress(this, file);
     try
     {
         var             req      = new HttpRequest(file.PathOnWeb);
         var             pathFile = "";
         HttpWebResponse response;
         Stream          res = req.DownloadData(out response);
         if (response != null)
         {
             var ext = Files.GetFileExtension(file.PathOnWeb, response.ContentType);
             TryCreateDirPath(file.PathOnWeb, ext, out pathFile);
             using (var f = System.IO.File.OpenWrite(pathFile))
             {
                 CopyStream(res, f);
                 f.Flush();
                 f.Close();
             }
             file.PathOnDisk         = pathFile;
             file.DownloadCompleted  = true;
             file.DownloadInprogress = false;
             req.TryAbort();
             DownloadComplete(this, file);
         }
         else
         {
             file.DownloadError = true;
             DownloadComplete(this, file);
         }
     }
     catch
     {
         file.DownloadError = true;
         DownloadComplete(this, file);
     }
 }
Exemplo n.º 2
0
 public void Init(Config config, HttpRequest request)
 {
     _config  = config;
     _request = request;
 }