示例#1
0
        /// <summary>
        /// Обработчик запуска службы.
        /// </summary>
        /// <param name="args">Аргументы запуска.</param>
        protected override void OnStart(string[] args)
        {
            try
            {
                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
                //инициализация движка
                using (StorageEngine engine = new StorageEngine())
                    engine.Init();

                this.EventLog.WriteEntry("Инициализация успешно завершена");

                //wcf
                if (_serviceHost != null)
                {
                    _serviceHost.Close();
                }

                if (_replicationServiceHost != null)
                {
                    _replicationServiceHost.Close();
                }

                _serviceHost          = new ServiceHost(typeof(StorageService));
                _serviceHost.Faulted += serviceHost_Faulted;
                _serviceHost.UnknownMessageReceived += serviceHost_UnknownMessageReceived;
                _serviceHost.Open();

                _replicationServiceHost          = new ServiceHost(typeof(StorageReplicationService));
                _replicationServiceHost.Faulted += (s, e) =>
                {
                    this.EventLog.WriteEntry("ReplicationServiceHostFaulted!", EventLogEntryType.Error);
                };
                _replicationServiceHost.UnknownMessageReceived += serviceHost_UnknownMessageReceived;
                _replicationServiceHost.Open();

                this.EventLog.WriteEntry("Хост службы файлового хранилища запущен");

                //http listener
                this.Listern();
            }
            catch (Exception ex)
            {
                this.EventLog.WriteEntry("Ошибка запуска службы файлового хранилища. Текст ошибки: " + ex.ToString(), EventLogEntryType.Error);
            }
        }