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)); }
public void BuildExperimentsSummary() { var domain = new Z3Domain(); var benchmarkResults1 = Enumerable.Concat(BuildResults(1, 3, "a"), BuildResults(1, 2, "b")); var catSummary1 = ExperimentSummary.Build(benchmarkResults1, domain); Assert.AreEqual(2, catSummary1.Count, "2 categories"); AssertCatSummary(3, catSummary1["a"]); AssertCatSummary(2, catSummary1["b"]); Table table0 = Table.Empty; var experimentSummary1 = new ExperimentSummary(1, DateTimeOffset.Now, catSummary1); Table table1 = ExperimentSummaryStorage.AppendOrReplace(table0, experimentSummary1); var benchmarkResults2 = Enumerable.Concat(BuildResults(1, 3, "b"), BuildResults(1, 2, "c")); var catSummary2 = ExperimentSummary.Build(benchmarkResults2, domain); var experimentSummary2 = new ExperimentSummary(2, DateTimeOffset.Now, catSummary2); Table table2 = ExperimentSummaryStorage.AppendOrReplace(table1, experimentSummary2); Assert.IsTrue(table2.Count >= 2 + 3 * (5 + 8), "Number of columns"); Assert.AreEqual(2, table2.RowsCount, "Number of rows"); AreEqualArrays(new[] { "1", "2" }, table2["ID"].Rows.AsString.ToArray()); AreEqualArrays(new[] { "3", "" }, table2["a|SAT"].Rows.AsString.ToArray()); AreEqualArrays(new[] { "2", "3" }, table2["b|SAT"].Rows.AsString.ToArray()); AreEqualArrays(new[] { "", "2" }, table2["c|SAT"].Rows.AsString.ToArray()); }
public async Task <ExperimentSummary[]> GetTimeline(string timelineName) { var results = await DownloadSummary(timelineName, true); var summaries = ExperimentSummaryStorage.LoadFromTable(results.Item1); return(summaries); }
public async Task <Tuple <ExperimentSummary[], RecordsTable> > GetTimelineAndRecords(string timelineName) { var results = await DownloadSummary(timelineName); var records = results.Item2; var summaries = ExperimentSummaryStorage.LoadFromTable(results.Item1); return(Tuple.Create(summaries, records)); }
public async Task <ExperimentSummary[]> Update(string timelineName, params int[] experiments) { if (experiments == null) { throw new ArgumentNullException(nameof(experiments)); } Trace.WriteLine("Downloading experiment results..."); var all_summaries = await DownloadSummary(timelineName); Table timeline = all_summaries.Item1; RecordsTable records = all_summaries.Item2; string etag = all_summaries.Item3; foreach (var experimentId in experiments) { var exp = await storage.GetExperiment(experimentId); // fails if not found var domain = resolveDomain.GetDomain(exp.DomainName); var results = (await storage.GetResults(experimentId)).Benchmarks; Trace.WriteLine("Building summary for the experiment " + experimentId); var catSummary = ExperimentSummary.Build(results, domain, ExperimentSummary.DuplicateResolution.Ignore); var expSummary = new ExperimentSummary(experimentId, DateTimeOffset.Now, catSummary); timeline = ExperimentSummaryStorage.AppendOrReplace(timeline, expSummary); Trace.WriteLine("Updating records..."); records.UpdateWith(results, domain); } await UploadSummary(timelineName, timeline, records, all_summaries.Item3); var resultfromTable = ExperimentSummaryStorage.LoadFromTable(timeline); Array.Sort(resultfromTable, (el1, el2) => DateTimeOffset.Compare(el2.Date, el1.Date)); return(resultfromTable); }