public void ConfigureServices(IServiceCollection services) { // Completely disable the database. EntityContext.Enabled = false; // Allow 32 concurrent outgoing connections. ServicePointManager.DefaultConnectionLimit = 32; // Set the user agent for the HTTP client. var userAgentStringBuilder = new UserAgentStringBuilder("Knapcode.ExplorePackages.Website.Bot"); UserAgent.SetUserAgentString(userAgentStringBuilder); // Enable ExplorePackages dependencies. var explorePackagesSettings = new ExplorePackagesSettings(); Configuration.Bind("ExplorePackages", explorePackagesSettings); services.AddExplorePackages(explorePackagesSettings); // Add stuff specific to the website. services.AddLogging(); services.AddSingleton <IHostedService, SearchSearchUrlCacheRefresher>(); services.AddMvc(); services.AddSignalR(o => { o.JsonSerializerSettings.Converters.Add(new StringEnumConverter()); }); }
private static async Task InitializeGlobalState(ExplorePackagesSettings settings, bool initializeDatabase, ILogger logger) { logger.LogInformation("===== initialize ====="); // Initialize the database. EntityContext.ConnectionString = "Data Source=" + settings.DatabasePath; EntityContext.Enabled = initializeDatabase; if (initializeDatabase) { using (var entityContext = new EntityContext()) { await entityContext.Database.MigrateAsync(); logger.LogInformation("The database schema is up to date."); } } else { logger.LogInformation("The database will not be used."); } // Set the user agent. var userAgentStringBuilder = new UserAgentStringBuilder("Knapcode.ExplorePackages.Bot"); UserAgent.SetUserAgentString(userAgentStringBuilder); logger.LogInformation("The following user agent will be used: {UserAgent}", UserAgent.UserAgentString); logger.LogInformation("======================" + Environment.NewLine); }
private static ServiceCollection InitializeServiceCollection(ExplorePackagesSettings settings) { var serviceCollection = new ServiceCollection(); serviceCollection.AddExplorePackages(settings); serviceCollection.AddSingleton(new LoggerFactory().AddMinimalConsole()); serviceCollection.AddLogging(); foreach (var pair in Commands) { serviceCollection.AddTransient(pair.Value); } return(serviceCollection); }
public UpdateCommand( V2ToDatabaseCommand v2ToDatabase, FetchCursorsCommand fetchCursors, CatalogToDatabaseCommand catalogToDatabase, CatalogToNuspecsCommand catalogToNuspecs, MZipCommand mzip, MZipToDatabaseCommand mzipToDatabase, DependenciesToDatabaseCommand dependenciesToDatabase, DependencyPackagesToDatabaseCommand dependencyPackagesToDatabase, DownloadsToDatabaseCommand downloadsToDatabase, PackageQueriesCommand packageQueries, ExplorePackagesSettings settings, ILogger <CommandExecutor> logger) { var commands = new List <ICommand> { v2ToDatabase, fetchCursors, catalogToDatabase, catalogToNuspecs, mzip, mzipToDatabase, dependenciesToDatabase, dependencyPackagesToDatabase, }; if (settings.DownloadsV1Url != null) { commands.Add(downloadsToDatabase); } commands.AddRange(new[] { packageQueries, }); _commands = commands; _logger = logger; }