コード例 #1
0
        /// <summary>
        /// Saves the 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>
        /// <returns>
        ///     <c>true</c> if the data model is saved; otherwise, <c>false</c>.
        /// </returns>
        public static bool SaveAs(ViewModel <TController, TModel> viewModel, Window owner)
        {
            string currentDirectory = Environment.CurrentDirectory; // this is line X.  line X and line Y are necessary for back-compat with windows XP.

            // Get the save path from the user
            // NOTE: For now, use the WinForms SaveFileDialog since it supports the Vista style common save file dialog.
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter   = "Configuration file (*.zip)|*.zip";
            saveFileDialog.FileName = viewModel.Title;

            bool succeeded = false;

            //if (saveFileDialog.ShowDialog (owner) == true)
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Environment.CurrentDirectory = System.IO.Path.GetTempPath();

                string tempFileName = "_Configuration.xml";
                succeeded = viewModel.Save(tempFileName);
                ZipUtility.Zip(saveFileDialog.FileName, new string[] { tempFileName });
                File.Delete(tempFileName);
            }
            else
            {
                succeeded = false;
            }

            Environment.CurrentDirectory = currentDirectory; // this is line Y.  line X and line Y are necessary for back-compat with windows XP.
            return(succeeded);
        }
コード例 #2
0
        /// <summary>
        /// Saves the 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="savePath">The path to the file to which to save.</param>
        /// <returns>
        ///     <c>true</c> if the data model is saved; otherwise, <c>false</c>.
        /// </returns>
        public static bool Save(ViewModel <TController, TModel> viewModel, Window owner, string savePath)
        {
            // Get the save path from the controller
            if (string.IsNullOrEmpty(savePath))
            {
                savePath = viewModel.Controller.SavePath;
            }

            // Save using the save path
            if (!string.IsNullOrEmpty(savePath))
            {
                return(viewModel.Save(savePath));
            }

            // No save path specified - fall back to SaveAs
            return(SaveAsCommand <TController, TModel> .SaveAs(viewModel, owner));
        }