Exemplo n.º 1
0
 internal void Update(object sender, HistoryUpdateEvent e)
 {
     App.Current.Dispatcher.Invoke((System.Action) delegate
     {
         TimeStamp = $"{DateTime.Now.ToString()} - Last 30 records";
         Data.History.Clear();
         TableData = new ObservableCollection <HistoryDto>();
         foreach (var item in e.History)
         {
             TableData.Add(Mapper.Map <HistoryDto>(item));
             Data.History.Add(Mapper.Map <HistoryDto>(item));
         }
     });
 }
Exemplo n.º 2
0
        private void DoWork()
        {
            while (executionFlag)
            {
                DomUpdateEvent dom = new DomUpdateEvent()
                {
                    DomData = ScadaProxyFactory.Instance().DOMProxy().GetAll().ToSwitchingEquipment()
                };
                HistoryUpdateEvent history = new HistoryUpdateEvent()
                {
                    History = ScadaProxyFactory.Instance().HistoryProxy().GetAll()
                };
                HistoryGraphicalEvent graph = new HistoryGraphicalEvent()
                {
                    Graph = ScadaProxyFactory.Instance().HistoryProxy().GetGraph()
                };
                ScadaUpdateEvent ev = new ScadaUpdateEvent()
                {
                    Points = new List <SCADA.Common.DataModel.ScadaPointDto>()
                };
                var all      = ScadaProxyFactory.Instance().ScadaStorageProxy().GetModel().Values.ToList();
                var analogs  = all.Where(x => x.RegisterType == RegisterType.ANALOG_INPUT || x.RegisterType == RegisterType.ANALOG_OUTPUT).Cast <AnalogPoint>().ToList();
                var binaries = all.Where(x => x.RegisterType == RegisterType.BINARY_INPUT || x.RegisterType == RegisterType.BINARY_OUTPUT).Cast <DiscretePoint>().ToList();
                ev.Points.AddRange(Mapper.MapCollection <AnalogPoint, ScadaPointDto>(analogs));
                ev.Points.AddRange(Mapper.MapCollection <DiscretePoint, ScadaPointDto>(binaries));
                if (ev.Points.Count > 0)
                {
                    endpoint.Publish(ev).ConfigureAwait(false);
                }
                if (dom.DomData.Count > 0)
                {
                    endpoint.Publish(dom).ConfigureAwait(false);
                }
                if (history.History.Count > 0)
                {
                    endpoint.Publish(history).ConfigureAwait(false);
                }
                endpoint.Publish(graph).ConfigureAwait(false);

                Thread.Sleep(GetConfigTime());
            }
        }
Exemplo n.º 3
0
 public Task Handle(HistoryUpdateEvent message, IMessageHandlerContext context)
 {
     historyUpdate.Invoke(this, message);
     return(Task.CompletedTask);
 }
Exemplo n.º 4
0
        private void Update()
        {
            var            domService     = new DomServiceProxy(ConfigurationReader.ReadValue(Context, "Settings", "Dom"));
            var            historyService = new HistoryServiceProxy(ConfigurationReader.ReadValue(Context, "Settings", "History"));
            var            storageService = new ScadaStorageProxy(ConfigurationReader.ReadValue(Context, "Settings", "Storage"));
            var            domData        = domService.GetAll().GetAwaiter().GetResult();
            DomUpdateEvent dom            = new DomUpdateEvent()
            {
                DomData = domData.ToSwitchingEquipment()
            };
            HistoryUpdateEvent history = new HistoryUpdateEvent()
            {
                History = historyService.GetAll().GetAwaiter().GetResult()
            };
            HistoryGraphicalEvent graph = new HistoryGraphicalEvent()
            {
                Graph = historyService.GetGraph().GetAwaiter().GetResult()
            };
            ScadaUpdateEvent ev = new ScadaUpdateEvent()
            {
                Points = new List <SCADA.Common.DataModel.ScadaPointDto>()
            };

            var all      = (storageService.GetModel().GetAwaiter().GetResult()).Values.ToList();
            var analogs  = all.Where(x => x.RegisterType == RegisterType.ANALOG_INPUT || x.RegisterType == RegisterType.ANALOG_OUTPUT).Cast <AnalogPoint>().ToList();
            var binaries = all.Where(x => x.RegisterType == RegisterType.BINARY_INPUT || x.RegisterType == RegisterType.BINARY_OUTPUT).Cast <DiscretePoint>().ToList();

            ev.Points.AddRange(Mapper.MapCollection <AnalogPoint, ScadaPointDto>(analogs));
            ev.Points.AddRange(Mapper.MapCollection <DiscretePoint, ScadaPointDto>(binaries));

            Subscription subs      = new Subscription();
            Publisher    publisher = new Publisher(subs.Topic, subs.ConnectionString);

            if (ev.Points.Count > 0)
            {
                publisher.SendMessage(new PubSubMessage()
                {
                    ContentType = ContentType.SCADA_UPDATE,
                    Sender      = Sender.SCADA,
                    Content     = JsonTool.Serialize <ScadaUpdateEvent>(ev)
                }).ConfigureAwait(false);
            }
            if (dom.DomData.Count > 0)
            {
                publisher.SendMessage(new PubSubMessage()
                {
                    ContentType = ContentType.SCADA_DOM,
                    Sender      = Sender.SCADA,
                    Content     = JsonTool.Serialize <DomUpdateEvent>(dom)
                }).ConfigureAwait(false);
            }
            if (history.History.Count > 0)
            {
                publisher.SendMessage(new PubSubMessage()
                {
                    ContentType = ContentType.SCADA_HISTORY,
                    Sender      = Sender.SCADA,
                    Content     = JsonTool.Serialize <HistoryUpdateEvent>(history)
                }).ConfigureAwait(false);
            }
            publisher.SendMessage(new PubSubMessage()
            {
                ContentType = ContentType.SCADA_HISTORY_GRAPH,
                Sender      = Sender.SCADA,
                Content     = JsonTool.Serialize <HistoryGraphicalEvent>(graph)
            }).ConfigureAwait(false);
        }