public void AddElement(IOutageTopologyElement newElement) { if (!OutageTopology.ContainsKey(newElement.Id)) { OutageTopology.Add(newElement.Id, newElement); } }
public bool TraceDFS(HashSet <long> visited, IOutageTopologyElement topologyElement, bool FoundOutage) { if (this.potentialOutages.Count == 0) { return(FoundOutage); } if (this.potentialOutages.Contains(topologyElement.Id)) { potentialOutages.Remove(topologyElement.Id); FoundOutage = true; } visited.Add(topologyElement.Id); foreach (var item in topologyElement.SecondEnd) { if (this.outageModel.TopologyModel.GetElementByGid(item, out topologyElement)) { if (topologyElement.DmsType != "ENERGYCONSUMER" && !visited.Contains(topologyElement.Id) && !topologyElement.IsRemote) { FoundOutage = TraceDFS(visited, topologyElement, FoundOutage); } } } return(FoundOutage); }
public bool GetElementByGid(long gid, out IOutageTopologyElement topologyElement) { bool success = false; if (OutageTopology.TryGetValue(gid, out topologyElement)) { success = true; } else { topologyElement = null; } return(success); }
public bool GetElementByGidFirstEnd(long gid, out IOutageTopologyElement topologyElement) { bool success = GetElementByGid(gid, out topologyElement); if (success) { success = GetElementByGid(topologyElement.FirstEnd, out topologyElement); if (!success) { topologyElement = null; } } else { topologyElement = null; } return(success); }
public bool StartLocationAndIsolationAlgorithm(OutageEntity outageEntity) { IOutageTopologyElement topologyElement = null; long reportedGid = outageEntity.DefaultIsolationPoints.First().EquipmentId; long outageElementId = -1; long UpBreaker; Task.Delay(5000).Wait(); using (OutageSimulatorServiceProxy proxy = proxyFactory.CreateProxy <OutageSimulatorServiceProxy, IOutageSimulatorContract>(EndpointNames.OutageSimulatorServiceEndpoint)) { if (proxy == null) { string message = "OutageModel::SendLocationIsolationCrew => OutageSimulatorProxy is null"; Logger.LogError(message); throw new NullReferenceException(message); } //Da li je prijaveljen element OutageElement if (proxy.IsOutageElement(reportedGid)) { outageElementId = reportedGid; } else { //Da li je mozda na ACL-novima ispod prijavljenog elementa if (outageModel.TopologyModel.GetElementByGid(reportedGid, out topologyElement)) { try { for (int i = 0; i < topologyElement.SecondEnd.Count; i++) { if (proxy.IsOutageElement(topologyElement.SecondEnd[i])) { if (outageElementId == -1) { outageElementId = topologyElement.SecondEnd[i]; outageEntity.OutageElementGid = outageElementId; } else { OutageEntity entity = new OutageEntity() { OutageElementGid = topologyElement.SecondEnd[i], ReportTime = DateTime.UtcNow }; dbContext.OutageRepository.Add(entity); } } } } catch (Exception ex) { Logger.LogError("OutageModel::SendLocationIsolationCrew => failed with error", ex); throw; } } } //Tragamo za ACL-om gore ka source-u while (outageElementId == -1 && !topologyElement.IsRemote && topologyElement.DmsType != "ENERGYSOURCE") { if (proxy.IsOutageElement(topologyElement.Id)) { outageElementId = topologyElement.Id; outageEntity.OutageElementGid = outageElementId; } outageModel.TopologyModel.GetElementByGid(topologyElement.FirstEnd, out topologyElement); } if (outageElementId == -1) { outageEntity.OutageState = OutageState.REMOVED; dbContext.OutageRepository.Remove(outageEntity); Logger.LogError("End of feeder no outage detected."); return(false); } outageModel.TopologyModel.GetElementByGidFirstEnd(outageEntity.OutageElementGid, out topologyElement); while (topologyElement.DmsType != "BREAKER") { outageModel.TopologyModel.GetElementByGidFirstEnd(topologyElement.Id, out topologyElement); } UpBreaker = topologyElement.Id; long nextBreaker = outageModel.GetNextBreaker(outageEntity.OutageElementGid); if (!outageModel.TopologyModel.OutageTopology.ContainsKey(nextBreaker)) { string message = $"Breaker (next breaker) with id: 0x{nextBreaker:X16} is not in topology"; Logger.LogError(message); throw new Exception(message); } long outageElement = outageModel.TopologyModel.OutageTopology[nextBreaker].FirstEnd; if (!outageModel.TopologyModel.OutageTopology[UpBreaker].SecondEnd.Contains(outageElement)) { string message = $"Outage element with gid: 0x{outageElement:X16} is not on a second end of current breaker id"; Logger.LogError(message); throw new Exception(message); } outageEntity.OptimumIsolationPoints = outageModel.GetEquipmentEntity(new List <long>() { UpBreaker, nextBreaker }); outageEntity.IsolatedTime = DateTime.UtcNow; outageEntity.OutageState = OutageState.ISOLATED; dbContext.OutageRepository.Update(outageEntity); SendSCADACommand(UpBreaker, DiscreteCommandingType.OPEN); SendSCADACommand(nextBreaker, DiscreteCommandingType.OPEN); } return(true); }