/// <summary> /// Fires when the windows service starts. /// </summary> /// <param name="args">The arguments passed, if any.</param> protected override void OnStart(string[] args) { LoggerContainer.Instance.Info("Cache Host is starting", "Cache Host is starting"); // Configure the thread pool's minimum threads ThreadPool.SetMinThreads(128, 128); LoggerContainer.Instance.Info("Cache Host is starting", "Verifying settings"); try { IWindsorContainer container = new Castle.Windsor.WindsorContainer(); // Initialize the mem cache container instance var physicalMemoryLimitPercentage = CacheHostConfigurationSection.Settings.CacheMemoryLimitPercentage; var cacheConfig = new NameValueCollection(); cacheConfig.Add("pollingInterval", "00:00:15"); cacheConfig.Add("physicalMemoryLimitPercentage", physicalMemoryLimitPercentage.ToString()); // Initialize the client to cache service host ServiceHost clientToCacheServiceHost = SetupServiceHost(); Uri serviceHostAddress = clientToCacheServiceHost.Description.Endpoints.First().Address.Uri; container.Install(new MemcacheInstaller(string.Format("{0}_{1}", serviceHostAddress.Host, serviceHostAddress.Port), false)); CustomPerformanceCounterManagerContainer.Instance = container.Resolve<CustomPerformanceCounterManager>(); IMemCache memCache = container.Resolve<IMemCache>(new { cacheName = "Dache", cacheConfig = cacheConfig }); // Initialize the cache host information poller var cacheHostInformationPoller = new CacheHostInformationPoller(1000); // Instantiate the cache host engine _cacheHostEngine = new CacheHostEngine(cacheHostInformationPoller, memCache, clientToCacheServiceHost); } catch (Exception ex) { // The inner exception has the actual details of the configuration error if (ex.InnerException != null && ex.InnerException.Message != null && ex.InnerException.Message.StartsWith("The value for the property", StringComparison.OrdinalIgnoreCase)) { ex = ex.InnerException; } // Log the error LoggerContainer.Instance.Error("Cache Host failed to start", ex.Message); // Stop the service Stop(); } LoggerContainer.Instance.Info("Cache Host is starting", "Settings verified successfully"); _cacheHostEngine.Start(); }
public void Setup() { IWindsorContainer container = new Castle.Windsor.WindsorContainer(); container.Install(new MemcacheInstaller("Dache_Test",false)); _memCache = container.Resolve<IMemCache>(new { cacheName = TestName, cacheConfig = Config }); }