override public void SaveConfig() { try { string filename = GetStateConfigFileName(DlgMode); OLVStateAdv state = new OLVStateAdv(); SaveUserSettings(state.UserSettings); if (listView != null) { OLVHelper.SaveStateAdvanced(listView, state); } state.HotItemStyle = HotItemStyle; //use save with defaults (sort column = 0); string newConfigStr = JsonSerializeHelper.SaveToStringWithNullAndDefaultValues(state); if (newConfigStr.Equals(configFileStr) == false) { File.WriteAllText(filename, newConfigStr, Encoding.UTF8); configFileStr = newConfigStr; //Log.ProcessDebug("@@@@@ Saved config for OLV list " + SourceObjectType); } } catch (Exception ex) { Log.LogError("Can not write config for " + GetType().ToString(), ex); } }
private void LoadConfig() { try { string filename = null; if (DlgMode) { filename = GetStateConfigFileName(true); if (!File.Exists(filename)) { filename = GetStateConfigFileName(false); } } else { filename = GetStateConfigFileName(false); } if (File.Exists(filename)) { configFileStr = File.ReadAllText(filename, Encoding.UTF8); savedTreeState = JsonSerializeHelper.LoadFromString <TreeListState>(configFileStr); } else { savedTreeState = new TreeListState(); } LoadUserSettings(savedTreeState.UserSettings); } catch (Exception ex) { Log.LogError("Can not read config for " + GetType().ToString(), ex); } }
private void LoadConfig() { try { string filename = null; if (DlgMode) { filename = GetStateConfigFileName(true); if (!File.Exists(filename)) { filename = GetStateConfigFileName(false); } } else { filename = GetStateConfigFileName(false); } if (File.Exists(filename)) { configFileStr = File.ReadAllText(filename, Encoding.UTF8); OLVStateAdv state = JsonSerializeHelper.LoadFromString <OLVStateAdv>(configFileStr); if (listView != null) { OLVHelper.RestoreStateAdvanced(listView, state); } HotItemStyle = state.HotItemStyle; OLVHelper.SetHotItemStyle(listView, HotItemStyle); LoadUserSettings(state.UserSettings); } } catch (Exception ex) { Log.LogError("Can not read config for " + GetType().ToString(), ex); } }
private SData LoadEntityFromDisk(Type t) { JEntity entityAttr = AttrHelper.GetClassAttribute <JEntity>(t); if (entityAttr.DsType != typeof(JsonDs)) { throw new InvalidOperationException("Not a json file stored entity"); } //long tstart = DateTime.Now.Ticks; SData sdata = new SData() { DataType = t }; Type lt = typeof(List <>); Type listType = lt.MakeGenericType(t); object list = null; string filename = GetDataFilePathForType(t); FileInfo fileInfo = new FileInfo(filename); if (fileInfo.Exists) { list = JsonSerializeHelper.LoadForType(filename, listType); } else { list = Activator.CreateInstance(listType); } foreach (var x in (IList)list) { INotifyPropertyChanged notifier = x as INotifyPropertyChanged; if (notifier != null) { notifier.PropertyChanged += Notifier_PropertyChanged; } } PropertyInfo pkProp = AttrHelper.GetProperty <JPrimaryKey>(t); if (pkProp != null) { foreach (var o in (IList)list) { object pk = pkProp.GetValue(o); try { sdata.PkCache.Add(pk, o); } catch (ArgumentException ex) { Log.ProcessDebug("Dublicate pk entity: " + t + " pk value: " + pk + " Error text: " + ex); } } } sdata.DataList = list; sdatas.Add(sdata); return(sdata); }
protected JoinEntityData FindAllJoinData(Type t1, Type t2, string joinTableName) { JoinEntityData joinData = GetJoinData(t1, t2, joinTableName); if (joinData == null) { long tstart = DateTime.Now.Ticks; //sort before add TypeComparer typeComparer = new TypeComparer(); Type[] ts = new Type[] { t1, t2 }; Array.Sort(ts, typeComparer); joinData = new JoinEntityData() { DataType1 = ts[0], DataType2 = ts[1], JoinTableName = joinTableName }; var listType = typeof(List <JoinEntityDataItem>); List <JoinEntityDataItem> list = null; string filename = Path.Combine(Path.Combine(FrwConfig.Instance.ProfileDir, DATA_STORAGE), joinData.DataType1.FullName + "_" + joinData.DataType2.FullName + (joinTableName != null ? ("_" + joinTableName) : "") + ".json"); FileInfo fileInfo = new FileInfo(filename); if (fileInfo.Exists) { list = JsonSerializeHelper.LoadForType(filename, listType); } else { list = (List <JoinEntityDataItem>)Activator.CreateInstance(listType); } joinData.DataList = list; long tstartConvert = DateTime.Now.Ticks; PropertyInfo pkProp1 = AttrHelper.GetProperty <JPrimaryKey>(joinData.DataType1); if (pkProp1.PropertyType != typeof(string)) { foreach (var l in joinData.DataList) { l.Pk1 = JsonSerializeHelper.DeserializeString(l.Pk1.ToString(), pkProp1.PropertyType); } } PropertyInfo pkProp2 = AttrHelper.GetProperty <JPrimaryKey>(joinData.DataType1); if (pkProp2.PropertyType != typeof(string)) { foreach (var l in joinData.DataList) { l.Pk2 = JsonSerializeHelper.DeserializeString(l.Pk2.ToString(), pkProp2.PropertyType); } } joinDatas.Add(joinData); long tend = DateTime.Now.Ticks; //Log.ProcessDebug("======= Loaded join data : " + sdata.DataType1 + " " + sdata.DataType2 + " Count: " + ((IList)list).Count + " Time: " + (tend - tstart) / 10000 + " mils" + " include time converting: " + (tend - tstartConvert) / 10000 + " mils"); } return(joinData); }
private void SaveJoinEntityDataLocal(JoinEntityData s) { string dirPath = Path.Combine(FrwConfig.Instance.ProfileDir, DATA_STORAGE); DirectoryInfo dir = new DirectoryInfo(dirPath); if (dir.Exists == false) { Directory.CreateDirectory(dir.FullName); } string filename = Path.Combine(dirPath, s.DataType1.FullName + "_" + s.DataType2.FullName + ".json"); object list = s.DataList; JsonSerializeHelper.SaveToFile(list, filename); s.Modified = false; }
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); } }
private void SaveEntityDataLocal(IList list, Type type, string customDirPath) { string filename = GetDataFilePathForType(type, customDirPath); var lt = typeof(List <>); var listType = lt.MakeGenericType(type); IList alist = (IList)Activator.CreateInstance(listType); foreach (object v in list) { object av = Dm.CloneObject(v, CloneObjectType.ForSave); alist.Add(av); } // if (alist.Count > 5000)//todo better check size { JsonSerializeHelper.SaveToFileLageData(alist, filename); } else { JsonSerializeHelper.SaveToFile(alist, filename); } }
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); } }
protected void LoadConfig() { ///////////////////////////////////////////////// try { string filename = GetStateConfigFileName(); if (File.Exists(filename)) { configFileStr = File.ReadAllText(filename, Encoding.UTF8); DocPanelState state = JsonSerializeHelper.LoadFromString <DocPanelState>(configFileStr); LoadUserSettings(state.UserSettings); } } catch (Exception ex) { Log.LogError("Can not read config for " + GetType().ToString(), ex); } string configFile = GetContentConfigFileName(); if (File.Exists(configFile)) { configLayoutStr = File.ReadAllText(configFile); Stream xmlStream = new MemoryStream(Encoding.UTF8.GetBytes(configLayoutStr)); dockPanel.LoadFromXml(xmlStream, m_deserializeDockContent); //xmlStream.Close(); } try { // Font installation for all forms WinFormsUtils.SetNewControlFont(this, (Font)FrwConfig.Instance.GetPropertyValue(FrwSimpleWinCRUDConfig.APPLICATION_FONT));//if this.AutoScaleMode = Font - Setting the font will change the size of the window } catch (Exception ex) { Log.LogError("Can not set font ", 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(); }