/// <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;
            }
        }
Пример #2
0
        static ExchangeEmailMonitor()
        {
            _analyzers.Add(new EmailAnalyzer());

            // Retrieve Exchange Server Settings
            AssetInventoryConnectionString connectionString = new AssetInventoryConnectionString(GlobalSettings.Items[Setting.AssetInventoryDatabase]);

            using (AssetInventoryContext context = new AssetInventoryContext(connectionString))
            {
                string          serverType = ServerType.Exchange.ToString();
                FrameworkServer server     = context.FrameworkServers.FirstOrDefault(n => n.ServerTypes.Any(m => m.Name == serverType) && n.Active);
                _exchangeServerSettings = new SettingsDictionary(server.ServerSettings.ToDictionary(n => n.Name, n => n.Value));
            }
        }
        /// <summary>
        /// Constructs a new instance of <see cref="VMInventorySynchronizer" />.
        /// </summary>
        /// <param name="credential">The VCenter account to use in the synchronization operations.</param>
        /// <param name="vCenterServerUri">The URI of the VCenter Server.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="UriFormatException"></exception>
        public VMInventorySynchronizer(NetworkCredential credential, Uri vCenterServerUri, AssetInventoryConnectionString connectionString)
        {
            if (vCenterServerUri == null)
            {
                throw new ArgumentNullException(nameof(vCenterServerUri));
            }

            if (credential == null)
            {
                throw new ArgumentNullException(nameof(credential));
            }

            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            _vCenterUri       = vCenterServerUri;
            _credential       = credential;
            _connectionString = connectionString;

            _syncCheckTimer = new Timer(SyncInventory, null, _syncCheckFrequency, _syncCheckFrequency);
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReservationExpirationManager" /> class.
 /// </summary>
 /// <param name="connectionString">The <see cref="AssetInventoryConnectionString" />.</param>
 /// <exception cref="ArgumentNullException"><paramref name="connectionString" /> is null.</exception>
 public ReservationExpirationManager(AssetInventoryConnectionString connectionString)
 {
     _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PrinterStatusSynchronizer" /> class.
 /// </summary>
 /// <param name="connectionString">The <see cref="AssetInventoryConnectionString" />.</param>
 /// <exception cref="ArgumentNullException"><paramref name="connectionString" /> is null.</exception>
 public PrinterStatusSynchronizer(AssetInventoryConnectionString connectionString)
 {
     _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
 }
        private static IEnumerable <IAssetInventoryMaintenanceManager> GetAllManagers(AssetInventoryConnectionString connectionString)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            yield return(new ReservationExpirationManager(connectionString));

            yield return(new LicenseExpirationManager(connectionString));

            yield return(new PrinterStatusSynchronizer(connectionString));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetInventoryService" /> class with all available maintenance managers.
 /// </summary>
 /// <param name="connectionString">The <see cref="AssetInventoryConnectionString" />.</param>
 /// <param name="expirationNotifier">The <see cref="ExpirationNotifier" />.</param>
 /// <exception cref="ArgumentNullException"><paramref name="connectionString" /> is null.</exception>
 public AssetInventoryService(AssetInventoryConnectionString connectionString, ExpirationNotifier expirationNotifier)
     : this(GetAllManagers(connectionString), expirationNotifier)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetReservationManager" /> class.
 /// </summary>
 /// <param name="connectionString">The <see cref="AssetInventoryConnectionString" />.</param>
 /// <param name="requester">The source that is requesting the reservation.</param>
 /// <exception cref="ArgumentNullException"><paramref name="connectionString" /> is null.</exception>
 public AssetReservationManager(AssetInventoryConnectionString connectionString, string requester)
 {
     _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
     _requester        = requester;
 }