Exemple #1
0
        /// <summary>
        /// <para>Opens the configuration settings and registers them with the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public void Open(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext       = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);
            ConfigurationSectionCollectionNode sectionsNode = null;
            ConfigurationNode configurationNode             = ServiceHelper.GetCurrentRootNode(serviceProvider);

            RemoveCurrentConfigurationSectionCollectionNode(serviceProvider);
            try
            {
                string appName = SR.DefaultApplicationName;
                ConfigurationSettings configurationSettings = configurationContext.GetMetaConfiguration();
                if (null != configurationSettings)
                {
                    appName = configurationSettings.ApplicationName;
                    if (configurationSettings.ConfigurationSections.Count > 0)
                    {
                        sectionsNode = new ConfigurationSectionCollectionNode(configurationSettings);
                        configurationNode.Nodes.Add(sectionsNode);
                    }
                }
                if (configurationNode is ApplicationConfigurationNode)
                {
                    ((ApplicationConfigurationNode)configurationNode).Name = appName;
                }
            }
            catch (ConfigurationException e)
            {
                ServiceHelper.LogError(serviceProvider, sectionsNode, e);
            }
        }
Exemple #2
0
        private static void RemoveCurrentConfigurationSectionCollectionNode(IServiceProvider serviceProvider)
        {
            ConfigurationSectionCollectionNode currentNode = ServiceHelper.GetCurrentHierarchy(serviceProvider).FindNodeByType(typeof(ConfigurationSectionCollectionNode)) as ConfigurationSectionCollectionNode;

            if (currentNode != null)
            {
                currentNode.Remove();
            }
        }
        /// <summary>
        /// <para>Creates a <see cref="ConfigurationSectionNode"/> for the parent node.</para>
        /// </summary>
        /// <param name="node">
        /// <para>The parent node to add the newly created <see cref="ConfigurationSectionNode"/>.</para>
        /// </param>
        protected override void ExecuteCore(ConfigurationNode node)
        {
            ConfigurationSectionCollectionNode sectionsNode = SelectConfigurationSectionsNode();
            ConfigurationSectionNode           sectionNode  = UIHierarchyService.SelectedHierarchy.FindNodeByName(sectionsNode, sectionName) as ConfigurationSectionNode;

            newSectionNode = sectionNode;
            if (sectionNode == null)
            {
                newSectionNode = ConfigurationSectionNode.CreateReadOnlyDefault(sectionName, sectionsNode);
            }
            base.ExecuteCore(node);
        }
        private ConfigurationSectionCollectionNode SelectConfigurationSectionsNode()
        {
            IUIHierarchy hierarchy = UIHierarchyService.SelectedHierarchy;
            ApplicationConfigurationNode applicationNode = hierarchy.RootNode as ApplicationConfigurationNode;

            Debug.Assert(applicationNode != null, "Expected an application node to be root for this node.");
            ConfigurationSectionCollectionNode sectionsNode = (ConfigurationSectionCollectionNode)hierarchy.FindNodeByType(hierarchy.RootNode, typeof(ConfigurationSectionCollectionNode));

            if (sectionsNode == null)
            {
                sectionsNode = new ConfigurationSectionCollectionNode();
                applicationNode.Nodes.AddWithDefaultChildren(sectionsNode);
            }
            return(sectionsNode);
        }
        protected override void ExecuteCore(ConfigurationNode node)
        {
            ConfigurationSectionCollectionNode configurationSectionCollectionNode = CurrentHierarchy.FindNodeByType(typeof(ConfigurationSectionCollectionNode)) as ConfigurationSectionCollectionNode;

            if (configurationSectionCollectionNode == null)
            {
                return;
            }

            IXmlIncludeTypeService service = XmlIncludeTypeService;

            Type[] types = null;
            XmlSerializerTransformerNode transformerNode = null;

            foreach (ConfigurationNode configurationNode in configurationSectionCollectionNode.Nodes)
            {
                transformerNode = CurrentHierarchy.FindNodeByType(configurationNode, typeof(XmlSerializerTransformerNode)) as XmlSerializerTransformerNode;
                if (transformerNode == null)
                {
                    continue;
                }
                types = service.GetXmlIncludeTypes(configurationNode.Name);
                if (types == null)
                {
                    continue;
                }
                ArrayList nodesToRemove = new ArrayList();
                foreach (Type t in types)
                {
                    if (!FindNodTypeToDataTypeMatchRecursive(node, t))
                    {
                        continue;
                    }
                    foreach (XmlIncludeTypeNode xmlIncludeTypeNode in transformerNode.Nodes)
                    {
                        Type includeType = Type.GetType(xmlIncludeTypeNode.TypeName, false, true);
                        if (includeType.Equals(t))
                        {
                            nodesToRemove.Add(xmlIncludeTypeNode);
                        }
                    }
                }
                foreach (ConfigurationNode nodeToRemove in nodesToRemove)
                {
                    nodeToRemove.Remove();
                }
            }
        }
Exemple #6
0
        private static ConfigurationSettings GetConfigurationSettings(IServiceProvider serviceProvider)
        {
            ConfigurationNode rootNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
            ConfigurationSectionCollectionNode sectionsNode = rootNode.Hierarchy.FindNodeByType(rootNode, typeof(ConfigurationSectionCollectionNode)) as ConfigurationSectionCollectionNode;
            ConfigurationSettings configurationSettings     = null;

            if (sectionsNode == null)
            {
                configurationSettings = new ConfigurationSettings();
            }
            else
            {
                configurationSettings = sectionsNode.ConfigurationSettings;
            }
            return(configurationSettings);
        }
Exemple #7
0
        protected override void ExecuteCore(ConfigurationNode node)
        {
            ConfigurationSectionCollectionNode configurationSectionCollectionNode = node.Hierarchy.FindNodeByType(typeof(ConfigurationSectionCollectionNode)) as ConfigurationSectionCollectionNode;

            if (configurationSectionCollectionNode == null)
            {
                return;
            }

            IXmlIncludeTypeService service = GetService(typeof(IXmlIncludeTypeService)) as IXmlIncludeTypeService;

            Type[] types = null;
            XmlSerializerTransformerNode transformerNode = null;

            foreach (ConfigurationNode configurationNode in configurationSectionCollectionNode.Nodes)
            {
                transformerNode = node.Hierarchy.FindNodeByType(configurationNode, typeof(XmlSerializerTransformerNode)) as XmlSerializerTransformerNode;
                if (transformerNode == null)
                {
                    continue;
                }
                types = service.GetXmlIncludeTypes(configurationNode.Name);
                if (types == null)
                {
                    continue;
                }
                foreach (Type t in types)
                {
                    INodeCreationService nodeCreationService = (INodeCreationService)GetService(typeof(INodeCreationService));
                    if (!nodeCreationService.DoesNodeTypeMatchDataType(nodeType, t))
                    {
                        continue;
                    }
                    if (node.Hierarchy.FindNodeByName(transformerNode, t.Name) == null)
                    {
                        transformerNode.Nodes.Add(new XmlIncludeTypeNode(new XmlIncludeTypeData(t.Name, t.AssemblyQualifiedName)));
                    }
                }
            }
        }