Exemple #1
0
        /// <summary>
        /// Initialize installer
        /// </summary>
        private void InitializeInstaller()
        {
            //Recupero l'attributo di servizio applicato sull'installer
            ManagedServiceTypeAttribute attribute = ReflectionUtils.GetSingleAttribute <ManagedServiceTypeAttribute>(GetType(), false);

            //Se non è stato trovato l'attributo, emetto eccezione
            if (attribute == null)
            {
                throw new InvalidOperationException(string.Format("Unable to find attribute of type '{0}' " +
                                                                  "on service installer '{1}'. This attribute is required in order to associate installer " +
                                                                  "to the windows service that needs to be installed.", typeof(ManagedServiceTypeAttribute).FullName, GetType().FullName));
            }

            //Eseguo la generazione dell'istanza del servizio come base
            ServiceBase serviceInstance = Activator.CreateInstance(attribute.ManagedServiceType) as ServiceBase;

            //Se il tipo specificato nell'attributo non è subclasse del servizio, emetto eccezione
            if (serviceInstance == null)
            {
                throw new InvalidOperationException(string.Format("Type '{0}', specified in attribute of type '{1}' on " +
                                                                  "class '{2}' is not subclass of '{3}' windows service.", attribute.ManagedServiceType.FullName,
                                                                  typeof(ManagedServiceTypeAttribute).FullName, GetType().FullName, typeof(ServiceBase)));
            }

            //Eseguo la conversione del servizio nell'interfaccia
            IManagedService windowsServiceInstance = serviceInstance as IManagedService;

            //Se l'interfaccia del servizio windows non è implementata, imposto i default
            if (windowsServiceInstance != null)
            {
                //Imposto i valori recuperati direttamente dal servizio
                _ServiceProcessInstaller.Account     = windowsServiceInstance.Account;
                _ServiceProcessInstaller.Password    = windowsServiceInstance.Password;
                _ServiceProcessInstaller.Username    = windowsServiceInstance.Username;
                _ServiceInstaller.ServiceName        = windowsServiceInstance.ServiceName;
                _ServiceInstaller.DisplayName        = windowsServiceInstance.DisplayName;
                _ServiceInstaller.Description        = windowsServiceInstance.Description;
                _ServiceInstaller.StartType          = windowsServiceInstance.StartType;
                _ServiceInstaller.ServicesDependedOn = windowsServiceInstance.ServicesDependedOn;
            }
            else
            {
                //Imposto i valori di default di installazione del servizio
                _ServiceProcessInstaller.Account  = ServiceAccount.LocalSystem;
                _ServiceProcessInstaller.Password = null;
                _ServiceProcessInstaller.Username = null;
                _ServiceInstaller.ServiceName     = serviceInstance.ServiceName;
                _ServiceInstaller.DisplayName     = serviceInstance.ServiceName;
                _ServiceInstaller.StartType       = ServiceStartMode.Manual;
            }
        }
Exemple #2
0
        private void SetupEssentials(IServiceScopeFactory scopeFactory)
        {
            _logger.LogInformation("Setting up essentials");
            var scope = scopeFactory.CreateScope();

            _probeMonitor = scope.ServiceProvider.GetRequiredService <ProbeMonitor>();
            _probeMonitor.MonitorStateChanged += MonitorStateChanged;

            _syncManager = scope.ServiceProvider.GetRequiredService <SyncManager>();
            _syncManager.SyncStateChanged += SyncStateChanged;

            _managedService = scope.ServiceProvider.GetRequiredService <DnsService>();
            _managedService.ServiceStateChanged += ServiceStateChanged;

            _serviceControl = scope.ServiceProvider.GetRequiredService <ServiceControl>();
            _serviceControl.ServiceControlRequest += ServiceControlActionRequest;

            _logger.LogInformation("Essentials have been set up");
        }