Esempio n. 1
0
        /// <summary>
        ///		Чтение настроек приложения из файла Config.config
        /// </summary>
        /// <returns></returns>
        public bool TryGetParamsFromFile()
        {
            if (!File.Exists("Config.config"))
            {
                _logger?.Log("Config not found. Ensure, it is exists in the application directory.",
                             OutputTarget.Console | OutputTarget.File);
                return(false);
            }

            var xFile = new XmlDocument();

            try
            {
                xFile.Load("Config.config");
                var xElement = xFile.DocumentElement;

                GetAdParams(xElement);
                GetBotParams(xElement);
                GetUsersParams(xElement);
            }
            catch (XPathException e)
            {
                _logger?.Log($"Error occured on reading params from Config: {e.Message}",
                             OutputTarget.Console | OutputTarget.File);
                return(false);
            }
            catch (XmlException e)
            {
                _logger?.Log($"Error occured on reading params Config: {e.Message}",
                             OutputTarget.Console | OutputTarget.File);
                return(false);
            }
            catch (IOException e)
            {
                _logger?.Log($"Error occured on reading file Config: {e.Message}",
                             OutputTarget.Console | OutputTarget.File);
                return(false);
            }
            catch (UnauthorizedAccessException e)
            {
                _logger?.Log($"Error occured on reading file Config: {e.Message}",
                             OutputTarget.Console | OutputTarget.File);
                return(false);
            }

            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(UserPassword) ||
                string.IsNullOrEmpty(ServerAddress) || string.IsNullOrEmpty(TelegramBotToken))
            {
                _logger?.Log("Ensure, Config has correct parameters inside.", OutputTarget.Console | OutputTarget.File);
                return(false);
            }

            OnConfigUpdated?.Invoke(this);
            return(true);
        }
Esempio n. 2
0
 public void SetMaxWorker(int numberOfWorker)
 {
     Config.MaxWorkers = numberOfWorker;
     OnConfigUpdated?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 3
0
 /// <inheritdoc/>
 public void TriggerConfigUpdate(object sender, EventArgs eventArgs)
 {
     OnConfigUpdated?.Invoke(sender, eventArgs);
 }