Example #1
0
        /// <summary> Parses the extension definition stream and creates a collection of Extension Map. </summary>
        /// <returns>Instance of <see cref="ExtensionService"/></returns>
        public ExtensionPointMap Parse()
        {
            ExtensionPointMap map = new ExtensionPointMap();
            XDocument         xmlDocument;

            try {
                xmlDocument = XDocument.Load(_stream);
            } catch (Exception ex) {
                throw new ExtensionsParsingException("Error on parsing the 'extensions.xml'.", ex);
            }

            IEnumerable <XElement> extensions = from extension in xmlDocument.Descendants("extension")
                                                select extension;

            foreach (XElement extension in extensions)
            {
                XAttribute attrPoint = extension.Attribute(PointDefinition);
                if (attrPoint == null)
                {
                    throw new ExtensionsParsingException("Attribute 'point' is missing or invalid!");
                }

                string id = attrPoint.Value;

                IList <IConfigurationElement> configurationElements = ParseConfigurationElements(extension);
                map.AddAll(id, configurationElements);
            }

            return(map);
        }
Example #2
0
        /// <summary> Starts the Extension Service. </summary>
        public void Start()
        {
            if (_started)
            {
                return;
            }

            iLogger.Debug("Starting extension service");

            IList <IPluginInfo> providedPlugins = PluginService.Instance.ProvidedPlugins;

            for (int i = -1; ++i != providedPlugins.Count;)
            {
                IPluginInfo plugin = providedPlugins[i];

                Stream stream = plugin.Bundle.GetResourceAsStream(ExtensionFileName);
                if (stream == null)
                {
                    continue;
                }

                // Create a parser and parse the stream
                ExtensionFileParser parser = ExtensionFileParser.GetInstance(stream);
                ExtensionPointMap   map    = parser.Parse();

                // Map bundle to Configuration Elements
                IList <IConfigurationElement> cfgElements = new List <IConfigurationElement>(map.Count);

                using (IEnumerator <KeyValuePair <string, IList <IConfigurationElement> > > itr = map.GetEnumerator()) {
                    while (itr.MoveNext())
                    {
                        KeyValuePair <string, IList <IConfigurationElement> > entry = itr.Current;
                        IList <IConfigurationElement> cfgElementSet = entry.Value;

                        for (int j = -1; ++j != cfgElementSet.Count;)
                        {
                            IConfigurationElement cfgEl = cfgElementSet[j];
                            cfgElements.Add(cfgEl);
                        }
                    }
                }

                _bundleToConfigurationElementMap.Add(plugin.Bundle, cfgElements);

                // Merge the new elements to the existing ones
                _extensionPointMap.Merge(map);
            }

            _started = true;
            iLogger.Debug("Extension service started");
        }
Example #3
0
        /// <summary> Adds all items of the given map to this one. </summary>
        /// <param name="map">Map which contains all items that will be added to this one</param>
        public void Merge(ExtensionPointMap map)
        {
            using (IEnumerator <string> itr = map._idToCollectionMap.Keys.GetEnumerator()) {
                while (itr.MoveNext())
                {
                    string id = itr.Current;
                    if (id == null)
                    {
                        continue;
                    }

                    IList <IConfigurationElement> elements = map._idToCollectionMap[id];
                    AddAll(id, elements);
                }
            }
        }