コード例 #1
0
        public bool PublishOutage(Topic topic, OutageMessage outageMessage)
        {
            bool success;

            OutagePublication outagePublication = new OutagePublication(topic, outageMessage);

            using (PublisherProxy publisherProxy = proxyFactory.CreateProxy <PublisherProxy, IPublisher>(EndpointNames.PublisherEndpoint))
            {
                if (publisherProxy == null)
                {
                    string errMsg = "Publisher proxy is null";
                    Logger.LogWarn(errMsg);
                    throw new NullReferenceException(errMsg);
                }

                try
                {
                    publisherProxy.Publish(outagePublication, "OUTAGE_PUBLISHER");
                    Logger.LogInfo($"Outage service published data from topic: {outagePublication.Topic}");
                    success = true;
                }
                catch (Exception e)
                {
                    string message = $"OutageModel::PublishActiveOutage => exception on PublisherProxy.Publish()";
                    Logger.LogError(message, e);
                    success = false;
                }
            }

            return(success);
        }
コード例 #2
0
        private void PublishScadaData(Topic topic, SCADAMessage scadaMessage)
        {
            SCADAPublication scadaPublication = new SCADAPublication(topic, scadaMessage);

            using (PublisherProxy publisherProxy = proxyFactory.CreateProxy <PublisherProxy, IPublisher>(EndpointNames.PublisherEndpoint))
            {
                if (publisherProxy == null)
                {
                    string errMsg = "PublisherProxy is null.";
                    Logger.LogWarn(errMsg);
                    throw new NullReferenceException(errMsg);
                }

                publisherProxy.Publish(scadaPublication, "SCADA_PUBLISHER");
                Logger.LogInfo($"SCADA service published data from topic: {scadaPublication.Topic}");

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("MeasurementCache content: ");

                foreach (long gid in MeasurementsCache.Keys)
                {
                    IModbusData data = MeasurementsCache[gid];

                    if (data is AnalogModbusData analogModbusData)
                    {
                        sb.AppendLine($"Analog data line: [gid] 0x{gid:X16}, [value] {analogModbusData.Value}, [alarm] {analogModbusData.Alarm}");
                    }
                    else if (data is DiscreteModbusData discreteModbusData)
                    {
                        sb.AppendLine($"Discrete data line: [gid] 0x{gid:X16}, [value] {discreteModbusData.Value}, [alarm] {discreteModbusData.Alarm}");
                    }
                    else
                    {
                        sb.AppendLine($"UNKNOWN data type: {data.GetType()}");
                    }
                }

                Logger.LogDebug(sb.ToString());
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //ChannelFactory<IPublisher> factory = new ChannelFactory<IPublisher>("PubSubService");
            //IPublisher proxy = factory.CreateChannel();
            Console.WriteLine("Connected..");
            var proxy = new PublisherProxy("PubSubService");

            Thread thread = new Thread(() => Send(proxy));

            thread.Start();
            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(1000);

                proxy.Publish(new Publication(PubSubCommon.Enums.Topic.Measurement, ("Hello " + i)));
                Console.WriteLine($"Message \" Hello {i} \" sent.");
            }



            Console.ReadLine();
        }
コード例 #4
0
        public void WebTopologyModelProviderDelegate(List <UIModel> uIModels)
        {
            //Dok se ne sredi logika za vise root-ova na WEB-u
            UIModel uIModel;

            if (uIModels.Count == 0)
            {
                uIModel = new UIModel();
            }
            else
            {
                uIModel = uIModels.First();
            }
            TopologyForUIMessage         message     = new TopologyForUIMessage(uIModel);
            CalculationEnginePublication publication = new CalculationEnginePublication(Topic.TOPOLOGY, message);

            try
            {
                using (PublisherProxy publisherProxy = proxyFactory.CreateProxy <PublisherProxy, IPublisher>(EndpointNames.PublisherEndpoint))
                {
                    if (publisherProxy == null)
                    {
                        string errMessage = "WebTopologyModelProviderDelegate => PublisherProxy is null.";
                        logger.LogError(errMessage);
                        throw new NullReferenceException(errMessage);
                    }


                    publisherProxy.Publish(publication, "CE_PUBLISHER");
                    logger.LogDebug("Topology publisher published new ui model successfully.");
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Topology publisher failed to publish new ui model. Exception: {ex.Message}");
            }
        }
コード例 #5
0
        public void TopologyToOMSConvertDelegate(List <IOutageTopologyModel> outageTopologyModels)
        {
            IOutageTopologyModel outageTopologyModel;

            if (outageTopologyModels.Count == 0)
            {
                outageTopologyModel = new OutageTopologyModel();
            }
            else
            {
                outageTopologyModel = outageTopologyModels.First();
            }

            OMSModelMessage message = new OMSModelMessage(outageTopologyModel);
            CalculationEnginePublication publication = new CalculationEnginePublication(Topic.OMS_MODEL, message);

            try
            {
                using (PublisherProxy publisherProxy = proxyFactory.CreateProxy <PublisherProxy, IPublisher>(EndpointNames.PublisherEndpoint))
                {
                    if (publisherProxy == null)
                    {
                        string errMessage = "TopologyToOMSConvertDelegate => PublisherProxy is null.";
                        logger.LogError(errMessage);
                        throw new NullReferenceException(errMessage);
                    }

                    publisherProxy.Publish(publication, "CE_PUBLICATION");
                    logger.LogDebug("Topology publisher published new oms model successfully.");
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Topology publisher failed to publish new oms model. Exception: {ex.Message}");
            }
        }