bool HandleNetworkModelChange(NetworkModelChanged msg) { NetworkModelDownload download = new NetworkModelDownload(); if (!download.Download()) { return(false); } NetworkModel tModel = new NetworkModel(download); Interlocked.Exchange(ref model, tModel); Notify(new ObservableMessage(EObservableMessageType.NetworkModelChanged)); return(true); }
public NetworkModel(NetworkModelDownload download) { Dictionary <long, IdentifiedObject> terminalContainer = download.Containers[DMSType.Terminal]; Dictionary <long, IdentifiedObject> conNodeContainer = download.Containers[DMSType.ConnectivityNode]; List <Node> trees = new List <Node>(); Dictionary <long, RecloserNode> reclosers = new Dictionary <long, RecloserNode>(); foreach (KeyValuePair <long, IdentifiedObject> source in download.Containers[DMSType.EnergySource]) { if (source.Value == null) { continue; } Node root = new Node(null, source.Value); Stack <Node> stack = new Stack <Node>(); stack.Push(root); while (stack.Count > 0) { Node node = stack.Pop(); IdentifiedObject io = node.io; DMSType type = ModelCodeHelper.GetTypeFromGID(io.GID); switch (type) { case DMSType.ConnectivityNode: { foreach (long terminalGID in ((ConnectivityNode)io).Terminals) { long condEqGID = ((Terminal)terminalContainer[terminalGID]).ConductingEquipment; if (condEqGID == node.parent.io.GID) { continue; } DMSType condEqType = ModelCodeHelper.GetTypeFromGID(condEqGID); ConductingEquipment condEq = (ConductingEquipment)download.Containers[condEqType][condEqGID]; if (condEq is Recloser) { RecloserNode rn; if (reclosers.TryGetValue(condEqGID, out rn)) { if (rn.node2 == null) { rn.node2 = node; } } else { reclosers.Add(condEqGID, new RecloserNode(condEq) { node1 = node }); } continue; } Node childNode = new Node(node, condEq); node.children.Add(childNode); stack.Push(childNode); } } break; case DMSType.TransformerWinding: { TransformerWinding tw = io as TransformerWinding; if (tw == null) { break; } PowerTransformer pt = GetInternal(download.Containers, tw.PowerTransformer) as PowerTransformer; if (pt == null) { break; } foreach (long twGID in pt.TransformerWindings) { if (twGID == tw.GID || (node.parent != null && twGID == node.parent.io.GID)) { continue; } TransformerWinding twChild = GetInternal(download.Containers, twGID) as TransformerWinding; if (twChild == null) { continue; } Node childNode = new Node(node, twChild); node.children.Add(childNode); stack.Push(childNode); } foreach (long terminalGID in tw.Terminals) { long conNodeGID = ((Terminal)terminalContainer[terminalGID]).ConnectivityNode; if (node.parent != null && conNodeGID == node.parent.io.GID) { continue; } Node childNode = new Node(node, conNodeContainer[conNodeGID]); node.children.Add(childNode); stack.Push(childNode); } } break; default: { ConductingEquipment condEq = io as ConductingEquipment; if (condEq == null) { break; } foreach (long terminalGID in condEq.Terminals) { long conNodeGID = ((Terminal)terminalContainer[terminalGID]).ConnectivityNode; if (node.parent != null && conNodeGID == node.parent.io.GID) { continue; } Node childNode = new Node(node, conNodeContainer[conNodeGID]); node.children.Add(childNode); stack.Push(childNode); } } break; } } trees.Add(root); } this.trees = trees; this.reclosers = reclosers; this.containers = download.Containers; }