Esempio n. 1
0
        /// <summary>
        /// Opens a data model for the specified <see cref="ViewModel&lt;TController, TModel&gt;"/>.
        /// </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));
                    }
                }
            }
        }