示例#1
0
        private AnalogStoreBlock GetBlock(int timeout)
        {
            AnalogStoreBlock block = null;

            lock (((ICollection)queueBlock).SyncRoot)
            {
                if (queueBlock.Count > 0)
                {
                    block = queueBlock.Dequeue();
                }
                else
                {
                    blockFinishedEvent.Reset();
                }
            }
            if (block != null || timeout == 0)
            {
                return(block);
            }

            if (timeout > 0)
            {
                blockFinishedEvent.WaitOne(timeout, false);
            }
            else
            {
                blockFinishedEvent.WaitOne();
            }
            return(GetBlock(0));
        }
示例#2
0
        public AnalogFile(AnalogDataManager manager, int type, int index)
        {
            this.dataManager = manager;
            this.Type        = type;
            this.Index       = index;
            if (type == 0x42)                              //半自动电压和电流
            {
                this.MaxFileSize = 100 * 10 * 1024 * 1024; //每天大约10M文件 按100天计算
            }
            else
            {
                this.MaxFileSize = 100 * 1024 * 1024; //每天大约1M文件
            }
            fileIndex = new AnalogIndexFile(this);
            fileData  = new AnalogRecordFile(this);

            for (int i = 0; i < BlockNum; i++)
            {
                queueBlock.Enqueue(new AnalogStoreBlock(i, this));
            }

            Random rnd = new Random();

            this.reserveCount = rnd.Next(AnalogStoreBlock.MaxPoint);
            currentBlock      = NewBlock(null, false);
            currentBlock.AddPrevNULL();
        }
示例#3
0
        public AnalogFile(AnalogDataManager manager, int type,int index)
        {
            this.dataManager = manager;
            this.Type = type;
            this.Index = index;
            if (type == 0x42) //半自动电压和电流
            {
                this.MaxFileSize =100 * 10 * 1024 * 1024; //每天大约10M文件 按100天计算
            }
            else
            {
                this.MaxFileSize = 100 * 1024 * 1024; //每天大约1M文件
            }
            fileIndex = new AnalogIndexFile(this);
            fileData = new AnalogRecordFile(this);

            for (int i = 0; i < BlockNum; i++)
            {
                queueBlock.Enqueue(new AnalogStoreBlock(i, this));
            }

            Random rnd = new Random();

            this.reserveCount = rnd.Next(AnalogStoreBlock.MaxPoint);
            currentBlock = NewBlock(null, false);
            currentBlock.AddPrevNULL();
        }
示例#4
0
 public void PutBlock(AnalogStoreBlock block)
 {
     lock (((ICollection)queueBlock).SyncRoot)
     {
         queueBlock.Enqueue(block);
         blockFinishedEvent.Set();
     }
 }
示例#5
0
        public void Stop()
        {
            FinishAll();

            AnalogStoreBlock blockStop = new AnalogStoreBlock();

            PutDataBlock(blockStop);

            blockStop.Wait(10000);
        }
示例#6
0
 public void Flush(bool newOrder)
 {
     this.dataManager.PutDataBlock(currentBlock);
     currentBlock = NewBlock(currentBlock, false);
     reserveCount = 0;
     if (newOrder)
     {
         Random rand = new Random();
         reserveCount = rand.Next(AnalogStoreBlock.MaxPoint);
     }
 }
示例#7
0
        private AnalogStoreBlock NewBlock(AnalogStoreBlock oldBlock, bool newIndex)
        {
            AnalogStoreBlock newBlock = GetBlock(-1);

            if ((oldBlock == null) && (!newIndex))
            {
                newBlock.IndexRecord = fileIndex.LastIndex;
            }
            else if (newIndex)
            {
                newBlock.IndexRecord = fileIndex.NewIndex();
            }
            else
            {
                newBlock.IndexRecord = oldBlock.IndexRecord;
            }
            newBlock.Clear();
            return(newBlock);
        }
示例#8
0
        public void AddAnalog(DateTime time, float value, byte digit)
        {
            if (currentBlock == null)
            {
                currentBlock = NewBlock(null, false);
            }
            int pointNum = currentBlock.AddAnalog(time, value, digit);

            if (pointNum >= 0)
            {
                if (pointNum + reserveCount >= AnalogStoreBlock.MaxPoint)
                {
                    Flush(false);
                }
            }
            else
            {
                this.dataManager.PutDataBlock(currentBlock);
                currentBlock = NewBlock(currentBlock, true);
                currentBlock.IndexRecord.Type = (pointNum == -2) ? FallbackType.Fallback : FallbackType.Normal;
                currentBlock.AddAnalog(time, value, digit);
            }
        }
示例#9
0
 public void AddAnalog(DateTime time, float value, byte digit)
 {
     if (currentBlock == null)
     {
         currentBlock = NewBlock(null,false);
     }
     int pointNum = currentBlock.AddAnalog(time, value, digit);
     if (pointNum >= 0)
     {
         if (pointNum + reserveCount >= AnalogStoreBlock.MaxPoint)
         {
             Flush(false);
         }
     }
     else
     {
         this.dataManager.PutDataBlock(currentBlock);
         currentBlock = NewBlock(currentBlock, true);
         currentBlock.IndexRecord.Type = (pointNum == -2) ? FallbackType.Fallback : FallbackType.Normal;
         currentBlock.AddAnalog(time, value, digit);
     }
 }
示例#10
0
 private AnalogStoreBlock NewBlock(AnalogStoreBlock oldBlock,bool newIndex)
 {
     AnalogStoreBlock newBlock = GetBlock(-1);
     if ((oldBlock == null) && (!newIndex))
     {
         newBlock.IndexRecord = fileIndex.LastIndex;
     }
     else if (newIndex)
     {
         newBlock.IndexRecord = fileIndex.NewIndex();
     }
     else
     {
         newBlock.IndexRecord = oldBlock.IndexRecord;
     }
     newBlock.Clear();
     return newBlock;
 }
示例#11
0
 public void PutBlock(AnalogStoreBlock block)
 {
     lock (((ICollection)queueBlock).SyncRoot)
     {
         queueBlock.Enqueue(block);
         blockFinishedEvent.Set();
     }
 }
示例#12
0
 public void Flush(bool newOrder)
 {
     this.dataManager.PutDataBlock(currentBlock);
     currentBlock = NewBlock(currentBlock, false);
     reserveCount = 0;
     if (newOrder)
     {
         Random rand = new Random();
         reserveCount = rand.Next(AnalogStoreBlock.MaxPoint);
     }
 }
示例#13
0
        public void Stop()
        {
            FinishAll();

            AnalogStoreBlock blockStop = new AnalogStoreBlock();

            PutDataBlock(blockStop);

            blockStop.Wait(10000);
        }