private async Task DownloadArtifacts(IExecutionContext executionContext, List <AgentArtifactDefinition> agentArtifactDefinitions, string artifactsWorkingFolder)
        {
            Trace.Entering();

            foreach (AgentArtifactDefinition agentArtifactDefinition in agentArtifactDefinitions)
            {
                // We don't need to check if its old style artifact anymore. All the build data has been fixed and all the build artifact has Alias now.
                ArgUtil.NotNullOrEmpty(agentArtifactDefinition.Alias, nameof(agentArtifactDefinition.Alias));

                var extensionManager         = HostContext.GetService <IExtensionManager>();
                IArtifactExtension extension = (extensionManager.GetExtensions <IArtifactExtension>()).FirstOrDefault(x => agentArtifactDefinition.ArtifactType == x.ArtifactType);

                if (extension == null)
                {
                    throw new InvalidOperationException(StringUtil.Loc("RMArtifactTypeNotSupported"));
                }

                Trace.Info($"Found artifact extension of type {extension.ArtifactType}");
                executionContext.Output(StringUtil.Loc("RMStartArtifactsDownload"));
                ArtifactDefinition artifactDefinition = ConvertToArtifactDefinition(agentArtifactDefinition, executionContext, extension);
                executionContext.Output(StringUtil.Loc("RMArtifactDownloadBegin", agentArtifactDefinition.Alias));
                executionContext.Output(StringUtil.Loc("RMDownloadArtifactType", agentArtifactDefinition.ArtifactType));

                // Get the local path where this artifact should be downloaded.
                string downloadFolderPath = Path.GetFullPath(Path.Combine(artifactsWorkingFolder, agentArtifactDefinition.Alias ?? string.Empty));

                // Create the directory if it does not exist.
                if (!Directory.Exists(downloadFolderPath))
                {
                    // TODO: old windows agent has a directory cache, verify and implement it if its required.
                    Directory.CreateDirectory(downloadFolderPath);
                    executionContext.Output(StringUtil.Loc("RMArtifactFolderCreated", downloadFolderPath));
                }

                // download the artifact to this path.
                RetryExecutor retryExecutor = new RetryExecutor();
                await retryExecutor.ExecuteAsync(
                    async() =>
                {
                    //TODO:SetAttributesToNormal
                    var releaseFileSystemManager = HostContext.GetService <IReleaseFileSystemManager>();
                    releaseFileSystemManager.CleanupDirectory(downloadFolderPath, executionContext.CancellationToken);

                    if (agentArtifactDefinition.ArtifactType == AgentArtifactType.GitHub ||
                        agentArtifactDefinition.ArtifactType == AgentArtifactType.TFGit ||
                        agentArtifactDefinition.ArtifactType == AgentArtifactType.Tfvc)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        await extension.DownloadAsync(executionContext, artifactDefinition, downloadFolderPath);
                    }
                });

                executionContext.Output(StringUtil.Loc("RMArtifactDownloadFinished", agentArtifactDefinition.Alias));
            }

            executionContext.Output(StringUtil.Loc("RMArtifactsDownloadFinished"));
        }
Пример #2
0
            public void Initialize()
            {
                ElementSchema element = null;

                this.store = new Store(VsIdeTestHostContext.ServiceProvider,
                    new Type[] { typeof(CoreDesignSurfaceDomainModel), typeof(PatternModelDomainModel), typeof(LibraryDomainModel) });

                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    this.store.ElementFactory.CreateElement<PatternModelSchema>();
                    element = this.store.ElementFactory.CreateElement<ElementSchema>();
                });

                this.artifactExtension = element.GetExtensions<IArtifactExtension>().FirstOrDefault();
                this.container = element as IPatternElementSchema;
            }
Пример #3
0
            public void Initialize()
            {
                ElementSchema element = null;

                this.store = new Store(VsIdeTestHostContext.ServiceProvider,
                                       new Type[] { typeof(CoreDesignSurfaceDomainModel), typeof(PatternModelDomainModel), typeof(LibraryDomainModel) });

                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    this.store.ElementFactory.CreateElement <PatternModelSchema>();
                    element = this.store.ElementFactory.CreateElement <ElementSchema>();
                });

                this.artifactExtension = element.GetExtensions <IArtifactExtension>().FirstOrDefault();
                this.container         = element as IPatternElementSchema;
            }
Пример #4
0
        private ArtifactDefinition ConvertToArtifactDefinition(AgentArtifactDefinition agentArtifactDefinition, IExecutionContext executionContext, IArtifactExtension extension)
        {
            Trace.Entering();

            ArgUtil.NotNull(agentArtifactDefinition, nameof(agentArtifactDefinition));
            ArgUtil.NotNull(executionContext, nameof(executionContext));

            var artifactDefinition = new ArtifactDefinition
            {
                ArtifactType = agentArtifactDefinition.ArtifactType,
                Name = agentArtifactDefinition.Name,
                Version = agentArtifactDefinition.Version
            };

            artifactDefinition.Details = extension.GetArtifactDetails(executionContext, agentArtifactDefinition);
            return artifactDefinition;
        }
Пример #5
0
        private ArtifactDefinition ConvertToArtifactDefinition(AgentArtifactDefinition agentArtifactDefinition, IExecutionContext executionContext, IArtifactExtension extension)
        {
            Trace.Entering();

            ArgUtil.NotNull(agentArtifactDefinition, nameof(agentArtifactDefinition));
            ArgUtil.NotNull(executionContext, nameof(executionContext));

            var artifactDefinition = new ArtifactDefinition
            {
                ArtifactType = agentArtifactDefinition.ArtifactType,
                Name         = agentArtifactDefinition.Name,
                Version      = agentArtifactDefinition.Version
            };

            artifactDefinition.Details = extension.GetArtifactDetails(executionContext, agentArtifactDefinition);
            return(artifactDefinition);
        }
Пример #6
0
        private async Task DownloadArtifacts(IExecutionContext executionContext,
                                             IList <AgentArtifactDefinition> agentArtifactDefinitions, string artifactsWorkingFolder)
        {
            Trace.Entering();

            CreateArtifactsFolder(executionContext, artifactsWorkingFolder);

            executionContext.Output(StringUtil.Loc("RMDownloadingArtifact"));

            foreach (AgentArtifactDefinition agentArtifactDefinition in agentArtifactDefinitions)
            {
                // We don't need to check if its old style artifact anymore. All the build data has been fixed and all the build artifact has Alias now.
                ArgUtil.NotNullOrEmpty(agentArtifactDefinition.Alias, nameof(agentArtifactDefinition.Alias));

                var extensionManager         = HostContext.GetService <IExtensionManager>();
                IArtifactExtension extension =
                    (extensionManager.GetExtensions <IArtifactExtension>()).FirstOrDefault(x =>
                                                                                           agentArtifactDefinition.ArtifactType == x.ArtifactType);

                if (extension == null)
                {
                    throw new InvalidOperationException(StringUtil.Loc("RMArtifactTypeNotSupported",
                                                                       agentArtifactDefinition.ArtifactType));
                }

                Trace.Info($"Found artifact extension of type {extension.ArtifactType}");
                executionContext.Output(StringUtil.Loc("RMStartArtifactsDownload"));
                ArtifactDefinition artifactDefinition =
                    ConvertToArtifactDefinition(agentArtifactDefinition, executionContext, extension);
                executionContext.Output(StringUtil.Loc("RMArtifactDownloadBegin", agentArtifactDefinition.Alias,
                                                       agentArtifactDefinition.ArtifactType));

                // Get the local path where this artifact should be downloaded.
                string downloadFolderPath = Path.GetFullPath(Path.Combine(artifactsWorkingFolder,
                                                                          agentArtifactDefinition.Alias ?? string.Empty));

                // download the artifact to this path.
                RetryExecutor retryExecutor = new RetryExecutor();
                retryExecutor.ShouldRetryAction = (ex) =>
                {
                    executionContext.Output(StringUtil.Loc("RMErrorDuringArtifactDownload", ex));

                    bool retry = true;
                    if (ex is ArtifactDownloadException)
                    {
                        retry = false;
                    }
                    else
                    {
                        executionContext.Output(StringUtil.Loc("RMRetryingArtifactDownload"));
                        Trace.Warning(ex.ToString());
                    }

                    return(retry);
                };

                await retryExecutor.ExecuteAsync(
                    async() =>
                {
                    var releaseFileSystemManager = HostContext.GetService <IReleaseFileSystemManager>();
                    executionContext.Output(StringUtil.Loc("RMEnsureArtifactFolderExistsAndIsClean",
                                                           downloadFolderPath));
                    releaseFileSystemManager.EnsureEmptyDirectory(downloadFolderPath,
                                                                  executionContext.CancellationToken);

                    await extension.DownloadAsync(executionContext, artifactDefinition, downloadFolderPath);
                });

                executionContext.Output(StringUtil.Loc("RMArtifactDownloadFinished",
                                                       agentArtifactDefinition.Alias));
            }

            executionContext.Output(StringUtil.Loc("RMArtifactsDownloadFinished"));
        }
Пример #7
0
        private ArtifactDefinition ConvertToArtifactDefinition(AgentArtifactDefinition agentArtifactDefinition, IExecutionContext executionContext, IArtifactExtension extension)
        {
            Trace.Entering();

            ArgUtil.NotNull(agentArtifactDefinition, nameof(agentArtifactDefinition));
            ArgUtil.NotNull(executionContext, nameof(executionContext));

            var artifactDefinition = new ArtifactDefinition
            {
                ArtifactType = agentArtifactDefinition.ArtifactType,
                Name         = agentArtifactDefinition.Name,
                Version      = agentArtifactDefinition.Version
            };

            RetryExecutor retryExecutor = new RetryExecutor();

            retryExecutor.ShouldRetryAction = (ex) =>
            {
                bool retry = true;
                if (ex is InvalidOperationException)
                {
                    retry = false;
                }
                else
                {
                    Trace.Warning(ex.ToString());
                }

                return(retry);
            };

            retryExecutor.Execute(
                () =>
            {
                artifactDefinition.Details = extension.GetArtifactDetails(executionContext, agentArtifactDefinition);
            });

            return(artifactDefinition);
        }