private async Task GetTask(Guid scenarioId, string fileId, bool compressed, string localFolder) { // Set name of local file var localFile = Path.Combine(localFolder, GetFileName(fileId, compressed)); if (File.Exists(localFile)) { File.Delete(localFile); } var uploadFilePath = GetUploadFilePath(scenarioId, fileId, _compression); using (var downloadedStream = await _session.DownloadAsync(uploadFilePath).ConfigureAwait(false)) using (var fileStream = System.IO.File.Create(localFile)) { if (compressed) // Leave compressed { downloadedStream.CopyTo(fileStream); } else // Decompress { using (var outputStream = DecompressGZIP(downloadedStream)) { outputStream.CopyTo(fileStream); } } } }
public async Task Foo() { IFilesStore store = null; #region session_usage_1 using (IAsyncFilesSession session = store.OpenAsyncSession()) { using (Stream content = File.OpenRead(@"C:\intro.avi")) { session.RegisterUpload("/movies/intro.avi", content); await session.SaveChangesAsync(); } } using (IAsyncFilesSession session = store.OpenAsyncSession()) { FileHeader file = await session.LoadFileAsync("/movies/intro.avi"); using (Stream content = await session.DownloadAsync(file.FullPath)) { /* ... */ } if (file.CreationDate < DateTime.Now.AddDays(-1)) { session.RegisterFileDeletion(file); } await session.SaveChangesAsync(); } #endregion using (IAsyncFilesSession session = store.OpenAsyncSession()) { #region unit_of_work_1 Assert.Same(await session.LoadFileAsync("/movies/intro.avi"), await session.LoadFileAsync("/movies/intro.avi")); #endregion } #region unit_of_work_2 using (IAsyncFilesSession session = store.OpenAsyncSession()) { FileHeader file = await session.LoadFileAsync("/movies/intro.avi"); file.Metadata.Add("Owner", "James"); await session.SaveChangesAsync(); // will sent the metadata update to the file system } #endregion }
public async Task Foo() { IAsyncFilesSession session = null; Stream localFile = null; #region download_2 Reference <RavenJObject> metadata = new Reference <RavenJObject>(); Stream content = await session.DownloadAsync("/movies/intro.avi", metadata); Console.WriteLine("Downloaded {0} bytes", metadata.Value.Value <long>("RavenFS-Size")); #endregion }