private void SendSCADACommand(long currentBreakerId, DiscreteCommandingType discreteCommandingType) { long measrement = -1; using (MeasurementMapProxy measurementMapProxy = proxyFactory.CreateProxy <MeasurementMapProxy, IMeasurementMapContract>(EndpointNames.MeasurementMapEndpoint)) { List <long> measuremnts = new List <long>(); try { measuremnts = measurementMapProxy.GetMeasurementsOfElement(currentBreakerId); } catch (Exception e) { //Logger.LogError("Error on GetMeasurementsForElement() method", e); throw e; } if (measuremnts.Count > 0) { measrement = measuremnts[0]; } } if (measrement != -1) { if (discreteCommandingType == DiscreteCommandingType.OPEN && !outageModel.commandedElements.Contains(currentBreakerId)) { //TODO: add at list outageModel.commandedElements.Add(currentBreakerId); } using (SwitchStatusCommandingProxy scadaCommandProxy = proxyFactory.CreateProxy <SwitchStatusCommandingProxy, ISwitchStatusCommandingContract>(EndpointNames.SwitchStatusCommandingEndpoint)) { try { scadaCommandProxy.SendOpenCommand(measrement); } catch (Exception e) { if (discreteCommandingType == DiscreteCommandingType.OPEN && outageModel.commandedElements.Contains(currentBreakerId)) { outageModel.commandedElements.Remove(currentBreakerId); } throw e; } } } }
private void SendSCADACommand(long currentBreakerId, DiscreteCommandingType discreteCommandingType) { long measrement = -1; using (MeasurementMapProxy measurementMapProxy = proxyFactory.CreateProxy <MeasurementMapProxy, IMeasurementMapContract>(EndpointNames.MeasurementMapEndpoint)) { List <long> measuremnts = new List <long>(); try { measuremnts = measurementMapProxy.GetMeasurementsOfElement(currentBreakerId); } catch (Exception e) { //Logger.LogError("Error on GetMeasurementsForElement() method", e); throw e; } if (measuremnts.Count > 0) { measrement = measuremnts[0]; } } if (measrement != -1) { if (discreteCommandingType == DiscreteCommandingType.OPEN && !outageModel.commandedElements.Contains(currentBreakerId)) { //TODO: add at list outageModel.commandedElements.Add(currentBreakerId); } using (SCADACommandProxy scadaCommandProxy = proxyFactory.CreateProxy <SCADACommandProxy, ISCADACommand>(EndpointNames.SCADACommandService)) { try { bool success = scadaCommandProxy.SendDiscreteCommand(measrement, (ushort)discreteCommandingType, CommandOriginType.ISOLATING_ALGORITHM_COMMAND); } catch (Exception e) { if (discreteCommandingType == DiscreteCommandingType.OPEN && outageModel.commandedElements.Contains(currentBreakerId)) { outageModel.commandedElements.Remove(currentBreakerId); } throw e; } } } }
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); }