Beispiel #1
0
        /// <summary>
        /// Generates a single ILibraryOperationResult with a collection of IErros based on the collection of FileConflict
        /// </summary>
        /// <param name="fileConflicts"></param>
        /// <returns></returns>
        private static ILibraryOperationResult GetConflictErrors(IEnumerable <FileConflict> fileConflicts)
        {
            if (fileConflicts.Any())
            {
                var errors = new List <IError>();
                foreach (FileConflict conflictingLibraryGroup in fileConflicts)
                {
                    errors.Add(PredefinedErrors.ConflictingFilesInManifest(conflictingLibraryGroup.File, conflictingLibraryGroup.Libraries.Select(l => l.Name).ToList()));
                }

                return(new LibraryOperationResult(errors.ToArray()));
            }

            return(LibraryOperationResult.FromSuccess(null));
        }
Beispiel #2
0
        protected override async Task <int> ExecuteInternalAsync()
        {
            if (!File.Exists(Settings.ManifestFileName))
            {
                await CreateManifestAsync(Provider.Value(), null, Settings, CancellationToken.None);
            }

            _manifest = await GetManifestAsync();

            ValidateParameters(_manifest);

            List <string> files = Files.HasValue() ? Files.Values : null;

            (string libraryId, ILibrary library) = await ValidateLibraryExistsInCatalogAsync(CancellationToken.None);

            string providerIdToUse = Provider.Value();

            if (string.IsNullOrWhiteSpace(_manifest.DefaultProvider) && string.IsNullOrWhiteSpace(providerIdToUse))
            {
                // If there was previously no default provider and the user did not specify on commandline,
                // we get this value by prompting to the user and set it as the default for the manifest.
                _manifest.DefaultProvider = ProviderId;
            }

            InstallDestination = Destination.HasValue() ? Destination.Value() : _manifest.DefaultDestination;
            if (string.IsNullOrWhiteSpace(InstallDestination))
            {
                string destinationHint = Path.Combine(Settings.DefaultDestinationRoot, ProviderToUse.GetSuggestedDestination(library));
                InstallDestination = HostEnvironment.InputReader.GetUserInputWithDefault(nameof(Destination), destinationHint);
            }

            string destinationToUse = Destination.Value();

            if (string.IsNullOrWhiteSpace(_manifest.DefaultDestination) && string.IsNullOrWhiteSpace(destinationToUse))
            {
                destinationToUse = InstallDestination;
            }

            IEnumerable <ILibraryOperationResult> results = await _manifest.InstallLibraryAsync(libraryId, providerIdToUse, files, destinationToUse, CancellationToken.None);

            if (results.All(r => r.Success))
            {
                await _manifest.SaveAsync(Settings.ManifestFileName, CancellationToken.None);

                Logger.Log(string.Format(Resources.InstalledLibrary, libraryId, InstallDestination), LogLevel.Operation);
            }
            else
            {
                bool isFileConflicts = false;
                Logger.Log(string.Format(Resources.InstallLibraryFailed, libraryId), LogLevel.Error);
                foreach (ILibraryOperationResult result in results)
                {
                    foreach (IError error in result.Errors)
                    {
                        Logger.Log(string.Format("[{0}]: {1}", error.Code, error.Message), LogLevel.Error);
                        if (error.Code == PredefinedErrors.ConflictingFilesInManifest("", new List <string>()).Code)
                        {
                            isFileConflicts = true;
                        }
                    }
                }

                if (isFileConflicts)
                {
                    Logger.Log(Resources.SpecifyDifferentDestination, LogLevel.Error);
                }
            }

            return(0);
        }