Beispiel #1
0
        /// <summary>
        /// Writes the current data.
        /// </summary>
        public override void WriteData(ICurrentData curData)
        {
            stopwatch.Restart();
            InitCnlIndexes(curData, ref cnlIndexes);

            lock (pointQueue.SyncRoot)
            {
                for (int i = 0, cnlCnt = CnlNums.Length; i < cnlCnt; i++)
                {
                    int cnlIndex = cnlIndexes[i];
                    pointQueue.EnqueueWithoutLock(CnlNums[i], curData.Timestamps[cnlIndex], curData.CnlData[cnlIndex]);
                }
            }

            pointQueue.RemoveExcessPoints();
            stopwatch.Stop();
            arcLog?.WriteAction(ServerPhrases.QueueingPointsCompleted, CnlNums.Length, stopwatch.ElapsedMilliseconds);
        }
Beispiel #2
0
        /// <summary>
        /// Processes new data.
        /// </summary>
        /// <remarks>Returns true if the data has been written to the archive.</remarks>
        public override bool ProcessData(ICurrentData curData)
        {
            if (archiveOptions.WritingMode == WritingMode.AutoWithPeriod)
            {
                if (nextWriteTime <= curData.Timestamp)
                {
                    DateTime writeTime = GetClosestWriteTime(curData.Timestamp, writingPeriod);
                    nextWriteTime = writeTime.AddSeconds(writingPeriod);

                    stopwatch.Restart();
                    InitCnlIndexes(curData, ref cnlIndexes);
                    int cnlCnt = CnlNums.Length;

                    lock (pointQueue.SyncRoot)
                    {
                        for (int i = 0; i < cnlCnt; i++)
                        {
                            pointQueue.EnqueueWithoutLock(CnlNums[i], writeTime, curData.CnlData[cnlIndexes[i]]);
                        }
                    }

                    pointQueue.RemoveExcessPoints();
                    stopwatch.Stop();
                    arcLog?.WriteAction(ServerPhrases.QueueingPointsCompleted, cnlCnt, stopwatch.ElapsedMilliseconds);
                    return(true);
                }
            }
            else if (archiveOptions.WritingMode == WritingMode.AutoOnChange)
            {
                stopwatch.Restart();
                int  changesCnt = 0;
                bool firstTime  = cnlIndexes == null;
                InitCnlIndexes(curData, ref cnlIndexes);

                if (firstTime)
                {
                    // do not write data for the first time
                    for (int i = 0, cnlCnt = CnlNums.Length; i < cnlCnt; i++)
                    {
                        prevCnlData[i] = curData.CnlData[cnlIndexes[i]];
                    }
                }
                else
                {
                    for (int i = 0, cnlCnt = CnlNums.Length; i < cnlCnt; i++)
                    {
                        CnlData curCnlData = curData.CnlData[cnlIndexes[i]];

                        if (prevCnlData[i] != curCnlData)
                        {
                            pointQueue.EnqueuePoint(CnlNums[i], curData.Timestamp, curCnlData);
                            prevCnlData[i] = curCnlData;
                            changesCnt++;
                        }
                    }
                }

                if (changesCnt > 0)
                {
                    pointQueue.RemoveExcessPoints();
                    stopwatch.Stop();
                    arcLog?.WriteAction(ServerPhrases.QueueingPointsCompleted,
                                        changesCnt, stopwatch.ElapsedMilliseconds);
                    return(true);
                }
                else
                {
                    stopwatch.Stop();
                }
            }

            return(false);
        }