Пример #1
0
        private async Task InitializeMonitoredPoints(SimulatedOutage outage)
        {
            var measurementMapClient    = MeasurementMapClient.CreateClient();
            var measurementToElementGid = await measurementMapClient.GetMeasurementToElementMap();

            var scadaClient = ScadaIntegrityUpdateClient.CreateClient();
            var publication = await scadaClient.GetIntegrityUpdateForSpecificTopic(Common.Cloud.Topic.SWITCH_STATUS);

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

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

                var elementGid = measurementToElementGid[measurementGid];

                if (!outage.ElementsOfInteres.Contains(elementGid))
                {
                    continue;
                }

                var modbusData = multipleDiscreteValueSCADAMessage.Data[measurementGid];

                var monitoredPoint = new MonitoredIsolationPoint()
                {
                    IsolationElementGid       = elementGid,
                    DiscreteMeasurementGid    = measurementGid,
                    SimulatedOutageElementGid = outage.OutageElementGid,
                    DiscreteModbusData        = modbusData,
                    IsolationPointType        = outage.OptimumIsolationPointGids.Contains(elementGid) ?
                                                IsolationPointType.OPTIMUM :
                                                outage.DefaultIsolationPointGids.Contains(elementGid) ?
                                                IsolationPointType.DEFAULT :
                                                0,
                };

                await MonitoredIsolationPoints.SetAsync(measurementGid, monitoredPoint);
            }
        }
        private async Task <bool> StartIsolationAlgorthm(OutageEntity outageToIsolate)
        {
            var result = await CreateIsolatingAlgorithm(outageToIsolate);

            if (!result.HasValue)
            {
                Logger.LogError($"{baseLogString} StartIsolationAlgorthm => CreateIsolatingAlgorithm did not return a vaule.");
                return(false);
            }

            var algorithm = result.Value;

            Logger.LogInformation($"{baseLogString} StartIsolationAlgorthm => HeadBreakerGid: 0x{algorithm.HeadBreakerGid:X16}, RecloserGd: 0x{algorithm.RecloserGid:X16} (Recloser gid is -1 if there is no recloser...).");

            var scadaClient      = ScadaIntegrityUpdateClient.CreateClient();
            var scadaPublication = await scadaClient.GetIntegrityUpdateForSpecificTopic(Topic.SWITCH_STATUS);

            if (!(scadaPublication.Message is MultipleDiscreteValueSCADAMessage multipleDiscreteValueSCADAMessage))
            {
                Logger.LogError($"{baseLogString} StartIsolationAlgorthm => ScadaPublication message is not of expected type: {typeof(MultipleDiscreteValueSCADAMessage)}, but of type: {scadaPublication.Message.GetType()}");
                return(false);
            }

            if (!multipleDiscreteValueSCADAMessage.Data.ContainsKey(algorithm.HeadBreakerMeasurementGid))
            {
                Logger.LogError($"{baseLogString} StartIsolationAlgorthm => HeadBreakerMeasurement with gid: 0x{algorithm.HeadBreakerMeasurementGid:X16} not found in integrity update data received from scada.");
                return(false);
            }

            var discreteModbusData = multipleDiscreteValueSCADAMessage.Data[algorithm.HeadBreakerMeasurementGid];
            await MonitoredHeadBreakerMeasurements.SetAsync(algorithm.HeadBreakerMeasurementGid, discreteModbusData);

            await StartedIsolationAlgorithms.SetAsync(algorithm.HeadBreakerGid, algorithm);

            return(true);
        }