Ejemplo n.º 1
0
        /// <summary>A protected method that processes added packages.</summary>
        /// <param name="package">The package to process.</param>
        /// <param name="packageEvent">The package event that generated the package.</param>
        /// <returns>
        ///   <c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        protected virtual async Task <bool> ProcessPackageAddedAsync(Package package, PackageEvent packageEvent)
        {
            if (IgnorePackage(package))
            {
                Logger.LogDebug($"Package ({package.Id} is being ignored due to configuration");
                await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageIgnored,
                                                                                $"Package ({package.Id} is being ignored due to configuration", null, package));

                return(true);
            }

            try
            {
                Logger.LogDebug($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}");
                var packageWithContent = await SourceRepository.FetchAsync(package.Id, package.Version);

                Logger.LogTrace($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}...done");

                switch (await ProcessCommandsAsync(package, packageEvent))
                {
                case CommandFailureAction.Continue:
                    Logger.LogInformation($"Adding package {package.Id}.{package.Version} to {TargetRepository.Name}");
                    await TargetRepository.AddAsync(packageWithContent);

                    Logger.LogTrace($"Adding package {package.Id}.{package.Version} to {TargetRepository.Name}...done");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageSuccess,
                                                                                    $"Package added {package.Id}.{package.Version} to {TargetRepository.Name}",
                                                                                    null, package));

                    break;

                case CommandFailureAction.FailPackage:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.",
                                                                                    null, package));

                    return(true);

                case CommandFailureAction.FailAction:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.",
                                                                                    null,
                                                                                    package));

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error adding package {package.Id}.{package.Version}. Exception: {ex.Message}", ex);
                if (ActionSettings.FailOnError)
                {
                    throw;
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>The method in the action that processes the package.</summary>
        /// <param name="package">The package to process.</param>
        /// <param name="packageEvent">The type of event associated with the package.</param>
        /// <returns>
        ///   <c>true</c> if the process was successful and processing should continue, <c>false</c> otherwise.</returns>
        public override async Task <bool> ProcessPackageAsync(Package package, PackageEvent packageEvent)
        {
            if (IgnorePackage(package))
            {
                Logger.LogDebug($"Package ({package.Id} is being ignored due to configuration");
                await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageIgnored,
                                                                                $"Package ({package.Id} is being ignored due to configuration", null, package));

                return(true);
            }

            try
            {
                Package packageWithContent = package;
                if (packageEvent != PackageEvent.Deleted)
                {
                    Logger.LogDebug($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}");
                    packageWithContent = await SourceRepository.FetchAsync(package.Id, package.Version);

                    Logger.LogTrace($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}...done");
                    if (packageWithContent == null)
                    {
                        Logger.LogWarning($"Package not found: {package.Id}.{package.Version} from {SourceRepository.Name}. Ignoring but expecting failure.");
                        packageWithContent = package;
                    }
                }

                switch (await ProcessCommandsAsync(packageWithContent, packageEvent))
                {
                case CommandFailureAction.Continue:
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageSuccess,
                                                                                    $"Command successful on {package.Id}.{package.Version}", null, package));

                    return(true);

                case CommandFailureAction.FailPackage:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.", null, package));

                    return(true);

                case CommandFailureAction.FailAction:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.", null, package));

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error processing package {package.Id}.{package.Version}. Exception: {ex.Message}", ex);
                if (ActionSettings.FailOnError)
                {
                    throw;
                }
            }

            return(true);
        }