Beispiel #1
0
        public async Task DownloadFile()
        {
            EntityDownload.DateDownloaded = DateTime.Now;
            EntityDownload.Status         = EnumFileDownloader.DownloadStatus.Downloading;

            if (EntityDownload.Id == 0)
            {
                _serviceExternalDownload.Add(EntityDownload);
            }
            else
            {
                _serviceExternalDownload.Update(EntityDownload);
            }

            _destinationDir = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads", EntityDownload.ModuleGuid);
            var dirResult = CreateDirectory();

            if (dirResult != null)
            {
                EntityDownload.Status       = EnumFileDownloader.DownloadStatus.Error;
                EntityDownload.ErrorMessage = dirResult;
                _serviceExternalDownload.Update(EntityDownload);
                return;
            }

            using (_webClient = new WebClient())
            {
                _webClient.DownloadProgressChanged += wc_DownloadProgressChanged;
                _webClient.DownloadFileCompleted   += wc_DownloadFileCompleted;
                await _webClient.DownloadFileTaskAsync(new Uri(EntityDownload.Url), Path.Combine(_destinationDir, EntityDownload.FileName));
            }
        }
 public DtoActionResult Post(EntityExternalDownload download)
 {
     return(_downloadService.Add(download));
 }