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.UploadAssets(item, clientThrottle, UploadTimeoutInMinutes, Overwrite))); } } }
public async Task <bool> ExecuteAsync() { try { Log.LogMessage(MessageImportance.High, "Performing feed push..."); if (ItemsToPush == null) { Log.LogError($"No items to push. Please check ItemGroup ItemsToPush."); } else { BlobFeedAction blobFeedAction = new BlobFeedAction(ExpectedFeedUrl, AccountKey, Log); if (!SkipCreateContainer) { await blobFeedAction.CreateContainerAsync(this.BuildEngine); } List <string> items = ConvertToStringLists(ItemsToPush); if (!PublishFlatContainer) { await blobFeedAction.PushToFeed(items, Overwrite); } else { using (var clientThrottle = new SemaphoreSlim(this.MaxClients, this.MaxClients)) { Log.LogMessage($"Uploading {ItemsToPush.Length} items..."); await Task.WhenAll(ItemsToPush.Select(item => blobFeedAction.UploadAssets(item, clientThrottle, Overwrite))); } } } } catch (Exception e) { Log.LogErrorFromException(e, true); } return(!Log.HasLoggedErrors); }
private async Task PushBuildManifestAsync( BlobFeedAction blobFeedAction, IEnumerable <BlobArtifactModel> blobArtifacts, IEnumerable <PackageArtifactModel> packageArtifacts) { bool disabledByBlob = await blobFeedAction.feed.CheckIfBlobExists( $"{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.DownloadBlobAsString( $"{blobFeedAction.feed.RelativePath}{blobPath}"); BuildModel buildModel; if (existingStr != null) { buildModel = BuildModel.Parse(XElement.Parse(existingStr)); } else { buildModel = new BuildModel( new BuildIdentity( ManifestName, ManifestBuildId, ManifestBranch, 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.UploadAssets( item, clientThrottle, UploadTimeoutInMinutes, allowOverwrite : true); } } finally { if (tempFile != null) { File.Delete(tempFile); } } }