示例#1
0
        /// <summary>
        /// Requests events from the server.
        /// </summary>
        private EventPacket RequestEvents(int archiveBit, TimeRange timeRange,
                                          EventFilter filter, long filterID, bool useCache)
        {
            List <Event> events = filterID > 0
                ? clientAccessor.ScadaClient.GetEvents(archiveBit, timeRange, ref filterID)
                : clientAccessor.ScadaClient.GetEvents(archiveBit, timeRange, filter, useCache, out filterID);

            int eventCnt = events.Count;

            EventRecord[]    records   = new EventRecord[eventCnt];
            CnlDataFormatter formatter = CreateFormatter();

            for (int i = 0; i < eventCnt; i++)
            {
                Event ev = events[i];
                records[i] = new EventRecord
                {
                    Id = ev.EventID.ToString(),
                    E  = ev,
                    Ef = formatter.FormatEvent(ev)
                };
            }

            return(new EventPacket
            {
                Records = records,
                FilterID = filterID.ToString()
            });
        }
示例#2
0
        /// <summary>
        /// Requests the current data from the server.
        /// </summary>
        private CurData RequestCurData(IList <int> cnlNums, long cnlListID, bool useCache)
        {
            int cnlCnt = cnlNums == null ? 0 : cnlNums.Count;

            CurDataRecord[] records = new CurDataRecord[cnlCnt];
            CurData         curData = new()
            {
                ServerTime = TimeRecord.Create(DateTime.UtcNow, userContext.TimeZone),
                Records    = records,
                CnlListID  = "0"
            };

            if (cnlCnt > 0)
            {
                CnlData[] cnlDataArr = cnlListID > 0
                    ? clientAccessor.ScadaClient.GetCurrentData(ref cnlListID)
                    : clientAccessor.ScadaClient.GetCurrentData(cnlNums.ToArray(), useCache, out cnlListID);
                curData.CnlListID = cnlListID.ToString();
                CnlDataFormatter formatter = CreateFormatter();

                for (int i = 0; i < cnlCnt; i++)
                {
                    int     cnlNum  = cnlNums[i];
                    CnlData cnlData = i < cnlDataArr.Length ? cnlDataArr[i] : CnlData.Empty;

                    records[i] = new CurDataRecord
                    {
                        D  = new CurDataPoint(cnlNum, cnlData),
                        Df = formatter.FormatCnlData(cnlData, cnlNum, false)
                    };
                }
            }

            return(curData);
        }
示例#3
0
        /// <summary>
        /// Requests historical data from the server.
        /// </summary>
        private HistData RequestHistData(int archiveBit, TimeRange timeRange, IList <int> cnlNums)
        {
            if (cnlNums == null)
            {
                cnlNums = Array.Empty <int>();
            }

            int cnlCnt = cnlNums.Count;

            HistData.RecordList[] trends = new HistData.RecordList[cnlCnt];

            HistData histData = new()
            {
                CnlNums    = cnlNums,
                Timestamps = Array.Empty <TimeRecord>(),
                Trends     = trends
            };

            if (cnlCnt > 0)
            {
                // request trends
                TrendBundle trendBundle = clientAccessor.ScadaClient.GetTrends(
                    archiveBit, timeRange, cnlNums.ToArray());

                // copy timestamps
                int          pointCount = trendBundle.Timestamps.Count;
                TimeRecord[] timestamps = new TimeRecord[pointCount];
                histData.Timestamps = timestamps;

                for (int i = 0; i < pointCount; i++)
                {
                    timestamps[i] = TimeRecord.Create(trendBundle.Timestamps[i], userContext.TimeZone);
                }

                // copy channel data
                CnlDataFormatter formatter = CreateFormatter();

                for (int cnlIdx = 0; cnlIdx < cnlCnt; cnlIdx++)
                {
                    int cnlNum = cnlNums[cnlIdx];
                    Cnl cnl    = webContext.ConfigDatabase.CnlTable.GetItem(cnlNum);
                    HistData.RecordList     records     = trends[cnlIdx] = new(pointCount);
                    TrendBundle.CnlDataList cnlDataList = trendBundle.Trends[cnlIdx];

                    for (int ptIdx = 0; ptIdx < pointCount; ptIdx++)
                    {
                        CnlData cnlData = cnlDataList[ptIdx];
                        records.Add(new HistDataRecord
                        {
                            D  = cnlData,
                            Df = formatter.FormatCnlData(cnlData, cnl, false)
                        });
                    }
                }
            }

            return(histData);
        }
示例#4
0
        private TrendBundle trendBundle;                  // the chart data of many channels


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public ChartDataBuilder(ConfigDataset configDataset, ScadaClient scadaClient, ChartDataBuilderOptions options)
        {
            this.configDataset = configDataset ?? throw new ArgumentNullException(nameof(configDataset));
            this.scadaClient   = scadaClient ?? throw new ArgumentNullException(nameof(scadaClient));
            this.options       = options ?? throw new ArgumentNullException(nameof(options));
            options.Validate();
            formatter = new CnlDataFormatter(configDataset);

            cnls        = Array.Empty <Cnl>();
            singleTrend = null;
            trendBundle = null;
        }