예제 #1
0
        private static void OnUpdateEvent(object sender, EventArgs e)
        {
            ScadaStorageProxy proxy = ScadaProxyFactory.Instance().ScadaStorageProxy();
            ScadaUpdateEvent  ev    = new ScadaUpdateEvent()
            {
                Points = new List <ScadaPointDto>()
            };

            var all      = proxy.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));

            DomUpdateEvent dom = new DomUpdateEvent()
            {
                DomData = proxy.GetDomModel()
            };

            try
            {
                instace.Publish(ev).ConfigureAwait(false).GetAwaiter().GetResult();
                instace.Publish(dom).ConfigureAwait(false).GetAwaiter().GetResult();
            }
            catch (Exception ex) { }
        }
예제 #2
0
        public void UpdateMeasurements(object sender, ScadaUpdateEvent e)
        {
            if (!IsModelRetrieved)
            {
                return;
            }

            App.Current.Dispatcher.Invoke((System.Action) delegate
            {
                measurementUpdater.UpdateValues(e);
                var lvl = e.Points.SingleOrDefault(x => x.Mrid.Contains("Level"));
                if (lvl != null)
                {
                    Level = $"Fluid Level: {lvl.Value}";
                }
            });
        }
예제 #3
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());
            }
        }
예제 #4
0
 public void Update(object sender, ScadaUpdateEvent e)
 {
     e.Points = e.Points.Where(x => !String.IsNullOrEmpty(x.Mrid)).ToList();
     UpdatePoints(e.Points);
 }
예제 #5
0
 public Task Handle(ScadaUpdateEvent message, IMessageHandlerContext context)
 {
     scadaUpdate.Invoke(this, message);
     return(Task.CompletedTask);
 }
예제 #6
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);
        }
예제 #7
0
        public void UpdateValues(ScadaUpdateEvent updateEvent)
        {
            lock (lockobj)
            {
                flows = new Dictionary <string, string>();

                foreach (var point in updateEvent.Points)
                {
                    var nodeToUpdate = nodeLookupByMrid.Find(point.ObjectMrid);
                    if (nodeToUpdate == null)
                    {
                        continue;
                    }

                    if (point.Mrid.Contains("Flow"))
                    {
                        flows[point.Mrid] = point.Value.ToString();
                    }

                    nodeToUpdate.Item.UpdateMeasurements(Map(point));
                    if (point.RegisterType == RegisterType.ANALOG_OUTPUT && point.Mrid.Contains("Tap"))
                    {
                        nodeToUpdate.TurnedOn = nodeToUpdate.Active = point.Value > 0;
                    }
                    if (point.RegisterType == RegisterType.BINARY_OUTPUT)
                    {
                        nodeToUpdate.TurnedOn = nodeToUpdate.Active = point.Value == 1;
                    }
                }
                try
                {
                    if (updateEvent.Points.Count == 15)
                    {
                        var pump2 = nodeLookupByMrid.Find("AsyncM_2");
                        var flow2 = nodeLookupByMrid.Find("Flow_AM2");
                        if (pump2 == null)
                        {
                            return;
                        }
                        var list = new List <string>()
                        {
                            "Disc_01", "Breaker_01", "Disc_02", "Disc_12", "Breaker_12", "Disc_22", "RatioTC_2", "Breaker_22"
                        };

                        var nodes = new List <EquipmentTreeNode>();
                        list.ForEach(x => nodes.Add(nodeLookupByMrid.Find(x)));

                        var result = nodes.Any(x => x.TurnedOn == false);
                        pump2.TurnedOn     = !result;
                        pump2.Active       = true;
                        pump2.SpecialValue = flows["Flow_AM2"];


                        if (result)
                        {
                            foreach (var item in nodes)
                            {
                                if (!item.TurnedOn || !item.Active)
                                {
                                    item.Active = false;
                                    foreach (var eq in item.Children)
                                    {
                                        eq.Active = false;
                                    }
                                }
                            }
                        }
                    }
                    else if (updateEvent.Points.Count == 24)
                    {
                        var pump1 = nodeLookupByMrid.Find("AsyncM_1");
                        var pump2 = nodeLookupByMrid.Find("AsyncM_2");
                        if (pump1 == null || pump2 == null)
                        {
                            return;
                        }
                        var list1 = new List <string>()
                        {
                            "Disc_01", "Breaker_01", "Disc_02", "Disc_11", "Breaker_11", "Disc_21", "RatioTC_1", "Breaker_21"
                        };
                        var list2 = new List <string>()
                        {
                            "Disc_01", "Breaker_01", "Disc_02", "Disc_12", "Breaker_12", "Disc_22", "RatioTC_2", "Breaker_22"
                        };

                        var nodes1 = new List <EquipmentTreeNode>();
                        list1.ForEach(x => nodes1.Add(nodeLookupByMrid.Find(x)));

                        var nodes2 = new List <EquipmentTreeNode>();
                        list2.ForEach(x => nodes2.Add(nodeLookupByMrid.Find(x)));

                        var result1 = nodes1.Any(x => x.TurnedOn == false);
                        pump1.TurnedOn     = !result1;
                        pump1.Active       = true;
                        pump1.SpecialValue = flows["Flow_AM1"];

                        var result2 = nodes2.Any(x => x.TurnedOn == false);
                        pump2.TurnedOn     = !result2;
                        pump2.Active       = true;
                        pump2.SpecialValue = flows["Flow_AM2"];

                        if (result1)
                        {
                            foreach (var item in nodes1)
                            {
                                if (!item.TurnedOn || !item.Active)
                                {
                                    item.Active = false;
                                    foreach (var eq in item.Children)
                                    {
                                        eq.Active = false;
                                    }
                                }
                            }
                        }

                        if (result2)
                        {
                            foreach (var item in nodes2)
                            {
                                if (!item.TurnedOn || !item.Active)
                                {
                                    item.Active = false;
                                    foreach (var eq in item.Children)
                                    {
                                        eq.Active = false;
                                    }
                                }
                            }
                        }
                    }
                    else if (updateEvent.Points.Count == 33)
                    {
                        var pump1 = nodeLookupByMrid.Find("AsyncM_1");
                        var pump2 = nodeLookupByMrid.Find("AsyncM_2");
                        var pump3 = nodeLookupByMrid.Find("AsyncM_3");
                        if (pump1 == null || pump2 == null || pump3 == null)
                        {
                            return;
                        }
                        var list1 = new List <string>()
                        {
                            "Disc_01", "Breaker_01", "Disc_02", "Disc_11", "Breaker_11", "Disc_21", "RatioTC_1", "Breaker_21"
                        };
                        var list2 = new List <string>()
                        {
                            "Disc_01", "Breaker_01", "Disc_02", "Disc_12", "Breaker_12", "Disc_22", "RatioTC_2", "Breaker_22"
                        };
                        var list3 = new List <string>()
                        {
                            "Disc_01", "Breaker_01", "Disc_02", "Disc_13", "Breaker_13", "Disc_23", "RatioTC_3", "Breaker_23"
                        };

                        var nodes1 = new List <EquipmentTreeNode>();
                        list1.ForEach(x => nodes1.Add(nodeLookupByMrid.Find(x)));

                        var nodes2 = new List <EquipmentTreeNode>();
                        list2.ForEach(x => nodes2.Add(nodeLookupByMrid.Find(x)));

                        var nodes3 = new List <EquipmentTreeNode>();
                        list3.ForEach(x => nodes3.Add(nodeLookupByMrid.Find(x)));

                        var result1 = nodes1.Any(x => x.TurnedOn == false);
                        pump1.TurnedOn     = !result1;
                        pump1.Active       = true;
                        pump1.SpecialValue = flows["Flow_AM1"];

                        var result2 = nodes2.Any(x => x.TurnedOn == false);
                        pump2.TurnedOn     = !result2;
                        pump2.Active       = true;
                        pump2.SpecialValue = flows["Flow_AM2"];

                        var result3 = nodes3.Any(x => x.TurnedOn == false);
                        pump3.TurnedOn     = !result3;
                        pump3.Active       = true;
                        pump3.SpecialValue = flows["Flow_AM3"];

                        if (result1)
                        {
                            foreach (var item in nodes1)
                            {
                                if (!item.TurnedOn || !item.Active)
                                {
                                    item.Active = false;
                                    foreach (var eq in item.Children)
                                    {
                                        eq.Active = false;
                                    }
                                }
                            }
                        }

                        if (result2)
                        {
                            foreach (var item in nodes2)
                            {
                                if (!item.TurnedOn || !item.Active)
                                {
                                    item.Active = false;
                                    foreach (var eq in item.Children)
                                    {
                                        eq.Active = false;
                                    }
                                }
                            }
                        }

                        if (result3)
                        {
                            foreach (var item in nodes3)
                            {
                                if (!item.TurnedOn || !item.Active)
                                {
                                    item.Active = false;
                                    foreach (var eq in item.Children)
                                    {
                                        eq.Active = false;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception) { }
            }
        }
예제 #8
0
 public void Update(object sender, ScadaUpdateEvent e)
 {
     UpdatePoints(e.Points);
 }