コード例 #1
0
        public void ReadPluginsData(object o)
        {
            Guid    prevPluginId      = _currentPluginId;
            Version prevPluginVersion = _currentPluginVersion;
            string  prevPluginName    = _currentPluginName;

            try
            {
                XmlReader r = _reader.Xml;
                while (r.IsStartElement("p"))
                {
                    Guid    p = SimpleUniqueId.InvalidId.UniqueId;
                    Version v = null;
                    string  n = null;
                    try
                    {
                        p = new Guid(r.GetAttribute("guid"));
                        v = r.GetAttributeVersion("version", Util.EmptyVersion);
                        // Since the public name of the plugin is not a key data in any manner,
                        // we may use here the actual uid.PublicName but this would introduce
                        // a diff between the exposed version (which is the version form the input stream)
                        // and the public name.
                        // We prefer here to stay consistent: we expose read information for version and name.
                        n = r.GetAttribute("name") ?? String.Empty;
                        INamedVersionedUniqueId uid = _dic.FindPlugin(p);
                        if (uid != null)
                        {
                            FinalDictionary fDic = _dic.GetFinalDictionary(o, uid, true);

                            r.Read();
                            _currentPluginId      = p;
                            _currentPluginVersion = v;
                            _currentPluginName    = n;

                            SharedDictionaryReaderEventArgs ev = null;
                            if (BeforePluginsData != null)
                            {
                                BeforePluginsData(this, (ev = new SharedDictionaryReaderEventArgs(this, fDic)));
                            }

                            if (_mergeMode == MergeMode.None)
                            {
                                fDic.Clear();
                            }
                            fDic.ReadData(this);

                            if (AfterPluginsData != null)
                            {
                                AfterPluginsData(this, ev ?? new SharedDictionaryReaderEventArgs(this, fDic));
                            }

                            r.ReadEndElement();
                        }
                        else
                        {
                            _dic.StoreSkippedFragment(o, p, v, _reader.CreateBookmark());
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ErrorCollector != null)
                        {
                            if (p == SimpleUniqueId.InvalidId.UniqueId)
                            {
                                ErrorCollector.Add(new ReadElementObjectInfo(ReadElementObjectInfo.ReadStatus.ErrorGuidAttributeMissing, r, ex.Message));
                            }
                            else if (v == null)
                            {
                                ErrorCollector.Add(new ReadElementObjectInfo(ReadElementObjectInfo.ReadStatus.ErrorVersionAttributeInvalid, r, ex.Message));
                            }
                            else
                            {
                                ErrorCollector.Add(new ReadElementObjectInfo(ReadElementObjectInfo.ReadStatus.ErrorXmlRead, r, ex.Message));
                            }
                        }
                        r.Skip();
                    }
                }
            }
            finally
            {
                _currentPluginId      = prevPluginId;
                _currentPluginVersion = prevPluginVersion;
                _currentPluginName    = prevPluginName;
            }
        }