/// <summary> /// Opens file dialog and if everything's fine, loads project from JSON file /// </summary> private void LoadProject() { try { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.ShowDialog(); string fileName = fileDialog.FileName; //TODO: Last used bitmap load FilterProject project = JsonConvert.DeserializeObject <FilterProject>(File.ReadAllText(fileName), jsonSerializerSettings); Filters.Clear(); foreach (FilterVMData data in project.filterData) { Filters.Add(new FilterVM(data)); } try { //load image at project path executionEngineVM.CurrentlyLoadedBitmap = new Bitmap(project.usedBitmapPath); } catch (FileNotFoundException) { } catch (ArgumentException) { } } catch (JsonException jex) { Debug.WriteLine("Could not parse project JSON file. Reason: " + jex.Message); } catch (IOException ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// Opens file dialog and if everything's fine, saves project to a JSON file /// </summary> private void SaveProject() { SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.ShowDialog(); string fileName = fileDialog.FileName; //TODO: Data save FilterProject project = new FilterProject(); project.usedBitmapPath = ExecutionEngineVM.currentlyLoadedBitmapPath; // project.usedBitmapPath = ExecutionEngineVM.CurrentlyLoadedBitmap.Save("") foreach (FilterVM vm in Filters) { project.filterData.Add(new FilterVMData(vm)); } string jsonContents = JsonConvert.SerializeObject(project, jsonSerializerSettings); Debug.WriteLine(jsonContents); File.WriteAllText(fileName, jsonContents); }