private static void CopyNodesAndEdges( DAG graph, SortedSet <long> nodeIdSubset, DAG subgraph) { subgraph.NodeEnumeration = new SortedDictionary <long, DAGNode>(); foreach (long nodeId in nodeIdSubset) { DAGNode subgraphNode = new(nodeId); subgraph.AddNode(subgraphNode); } List <KeyValuePair <KeyValuePair <long, long>, DAGEdge> > nodePairList1 = graph.NodePairEnumeration.Where( t => subgraph.NodeEnumeration.ContainsKey(t.Key.Key)).ToList(); List <KeyValuePair <KeyValuePair <long, long>, DAGEdge> > nodePairList2 = nodePairList1.Where( t => subgraph.NodeEnumeration.ContainsKey(t.Key.Value)).ToList(); subgraph.NodePairEnumeration = new SortedDictionary <KeyValuePair <long, long>, DAGEdge>( new KeyValueComparer()); foreach (KeyValuePair <KeyValuePair <long, long>, DAGEdge> nodePair in nodePairList2) { DAGNode uSubgraphNode = subgraph.NodeEnumeration[nodePair.Key.Key]; DAGNode vSubgraphNode = subgraph.NodeEnumeration[nodePair.Key.Value]; DAGEdge subgraphEdge = new(nodePair.Value.Id, uSubgraphNode, vSubgraphNode); subgraph.AddEdge(subgraphEdge); } }
internal static void LoadAndInitializePlugins(TalknetEnv env) { var pluginsCache = new List <LoadedPlugin>(); pluginsCache.AddRange(LoadSelf()); pluginsCache.AddRange(LoadFromPluginDirectory()); // unique foreach (var plugin in pluginsCache) { var name = plugin.Info.Name; if (Plugins.ContainsKey(name)) { if (plugin.PluginInstance.GetType().IsInstanceOfType(Plugins[name].PluginInstance)) { continue; } throw new PluginLoadingException(string.Format(ErrMsg.PluginSameName, name, Plugins[name], plugin)); } Plugins[name] = plugin; } // check requirements var refs = new DAG <string>(Plugins.Keys); foreach (var plugin in pluginsCache) { var thisName = plugin.Info.Name; foreach (var req in plugin.Requirements) { var reqName = req.Requirement; if (!Plugins.ContainsKey(reqName)) { throw PluginLoadingException.ErrorReqNotSatisfied(plugin, reqName); } switch (req.Order) { case LoadOrderType.ThisFirst: refs.AddEdge(thisName, reqName); break; case LoadOrderType.RequiredFirst: refs.AddEdge(reqName, thisName); break; default: continue; } } } _order = null; try { _order = refs.TopologicalOrder(); } catch (NotADagException) { throw new PluginLoadingException(ErrMsg.LoadOrderCannotBeSatisfied); } foreach (var it in _order) { Plugins[it].PluginInstance.PluginInitialize(env); } }