private async Task UploadSummary(string timelineName, Table summary, RecordsTable records, string etag) { using (Stream zipStream = new MemoryStream()) { using (ZipFile zip = new ZipFile()) using (Stream s1 = new MemoryStream()) using (Stream s2 = new MemoryStream()) using (Stream s3 = new MemoryStream()) { ExperimentSummaryStorage.SaveTable(summary, s1); s1.Position = 0; zip.AddEntry(fileNameTimeline, s1); RecordsStorage.SaveBenchmarksRecords(records.BenchmarkRecords, s2); s2.Position = 0; zip.AddEntry(fileNameRecords, s2); RecordsStorage.SaveSummaryRecords(records.CategoryRecords, s3); s3.Position = 0; zip.AddEntry(fileNameRecordsSummary, s3); zip.Save(zipStream); } zipStream.Position = 0; var blobName = string.Format("{0}.zip", AzureUtils.ToBinaryPackBlobName(timelineName)); var blob = summaryContainer.GetBlockBlobReference(blobName); await blob.UploadFromStreamAsync(zipStream, etag == null?AccessCondition.GenerateIfNotExistsCondition() : AccessCondition.GenerateIfMatchCondition(etag), new BlobRequestOptions { RetryPolicy = retryPolicy }, null); } }
private async Task <Tuple <Table, RecordsTable, string> > DownloadSummary(string timelineName, bool onlySummary = false) { var blobName = string.Format("{0}.zip", AzureUtils.ToBinaryPackBlobName(timelineName)); var blob = summaryContainer.GetBlockBlobReference(blobName); Table summary; Dictionary <string, Record> records = null; Dictionary <string, CategoryRecord> records_summary = null; string etag = null; try { using (MemoryStream ms = new MemoryStream()) { await blob.DownloadToStreamAsync(ms); etag = blob.Properties.ETag; ms.Position = 0; using (ZipFile zip = ZipFile.Read(ms)) { var zip_summary = zip[fileNameTimeline]; using (MemoryStream mem = new MemoryStream((int)zip_summary.UncompressedSize)) { zip_summary.Extract(mem); mem.Position = 0; summary = ExperimentSummaryStorage.LoadTable(mem); } if (!onlySummary) { var zip_records = zip[fileNameRecords]; using (MemoryStream mem = new MemoryStream((int)zip_records.UncompressedSize)) { zip_records.Extract(mem); mem.Position = 0; records = RecordsStorage.LoadBenchmarksRecords(mem); } var zip_records_summary = zip[fileNameRecordsSummary]; using (MemoryStream mem = new MemoryStream((int)zip_records_summary.UncompressedSize)) { zip_records_summary.Extract(mem); mem.Position = 0; records_summary = RecordsStorage.LoadSummaryRecords(mem); } } } } } catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)System.Net.HttpStatusCode.NotFound) { summary = ExperimentSummaryStorage.EmptyTable(); records = new Dictionary <string, Record>(); records_summary = new Dictionary <string, CategoryRecord>(); etag = null; } return(Tuple.Create(summary, new RecordsTable(records, records_summary), etag)); }