/// <summary> /// Starts this service instance. /// </summary> /// <param name="args">The <see cref="CommandLineArguments" /> provided to the start command.</param> protected override void StartService(CommandLineArguments args) { try { string assetInventoryServer = ConfigurationManager.AppSettings["AssetInventoryDatabase"]; AssetInventoryConnectionString connectionString = new AssetInventoryConnectionString(assetInventoryServer); TraceFactory.Logger.Debug($"Starting {ServiceName}. Connecting to database on: {assetInventoryServer}"); string adminEmailServer = ConfigurationManager.AppSettings["AdminEmailServer"]; _service = new AssetInventoryService(connectionString, new ExpirationNotifier(adminEmailServer)); string vmServiceAccount = ConfigurationManager.AppSettings["VMServiceAccount"]; string vmAccountPwd = ConfigurationManager.AppSettings["VMAccountPwd"]; NetworkCredential vmAccount = new NetworkCredential(vmServiceAccount, vmAccountPwd, Environment.UserDomainName); Uri vCenterServerUri = new Uri(ConfigurationManager.AppSettings["VCenterServerUri"]); _vmInventorySynchronizer = new VMInventorySynchronizer(vmAccount, vCenterServerUri, connectionString); } catch (Exception ex) { TraceFactory.Logger.Debug(ex.ToString()); //We want to throw here so the OS doesn't think the Windows Service started when it really didn't. throw; } }
/// <summary> /// Starts this service instance. /// </summary> /// <param name="args">The <see cref="CommandLineArguments" /> provided to the start command.</param> protected override void StartService(CommandLineArguments args) { if (args == null) { throw new ArgumentNullException("args"); } // Load the settings, either from the command line or the local cache FrameworkServiceHelper.LoadSettings(args); ReservationExpirationManager expirationManager = new ReservationExpirationManager(DbConnect.AssetInventoryConnectionString); ExpirationNotifier expirationNotifier = new ExpirationNotifier(GlobalSettings.Items[Setting.AdminEmailServer]); _assetInventory = new AssetInventoryService(new[] { expirationManager }, expirationNotifier); Task.Factory.StartNew(() => _lock.Open()); DataLogConnectionString connectionString = new DataLogConnectionString(GlobalSettings.Items[Setting.DataLogDatabase]); _dataLogService = new WcfHost<IDataLogService>(new DataLogService(connectionString), DataLogServiceEndpoint.MessageTransferType, DataLogServiceEndpoint.BuildUri("localhost")); Task.Factory.StartNew(() => _dataLogService.Open()); }