private DialogResult GetApplicationFileFromUI()
        {
            ApplicationConfigurationNode node = (ApplicationConfigurationNode)ServiceHelper.GetCurrentRootNode(ServiceProvider);
            SaveFileDialog dialog             = new SaveFileDialog();

            dialog.Filter = SR.ConfigurationFileDialogFilter;
            dialog.Title  = System.String.Concat(SR.SaveApplicationCaption, " : ", node.Name);
            IUIService uiService = ServiceHelper.GetUIService(ServiceProvider);

            System.Windows.Forms.DialogResult result = uiService.ShowSaveDialog(dialog);
            if (System.Windows.Forms.DialogResult.OK == result)
            {
                FileName = dialog.FileName;
                node.ConfigurationFile = FileName;
                node.Hierarchy.StorageTable.MetaConfigurationFile = FileName;
            }
            return(result);
        }
        /// <summary>
        /// Determines if the current <see cref="FileName"/> can be overwrriten. It will prompt the user throuth the user interface if the user wants to overwrite the file.
        /// </summary>
        /// <returns>
        /// <see langword="true"/> if the file can be overwritten; otherwise, <see langword="false"/>.
        /// </returns>
        protected bool CanOverwriteFile()
        {
            if (IsFileReadOnly(fileName))
            {
                IUIService uiService = ServiceHelper.GetUIService(ServiceProvider);

                DialogResult result = uiService.ShowMessage(string.Format(CultureInfo.CurrentUICulture, Resources.OverwriteFileMessage, fileName), Resources.OverwriteFileCaption, System.Windows.Forms.MessageBoxButtons.YesNo);
                if (DialogResult.Yes == result)
                {
                    ChangeFileAttributesToWritable(fileName);
                }
                else
                {
                    ServiceHelper.LogError(ServiceProvider, new ConfigurationError(null, Resources.ExceptionFilesNotSaved));
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// <para>Determines if the current <see cref="FileName"/> can be overwrriten. It will prompt the user throuth the user interface if the user wants to overwrite the file.</para>
 /// </summary>
 /// <returns>
 /// <para><see langword="true"/> if the file can be overwritten; otherwise, <see langword="false"/>.</para>
 /// </returns>
 protected bool CanOverwriteFile()
 {
     if (FileHelper.IsFileReadOnly(fileName))
     {
         IUIService   uiService = ServiceHelper.GetUIService(ServiceProvider);
         DialogResult result    = uiService.ShowMessage(SR.OverwriteFileMessage(fileName), SR.OverwriteFileCaption, System.Windows.Forms.MessageBoxButtons.YesNo);
         if (DialogResult.Yes == result)
         {
             FileHelper.ChangeFileAttributesToWritable(fileName);
         }
         else
         {
             IConfigurationErrorLogService logService = ServiceHelper.GetConfigurationErrorService(ServiceProvider);
             logService.LogError(new ConfigurationError(null, SR.ExceptionFilesNotSaved));
             return(false);
         }
     }
     return(true);
 }
        private DialogResult GetApplicationFileFromUI()
        {
            ConfigurationApplicationNode node = (ConfigurationApplicationNode)ServiceHelper.GetCurrentRootNode(ServiceProvider);
            SaveFileDialog dialog             = new SaveFileDialog();

            dialog.Filter = Resources.ConfigurationFileDialogFilter;
            dialog.Title  = System.String.Concat(Resources.SaveApplicationCaption, " : ", node.Name);
            IUIService uiService = ServiceHelper.GetUIService(ServiceProvider);

            System.Windows.Forms.DialogResult result = uiService.ShowSaveDialog(dialog);
            Application.DoEvents();
            // we need this because the wait cursor gets set back by the save dialog
            Cursor.Current = Cursors.WaitCursor;
            if (System.Windows.Forms.DialogResult.OK == result)
            {
                DeleteFileIfItExists(dialog.FileName);
                FileName = dialog.FileName;
                node.ConfigurationFile = FileName;
                node.Hierarchy.StorageService.ConfigurationFile = FileName;
                uiService.RefreshPropertyGrid();
            }
            return(result);
        }