private async Task DownloadArtifact( IExecutionContext executionContext, IHostContext hostContext, string localFolderPath, CustomArtifactDetails customArtifactDetails, CustomArtifactDownloadDetails artifact) { IDictionary <string, string> artifactTypeStreamMapping = customArtifactDetails.ArtifactTypeStreamMapping; string streamType = GetArtifactStreamType(artifact, artifactTypeStreamMapping); if (string.Equals(streamType, WellKnownStreamTypes.FileShare, StringComparison.OrdinalIgnoreCase)) { if (!PlatformUtil.RunningOnWindows) { throw new NotSupportedException(StringUtil.Loc("RMFileShareArtifactErrorOnNonWindowsAgent")); } var fileShareArtifact = new FileShareArtifact(); customArtifactDetails.RelativePath = artifact.RelativePath ?? string.Empty; var location = artifact.FileShareLocation ?? artifact.DownloadUrl; await fileShareArtifact.DownloadArtifactAsync(executionContext, hostContext, new ArtifactDefinition { Details = customArtifactDetails }, new Uri(location).LocalPath, localFolderPath); } else if (string.Equals(streamType, WellKnownStreamTypes.Zip, StringComparison.OrdinalIgnoreCase)) { try { IEndpointAuthorizer authorizer = SchemeBasedAuthorizerFactory.GetEndpointAuthorizer( ToServiceEndpoint(customArtifactDetails.Endpoint), customArtifactDetails.AuthorizationHeaders?.Select(header => ToAuthorizationHeader(header)).ToList()); using (HttpWebResponse webResponse = GetWebResponse(executionContext, artifact.DownloadUrl, authorizer)) { var zipStreamDownloader = HostContext.GetService <IZipStreamDownloader>(); await zipStreamDownloader.DownloadFromStream( executionContext, webResponse.GetResponseStream(), string.Empty, artifact.RelativePath ?? string.Empty, localFolderPath); } } catch (WebException) { executionContext.Output(StringUtil.Loc("ArtifactDownloadFailed", artifact.DownloadUrl)); throw; } } else { string resourceType = streamType; var warningMessage = StringUtil.Loc("RMStreamTypeNotSupported", resourceType); executionContext.Warning(warningMessage); } }
private static string GetArtifactStreamType(CustomArtifactDownloadDetails artifact, IDictionary <string, string> artifactTypeStreamMapping) { string streamType = artifact.StreamType; if (artifactTypeStreamMapping == null) { return(streamType); } var artifactTypeStreamMappings = new Dictionary <string, string>(artifactTypeStreamMapping, StringComparer.OrdinalIgnoreCase); if (artifactTypeStreamMappings.ContainsKey(artifact.StreamType)) { streamType = artifactTypeStreamMappings[artifact.StreamType]; } return(streamType); }