Example #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));
        }
Example #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();
        }
Example #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();
        }
Example #4
0
 public void PutBlock(AnalogStoreBlock block)
 {
     lock (((ICollection)queueBlock).SyncRoot)
     {
         queueBlock.Enqueue(block);
         blockFinishedEvent.Set();
     }
 }
Example #5
0
        public void Stop()
        {
            FinishAll();

            AnalogStoreBlock blockStop = new AnalogStoreBlock();

            PutDataBlock(blockStop);

            blockStop.Wait(10000);
        }
Example #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);
     }
 }
Example #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);
        }
Example #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);
            }
        }
Example #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);
     }
 }
Example #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;
 }
Example #11
0
 public void PutBlock(AnalogStoreBlock block)
 {
     lock (((ICollection)queueBlock).SyncRoot)
     {
         queueBlock.Enqueue(block);
         blockFinishedEvent.Set();
     }
 }
Example #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);
     }
 }
Example #13
0
        public void Stop()
        {
            FinishAll();

            AnalogStoreBlock blockStop = new AnalogStoreBlock();

            PutDataBlock(blockStop);

            blockStop.Wait(10000);
        }