/// <summary> /// Opens a data model for the specified <see cref="ViewModel<TController, TModel>"/>. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="owner">The owner window.</param> /// <param name="openPath">The path from which to open.</param> public static void Open(ShellViewModel viewModel) { if (!(viewModel.SelectedViewModel is HomeViewModel)) { HomeViewModel homeVM = new HomeViewModel(viewModel); viewModel.PushViewModel(homeVM); } }
/// <summary> /// Opens a data model for the specified <see cref="ViewModel<TController, TModel>"/>. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="owner">The owner window.</param> /// <param name="openPath">The path from which to open.</param> public static void Open(ShellViewModel viewModel, Window owner) { if (viewModel.ConfigViewModel != null) { viewModel.PushViewModel(viewModel.ConfigViewModel); viewModel.SystemState = SystemState.EditConfiguration; viewModel.ShowMigrationView = MigrationStatusViews.Progress; } else { Utilities.HandleException(new Exception("Could not open configuration file."), false, "Open Error", "Invalid XML"); } }
/// <summary> /// Opens a data model for the specified <see cref="ViewModel<TController, TModel>"/>. /// </summary> /// <param name="viewModel">The view model.</param> public static void Open(ShellViewModel viewModel) { bool allowOpen = true; if (viewModel.SystemState == SystemState.MigrationProgress && !viewModel.CanStart) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(Properties.ShellResources.StopSessionEditConfiguration, Properties.ShellResources.StopSessionTitle, MessageBoxButton.YesNo, MessageBoxImage.Stop); if (messageBoxResult == MessageBoxResult.Yes) { if (viewModel.CanStop) { viewModel.Stop(); } else { allowOpen = false; Utilities.ShowError(Properties.Resources.CannotStopError, Properties.Resources.CannotStopCaption); } } else { allowOpen = false; } } if (allowOpen) { if (viewModel.ConfigViewModel != null) { viewModel.PushViewModel(viewModel.ConfigViewModel); } else { Utilities.HandleException(new Exception("Could not open configuration file."), false, "Open Error", "Invalid XML"); } } }
/// <summary> /// Opens a data model for the specified <see cref="ViewModel<TController, TModel>"/>. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="owner">The owner window.</param> /// <param name="openPath">The path from which to open.</param> public static void Open(ViewModel <TController, TModel> viewModel, Window owner, string openPath) { bool allowOpen = true; ShellViewModel shellVM = viewModel as ShellViewModel; if (shellVM != null && shellVM.SystemState == SystemState.MigrationProgress && !shellVM.CanStart) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(Properties.ShellResources.StopSessionNewMigration, Properties.ShellResources.StopSessionTitle, MessageBoxButton.YesNo, MessageBoxImage.Stop); if (messageBoxResult == MessageBoxResult.Yes) { if (shellVM.CanStop) { shellVM.Stop(); } else { allowOpen = false; Utilities.ShowError(Properties.Resources.CannotStopError, Properties.Resources.CannotStopCaption); } } else { allowOpen = false; } } if (allowOpen) { // Get the open path from the user if (string.IsNullOrEmpty(openPath)) { string currentDirectory = Environment.CurrentDirectory; // this is line X. line X and line Y are necessary for back-compat with windows XP. // NOTE: For now, use the WinForms OpenFileDialog since it supports the Vista style common open file dialog. OpenFileDialog openFileDialog = new OpenFileDialog(); string assemblyParentFolder = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); openFileDialog.InitialDirectory = Path.Combine(assemblyParentFolder, "Configurations"); openFileDialog.Filter = "Configuration file (*.xml)|*.xml"; openFileDialog.Title = "Choose a template"; //if (openFileDialog.ShowDialog (owner) == true) if (openFileDialog.ShowDialog() == DialogResult.OK) { openPath = openFileDialog.FileName; } Environment.CurrentDirectory = currentDirectory; // this is line Y. line X and line Y are necessary for back-compat with windows XP. } // Open the file if (!string.IsNullOrEmpty(openPath)) { viewModel.Open(openPath); if (shellVM != null) { shellVM.IsCompleted = false; shellVM.ClearViewModels(); shellVM.PushViewModel(new HomeViewModel(shellVM)); } } } }