예제 #1
0
 public RegistryCacheInitializer(IConfiguration configuration, IHostEnvironment hostEnvironment, ILoggerFactory loggerFactory, RegistryCacheSingleton registryCacheSingleton)
 {
     this.configuration          = configuration;
     this.hostEnvironment        = hostEnvironment;
     this.loggerFactory          = loggerFactory;
     this.registryCacheSingleton = registryCacheSingleton;
 }
 public RegistryCacheInitializer(IConfiguration configuration, IHostEnvironment hostEnvironment, ILoggerFactory loggerFactory, IOptions <RegistryOptions> registryOptionsAccessor, RegistryCacheSingleton registryCacheSingleton)
 {
     this.configuration          = configuration;
     this.hostEnvironment        = hostEnvironment;
     this.loggerFactory          = loggerFactory;
     registryOptions             = registryOptionsAccessor.Value;
     this.registryCacheSingleton = registryCacheSingleton;
 }
예제 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var loggerRedirect = new NuGetRedirectLogger(LoggerFactory.CreateLogger("NuGet"));

            string url = "https://unitynuget-registry.azurewebsites.net/";

            bool isDevelopment = HostingEnvironment.IsDevelopment();

            if (isDevelopment)
            {
                var urls = Configuration[WebHostDefaults.ServerUrlsKey];

                // Select HTTPS in production, HTTP in development
                url = urls.Split(';').FirstOrDefault(x => !x.StartsWith("https"));
                if (url == null)
                {
                    throw new InvalidOperationException($"Unable to find a proper server URL from `{urls}`. Expecting a `http://...` URL in development");
                }
            }

            // Get the current directory /home/site/unity_packages or binary folder in dev
            var currentDirectory   = isDevelopment ? Path.GetDirectoryName(typeof(Startup).Assembly.Location) : Directory.GetCurrentDirectory();
            var unityPackageFolder = Path.Combine(currentDirectory, "unity_packages");

            loggerRedirect.LogInformation($"Using Unity Package folder `{unityPackageFolder}`");

            // Build the cache synchronously because ConfigureServices doesn't support async Task
            var initialCache = new RegistryCache(unityPackageFolder, url, loggerRedirect);

            initialCache.Build().GetAwaiter().GetResult();

            // Add the cache accessible from the services
            var singletonCache = new RegistryCacheSingleton(initialCache);

            services.AddSingleton(singletonCache);

            // Add the registry cache updater
            services.AddHostedService <RegistryCacheUpdater>();

            // Also enable NewtonsoftJson serialization
            services.AddControllers().AddNewtonsoftJson();
        }
예제 #4
0
 public RegistryCacheUpdater(RegistryCacheSingleton currentRegistryCache, ILogger <RegistryCacheUpdater> logger, IOptions <RegistryOptions> registryOptionsAccessor)
 {
     _currentRegistryCache = currentRegistryCache;
     _logger          = logger;
     _registryOptions = registryOptionsAccessor.Value;
 }
예제 #5
0
 public RegistryCacheUpdater(RegistryCacheSingleton currentRegistryCache, ILogger <RegistryCacheUpdater> logger)
 {
     _currentRegistryCache = currentRegistryCache;
     _logger = logger;
 }