public SharpImageFactory(SmartConfiguration appConfig) { switch (appConfig.ImagingMemoryAllocation) { case ImagingMemoryAllocation.Minimal: _memAllocator = ArrayPoolMemoryAllocator.CreateWithMinimalPooling(); break; case ImagingMemoryAllocation.Moderate: _memAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); break; case ImagingMemoryAllocation.Default: _memAllocator = ArrayPoolMemoryAllocator.CreateDefault(); break; case ImagingMemoryAllocation.Aggressive: _memAllocator = ArrayPoolMemoryAllocator.CreateWithAggressivePooling(); break; } SharpConfiguration.Default.MemoryAllocator = _memAllocator; // Release memory pool every 10 minutes var releaseInterval = TimeSpan.FromMinutes(10); _releaseMemTimer = new Timer(o => ReleaseMemory(), null, releaseInterval, releaseInterval); }
/// <inheritdoc /> public async Task StartAsync(CancellationToken cancellationToken) { this.logger.LogInformation($"Start initializing admin panel for port {this.settings.Port}."); Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithMinimalPooling(); // you might need to allow it first with netsh: // netsh http add urlacl http://+:1234/ user=[Username] this.host = Host.CreateDefaultBuilder() .ConfigureServices(serviceCollection => { serviceCollection.AddSingleton(this.servers); serviceCollection.AddSingleton(this.persistenceContextProvider); serviceCollection.AddSingleton(this.changeListener); serviceCollection.AddSingleton(this.loggerFactory); serviceCollection.AddSingleton(this.plugInChangeListener); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); webBuilder.UseStaticWebAssets(); // For testing purposes, we use http. Later we need to switch to https. // The self-signed certificate would otherwise cause a lot of warnings in the browser. webBuilder.UseUrls($"http://*:{this.settings.Port}"); }) .Build(); await this.host.StartAsync(cancellationToken); this.logger.LogInformation($"Admin panel initialized, port {this.settings.Port}."); }
private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services) { services.AddImageSharpCore( options => { options.Configuration = Configuration.Default; options.MaxBrowserCacheDays = 7; options.MaxCacheDays = 365; options.CachedNameLength = 8; options.OnParseCommands = _ => { }; options.OnBeforeSave = _ => { }; options.OnProcessed = _ => { }; options.OnPrepareResponse = _ => { }; }) .SetRequestParser <QueryCollectionRequestParser>() .SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling()) .SetCache(provider => { var p = new PhysicalFileSystemCache( provider.GetRequiredService <IHostingEnvironment>(), provider.GetRequiredService <MemoryAllocator>(), provider.GetRequiredService <IOptions <ImageSharpMiddlewareOptions> >()); p.Settings[PhysicalFileSystemCache.Folder] = PhysicalFileSystemCache.DefaultCacheFolder; return(p); }) .SetCacheHash <CacheHash>() .SetAsyncKeyLock <AsyncKeyLock>() .AddProvider <PhysicalFileSystemProvider>() .AddProcessor <ResizeWebProcessor>() .AddProcessor <FormatWebProcessor>() .AddProcessor <BackgroundColorWebProcessor>(); }
/// <summary> /// Initializes a new instance of the <see cref="AdminPanel" /> class. /// </summary> /// <param name="port">The port.</param> /// <param name="servers">All manageable servers, including game servers, connect servers etc.</param> /// <param name="persistenceContextProvider">The persistence context provider.</param> /// <param name="changeListener">The change listener.</param> /// <param name="loggingConfigurationPath">The logging configuration file path.</param> public AdminPanel(ushort port, IList <IManageableServer> servers, IPersistenceContextProvider persistenceContextProvider, IServerConfigurationChangeListener changeListener, string loggingConfigurationPath) { Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithMinimalPooling(); // you might need to allow it first with netsh: // netsh http add urlacl http://+:1234/ user=[Username] var host = Host.CreateDefaultBuilder() .ConfigureLogging(configureLogging => { configureLogging.ClearProviders(); var settings = new Log4NetSettings { ConfigFile = loggingConfigurationPath, Watch = true }; configureLogging.AddLog4Net(settings); }) .ConfigureServices(serviceCollection => { serviceCollection.AddSingleton(servers); serviceCollection.AddSingleton(persistenceContextProvider); serviceCollection.AddSingleton(changeListener); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); webBuilder.UseStaticWebAssets(); // For testing purposes, we use http. Later we need to switch to https. // The self-signed certificate would otherwise cause a lot of warnings in the browser. webBuilder.UseUrls($"http://*:{port}"); }) .Build(); host.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="AdminPanel" /> class. /// </summary> /// <param name="port">The port.</param> /// <param name="servers">All manageable servers, including game servers, connect servers etc.</param> /// <param name="persistenceContextProvider">The persistence context provider.</param> /// <param name="changeListener">The change listener.</param> /// <param name="loggingConfigurationPath">The logging configuration file path.</param> public AdminPanel(ushort port, IList <IManageableServer> servers, IPersistenceContextProvider persistenceContextProvider, IServerConfigurationChangeListener changeListener, string loggingConfigurationPath) { Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithMinimalPooling(); // you might need to allow it first with netsh: // netsh http add urlacl http://+:1234/ user=[Username] var host = WebHost.CreateDefaultBuilder() .ConfigureLogging(configureLogging => { configureLogging.ClearProviders(); var settings = new Log4NetSettings { ConfigFile = loggingConfigurationPath, Watch = true }; configureLogging.AddLog4Net(settings); }) .ConfigureServices(serviceCollection => { serviceCollection.AddSingleton(servers); serviceCollection.AddSingleton(persistenceContextProvider); serviceCollection.AddSingleton(changeListener); }) .UseKestrel(options => { // Default port options.ListenAnyIP(port); }) .UseStartup <Startup>() .Build(); host.Start(); SignalRGameServerStateObserver.Services = host.Services; SignalRMapStateObserver.Services = host.Services; }