Пример #1
0
 public SerializationMixin(
     Diagram diagram,
     MessageSystem messageSystem,
     ApplicationSettings applicationSettings)
 {
     _diagram = diagram;
     _messageSystem = messageSystem;
     _applicationSettings = applicationSettings;
     _fileName = applicationSettings.LastFile;
 }
Пример #2
0
 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);
     }
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
 public void New()
 {
     _fileName = null;
     _diagram.Reset();
     _messageSystem.Publish(_diagram.Classifiers, new ClassifiersResetEvent());
 }
Пример #5
0
        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);
                }
            }
        }