private void DoSaveCommand() { SaveFileDialog saveFileDialog = new SaveFileDialog(); if (saveFileDialog.ShowDialog() == true) { MainModelDto mainModelDto = new MainModelDto { CodedFilters = CodedFilters.Select(x => new CodedFilterDto { Name = x.Name, Code = x.Code }).ToList(), InputFilePaths = FilteredImages.Select(x => x.InputFilePath).ToList() }; File.WriteAllText(saveFileDialog.FileName, JsonConvert.SerializeObject(mainModelDto)); } }
private void DoLoadCommand() { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { MainModelDto mainModelDto = JsonConvert.DeserializeObject <MainModelDto>(File.ReadAllText(openFileDialog.FileName)); for (int i = CodedFilters.Count - 1; i >= 0; i--) { CodedFilters.RemoveAt(i); } for (int i = FilteredImages.Count - 1; i >= 0; i--) { foreach (FilteredImage filteredImage in FilteredImages[i].Images) { filteredImage.UnmanagedImage = null; } FilteredImages.RemoveAt(i); } foreach (CodedFilterDto codedFilterDto in mainModelDto.CodedFilters) { CodedFilters.Add(new CodedFilter { Name = codedFilterDto.Name, Code = codedFilterDto.Code }); } foreach (string inputFilePath in mainModelDto.InputFilePaths) { FilteredImages.Add(new FilteredImages(CodedFilters.Count) { InputFilePath = inputFilePath }); } } }