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)); }
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(); }
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(); }
public void PutBlock(AnalogStoreBlock block) { lock (((ICollection)queueBlock).SyncRoot) { queueBlock.Enqueue(block); blockFinishedEvent.Set(); } }
public void Stop() { FinishAll(); AnalogStoreBlock blockStop = new AnalogStoreBlock(); PutDataBlock(blockStop); blockStop.Wait(10000); }
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); } }
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); }
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); } }
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); } }
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; }