override public void SaveConfig() { try { string filename = GetStateConfigFileName(DlgMode); SaveUserSettings(savedTreeState.UserSettings); savedTreeState.NodeStates = treeControl.Nodes.GetExpansionState(); string newConfigStr = JsonSerializeHelper.SaveToString(savedTreeState); if (newConfigStr.Equals(configFileStr) == false) { File.WriteAllText(filename, newConfigStr, Encoding.UTF8); configFileStr = newConfigStr; } } catch (Exception ex) { Log.LogError("Can not write config for " + GetType().ToString(), ex); } }
protected void SaveConfig() { //todo - do not save if not modified CloseAllHiddenContents(); FrwConfig.Instance.SetPropertyValue(FrwSimpleWinCRUDConfig.APPLICATION_FONT, Font); string configFile = GetContentConfigFileName(); MemoryStream xmlStream = new MemoryStream(); dockPanel.SaveAsXml(xmlStream, Encoding.UTF8); string newConfigLayoutStr = Encoding.UTF8.GetString(xmlStream.ToArray()); if (newConfigLayoutStr.Equals(configLayoutStr) == false) { File.WriteAllText(configFile, newConfigLayoutStr); configLayoutStr = newConfigLayoutStr; //Log.ProcessDebug("@@@@@ Saved config for main window " + DocPanelIndex); } //////////////////////////////////////////////// try { string filename = GetStateConfigFileName(); DocPanelState state = new DocPanelState(); SaveUserSettings(state.UserSettings); string newConfigStr = JsonSerializeHelper.SaveToString(state); if (newConfigStr.Equals(configFileStr) == false) { File.WriteAllText(filename, newConfigStr, Encoding.UTF8); configFileStr = newConfigStr; //Log.ProcessDebug("@@@@@ Saved json config for main window " + DocPanelIndex); } } catch (Exception ex) { Log.LogError("Can not write config for " + GetType().ToString(), ex); } }
/// <summary> /// Saves all user settings /// </summary> public void SaveConfig() { foreach (var s in settings.Values) { if (s.Value != null && s.ValueType == null) { s.ValueType = s.Value.GetType(); } if (s.Value != null) { if (s.ValueType != typeof(string)) { JEntity entityAttr = AttrHelper.GetClassAttribute <JEntity>(s.ValueType); if (entityAttr != null) { if (s.AllowMultiValues) { IList list = (IList)s.Value; IList values = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(s.ValueType)); foreach (var realObject in list) { values.Add(AttrHelper.ReplaceObjectByPkOnlyObject(realObject)); } s.Value = values; } else { s.Value = AttrHelper.ReplaceObjectByPkOnlyObject(s.Value); } } else { TypeConverter converter = TypeDescriptor.GetConverter(s.ValueType); if (converter != null) { s.Value = converter.ConvertToString(s.Value); } } } } } string filename = Path.Combine(ProfileConfigDir, settingsFileName); FileInfo fileInfo = new FileInfo(filename); DirectoryInfo dir = fileInfo.Directory; if (dir.Exists == false) { Directory.CreateDirectory(dir.FullName); } List <JSetting> settingsList = new List <JSetting>(); foreach (var s in settings.Values) { if (!s.IsAttachedToComputer) { settingsList.Add(s); } } JsonSerializeHelper.SaveToFile(settingsList, filename); //stage 2 filename = Path.Combine(ComputerUserDir, settingsFileName); fileInfo = new FileInfo(filename); dir = fileInfo.Directory; if (dir.Exists == false) { Directory.CreateDirectory(dir.FullName); } settingsList = new List <JSetting>(); foreach (var s in settings.Values) { if (s.IsAttachedToComputer) { settingsList.Add(s); } } File.WriteAllText(filename, JsonSerializeHelper.SaveToString(settingsList), Encoding.UTF8);//short }
/// <summary> /// Loads all user settings. /// </summary> public void LoadConfig() { string filename = Path.Combine(ProfileConfigDir, settingsFileName); FileInfo fileInfo = new FileInfo(filename); DirectoryInfo dir = fileInfo.Directory; if (dir.Exists == false) { Directory.CreateDirectory(dir.FullName); } if (fileInfo.Exists) { List <JSetting> settingsList = null; settingsList = JsonSerializeHelper.LoadFromFile <List <JSetting> >(filename); foreach (var s in settingsList) { s.IsAttachedToComputer = false; settings.Add(s.Name, s); } } //Properties.Settings.Default path //https://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx //stage 2 if (ComputerUserDir != null) { filename = Path.Combine(ComputerUserDir, settingsFileName); fileInfo = new FileInfo(filename); dir = fileInfo.Directory; if (dir.Exists == false) { Directory.CreateDirectory(dir.FullName); } if (fileInfo.Exists) { List <JSetting> settingsList = null; settingsList = JsonSerializeHelper.LoadFromFile <List <JSetting> >(filename); foreach (var s in settingsList) { s.IsAttachedToComputer = true; settings[s.Name] = s; } } } foreach (JSetting setting in settings.Values) { if (setting.Value != null) { Type type = setting.ValueType; if (type != null) { if (type != typeof(string)) { JEntity entityAttr = AttrHelper.GetClassAttribute <JEntity>(type); if (entityAttr != null) { if (setting.AllowMultiValues) { IList list = (IList)setting.Value; IList values = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(type)); foreach (var pkOnlyObject in list) { string str = JsonSerializeHelper.SaveToString(pkOnlyObject); object realObject = JsonSerializeHelper.LoadFromString(str, type); values.Add(realObject); } setting.Value = values; } else { setting.Value = JsonSerializeHelper.LoadFromString(JsonSerializeHelper.SaveToString(setting.Value), type); } } else { TypeConverter converter = TypeDescriptor.GetConverter(type); if (converter != null)//for system types (Font, etc.) { setting.Value = converter.ConvertFromString((string)setting.Value); } } } } } } CreateProperties(); }