///// <summary>
        /////
        ///// </summary>
        //public ServiceInfo GetInfo()
        //{
        //	var serviceInfo = new ServiceInfo();
        //	_serviceInfo.CloneTo(serviceInfo);
        //	//serviceInfo.SortPropertiesByName();
        //	return serviceInfo;
        //}

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="updateParams"></param>
        //public void UpdateInfo(ServiceInfoUpdateParams updateParams)
        //{
        //	_serviceInfo.Online = updateParams.Online;
        //	_serviceInfo.InternalAddress = updateParams.InternalAddress;
        //	_serviceInfo.ExternalAddress = updateParams.ExternalAddress;
        //}

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="reinitService"></param>
        //public void SaveInfo(bool reinitService)
        //{
        //}


        #region IHostedService
        public Task StartAsync(CancellationToken cancellationToken)
        {
            return(Task.Run(() =>
            {
                _logger.LogTrace("Старт сервиса.");

                bool isSchemaValid = false;

                try
                {
                    _serviceInfo.StartTime = DateTime.Now;

                    _database.Schema = _busSettings.Database.Schema;
                    _database.ConnectionString = _busSettings.Database.ConnectionString;
                    //_database.ConnectionTimeout = (int)_databaseSettings.ConnectionTimeout.TotalSeconds;
                    //_dataAdapter.ExecuteTimeout = (int)_databaseSettings.ExecuteTimeout.TotalSeconds;

                    while (!_database.TryConnect(out ConnectionException error))
                    {
                        _serviceInfo.StartupError = error;
                        System.Threading.Thread.Sleep(1000);
                    }

                    using DbContext dbContext = _database.ValidateSchema();
                    //using DbContext dbContext = _database.CreateOrUpdateSchema();
                    isSchemaValid = true;

                    List <DAO.ServiceInfo> instances = _dataAdapter.GetServiceInstances();
                    if (instances.Count > 0)
                    {
                        DAO.ServiceInfo service = instances[0];
                        _serviceInfo.LINK = service.LINK;
                        if (service.InstanceID != _serviceInfo.InstanceID && _busSettings.CheckInstanceID)
                        {
                            throw new ApplicationException("База данных принадлежит другому интеграционному сервису.");
                        }
                    }

                    _addinManager.LoadAddins();

                    //_licManager.LoadLicenses();
                    _channelManager.LoadChannels();

                    _serviceInfo.StartupError = null;
                    _serviceInfo.Running = true;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex);
                    _serviceInfo.StartupError = ex;
                }
                finally
                {
                    if (isSchemaValid)
                    {
                        _dataAdapter.SaveServiceInfo(_serviceInfo);
                    }
                }
            }, cancellationToken));
        }
Exemplo n.º 2
0
        internal void StartUp()
        {
            string moduleName = this.GetType().Assembly.GetName().Name;

            try
            {
                if (moduleName == "Framework")
                {
                    moduleName = "Dover Framework";
                }
                Logger.Info(String.Format(Messages.Starting, moduleName, this.GetType().Assembly.GetName().Version));
                var addins = licenseManager.ListAddins();
                dispatcher.RegisterEvents();
                StartFrameworkUI(); // load admin forms.
                addinManager.LoadAddins(addins);
                addinManager.Initialized = true;
                Logger.Info(String.Format(Messages.Started, moduleName, this.GetType().Assembly.GetName().Version));
            }
            catch (Exception e)
            {
                Logger.Fatal(string.Format(Messages.ErrorStartup, moduleName), e);
                Environment.Exit(10);
            }
        }