private static void BinDeserializeThisFrom(this ResizerHotkeyList rhkList_in, string fileName_in) { BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream(fileName_in, FileMode.Open)) rhkList_in.AddRange((ResizerHotkeyList)formatter.Deserialize(fs)); }
private static void XmlDeserializeThisFrom(this ResizerHotkeyList rhkList_in, string fileName_in) { XmlSerializer mySerializer = new XmlSerializer(typeof(ResizerHotkeyList)); using (FileStream myFileStream = new FileStream(fileName_in, FileMode.Open)) rhkList_in.AddRange((ResizerHotkeyList)mySerializer.Deserialize(myFileStream)); }
//public static void SerializeThis(this ResizerHotkeyList rhkList_in) //{ // String s = JSON.Instance.ToJSON(rhkList_in); //} private static void BinSerializeThisTo(this ResizerHotkeyList rhkList_in, string fileName_in) { BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream(fileName_in, FileMode.Create)) formatter.Serialize(fs, rhkList_in); }
private static void XmlSerializeThisTo(this ResizerHotkeyList rhkList_in, string fileName_in) { XmlSerializer mySerializer = new XmlSerializer(typeof(ResizerHotkeyList)); using (StreamWriter myWriter = new StreamWriter(fileName_in)) mySerializer.Serialize(myWriter, rhkList_in); }
public static void Init(this ResizerHotkeyList rhkList_in) { FileInfo BinaryOptionsFileInfo = new FileInfo(BinaryOptionsFilePath); FileInfo XmlOptionsFileInfo = new FileInfo(XmlOptionsFilePath); try { if (XmlOptionsFileInfo.Exists) { rhkList_in.DeserializeThisFrom(XmlOptionsFilePath, ESerializationType.Xml); } else if (BinaryOptionsFileInfo.Exists) { rhkList_in.DeserializeThisFrom(BinaryOptionsFilePath, ESerializationType.Binary); } else { rhkList_in.SetToDefault(); } } catch (Exception) { Application.Current.Dispatcher.BeginInvoke(new Action(delegate() { System.Windows.Forms.MessageBox.Show("Resizer Hotkey Init Error"); })); rhkList_in.SetToDefault(); } }
public static void DeserializeThisFrom(this ResizerHotkeyList rhkList_in, string fileName_in, ESerializationType serializationType_in) { switch (serializationType_in) { case ESerializationType.Binary: BinDeserializeThisFrom(rhkList_in, fileName_in); break; case ESerializationType.Xml: XmlDeserializeThisFrom(rhkList_in, fileName_in); break; case ESerializationType.Json: throw new NotImplementedException(); default: throw new InvalidOperationException(); } }
public static void SetToDefault(this ResizerHotkeyList rhkList) { rhkList.Clear(); bool isError = false; StringBuilder sbError = new StringBuilder(); foreach (Alignment wp in _posCommandKey.Keys) { ResizerHotKey hk = new ResizerHotKey(); foreach (Forms.Keys key in _posCommandKey[wp]) { try { hk.Add(_defaultModifiers, key); } catch (HotkeyAlreadyInUseException ex) { sbError.AppendFormat("Couldn't register: \"{0} + {1}\" hotkey. It won't work\r\n", _defaultModifiers, key); isError = true; } } if (hk.Count != 0) { foreach (double portion in _portions) { hk.ResizeStates.Add(new ResizerHotkeyState(wp.horizontalAlignment, wp.verticalAlignment, portion)); } rhkList.Add(hk); } } if (isError) { Application.Current.Dispatcher.BeginInvoke(new Action(delegate() { System.Windows.Forms.MessageBox.Show(sbError.ToString()); })); } }
public static void DeserializeThisFrom(this ResizerHotkeyList rhkList_in, string fileName_in) { DeserializeThisFrom(rhkList_in, fileName_in, ESerializationType.Binary); }
public static void Save(this ResizerHotkeyList rhkList_in) { rhkList_in.SerializeThisTo(BinaryOptionsFilePath, ESerializationType.Binary); rhkList_in.SerializeThisTo(XmlOptionsFilePath, ESerializationType.Xml); }