internal PluginInfo FindOrCreate(Runner.PluginInfo plugin) { PluginInfo f; if (!_dicPlugins.TryGetValue(new KeyValuePair <Guid, Version>(plugin.PluginId, plugin.Version), out f)) { if (plugin.IsOldVersion || !_discoverer._pluginsById.TryGetValue(plugin.PluginId, out f) || f.Version > plugin.Version) { f = new PluginInfo(_discoverer); _dicPlugins.Add(new KeyValuePair <Guid, Version>(plugin.PluginId, plugin.Version), f); _hasBeenDiscovered.Add(f); f.Initialize(this, plugin); if (plugin.IsOldVersion) { _newOldPlugins.Add(f); } else { _newPlugins.Add(f); } if (!plugin.HasError && !plugin.IsOldVersion) { _discoverer._plugins.Add(f); if (!_discoverer._pluginsById.ContainsKey(f.PluginId)) { _discoverer._pluginsById.Add(f.PluginId, f); } else { _discoverer._pluginsById[f.PluginId] = f; } } } else { _dicPlugins.Remove(new KeyValuePair <Guid, Version>(f.PluginId, f.Version)); PluginInfo newOldPlugin = f.Clone(); newOldPlugin.IsOldVersion = true; _newOldPlugins.Add(f); Debug.Assert(!_hasBeenDiscovered.Contains(f)); _hasBeenDiscovered.Add(f); _dicPlugins.Add(new KeyValuePair <Guid, Version>(newOldPlugin.PluginId, newOldPlugin.Version), newOldPlugin); _dicPlugins.Add(new KeyValuePair <Guid, Version>(plugin.PluginId, plugin.Version), f); f.Initialize(this, plugin); } } else { Debug.Assert(f != null && (_hasBeenDiscovered.Contains(f) || (f.LastChangedVersion != _discoverer.CurrentVersion))); if (f.LastChangedVersion != _discoverer.CurrentVersion && !_hasBeenDiscovered.Contains(f)) { _hasBeenDiscovered.Add(f); if (f.Merge(this, plugin)) { _changedPlugins.Add(f); if (f.IsOldVersion && !_newOldPlugins.Contains(f)) { _newOldPlugins.Add(f); } } } } return(f); }