Brush GetColor(EEnergization energization) { switch (energization) { case EEnergization.Energized: return(Brushes.Green); case EEnergization.NotEnergized: return(Brushes.Blue); } return(Brushes.SlateGray); }
public List <Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > > CalculateLineEnergization() { List <Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > > sourcesEnergization = new List <Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > >(subGraphs.Count); for (int i = 0; i < subGraphs.Count; ++i) { Stack <Tuple <Node, EEnergization> > stack = new Stack <Tuple <Node, EEnergization> >(); stack.Push(new Tuple <Node, EEnergization>(subGraphs[i], EEnergization.Energized)); HashSet <Tuple <long, long> > visitedEnergized = new HashSet <Tuple <long, long> >(); HashSet <Tuple <long, long> > visitedUnknown = new HashSet <Tuple <long, long> >(); while (stack.Count > 0) { Tuple <Node, EEnergization> node = stack.Pop(); EEnergization energization = node.Item2; long gid = node.Item1.IO.GID; if (energization != EEnergization.NotEnergized && ModelCodeHelper.ModelCodeClassIsSubClassOf(dmsTypeToModelCodeMap[ModelCodeHelper.GetTypeFromGID(gid)], ModelCode.SWITCH) && GetSwitchState((Switch)node.Item1.IO)) { energization = EEnergization.NotEnergized; } if (energization == EEnergization.NotEnergized) { continue; } if (energization == EEnergization.Energized) { for (int j = node.Item1.AdjacentOffset; j < node.Item1.AdjacentOffset + node.Item1.AdjacentCount; ++j) { Node adjacentNode = adjacency[j]; if (adjacentNode == null) { continue; } long adjacentGID = adjacentNode.IO.GID; Tuple <long, long> line = gid <= adjacentGID ? new Tuple <long, long>(gid, adjacentGID) : new Tuple <long, long>(adjacentGID, gid); if (visitedEnergized.Contains(line)) { continue; } stack.Push(new Tuple <Node, EEnergization>(adjacentNode, EEnergization.Energized)); visitedEnergized.Add(line); visitedUnknown.Remove(line); } } else { for (int j = node.Item1.AdjacentOffset; j < node.Item1.AdjacentOffset + node.Item1.AdjacentCount; ++j) { Node adjacentNode = adjacency[j]; if (adjacentNode == null) { continue; } long adjacentGID = adjacentNode.IO.GID; Tuple <long, long> line = gid <= adjacentGID ? new Tuple <long, long>(gid, adjacentGID) : new Tuple <long, long>(adjacentGID, gid); if (visitedEnergized.Contains(line) || visitedUnknown.Contains(line)) { continue; } stack.Push(new Tuple <Node, EEnergization>(adjacentNode, EEnergization.Unknown)); visitedUnknown.Add(line); } } } sourcesEnergization.Add(new Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > >(subGraphs[i].IO.GID, new List <Tuple <long, long> >(visitedEnergized), new List <Tuple <long, long> >(visitedUnknown))); } return(sourcesEnergization); }
void TopologyUpdated() { Client <ICalculationEngineServiceContract> client = new Client <ICalculationEngineServiceContract>("endpointCE"); client.Connect(); List <Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > > result = null; bool success; if (!client.Call <bool>(ce => { result = ce.GetLineEnergization(); return(true); }, out success) || !success) { client.Disconnect(); return; } client.Disconnect(); modelLock.EnterReadLock(); Dictionary <long, EEnergization> cnStates = new Dictionary <long, EEnergization>(reclosers.Count * 2); foreach (Tuple <Recloser, long, long, int> r in reclosers) { cnStates[r.Item2] = EEnergization.NotEnergized; cnStates[r.Item3] = EEnergization.NotEnergized; } List <long> reclosersWithoutSCADA = new List <long>(); try { foreach (Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > source in result) { foreach (Tuple <long, long> energizedLine in source.Item2) { if (cnStates.ContainsKey(energizedLine.Item1)) { cnStates[energizedLine.Item1] = EEnergization.Energized; } if (cnStates.ContainsKey(energizedLine.Item2)) { cnStates[energizedLine.Item2] = EEnergization.Energized; } } foreach (Tuple <long, long> unknownLine in source.Item3) { EEnergization state; if (cnStates.TryGetValue(unknownLine.Item1, out state) && state == EEnergization.Unknown) { cnStates[unknownLine.Item1] = EEnergization.Unknown; } if (cnStates.TryGetValue(unknownLine.Item2, out state) && state == EEnergization.Unknown) { cnStates[unknownLine.Item2] = EEnergization.Unknown; } } } foreach (Tuple <Recloser, long, long, int> r in reclosers) { EEnergization[] states = new EEnergization[] { cnStates[r.Item2], cnStates[r.Item3] }; if (states[0] == EEnergization.Unknown || states[1] == EEnergization.Unknown) { continue; } if (states[0] != states[1]) { if (r.Item4 < 0) { reclosersWithoutSCADA.Add(r.Item1.GID); } else { SetDiscreteInput(r.Item4, 0); } } } } finally { modelLock.ExitReadLock(); } if (reclosersWithoutSCADA.Count <= 0) { return; } client = new Client <ICalculationEngineServiceContract>("endpointCE"); client.Connect(); client.Call <bool>(ce => { foreach (long gid in reclosersWithoutSCADA) { ce.MarkSwitchState(gid, false); } return(true); }, out success); client.Disconnect(); }