Пример #1
0
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            reader.MoveToContent();
            _Id             = reader.GetAttribute("id");
            _name           = reader.GetAttribute("name");
            _description    = reader.GetAttribute("description");
            _activatorClass = reader.GetAttribute("activator");
            string version = reader.GetAttribute("version");

            _version          = string.IsNullOrEmpty(version) ? new Version() : new Version(version);
            _provider         = reader.GetAttribute("provider");
            _assemblyLocation = reader.GetAttribute("assemblyLocation");
            // only continue, if the XML start element is correct.
            if (reader.IsStartElement("bundle", RuntimeConstants.CurrentXmlSchemaNamespace) ||
                reader.IsStartElement("Bundle"))
            {
                if (reader.IsEmptyElement)
                {
                    reader.ReadStartElement();
                }
                else
                {
                    reader.ReadStartElement();
                    while (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "extensionPoint")
                    {
                        ExtensionPointConfiguration ep = new ExtensionPointConfiguration(_Id);
                        ep.ReadXml(reader);
                        if (!_contributedExtensionPoints.ContainsKey(ep.Id))
                        {
                            _contributedExtensionPoints.Add(ep.Id, ep);
                        }
                        else
                        {
                            throw new PlatformConfigurationException(
                                      string.Format(CultureInfo.InvariantCulture,
                                                    "Duplicate extension point with id '{0}' in bundle '{1}'.", ep.Id, _Id));
                        }
                    }
                    while (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "extension")
                    {
                        ExtensionConfiguration ext = ExtensionConfiguration.FromXml(_Id, reader);
                        if (!_contributedExtensions.ContainsKey(ext.Id))
                        {
                            _contributedExtensions.Add(ext.Id, ext);
                        }
                        else
                        {
                            throw new PlatformConfigurationException(
                                      string.Format(CultureInfo.InvariantCulture, "Duplicate extension with id '{0}' in bundle '{1}'.", ext.Id, _Id));
                        }
                    }
                    reader.ReadEndElement();
                }
            }
        }
            void IXmlSerializable.ReadXml(XmlReader reader)
            {
                if (!reader.IsStartElement("extensionRegistry"))
                {
                    throw new InvalidOperationException(
                              string.Concat("无效配置.期望节点是 'extensionRegistry 便实际是 '", reader.LocalName, "'."));
                }

                reader.ReadStartElement("extensionRegistry");

                if (!reader.IsStartElement("extensionPoints"))
                {
                    throw new InvalidOperationException(
                              string.Concat("无效配置.期望节点是 'extensionRegistry 便实际是 '", reader.LocalName, "'."));
                }

                if (reader.IsEmptyElement)
                {
                    reader.ReadStartElement("extensionPoints");
                }
                else
                {
                    reader.ReadStartElement("extensionPoints");

                    while (reader.IsStartElement("extensionPoint"))
                    {
                        ExtensionPointConfiguration cfg = new ExtensionPointConfiguration();
                        cfg.ReadXml(reader);
                        List <ExtensionConfiguration> extensionConfigs = new List <ExtensionConfiguration>();
                        XmlUtils.ReadElementsIntoList <ExtensionConfiguration>(reader, "extensions", "extension", extensionConfigs);

                        IExtensionPoint point = new ExtensionPoint(cfg);
                        _registry._extensionPoints.Add(point.Id, point);

                        for (int i = 0; i < extensionConfigs.Count; i++)
                        {
                            IExtension ext = new Extension(extensionConfigs[i], _extensionBuilder);
                            _registry._extensions.Add(ext.Id, ext);
                            ((ExtensionPoint)point).AddExtension(ext);
                        }
                    }

                    reader.ReadEndElement();
                }



                if (reader.IsStartElement("extensions"))
                {
                    if (reader.IsEmptyElement)
                    {
                        reader.ReadStartElement("extensions");
                    }
                    else
                    {
                        // read the orphans
                        reader.ReadStartElement("extensions");

                        while (reader.IsStartElement("extension"))
                        {
                            ExtensionConfiguration extCfg = ExtensionConfiguration.FromXml(reader);
                            if (!_registry._extensions.ContainsKey(extCfg.Id))
                            {
                                IExtension ext = new Extension(extCfg, _extensionBuilder);
                                _registry._extensions.Add(ext.Id, ext);
                            }
                        }

                        reader.ReadEndElement();
                    }
                }

                reader.ReadEndElement(); //</extensionRegistry>
            }