示例#1
0
        private string CreateMergedConfigurationFile(EnvironmentNode environmentNode, string originalFilePath, string originalDirectoryPath)
        {
            string environmentConfigurationFile = Path.Combine(originalDirectoryPath, environmentNode.EnvironmentConfigurationFile);

            EnsureDirectoryExists(Path.GetDirectoryName(environmentConfigurationFile));
            File.Copy(originalFilePath, environmentConfigurationFile, true);
            return(environmentConfigurationFile);
        }
示例#2
0
        protected override void ExecuteCore(ConfigurationNode node)
        {
            base.ExecuteCore(node);

            EnvironmentNode envNode = ChildNode as EnvironmentNode;

            if (envNode != null)
            {
                envNode.EnvironmentDeltaFile = string.Concat(envNode.Name, Resources.DefaultEnvironmentDeltaFileExtension);
            }
        }
示例#3
0
        private string CreateMergedConfigurationFile(EnvironmentNode environmentNode, string originalFilePath, string originalDirectoryPath)
        {
            string environmentConfigurationFile = Path.Combine(originalDirectoryPath, environmentNode.EnvironmentConfigurationFile);

            EnsureDirectoryExists(Path.GetDirectoryName(environmentConfigurationFile));
            File.Copy(originalFilePath, environmentConfigurationFile, true);

            // make the target file writable (it may have inherited the read-only attribute from the original file)
            FileAttributes attributes = File.GetAttributes(environmentConfigurationFile);

            File.SetAttributes(environmentConfigurationFile, attributes & ~FileAttributes.ReadOnly);

            return(environmentConfigurationFile);
        }
        /// <summary>
        /// Builds an <see cref="EnvironmentNode"/> given a Environment Delta file (.dconfig) and a <see cref="ConfigurationUIHierarchy"/>.
        /// </summary>
        /// <param name="environmentFileName">The path of the Environment Delta file (.dconfig) that should be used to construct the <see cref="EnvironmentNode"/>.</param>
        /// <param name="uiHierarchy">The <see cref="IConfigurationUIHierarchy"/> the created <see cref="EnvironmentNode"/> belongs to.</param>
        /// <returns>An instance of <see cref="EnvironmentNode"/> that represents the Environment Delta file (.dconfig) passed as <paramref name="environmentFileName"/>.</returns>
        public EnvironmentNode Build(string environmentFileName, IConfigurationUIHierarchy uiHierarchy)
        {
            EnvironmentMergeSection mergeSection = GetEnvrinmentMergeSection(environmentFileName);
            if (mergeSection != null)
            {
                EnvironmentMergeData data = ReadEnvironmentMergeData(mergeSection, uiHierarchy);
                data.EnvironmentName = mergeSection.EnvironmentName;
                data.EnvironmentDeltaFile = environmentFileName;
                data.EnvironmentConfigurationFile = mergeSection.EnvironmentDeltaFile;

                EnvironmentNode environmentNode = new EnvironmentNode(data);
                if (mergeSection.SectionInformation.IsProtected && mergeSection.SectionInformation.ProtectionProvider != null)
                {
                    environmentNode.ProtectionProvider = mergeSection.SectionInformation.ProtectionProvider.Name;
                }

                return environmentNode;
            }
            return new EnvironmentNode();
        }
示例#5
0
        /// <summary>
        /// Builds an <see cref="EnvironmentNode"/> given a Environment Delta file (.dconfig) and a <see cref="ConfigurationUIHierarchy"/>.
        /// </summary>
        /// <param name="environmentFileName">The path of the Environment Delta file (.dconfig) that should be used to construct the <see cref="EnvironmentNode"/>.</param>
        /// <param name="uiHierarchy">The <see cref="IConfigurationUIHierarchy"/> the created <see cref="EnvironmentNode"/> belongs to.</param>
        /// <returns>An instance of <see cref="EnvironmentNode"/> that represents the Environment Delta file (.dconfig) passed as <paramref name="environmentFileName"/>.</returns>
        public EnvironmentNode Build(string environmentFileName, IConfigurationUIHierarchy uiHierarchy)
        {
            EnvironmentMergeSection mergeSection = GetEnvrinmentMergeSection(environmentFileName);

            if (mergeSection != null)
            {
                EnvironmentMergeData data = ReadEnvironmentMergeData(mergeSection, uiHierarchy);
                data.EnvironmentName              = mergeSection.EnvironmentName;
                data.EnvironmentDeltaFile         = environmentFileName;
                data.EnvironmentConfigurationFile = mergeSection.EnvironmentDeltaFile;

                EnvironmentNode environmentNode = new EnvironmentNode(data);
                if (mergeSection.SectionInformation.IsProtected && mergeSection.SectionInformation.ProtectionProvider != null)
                {
                    environmentNode.ProtectionProvider = mergeSection.SectionInformation.ProtectionProvider.Name;
                }

                return(environmentNode);
            }
            return(new EnvironmentNode());
        }
示例#6
0
        protected override void ExecuteCore(ConfigurationNode node)
        {
            IUIService uiService = ServiceHelper.GetUIService(ServiceProvider);

            using (OpenFileDialog fileDialog = new OpenFileDialog())
            {
                fileDialog.Filter           = Resources.EnvironmentDeltaFileDialogFilter;
                fileDialog.CheckFileExists  = true;
                fileDialog.CheckPathExists  = true;
                fileDialog.AddExtension     = true;
                fileDialog.DefaultExt       = Resources.DefaultEnvironmentDeltaFileExtension;
                fileDialog.RestoreDirectory = true;

                if (DialogResult.OK == uiService.ShowOpenDialog(fileDialog))
                {
                    uiService.BeginUpdate();

                    try
                    {
                        EnvironmentNodeBuilder nodeBuilder = new EnvironmentNodeBuilder(ServiceProvider);
                        EnvironmentNode        childNode   = nodeBuilder.Build(fileDialog.FileName, node.Hierarchy);

                        node.AddNode(childNode);
                        uiService.SetUIDirty(node.Hierarchy);
                        uiService.ActivateNode(childNode);
                    }
                    catch (Exception e)
                    {
                        uiService.ShowError(e, Resources.ErrorOpeningEnvironmentMergeFile);
                    }
                    finally
                    {
                        uiService.EndUpdate();
                    }
                }
            }
        }
示例#7
0
        /// <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;
                            node.Hierarchy.ConfigurationParameter = 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);
                    }
                }
            }
        }
        private string CreateMergedConfigurationFile(EnvironmentNode environmentNode, string originalFilePath, string originalDirectoryPath)
        {
            string environmentConfigurationFile = Path.Combine(originalDirectoryPath, environmentNode.EnvironmentConfigurationFile);
            EnsureDirectoryExists(Path.GetDirectoryName(environmentConfigurationFile));
            File.Copy(originalFilePath, environmentConfigurationFile, true);

            // make the target file writable (it may have inherited the read-only attribute from the original file)
            FileAttributes attributes = File.GetAttributes(environmentConfigurationFile);
            File.SetAttributes(environmentConfigurationFile, attributes & ~FileAttributes.ReadOnly);

            return environmentConfigurationFile;
        }