/// <summary> /// This method loads the old app state. /// </summary> private void LoadOldAppState() { this.ZoomVM = new ZoomVM(); var filePath = Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).ToString()).ToString(); filePath = filePath + @"\app.dat"; MasterVMContainer b = ApplicationSerealizer.Load(filePath); if (b != null) { this.Grid = new GridVM(b.GridVMContainer); this.FunctionListVM = new FunctionListVM(b.FunctionalListVMContainer, this.Grid.SmallestXValue, this.Grid.BigestXValue, this.Grid.SmallestYValue, this.Grid.BigestYValue); } else { this.Grid = new GridVM(); this.FunctionListVM = new FunctionListVM(); this.FunctionListVM.SmallestXValueGrid = this.Grid.SmallestXValue; this.FunctionListVM.BigestXValueGrid = this.Grid.BigestXValue; this.FunctionListVM.SmallestYValueGrid = this.Grid.SmallestYValue; this.FunctionListVM.BigestYValueGrid = this.Grid.BigestYValue; } this.Grid.OnXYValueChanged += this.FunctionListVM.ChangeXYValueGrid; this.FunctionListVM.OnYMinChanged += this.Grid.ChangeYMinValue; this.FunctionListVM.OnYMaxChanged += this.Grid.ChangeYMaxValue; this.ZoomVM.OnXYChanged += this.Grid.Zoom; this.FunctionListVM.DrawNewPolyLines(); }
/// <summary> /// Saves the current application status to the file path. /// </summary> /// <param name="filePath"> The path to the file. </param> /// <param name="objToSerialize"> The object to be serialized. </param> public static void Save(string filePath, MasterVMContainer objToSerialize) { try { using (Stream stream = File.Open(filePath, FileMode.Create)) { BinaryFormatter bin = new BinaryFormatter(); bin.Serialize(stream, objToSerialize); } } catch (Exception e) { throw new ArgumentException("Error: " + e); } }