Example #1
0
 private async Task PublishToFlatContainerAsync(IEnumerable <ITaskItem> taskItems, BlobFeedAction blobFeedAction)
 {
     if (taskItems.Any())
     {
         using (var clientThrottle = new SemaphoreSlim(this.MaxClients, this.MaxClients))
         {
             Log.LogMessage($"Uploading {taskItems.Count()} items...");
             await Task.WhenAll(taskItems.Select(
                                    item => blobFeedAction.UploadAssetAsync(
                                        item,
                                        clientThrottle,
                                        UploadTimeoutInMinutes,
                                        CreatePushOptions())));
         }
     }
 }
Example #2
0
        private async Task PushBuildManifestAsync(
            BlobFeedAction blobFeedAction,
            IEnumerable <BlobArtifactModel> blobArtifacts,
            IEnumerable <PackageArtifactModel> packageArtifacts)
        {
            bool disabledByBlob = await blobFeedAction.feed.CheckIfBlobExistsAsync(
                $"{blobFeedAction.feed.RelativePath}{DisableManifestPushConfigurationBlob}");

            if (disabledByBlob)
            {
                Log.LogMessage(
                    MessageImportance.Normal,
                    $"Skipping manifest push: feed has '{DisableManifestPushConfigurationBlob}'.");
                return;
            }

            string blobPath = $"{AssetsVirtualDir}{ManifestAssetOutputDir}{ManifestName}.xml";

            string existingStr = await blobFeedAction.feed.DownloadBlobAsStringAsync(
                $"{blobFeedAction.feed.RelativePath}{blobPath}");

            BuildModel buildModel;

            if (existingStr != null)
            {
                buildModel = BuildModel.Parse(XElement.Parse(existingStr));
            }
            else
            {
                buildModel = new BuildModel(
                    new BuildIdentity
                {
                    Attributes = ParseManifestMetadataString(ManifestBuildData),
                    Name       = ManifestName,
                    BuildId    = ManifestBuildId,
                    Branch     = ManifestBranch,
                    Commit     = ManifestCommit
                });
            }

            buildModel.Artifacts.Blobs.AddRange(blobArtifacts);
            buildModel.Artifacts.Packages.AddRange(packageArtifacts);

            string tempFile = null;

            try
            {
                tempFile = Path.GetTempFileName();

                File.WriteAllText(tempFile, buildModel.ToXml().ToString());

                var item = new MSBuild.TaskItem(tempFile, new Dictionary <string, string>
                {
                    ["RelativeBlobPath"] = blobPath
                });

                using (var clientThrottle = new SemaphoreSlim(MaxClients, MaxClients))
                {
                    await blobFeedAction.UploadAssetAsync(
                        item,
                        clientThrottle,
                        UploadTimeoutInMinutes,
                        new PushOptions
                    {
                        AllowOverwrite = true
                    });
                }
            }
            finally
            {
                if (tempFile != null)
                {
                    File.Delete(tempFile);
                }
            }
        }