public async Task Notify(IPublishableMessage message, string publisherName)
        {
            while (!ReliableDictionariesInitialized)
            {
                await Task.Delay(1000);
            }

            if (!(message is MultipleDiscreteValueSCADAMessage multipleDiscreteValueSCADAMessage))
            {
                string errorMessage = $"SCADA returned wrong value for in SCADAPublication. {typeof(MultipleDiscreteValueSCADAMessage)} excepted.";
                Logger.LogError(errorMessage);
                throw new Exception(errorMessage);
            }

            var enumerableMonitoredPoints = await MonitoredIsolationPoints.GetEnumerableDictionaryAsync();

            var enumerableCommandedValues = await CommandedValues.GetEnumerableDictionaryAsync();

            foreach (long measurementGid in multipleDiscreteValueSCADAMessage.Data.Keys)
            {
                if (!enumerableMonitoredPoints.ContainsKey(measurementGid))
                {
                    continue;
                }

                var scadaDataValue = multipleDiscreteValueSCADAMessage.Data[measurementGid].Value;

                await UpdateMonitoredPoints(measurementGid, enumerableMonitoredPoints, scadaDataValue);

                await UpdateCommandedValues(measurementGid, enumerableCommandedValues, scadaDataValue);
            }
        }
Exemple #2
0
        public async Task Start()
        {
            while (!ReliableDictionariesInitialized)
            {
                await Task.Delay(1000);
            }

            var enumerableOutages = await SimulatedOutages.GetEnumerableDictionaryAsync();

            var enumerableMonitoredPoints = await MonitoredIsolationPoints.GetEnumerableDictionaryAsync();

            if (enumerableOutages.Count == 0 || enumerableMonitoredPoints.Count == 0)
            {
                Logger.LogVerbose($"{baseLogString} Start => No simulated outages. End of cycle.");
                return;
            }

            var defaultIsolationPointsToBeOpened = new Dictionary <long, DiscreteModbusData>();
            var measurementMapClient             = MeasurementMapClient.CreateClient();
            var elementToMeasurementMap          = await measurementMapClient.GetElementToMeasurementMap();

            foreach (var outage in enumerableOutages.Values)
            {
                foreach (long defaultPointElementGid in outage.DefaultIsolationPointGids)
                {
                    if (!elementToMeasurementMap.ContainsKey(defaultPointElementGid))
                    {
                        continue;
                    }

                    var defaultPointMeasurementGid = elementToMeasurementMap[defaultPointElementGid].FirstOrDefault();

                    if (!outage.DefaultToOptimumIsolationPointMap.ContainsKey(defaultPointElementGid))
                    {
                        continue;
                    }

                    long optimumPointElementGid = outage.DefaultToOptimumIsolationPointMap[defaultPointElementGid];

                    if (!elementToMeasurementMap.ContainsKey(optimumPointElementGid))
                    {
                        continue;
                    }

                    long optimumPointMeasurementGid = elementToMeasurementMap[optimumPointElementGid].FirstOrDefault();

                    if (!enumerableMonitoredPoints.ContainsKey(optimumPointMeasurementGid) || !enumerableMonitoredPoints.ContainsKey(defaultPointMeasurementGid))
                    {
                        continue;
                    }

                    var    defaultIsolationPoint      = enumerableMonitoredPoints[defaultPointMeasurementGid].DiscreteModbusData;
                    ushort optimumIsolationPointValue = enumerableMonitoredPoints[optimumPointMeasurementGid].DiscreteModbusData.Value;

                    if (optimumIsolationPointValue == (ushort)DiscreteCommandingType.CLOSE && defaultIsolationPoint.Value == (ushort)DiscreteCommandingType.CLOSE)
                    {
                        defaultIsolationPointsToBeOpened.Add(defaultPointMeasurementGid, defaultIsolationPoint);
                        Logger.LogInformation($"{baseLogString} Start => preparing command to OPEN 0x{defaultPointElementGid:X16} because element 0x{optimumPointElementGid:X16} is CLOSED.");
                    }
                }
            }

            await OpenIsolationPoints(defaultIsolationPointsToBeOpened);
        }