public static void CopyTo(this DAO.ServiceInfo dao, ServiceInfo obj)
        {
            #region Validate parameters
            if (dao == null)
            {
                throw new ArgumentNullException("dao");
            }

            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            #endregion

            obj.AuthorizeEnabled = (dao.AuthorizeEnabled == null ? false : dao.AuthorizeEnabled.Value);
            obj.DebugEnabled     = (dao.DebugEnabled == null ? false : dao.DebugEnabled.Value);
            obj.ExternalAddress  = dao.ExternalAddress;
            obj.InstanceID       = dao.InstanceID;
            obj.InternalAddress  = dao.InternalAddress;
            obj.LINK             = dao.LINK;
            obj.MaxUploadSize    = dao.MaxUploadSize;
            obj.Online           = (dao.Online == null ? false : dao.Online.Value);
            //obj.Properties = dao.Properties.Select(prop => prop.ToObj()).ToArray();
            obj.ServiceName    = dao.ServiceName;
            obj.ShutdownReason = dao.ShutdownReason;
            obj.ShutdownTime   = dao.ShutdownTime;
            obj.StartTime      = (dao.StartTime ?? DateTime.MinValue);
            obj.Version        = dao.Version;
        }
        ///// <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));
        }
        public static DAO.ServiceInfo ToDao(this ServiceInfo obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var dao = new DAO.ServiceInfo();

            dao.AuthorizeEnabled = (obj.AuthorizeEnabled == false ? new Nullable <bool>() : obj.AuthorizeEnabled);
            dao.DebugEnabled     = (obj.DebugEnabled == false ? new Nullable <bool>() : obj.DebugEnabled);
            dao.ExternalAddress  = (String.IsNullOrEmpty(obj.ExternalAddress) ? null : obj.ExternalAddress);
            dao.InstanceID       = obj.InstanceID;
            dao.InternalAddress  = (String.IsNullOrEmpty(obj.InternalAddress) ? null : obj.InternalAddress);
            dao.LINK             = obj.LINK;
            dao.MaxUploadSize    = obj.MaxUploadSize;
            dao.Online           = (obj.Online == false ? new Nullable <bool>() : obj.Online);
            //dao.Properties = obj.Properties.Select(prop => prop.ToDao(dao)).ToList();
            dao.ServiceName    = obj.ServiceName;
            dao.ShutdownReason = (String.IsNullOrEmpty(obj.ShutdownReason) ? null : obj.ShutdownReason);
            dao.ShutdownTime   = obj.ShutdownTime;
            dao.StartTime      = obj.StartTime;
            dao.Version        = obj.Version;

            return(dao);
        }