示例#1
0
        private bool TryAndSaveApplication(ConfigurationNode node)
        {
            SaveConfigurationApplicationNodeCommand cmd = new SaveConfigurationApplicationNodeCommand(ServiceProvider);

            cmd.Execute(node);
            return(cmd.SaveSucceeded);
        }
 private bool TryAndSaveApplication(ConfigurationNode node)
 {
     SaveConfigurationApplicationNodeCommand cmd = new SaveConfigurationApplicationNodeCommand(ServiceProvider);
     cmd.Execute(node);
     return cmd.SaveSucceeded;
 }
        private bool EnsureMainHierarchyIsSaved(IConfigurationUIHierarchy configurationHierarchy, IServiceProvider serviceProvider)
        {
            if (String.IsNullOrEmpty(configurationHierarchy.RootNode.ConfigurationFile))
            {
                IUIService uiService = ServiceHelper.GetUIService(serviceProvider);

                if (DialogResult.Yes
                    == uiService.ShowMessage(
                        Resources.SaveConfigurationFileBeforeEnvironmentMerge,
                        Resources.GenericDialogCaption,
                        MessageBoxButtons.YesNo))
                {
                    SaveConfigurationApplicationNodeCommand saveApplicationNodeCommand
                        = new SaveConfigurationApplicationNodeCommand(serviceProvider);
                    saveApplicationNodeCommand.Execute(configurationHierarchy.RootNode);

                    return saveApplicationNodeCommand.SaveSucceeded;
                }
                return false;
            }
            return true;
        }
        /// <summary>
        /// Performs the merging of configuration, given a specific <see cref="EnvironmentNode"/>.
        /// </summary>
        /// <param name="node">The <see cref="EnvironmentNode"/> this command should be executed on.</param>
        protected override void ExecuteCore(ConfigurationNode node)
        {
            EnvironmentNode environmentNode = node as EnvironmentNode;
            if (environmentNode != null)
            {
                if (EnsureMainHierarchyIsSaved(node.Hierarchy, node.Site))
                {
                    EnvironmentMergeAware environmentMergeService
                        = node.Site.GetService(typeof(EnvironmentMergeAware)) as EnvironmentMergeAware;

                    string originalFilePath = Path.GetFullPath(node.Hierarchy.RootNode.ConfigurationFile);
                    string originalDirectoryPath = Path.GetDirectoryName(originalFilePath);
                    environmentMergeService.SetEnvironmentalMergeInProgress(true);

                    try
                    {
                        UIService.BeginUpdate();

                        Dictionary<string, ConfigurationNodeMergeData> mergeDataByPath
                            = environmentNode.EnvironmentMergeData.UnfoldMergeData(environmentNode.Hierarchy, false);

                        string temporaryFilepath = Path.GetTempFileName();
                        bool temporarySaveSuccessful = false;
                        try
                        {
                            UpdateConfigurationSource(node.Hierarchy, temporaryFilepath);

                            SaveConfigurationApplicationNodeCommand saveConfigurationNodeCommand
                                = new SaveConfigurationApplicationNodeCommand(ServiceProvider);
                            saveConfigurationNodeCommand.Execute(ServiceHelper.GetCurrentRootNode(ServiceProvider));
                            temporarySaveSuccessful = saveConfigurationNodeCommand.SaveSucceeded;
                        }
                        finally
                        {
                            UpdateConfigurationSource(node.Hierarchy, originalFilePath);
                            node.Hierarchy.ConfigurationSource = null;
                        }

                        if (temporarySaveSuccessful)
                        {
                            using (TemporaryConfigurationHierarchy tempHierarchy
                                = new TemporaryConfigurationHierarchy(ServiceProvider, temporaryFilepath))
                            {
                                MergeHierarchy(tempHierarchy.Hierarchy, mergeDataByPath);

                                SaveConfigurationApplicationNodeCommand saveConfigurationApplication
                                    = new SaveConfigurationApplicationNodeCommand(ServiceProvider);

                                string environmentConfigurationFile
                                    = CreateMergedConfigurationFile(environmentNode, originalFilePath, originalDirectoryPath);

                                UpdateConfigurationSource(tempHierarchy.Hierarchy, environmentConfigurationFile);
                                RemoveConfigurationSourceElements(tempHierarchy.Hierarchy);

                                saveConfigurationApplication.Execute(tempHierarchy.Hierarchy.RootNode);

                                mergeSucceeded = saveConfigurationApplication.SaveSucceeded;
                                mergedConfigurationFile = environmentConfigurationFile;

                            }

                            try
                            {
                                File.Delete(temporaryFilepath);
                            }
                            catch (IOException)
                            {
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        IUIService uiService = ServiceHelper.GetUIService(ServiceProvider);
                        uiService.ShowError(e, Resources.ErrorSavingMergedConfigurationCaption);
                    }
                    finally
                    {
                        IConfigurationUIHierarchyService hierarchyService = ServiceHelper.GetUIHierarchyService(ServiceProvider);
                        hierarchyService.SelectedHierarchy = node.Hierarchy;

                        UIService.EndUpdate();

                        environmentMergeService.SetEnvironmentalMergeInProgress(false);
                    }
                }
            }
        }
示例#5
0
 private bool SaveApplication(IConfigurationUIHierarchy hierarchy)
 {
     using (new WaitCursor())
     {
         SaveConfigurationApplicationNodeCommand cmd = new SaveConfigurationApplicationNodeCommand(designHost);
         cmd.Execute(hierarchy.RootNode);
         return cmd.SaveSucceeded;
     }
 }