示例#1
0
        private ILibraryInstallationResult DeleteLibraryFiles(ILibraryInstallationState state, Action <string> deleteFileAction)
        {
            int filesDeleted = 0;

            IProvider provider = _dependencies.GetProvider(state.ProviderId);
            ILibraryInstallationResult updatedStateResult = provider.UpdateStateAsync(state, CancellationToken.None).Result;

            if (updatedStateResult.Success)
            {
                state = updatedStateResult.InstallationState;
                foreach (string file in state.Files)
                {
                    var url = new Uri(file, UriKind.RelativeOrAbsolute);

                    if (!url.IsAbsoluteUri)
                    {
                        string relativePath = Path.Combine(state.DestinationPath, file).Replace('\\', '/');
                        deleteFileAction?.Invoke(relativePath);
                        filesDeleted++;
                    }
                }

                if (state.Files != null && filesDeleted == state.Files.Count())
                {
                    return(LibraryInstallationResult.FromSuccess(updatedStateResult.InstallationState));
                }
            }

            return(updatedStateResult);
        }
示例#2
0
        /// <summary>
        /// Restores all libraries in the <see cref="Libraries"/> collection.
        /// </summary>
        /// <param name="cancellationToken">A token that allows for cancellation of the operation.</param>
        public async Task <IEnumerable <ILibraryInstallationResult> > RestoreAsync(CancellationToken cancellationToken)
        {
            //TODO: This should have an "undo scope"
            var results = new List <ILibraryInstallationResult>();
            var tasks   = new List <Task <ILibraryInstallationResult> >();

            if (!IsValidManifestVersion(Version))
            {
                results.Add(LibraryInstallationResult.FromErrors(new IError[] { PredefinedErrors.VersionIsNotSupported(Version) }));

                return(results);
            }

            foreach (ILibraryInstallationState state in Libraries)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    results.Add(LibraryInstallationResult.FromCancelled(state));
                    _hostInteraction.Logger.Log(Resources.Text.RestoreCancelled, LogLevel.Task);
                    return(results);
                }

                if (!state.IsValid(out IEnumerable <IError> errors))
                {
                    results.Add(new LibraryInstallationResult(state, errors.ToArray()));
                    continue;
                }

                _hostInteraction.Logger.Log(string.Format(Resources.Text.RestoringLibrary, state.LibraryId), LogLevel.Operation);

                IProvider provider = _dependencies.GetProvider(state.ProviderId);

                if (provider != null)
                {
                    tasks.Add(provider.InstallAsync(state, cancellationToken));
                }
                else
                {
                    results.Add(new LibraryInstallationResult(state, PredefinedErrors.ProviderUnknown(state.ProviderId)));
                }
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);

            results.AddRange(tasks.Select(t => t.Result));

            return(results);
        }