internal static ExtensionConfiguration FromXml(XmlReader reader)
        {
            ExtensionConfiguration cfg = new ExtensionConfiguration();

            cfg.ReadXml(reader);
            return(cfg);
        }
        internal static ExtensionConfiguration FromXml(string bundleId, XmlReader reader)
        {
            ExtensionConfiguration cfg = new ExtensionConfiguration(bundleId);

            cfg.ReadXml(reader);
            return(cfg);
        }
Ejemplo n.º 3
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();
                }
            }
        }
        internal static ExtensionConfiguration FromXml(string bundleId, string xml)
        {
            ExtensionConfiguration cfg        = new ExtensionConfiguration(bundleId);
            TextReader             textReader = new StringReader(xml);

            using (XmlReader reader = XmlReader.Create(textReader, XmlUtils.CreateFragmentReaderSettings()))
            {
                cfg.ReadXml(reader);
            }
            return(cfg);
        }
            void IXmlSerializable.WriteXml(XmlWriter writer)
            {
                writer.WriteAttributeString("type", Utils.GetImplementationName <ExtensionRegistry>());
                writer.WriteAttributeString("serializableType", Utils.GetImplementationName <Serializable>());
                writer.WriteAttributeString("extensionPoints", _registry._extensionPoints.Count.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("extensions", _registry._extensions.Count.ToString(CultureInfo.InvariantCulture));

                writer.WriteStartElement("extensionPoints");
                foreach (IExtensionPoint point in _registry.ExtensionPoints)
                {
                    List <ExtensionConfiguration> extensionConfigs = new List <ExtensionConfiguration>();
                    ExtensionPointConfiguration   cfg = (ExtensionPointConfiguration)_registry.GetExtensionPointConfigurationElement(point.Id);

                    for (int i = 0; i < point.Extensions.Length; i++)
                    {
                        ExtensionConfiguration extCfg = (ExtensionConfiguration)_registry.GetExtensionConfigurationElement(point.Extensions[i].Id);
                        if (null != extCfg)
                        {
                            extensionConfigs.Add(extCfg);
                        }
                    }

                    XmlUtils.WriteElement <ExtensionPointConfiguration>(writer, "extensionPoint", cfg);
                    XmlUtils.WriteElementsFromList <ExtensionConfiguration>(writer, "extensions", "extension", extensionConfigs);
                }
                writer.WriteFullEndElement();

                List <ExtensionConfiguration> orphanExtensionConfigs = new List <ExtensionConfiguration>();

                foreach (IExtension ext in _registry._extensions.Values)
                {
                    if (string.IsNullOrEmpty(ext.Point) || IsNonExistentExtensionPoint(ext.Point))
                    {
                        IExtensionConfiguration cfg = _registry.GetExtensionConfigurationElement(ext.Id);

                        ExtensionConfiguration extCfg = cfg as ExtensionConfiguration;

                        if (null != extCfg)
                        {
                            orphanExtensionConfigs.Add(extCfg);
                        }
                    }
                }

                XmlUtils.WriteElementsFromList <ExtensionConfiguration>(writer, "extensions", "extension", orphanExtensionConfigs);
            }
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            ExtensionConfiguration other = (ExtensionConfiguration)obj;

            if (
                Id != other.Id ||
                BundleId != other.BundleId ||
                Name != other.Name ||
                Description != other.Description ||
                Implementation != other.Implementation ||
                Point != other.Point ||
                Configuration != other.Configuration
                )
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
 internal void AddExtensionConfiguration(ExtensionConfiguration cfg)
 {
     _contributedExtensions.Add(cfg.Id, cfg);
 }
            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>
            }