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();
                }
            }
        }
Example #2
0
        private Type[] GetXmlIncludeTypes()
        {
            Type[] includeTypes = null;
            if (this.Parent == null)
            {
                return(includeTypes);
            }

            string sectionName             = this.Parent.Name;
            IXmlIncludeTypeService service = GetService(typeof(IXmlIncludeTypeService)) as IXmlIncludeTypeService;

            Debug.Assert(service != null, "Could not get the IXmlIncludeTypeService.");
            includeTypes = service.GetXmlIncludeTypes(sectionName);
            if (includeTypes == null)
            {
                return(includeTypes);
            }

            INodeCreationService nodeCreationService = GetService(typeof(INodeCreationService)) as INodeCreationService;

            Debug.Assert(nodeCreationService != null, "Could not get the INodeCreationService.");

            // make sure that we actually used these xml include types in the application
            ArrayList usedTypes = new ArrayList();

            foreach (Type includeType in includeTypes)
            {
                Type nodeType = nodeCreationService.GetNodeType(includeType);
                if (nodeType == null)
                {
                    continue;
                }
                if (Hierarchy.ContainsNodeType(nodeType))
                {
                    usedTypes.Add(includeType);
                }
            }
            includeTypes = new Type[usedTypes.Count];
            usedTypes.CopyTo(includeTypes);
            return(includeTypes);
        }
Example #3
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)));
                    }
                }
            }
        }