private async Task Initialize() { try { InitializeReliableCollections(); Logger.LogDebug($"{baseLogString} Initialize => ReliableDictionaries initialized."); var topologyProviderClient = TopologyProviderClient.CreateClient(); using (ITransaction tx = this.StateManager.CreateTransaction()) { var result = await StateManager.TryGetAsync <IReliableDictionary <string, OutageTopologyModel> >(ReliableDictionaryNames.OutageTopologyModel); if (result.HasValue) { await result.Value.SetAsync(tx, ReliableDictionaryNames.OutageTopologyModel, await topologyProviderClient.GetOMSModel()); await tx.CommitAsync(); } else { Logger.LogError($"{baseLogString} Initialize => Reliable dictionary {ReliableDictionaryNames.OutageTopologyModel} was not found."); } } var registerSubscriberClient = RegisterSubscriberClient.CreateClient(); await registerSubscriberClient.SubscribeToTopic(Topic.SWITCH_STATUS, MicroserviceNames.OmsOutageLifecycleService); await registerSubscriberClient.SubscribeToTopic(Topic.OMS_MODEL, MicroserviceNames.OmsOutageLifecycleService); Logger.LogDebug($"{baseLogString} Initialize => Successfully subscribed to topics."); } catch (Exception e) { Logger.LogError($"{baseLogString} Initialize => Exception: {e.Message}"); } }
public async Task Notify(IPublishableMessage message, string publisherName) { while (!ReliableDictionariesInitialized) { await Task.Delay(1000); } if (message is EmailToOutageMessage emailMessage) { if (emailMessage.Gid == 0) { Logger.LogError("Invalid email received."); return; } Logger.LogInformation($"Received call from Energy Consumer with GID: 0x{emailMessage.Gid:X16}."); if (!modelResourcesDesc.GetModelCodeFromId(emailMessage.Gid).Equals(ModelCode.ENERGYCONSUMER)) { Logger.LogWarning($"Received GID 0x{emailMessage.Gid:X16} is not id of energy consumer."); return; } var topologyProviderClient = TopologyProviderClient.CreateClient(); var topology = await topologyProviderClient.GetOMSModel(); if (!topology.GetElementByGid(emailMessage.Gid, out OutageTopologyElement elment)) { Logger.LogWarning($"Received GID 0x{emailMessage.Gid:X16} is not part of topology."); return; } if (!timer.Enabled) { timer.Start(); } await Calls.SetAsync(emailMessage.Gid, emailMessage.Gid); Logger.LogInformation($"Current number of calls is: {await Calls.GetCountAsync()}."); if (await Calls.GetCountAsync() >= expectedCalls) { await trackingAlgorithm.Start((await Calls.GetDataCopyAsync()).Keys.ToList()); await Calls.ClearAsync(); timer.Stop(); } } }
public async Task <OmsGraphViewModel> Handle(GetTopologyQuery request, CancellationToken cancellationToken) { ITopologyProviderContract topologyServiceClient = TopologyProviderClient.CreateClient(); try { Logger.LogInformation("[TopologyQueryHandler::GetTopologyQuery] Sending GET query to topology client."); UIModel topologyModel = await topologyServiceClient.GetUIModel(); OmsGraphViewModel graph = _mapper.Map(topologyModel); return(graph); } catch (Exception ex) { Logger.LogError("[TopologyQueryHandler::GetTopologyQuery] Sending GET query to topology client failed.", ex); return(null); } }
private async Task CommandToRecloser(long measurementGid, int value, CommandOriginType originType, ITopologyElement recloser) { string verboseMessage = $"{baseLogString} CommandToRecloser method called."; Logger.LogVerbose(verboseMessage); if (recloser == null) { string message = $"{baseLogString} CommandToRecloser => NULL value has been passed instead of element."; Logger.LogError(message); throw new Exception(message); } if (!(recloser is Recloser)) { string message = $"{baseLogString} CommandToRecloser => Element with GID {recloser.Id:X16} is not a recloser."; Logger.LogError(message); throw new Exception(message); } Logger.LogDebug($"{baseLogString} CommandToRecloser => Enetring in sleep for 20 seconds."); await Task.Delay(recloserInterval); Logger.LogDebug($"{baseLogString} CommandToRecloser => Waking up after 20 seconds."); var topologyProviderClient = TopologyProviderClient.CreateClient(); int counter = await topologyProviderClient.GetRecloserCount(recloser.Id); if (((Recloser)recloser).MaxNumberOfTries > counter) { topologyProviderClient = TopologyProviderClient.CreateClient(); await topologyProviderClient.RecloserOpened(recloser.Id); Logger.LogDebug($"{baseLogString} CommandToRecloser => Calling SendDiscreteCommand method from measurement provider. Measurement GID: {measurementGid:X16}, Value: {value}, OriginType {originType}."); var measurementProviderClient = MeasurementProviderClient.CreateClient(); await measurementProviderClient.SendSingleDiscreteCommand(measurementGid, value, originType); Logger.LogDebug($"{baseLogString} CommandToRecloser => SendDiscreteCommand method has been successfully called."); } }
public async Task Start(List <long> calls) { Logger.LogDebug("Starting tracking algorithm."); //on every start tracking algorithm get up to date outage topology model var topologyProviderClient = TopologyProviderClient.CreateClient(); outageTopologyModel = await topologyProviderClient.GetOMSModel(); this.potentialOutages = LocateSwitchesUsingCalls(calls); this.outages = new List <long>(); HashSet <long> visited = new HashSet <long>(); bool foundOutage = false; long currentGid, previousGid; currentGid = this.potentialOutages[0]; try { while (this.potentialOutages.Count > 0) { currentGid = this.potentialOutages[0]; previousGid = currentGid; this.outages.Add(currentGid); outageTopologyModel.GetElementByGid(currentGid, out OutageTopologyElement topologyElement); this.potentialOutages.Remove(currentGid); while (topologyElement.DmsType != "ENERGYSOURCE" && !topologyElement.IsRemote && this.potentialOutages.Count > 0) { foundOutage = false; if (TraceDFS(visited, topologyElement, foundOutage)) { this.outages.Remove(previousGid); this.outages.Add(currentGid); previousGid = currentGid; } topologyElement = GetSwitch(topologyElement.FirstEnd); if (topologyElement == null) { break; } currentGid = topologyElement.Id; } } } catch (Exception ex) { string message = $"Tracing algorithm failed with error: {ex.Message}"; Logger.LogError(message); Console.WriteLine(message); } var reportOutageClient = PotentialOutageReportingClient.CreateClient(); foreach (var potentialOutageElementGid in this.outages) { var ceModelProviderClient = CeModelProviderClient.CreateClient(); if (!await ceModelProviderClient.IsRecloser(potentialOutageElementGid)) { //TODO: razdvojiti metode scada, noScada await reportOutageClient.ReportPotentialOutage(potentialOutageElementGid, CommandOriginType.NON_SCADA_OUTAGE, NetworkType.NON_SCADA_NETWORK); } else { Logger.LogDebug($"{baseLogString} Start => Element with gid 0x{potentialOutageElementGid:X16} is a Recloser. ReportPotentialOutage call is not required."); } } }