예제 #1
0
        public void CreateSampleSettingsFile()
        {
            var defaultEmailSettingsList = new List <EmailSettings> {
                EmailSettings.CreateSample()
            };
            var defaultSettings         = new ProgramSettings(defaultEmailSettingsList);
            var defaultSettingsFilePath = Properties.Resources.ResourceManager.GetString("SettingsFilename");

            var fileAvailabilityValidator = new SettingsFileAvailabilityValidator();
            var validationResult          = fileAvailabilityValidator.Validate(defaultSettingsFilePath);

            if (!validationResult.IsValid)
            {
                foreach (var failure in validationResult.Errors)
                {
                    _logger.LogError(failure.ErrorMessage);
                }
            }

            File.WriteAllText(defaultSettingsFilePath, JObject.FromObject(defaultSettings).ToString());
            _logger.LogInformation(
                $"Создан образец файла настроек {defaultSettingsFilePath}. Измените настройки и перезапустите программу.");
        }