Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NuGetPackageManager"/> class
        /// </summary>
        /// <param name="packagesPersistentStorage">The persistent storage instance to be used for packages files</param>
        /// <param name="metadataPersistentStorage">The persistent storage instance to be used for metadata files</param>
        /// <param name="packageIndex">The package index instance to be used</param>
        public NuGetPackageManager(IPersistentStorage packagesPersistentStorage, IPersistentStorage metadataPersistentStorage, INuGetPackageIndex packageIndex)
        {
            if (packagesPersistentStorage == null)
            {
                throw new ArgumentNullException(nameof(packagesPersistentStorage));
            }
            if (metadataPersistentStorage == null)
            {
                throw new ArgumentNullException(nameof(metadataPersistentStorage));
            }
            if (packageIndex == null)
            {
                throw new ArgumentNullException(nameof(packageIndex));
            }

            this.packagesPersistentStorage = packagesPersistentStorage;
            this.metadataPersistentStorage = metadataPersistentStorage;
            this.packageIndex = packageIndex;
        }
Exemplo n.º 2
0
        private void AddDependencies(IServiceCollection services)
        {
            services.AddSingleton <ServiceIndex>(CreateServiceIndex());
            services.AddSingleton <INuGetPackageIndex>(serviceProvider =>
            {
                string packageIndexType = Configuration.GetValue <string>("PackageIndexType");
                var serviceIndex        = serviceProvider.GetService <ServiceIndex>();
                var telemetryClient     = serviceProvider.GetService <TelemetryClient>();

                INuGetPackageIndex instance = null;

                if ("InMemory".Equals(packageIndexType, StringComparison.OrdinalIgnoreCase))
                {
                    var logger = serviceProvider.GetService <ILogger <InMemoryNuGetPackageIndex> >();
                    instance   = new InMemoryNuGetPackageIndex(serviceIndex, logger);
                }
                else if ("File".Equals(packageIndexType, StringComparison.OrdinalIgnoreCase))
                {
                    var logger = serviceProvider.GetService <ILogger <FileNuGetPackageIndex> >();
                    instance   = new FileNuGetPackageIndex(serviceIndex, new FilePersistentStorage("./metadata"), logger, telemetryClient);
                }
                else
                {
                    throw new Exception($"Unknown package index type: '{packageIndexType}'");
                }

                instance.Initialize().Wait();

                return(instance);
            });
            services.AddSingleton <NuGetPackageManager>(serviceProvider =>
            {
                var packageIndex = serviceProvider.GetService <INuGetPackageIndex>();
                return(new NuGetPackageManager(new FilePersistentStorage("./packages"), new FilePersistentStorage("./metadata"), packageIndex));
            });
        }