/// <summary>
    /// Copies files or directories from another implementation fetched by an external 0install process.
    /// </summary>
    /// <param name="builder">The builder.</param>
    /// <param name="metadata">The path of the source and destination file or directory.</param>
    /// <param name="handler">A callback object used when the the user needs to be informed about IO tasks.</param>
    /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception>
    /// <exception cref="IOException">An IO operation failed.</exception>
    public static void CopyFrom(this IBuilder builder, CopyFromStep metadata, ITaskHandler handler)
    {
        if (metadata.Implementation == null)
        {
            throw new ArgumentException($"Must call {nameof(IRecipeStep.Normalize)}() first.", nameof(metadata));
        }

        handler.RunTask(new SimpleTask(string.Format(Resources.FetchingExternal, metadata.ID),
                                       () => ZeroInstallClient.Detect.FetchAsync(metadata.Implementation).Wait()));

        string path = ImplementationStores.Default().GetPath(metadata.Implementation);

        builder.CopyFrom(metadata, path, handler);
    }
 /// <summary>
 /// Registers a set of scoped services for using Zero Install functionality.
 /// </summary>
 /// <typeparam name="TTaskHandler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</typeparam>
 /// <param name="services">The service collection to add the services to.</param>
 public static IServiceCollection AddZeroInstall <TTaskHandler>(this IServiceCollection services)
     where TTaskHandler : class, ITaskHandler
 => services.AddScoped <ITaskHandler, TTaskHandler>()
 .AddScoped(x => Config.Load())
 .AddScoped(x => ImplementationStores.Default())
 .AddScoped(x => OpenPgp.Verifying())
 .AddScoped(x => FeedCaches.Default(x.GetService <IOpenPgp>()))
 .AddScoped(x => TrustDB.LoadSafe())
 .AddScoped <ITrustManager, TrustManager>()
 .AddScoped <IFeedManager, FeedManager>()
 .AddScoped <ICatalogManager, CatalogManager>()
 .AddScoped(x => PackageManagers.Default())
 .AddScoped <ISelectionsManager, SelectionsManager>()
 .AddScoped <ISolver, BacktrackingSolver>()
 .AddScoped <IFetcher, SequentialFetcher>()
 .AddScoped <IExecutor, Executor>()
 .AddScoped <ISelectionCandidateProvider, SelectionCandidateProvider>();
示例#3
0
 /// <summary>
 /// Registers a set of scoped services for using Zero Install functionality.
 /// </summary>
 /// <typeparam name="TTaskHandler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</typeparam>
 /// <param name="services">The service collection to add the services to.</param>
 /// <param name="configuration">An optional configuration source for building <see cref="Config"/> instead of the default config files.</param>
 public static IServiceCollection AddZeroInstall <TTaskHandler>(this IServiceCollection services, IConfiguration?configuration = null)
     where TTaskHandler : class, ITaskHandler
 => services.AddScoped <ITaskHandler, TTaskHandler>()
 .AddScoped(_ => (configuration == null) ? Config.Load() : Config.From(configuration))
 .AddScoped(_ => ImplementationStores.Default())
 .AddScoped(_ => OpenPgp.Verifying())
 .AddScoped(provider => FeedCaches.Default(provider.GetRequiredService <IOpenPgp>()))
 .AddScoped(_ => TrustDB.LoadSafe())
 .AddScoped <ITrustManager, TrustManager>()
 .AddScoped <IFeedManager, FeedManager>()
 .AddScoped <ICatalogManager, CatalogManager>()
 .AddScoped(_ => PackageManagers.Default())
 .AddScoped <ISelectionsManager, SelectionsManager>()
 .AddScoped <ISolver, BacktrackingSolver>()
 .AddScoped <IFetcher, Fetcher>()
 .AddScoped <IExecutor, Executor>()
 .AddScoped <ISelectionCandidateProvider, SelectionCandidateProvider>();