Exemple #1
0
        public async Task <TempDirectoryHandle> Download(string bundleId, string url, string filename)
        {
            if (Utility.IsLocalFile(url) && IsAlreadyInUploadsDir(url))
            {
                return(new TempDirectoryHandle(new DirectoryInfo(Path.GetDirectoryName(url))));
            }
            else
            {
                var tempDir = new TempDirectoryHandle(FindUniqueSubDirectoryName(new DirectoryInfo(pathHelper.GetUploadsDir())));
                tempDir.Dir.Create();
                var tempPath = new FileInfo(Path.Combine(tempDir.Dir.FullName, Path.GetFileName(filename)));

                if (Utility.IsLocalFile(url))
                {
                    await Utility.CopyFile(new FileInfo(url), tempPath);
                }
                else
                {
                    // download
                    using (var client = new HttpClient()) {
                        using (var download = await client.GetAsync(url)) {
                            using (var stream = await download.Content.ReadAsStreamAsync()) {
                                using (var outfile = File.OpenWrite(tempPath.FullName)) {
                                    await stream.CopyToAsync(outfile);
                                }
                            }
                        }
                    }
                }
                return(tempDir);
            }
        }
Exemple #2
0
 public async Task DownloadAndScheduleProcessFile(string bundleId, string url, string filename)
 {
     bundleRepo.SetBundleStatus(bundleId, BundleStatus.Downloading);
     try {
         using (TempDirectoryHandle tempDir = await downloadService.Download(bundleId, url, filename)) {
             // this class should only do downloading.
             // unf. i could not find a good way to *not* make this call from with DownloadService
             // hangfire supports continuations, but not parameterized. i found no way to pass the result (TempFileHandle) over to the continuation
             await ProcessDirRecursive(bundleId, tempDir.Dir);
         }
         bundleRepo.SetBundleStatus(bundleId, BundleStatus.Finished);
     } catch (Exception e) {
         bundleRepo.SetBundleStatus(bundleId, BundleStatus.Failed, e.ToString());
     }
 }
        public async Task DownloadAndScheduleProcessFileAsync(string bundleId, string url, string filename)
        {
            bundleRepo.SetBundleStatus(bundleId, BundleStatus.Downloading);
            try {
                using (TempDirectoryHandle tempDir = await downloadService.Download(bundleId, url, filename)) {
                    if (settings.Value.DuplicationDetectionEnabled && !SetHashAndCheckIfDuplicated(bundleId, new FileInfo(Path.Combine(tempDir.Dir.FullName, filename))))
                    {
                        // duplication detected
                        return;
                    }

                    // this class should only do downloading.
                    // unf. i could not find a good way to *not* make this call from with DownloadService
                    // hangfire supports continuations, but not parameterized. i found no way to pass the result (TempFileHandle) over to the continuation
                    await ProcessDirRecursive(bundleId, tempDir.Dir);
                }
                bundleRepo.SetBundleStatus(bundleId, BundleStatus.Finished);
            } catch (Exception e) {
                bundleRepo.SetBundleStatus(bundleId, BundleStatus.Failed, e.ToString());
            }
        }