Пример #1
0
 public void SafeSave(string filePath, RulesSettings data)
 {
     try
     {
         string dataAsText = JsonConvert.SerializeObject(data, Formatting.Indented);
         fileSystem.File.WriteAllText(filePath, dataAsText);
         logger?.WriteLine(CoreStrings.Settings_SavedSettingsFile, filePath);
     }
     catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex))
     {
         logger?.WriteLine(CoreStrings.Settings_ErrorSavingSettingsFile, filePath, ex.Message);
     }
 }
Пример #2
0
        public RulesSettings SafeLoad(string filePath)
        {
            RulesSettings settings = null;

            if (!fileSystem.File.Exists(filePath))
            {
                logger?.WriteLine(CoreStrings.Settings_NoSettingsFile, filePath);
            }
            else
            {
                try
                {
                    logger?.WriteLine(CoreStrings.Settings_LoadedSettingsFile, filePath);
                    var data = fileSystem.File.ReadAllText(filePath);
                    settings = JsonConvert.DeserializeObject <RulesSettings>(data);
                }
                catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex))
                {
                    logger?.WriteLine(CoreStrings.Settings_ErrorLoadingSettingsFile, filePath, ex.Message);
                }
            }
            return(settings);
        }
Пример #3
0
 public UserSettings(RulesSettings rulesSettings)
 {
     this.RulesSettings = rulesSettings ?? throw new ArgumentNullException(nameof(rulesSettings));
 }