public async Task <bool> SendSingleScadaCommandAsync(long breakerGid, DiscreteCommandingType discreteCommandingType, Dictionary <long, CommandedElement> commandedElements, CommandOriginType commandOriginType) { if (commandedElements.ContainsKey(breakerGid) && commandedElements[breakerGid].CommandingType == discreteCommandingType) { Logger.LogDebug($"{baseLogString} SendSingleScadaCommandAsync => Trying to send duplicate command. Aborting call."); return(false); } var measurementMapClient = MeasurementMapClient.CreateClient(); List <long> measurementGids = await measurementMapClient.GetMeasurementsOfElement(breakerGid); if (measurementGids.Count == 0) { Logger.LogWarning($"{baseLogString} SendSingleScadaCommandAsync => Element with gid: 0x{breakerGid:X16} has no measurements."); return(false); } var measurementGid = measurementGids.FirstOrDefault(); if (measurementGid == 0) { Logger.LogWarning($"{baseLogString} SendSingleScadaCommandAsync => Measurement gid is 0."); return(false); } var switchStatusCommandingClient = SwitchStatusCommandingClient.CreateClient(); bool sendCommandSuccess = false; if (discreteCommandingType == DiscreteCommandingType.OPEN) { sendCommandSuccess = await switchStatusCommandingClient.SendOpenCommand(measurementGid); } else if (discreteCommandingType == DiscreteCommandingType.CLOSE) { sendCommandSuccess = await switchStatusCommandingClient.SendCloseCommand(measurementGid); } return(sendCommandSuccess); }
public async Task <Unit> Handle(CloseSwitchCommand request, CancellationToken cancellationToken) { Logger.LogDebug($"[SwitchCommandHandler::TurnOnSwitchCommand] Sending {request.Command.ToString()} command to {request.Gid}"); CeContracts.ISwitchStatusCommandingContract switchStatusCommandingClient = SwitchStatusCommandingClient.CreateClient(); try { //commandingProxy.SendSwitchCommand(request.Gid, (int)request.Command); await switchStatusCommandingClient.SendCloseCommand(request.Gid); } catch (Exception ex) { Logger.LogError("[SwitchCommandHandler::TurnOnSwitchCommand] Failed on TurnOnSwitch handler.", ex); throw; } //return null; return(new Unit()); }
public async Task <Unit> Handle(OpenSwitchCommand request, CancellationToken cancellationToken) { Logger.LogInformation($"[SwitchCommandHandler::TurnOffSwitchCommand] Sending {request.Command.ToString()} command to {request.Gid}"); CeContracts.ISwitchStatusCommandingContract switchStatusCommandingClient = SwitchStatusCommandingClient.CreateClient(); try { await switchStatusCommandingClient.SendOpenCommand(request.Gid); } catch (Exception ex) { Logger.LogError("[SwitchCommandHandler::TurnOffSwitchCommand] SwitchCommandHandler failed on TurnOffSwitch handler.", ex); throw; } //return null; return(new Unit()); }