示例#1
0
        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);
            }
        }
示例#2
0
        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));
        }
示例#3
0
        public async Task <Tuple <string, DateTimeOffset?> > TryFindRecentExecutableBlob(string creator)
        {
            string prefix       = AzureUtils.ToBinaryPackBlobName(creator);
            string asciiCreator = StripNonAscii(creator);

            BlobContinuationToken token = null;
            List <CloudBlob>      best  = new List <CloudBlob>();

            do
            {
                var segment = await binContainer.ListBlobsSegmentedAsync(prefix, true, BlobListingDetails.Metadata, null,
                                                                         token, new BlobRequestOptions { RetryPolicy = retryPolicy }, null);

                CloudBlob bestBlob = null;
                foreach (var item in segment.Results)
                {
                    CloudBlob blob = item as CloudBlob;
                    if (blob == null)
                    {
                        continue;
                    }

                    string blobCreator;
                    if (!blob.Metadata.TryGetValue(KeyCreator, out blobCreator) || blobCreator != asciiCreator)
                    {
                        continue;
                    }


                    if (bestBlob == null || bestBlob.Properties.LastModified < blob.Properties.LastModified)
                    {
                        bestBlob = blob;
                    }
                }

                if (bestBlob != null)
                {
                    best.Add(bestBlob);
                }
                token = segment.ContinuationToken;
            } while (token != null);

            if (best.Count == 0)
            {
                return(null);
            }
            CloudBlob resultBlob = best[0];

            for (int i = 1; i < best.Count; i++)
            {
                var blob = best[i];
                if (resultBlob.Properties.LastModified < blob.Properties.LastModified)
                {
                    resultBlob = blob;
                }
            }
            return(Tuple.Create(resultBlob.Name, resultBlob.Properties.LastModified));
        }
示例#4
0
        public async Task <Tags> GetTags(string timelineName)
        {
            var blobName = string.Format("{0}.tags.csv", AzureUtils.ToBinaryPackBlobName(timelineName));
            var blob     = summaryContainer.GetBlockBlobReference(blobName);

            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    await blob.DownloadToStreamAsync(ms, AccessCondition.GenerateEmptyCondition(), new BlobRequestOptions { RetryPolicy = retryPolicy }, null);

                    ms.Position = 0;
                    Tags tags = TagsStorage.Load(ms);
                    return(tags);
                }
            }
            catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)System.Net.HttpStatusCode.NotFound)
            {
                return(new Tags());
            }
        }
示例#5
0
        /// <summary>
        /// Returns the uploaded blob name.
        /// </summary>
        public async Task <string> UploadNewExecutable(Stream source, string fileName, string creator)
        {
            if (!source.CanSeek)
            {
                throw new ArgumentException("Source stream must allow seeking", nameof(source));
            }

            string fileNameNoExt = Path.GetFileNameWithoutExtension(fileName);
            string extension     = Path.GetExtension(fileName);
            string esc_creator   = AzureUtils.ToBinaryPackBlobName(creator);
            string packageName;

            const string packageNameFormat = "{0}.{1}.{2:yyyy-MM-ddTHH-mm-ss-ffff}{3}";

            do
            {
                source.Position = 0;
                packageName     = string.Format(packageNameFormat, esc_creator, fileNameNoExt, DateTime.UtcNow, extension);
            } while (!await TryUploadNewExecutableAsBlob(source, packageName, creator, fileName));

            return(packageName);
        }