Beispiel #1
0
        public async Task <DataTable> GetData()
        {
            _pbService.ShowProgressBar("Fetching Signals from Db.....", 0);
            var signals = await _signalService.GetAllSignals();

            _pbService.ShowProgressBar("Preparing Signals....", 50);
            await Task.Delay(2000);

            double signalCount   = signals.Count;
            var    datatable     = new DataTable();
            var    colCollection = datatable.Columns;

            colCollection.Add(new DataColumn("SIG_NAME"));
            colCollection.Add(new DataColumn("TAG_SOURCE"));
            double Counter = 0;

            foreach (var signal in signals)
            {
                Counter++;
                double percent = (Counter / signalCount) * 100;
                var    dataRow = datatable.NewRow();
                dataRow["SIG_NAME"]   = signal.Name;
                dataRow["TAG_SOURCE"] = signal.TagSource;
                foreach (var attribute in signal?.Attributes)
                {
                    if (!colCollection.Contains(attribute.Key))
                    {
                        colCollection.Add(new DataColumn(attribute.Key));
                    }
                    dataRow[attribute.Key] = attribute.Value;
                }
                datatable.Rows.Add(dataRow);
                _pbService.ShowProgressBar("Iterating....", percent);
            }

            await Task.Delay(500);

            _pbService.ShowProgressBar("Completed", 100);
            _pbService.ResetProgressBar();
            return(datatable);
        }
Beispiel #2
0
        public List <API_GV_SCObj> GetSubSCObjs(string role, string id, int type)
        {
            var data = new List <API_GV_SCObj>();

            try {
                if (string.IsNullOrWhiteSpace(role))
                {
                    throw new ArgumentNullException("role");
                }

                if (string.IsNullOrWhiteSpace(id))
                {
                    throw new ArgumentNullException("id");
                }

                if ((int)EnmAPISCObj.Area == type)
                {
                    if ("root".Equals(id))
                    {
                        var roots = _workContext.GetAreas(role).FindAll(a => !a.HasParents);
                        if (roots.Count > 0)
                        {
                            foreach (var root in roots)
                            {
                                data.Add(new API_GV_SCObj {
                                    ID   = root.Current.Id,
                                    Name = root.Current.Name,
                                    Type = (int)EnmAPISCObj.Area
                                });
                            }
                        }
                    }
                    else
                    {
                        var current = _workContext.GetAreas(role).Find(a => a.Current.Id.Equals(id));
                        if (current != null)
                        {
                            if (current.HasChildren)
                            {
                                foreach (var child in current.ChildRoot)
                                {
                                    data.Add(new API_GV_SCObj {
                                        ID   = child.Current.Id,
                                        Name = child.Current.Name,
                                        Type = (int)EnmAPISCObj.Area
                                    });
                                }
                            }
                            else
                            {
                                var stations = _workContext.GetStations(role).FindAll(s => s.AreaId.Equals(id));
                                foreach (var child in stations)
                                {
                                    data.Add(new API_GV_SCObj {
                                        ID   = child.Id,
                                        Name = child.Name,
                                        Type = (int)EnmAPISCObj.Station
                                    });
                                }
                            }
                        }
                    }
                }
                else if ((int)EnmAPISCObj.Station == type)
                {
                    var rooms = _workContext.GetRooms(role).FindAll(s => s.StationId.Equals(id));
                    foreach (var child in rooms)
                    {
                        data.Add(new API_GV_SCObj {
                            ID   = child.Id,
                            Name = child.Name,
                            Type = (int)EnmAPISCObj.Room
                        });
                    }
                }
                else if ((int)EnmAPISCObj.Room == type)
                {
                    var devices = _workContext.GetDevices(role).FindAll(s => s.RoomId.Equals(id));
                    foreach (var child in devices)
                    {
                        data.Add(new API_GV_SCObj {
                            ID   = child.Id,
                            Name = child.Name,
                            Type = (int)EnmAPISCObj.Device
                        });
                    }
                }
                else if ((int)EnmAPISCObj.Device == type)
                {
                    var signals = _signalService.GetAllSignals(id);
                    foreach (var child in signals)
                    {
                        data.Add(new API_GV_SCObj {
                            ID   = Common.JoinKeys(id, child.PointId),
                            Name = child.PointName,
                            Type = (int)EnmAPISCObj.Signal
                        });
                    }
                }
            } catch { }

            return(data);
        }