public SerializationMixin( Diagram diagram, MessageSystem messageSystem, ApplicationSettings applicationSettings) { _diagram = diagram; _messageSystem = messageSystem; _applicationSettings = applicationSettings; _fileName = applicationSettings.LastFile; }
public void Load(string applicationSettingsPath) { var settingsFile = new FileName(applicationSettingsPath); _settingFilePath = settingsFile; // return default settings in case // file could not be loaded if (!settingsFile.IsValid) return; try { var content = System.IO.File.ReadAllText(settingsFile.Value); var settings = new JsonApplicationSettingSerializer().Load(new JsonContent(content)); // reset the newly loaded settings _data = settings; } catch (Exception) { // we could not load the settings, so return // default settings _data = new ApplicationSettingsDataMixin(_settingFilePath.Value); } }
public void Save() { if (_fileName == null) { var saveFileDialog = new SaveFileDialog { Filter = EditorStrings.UmlJsonFileFilter, InitialDirectory = GetFolderPath(SpecialFolder.MyDocuments) }; if (saveFileDialog.ShowDialog() == true) { _fileName = new FileName(saveFileDialog.FileName); StoreProjectFileName(); } } // user has not choosen any file, so skip here if (_fileName == null) return; var jsonContent = new JsonSerializer().Save(_diagram); try { System.IO.File.WriteAllText( _fileName.ToString(), jsonContent.ToString()); } catch (Exception ex) { MessageBox.Show( string.Format(EditorStrings.SaveFileError, ex.Message), EditorStrings.Save, MessageBoxButton.OK, MessageBoxImage.Error); } }
public void New() { _fileName = null; _diagram.Reset(); _messageSystem.Publish(_diagram.Classifiers, new ClassifiersResetEvent()); }
public void Open() { var path = _fileName?.Path; // use the path of the last file or use default path path = System.IO.Directory.Exists(path) ? path : GetFolderPath(SpecialFolder.MyDocuments); var openFileDialog = new OpenFileDialog { Filter = EditorStrings.UmlJsonFileFilter, InitialDirectory = path }; if (openFileDialog.ShowDialog() == true) { _fileName = new FileName(openFileDialog.FileName); try { LoadFile(); // update the application settings StoreProjectFileName(); } catch (Exception ex) { MessageBox.Show( string.Format(EditorStrings.OpenFileError, ex.Message), EditorStrings.Open, MessageBoxButton.OK, MessageBoxImage.Error); } } }