From ba87cd21f8e8e630aa965f09323bd4c96e2b1ac0 Mon Sep 17 00:00:00 2001 From: Candy Date: Mon, 28 Sep 2020 16:07:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=B8=B8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Driver/SimDriver/Driver.cs | 2 +- RunTime/DBHisData/HisQuery/DataFileManager.cs | 68 ++---- .../HisQuery/TimeFile/DataFileInfo.cs | 196 +++++++++++++----- .../DBInRun/Properties/launchSettings.json | 2 +- RunTime/DBRuntime/Driver/DriverManager.cs | 4 +- .../His/Compress/CompressEnginer2.cs | 5 +- .../DBRuntime/His/Compress/CompressMemory2.cs | 9 +- .../Compress/Special/DeadAreaCompressUnit2.cs | 34 ++- .../Compress/Special/LosslessCompressUnit2.cs | 21 +- .../Compress/Special/SlopeCompressUnit2.cs | 19 +- .../His/HisDataMemoryBlockCollection.cs | 4 + RunTime/DBRuntime/His/HisEnginer2.cs | 9 +- .../DBRuntime/His/ManualHisDataMemoryBlock.cs | 5 + RunTime/DBRuntime/His/SeriseEnginer2.cs | 68 +++--- .../Compress/Special/DeadAreaCompressUnit.cs | 18 +- .../Compress/Special/DoubleCompressBuffer.cs | 13 ++ .../Compress/Special/FloatCompressBuffer.cs | 12 ++ .../Compress/Special/LosslessCompressUnit.cs | 20 +- .../Compress/Special/SlopeCompressUnit.cs | 20 +- .../DBRuntime/Interface/IDataSerialize2.cs | 4 +- .../Properties/launchSettings.json | 2 +- 21 files changed, 384 insertions(+), 151 deletions(-) diff --git a/Driver/SimDriver/Driver.cs b/Driver/SimDriver/Driver.cs index 01fe900..402a1b7 100644 --- a/Driver/SimDriver/Driver.cs +++ b/Driver/SimDriver/Driver.cs @@ -192,7 +192,7 @@ namespace SimDriver #if DEBUG sw.Stop(); if (mNumber%10 == 0) - LoggerService.Service.Info("Sim Driver", "set value elapsed:" + sw.ElapsedMilliseconds); + LoggerService.Service.Debug("Sim Driver", "set value elapsed:" + sw.ElapsedMilliseconds); #endif Thread.Sleep(delay); } diff --git a/RunTime/DBHisData/HisQuery/DataFileManager.cs b/RunTime/DBHisData/HisQuery/DataFileManager.cs index 9b3e3ae..1f50220 100644 --- a/RunTime/DBHisData/HisQuery/DataFileManager.cs +++ b/RunTime/DBHisData/HisQuery/DataFileManager.cs @@ -36,6 +36,9 @@ namespace Cdy.Tag /// internal static Dictionary CurrentDateTime = new Dictionary(); + /// + /// + /// private string mDatabaseName; /// @@ -43,12 +46,15 @@ namespace Cdy.Tag /// public const string DataFileExtends = ".dbd"; + /// + /// + /// public const string LogFileExtends = ".log"; /// /// /// - public const int FileHeadSize = 72; + public const int FileHeadSize = 84; private System.IO.FileSystemWatcher hisDataWatcher; @@ -246,12 +252,12 @@ namespace Cdy.Tag var vifno = new System.IO.FileInfo(vv.Key); if (vv.Value == System.IO.WatcherChangeTypes.Created) { - LoggerService.Service.Info("DataFileMananger", "HisDataFile " + vv.Key + " is Created & will be add to dataFileCach!"); + LoggerService.Service.Info("DataFileMananger", "HisDataFile " + vv.Key + " is Created & will be add to dataFileCach!"); ParseFileName(vifno); } else { - LoggerService.Service.Info("DataFileMananger", "HisDataFile " + vv.Key + " is changed & will be processed!"); + LoggerService.Service.Info("DataFileMananger", "HisDataFile " + vv.Key + " is changed & will be processed!"); var vfile = CheckAndGetDataFile(vv.Key); if (vfile != null) @@ -293,11 +299,14 @@ namespace Cdy.Tag mFileCach.Add(e.FullPath, e.ChangeType); } } - //LoggerService.Service.Info("DataFileMananger", "LogFile "+ e.Name + " add to FileCach!"); - //ParseLogFile(e.FullPath); } } + /// + /// + /// + /// + /// private void HisDataWatcher_Changed(object sender, System.IO.FileSystemEventArgs e) { mResetEvent.Set(); @@ -312,17 +321,12 @@ namespace Cdy.Tag if (vifno.Extension == DataFileExtends) { mHisFileCach.Add(e.FullPath, e.ChangeType); - //ParseFileName(vifno); } } - //LoggerService.Service.Info("DataFileMananger", "HisDataFile " + e.Name + " is Created & will be add to dataFileCach!"); - } } else if(e.ChangeType == System.IO.WatcherChangeTypes.Changed) { - // LoggerService.Service.Info("DataFileMananger", "HisDataFile " + e.Name + " is changed & will be processed!"); - lock (mLocker) { if (!mHisFileCach.ContainsKey(e.FullPath)) @@ -331,26 +335,16 @@ namespace Cdy.Tag if (vifno.Extension == DataFileExtends) { mHisFileCach.Add(e.FullPath, e.ChangeType); - //ParseFileName(vifno); } } - - //if (vtmp.Extension == DataFileExtends) - //{ - // var vfile = CheckAndGetDataFile(e.Name); - // if (vfile != null) - // { - // vfile.UpdateLastDatetime(); - // } - // else - // { - // ParseFileName(vtmp); - // } - //} } } } + /// + /// + /// + /// public void ScanLogFile(string path) { System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path); @@ -541,7 +535,7 @@ namespace Cdy.Tag /// private bool CheckDataInLogFile(DateTime time,int id) { - string sname = mDatabaseName + id; + string sname = mDatabaseName + (id/ TagCountOneFile); if(CurrentDateTime.ContainsKey(sname)) return CurrentDateTime[sname] < time; else @@ -585,30 +579,6 @@ namespace Cdy.Tag /// public List GetDataFiles(DateTime starttime, DateTime endtime, out Tuple logFileTimes, int Id) { - //string sid = mDatabaseName + Id; - //if (CurrentDateTime.ContainsKey(sid)) - //{ - // if (starttime > CurrentDateTime[sid]) - // { - // logFileTimes = new Tuple(starttime, endtime); - // return new List(); - // } - // else if (endtime <= CurrentDateTime[sid]) - // { - // logFileTimes = new Tuple(DateTime.MinValue, DateTime.MinValue); - // return GetDataFiles(starttime, endtime - starttime, Id); - // } - // else - // { - // logFileTimes = new Tuple(CurrentDateTime[sid], endtime); - // return GetDataFiles(starttime, CurrentDateTime[sid] - starttime, Id); - // } - //} - //else - //{ - // logFileTimes = new Tuple(starttime, endtime); - // return GetDataFiles(starttime, endtime - starttime, Id); - //} DateTime dt = DateTime.MinValue; var vfiles = GetDataFiles(starttime, endtime - starttime, Id); foreach (var vv in vfiles) diff --git a/RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs b/RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs index 668a0c7..4a7491a 100644 --- a/RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs +++ b/RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs @@ -15,6 +15,23 @@ using System.Text; namespace Cdy.Tag { + /* + * ****文件结构**** + * 一个文件头 + 多个数据区组成 , 一个数据区:数据区头+数据块指针区+数据块区 + * [] 表示重复的一个或多个内容 + * + HisData File Structor + FileHead(84) + [HisDataRegion] + + FileHead: dataTime(8)(FileTime)+dataTime(8)(LastUpdateTime)+DataRegionCount(4)+DatabaseName(64) + + HisDataRegion Structor: RegionHead + DataBlockPoint Area + DataBlock Area + + RegionHead: PreDataRegionPoint(8) + NextDataRegionPoint(8) + Datatime(8)+ tagcount(4)+ tagid sum(8)+file duration(4)+block duration(4)+Time tick duration(4) + DataBlockPoint Area: [ID]+[block Point] + [block point]: [[tag1 point,tag2 point,....][tag1 point,tag2 point,...].....] 以时间单位对变量的数去区指针进行组织 + DataBlock Area: [block size + data block] + */ /// /// /// @@ -23,7 +40,7 @@ namespace Cdy.Tag #region ... Variables ... - private SortedDictionary> mTimeOffsets = new SortedDictionary>(); + private SortedDictionary> mTimeOffsets = new SortedDictionary>(); private bool mInited = false; @@ -31,6 +48,13 @@ namespace Cdy.Tag private DateTime mLastTime; + private long mLastProcessOffset = -1; + + /// + /// + /// + private int mRegionCount = 0; + #endregion ...Variables... #region ... Events ... @@ -73,15 +97,16 @@ namespace Cdy.Tag /// /// /// - public DateTime EndTime { - get + public DateTime EndTime + { + get { return StartTime + Duration; } set { Duration = value - StartTime; - } + } } /// @@ -114,7 +139,7 @@ namespace Cdy.Tag } } - + } @@ -125,33 +150,101 @@ namespace Cdy.Tag /// public void Scan() { + long offset = DataFileManager.FileHeadSize; + DateTime time, tmp; using (var ss = DataFileSeriserManager.manager.GetDefaultFileSersie()) { ss.OpenForReadOnly(FileName); - long offset = DataFileManager.FileHeadSize; - DateTime time; - + + //读取文件时间 + DateTime fileTime = ss.ReadDateTime(0); + //读取最后一次更新时间 + mLastTime = ss.ReadDateTime(8); + + var rcount = ss.ReadInt(16); + if(rcount!= mRegionCount) + { + mRegionCount = rcount; + } + else + { + return; + } + do { + //读取数据区时间 time = ss.ReadDateTime(offset + 16); long oset = offset; + //读取下个区域位置 offset = ss.ReadLong(offset + 8); if (offset != 0) { var dt2 = ss.ReadDateTime(offset + 16); - mTimeOffsets.Add(time, new Tuple(dt2 - time, oset,dt2)); - mLastTime = dt2; + mTimeOffsets.Add(time, new Tuple(dt2 - time, oset, dt2)); + tmp = dt2; } else { var tspan = StartTime + Duration - time; - if(tspan.TotalMilliseconds>0) - mTimeOffsets.Add(time, new Tuple(tspan, oset,time+tspan)); - mLastTime = time + tspan; + if (tspan.TotalMilliseconds > 0) + mTimeOffsets.Add(time, new Tuple(tspan, oset, time + tspan)); + tmp = time + tspan; } + mLastProcessOffset = oset; } while (offset != 0); + + if (mLastTime <= fileTime) + { + mLastTime = tmp; + } + + //if (mLastProcessOffset == -1) + //{ + + //} + //else + //{ + // offset = mLastProcessOffset; + // //读取数据区时间 + // time = ss.ReadDateTime(offset + 16); + // long oset = offset; + // //读取下个区域位置 + // offset = ss.ReadLong(offset + 8); + + // if (offset != 0) + // { + // var dt2 = ss.ReadDateTime(offset + 16); + // if (mTimeOffsets.ContainsKey(time)) + // { + // mTimeOffsets[time] = new Tuple(dt2 - time, oset, dt2); + // } + // else + // { + // mTimeOffsets.Add(time, new Tuple(dt2 - time, oset, dt2)); + // } + // tmp = dt2; + // } + // else + // { + // var tspan = StartTime + Duration - time; + // if (tspan.TotalMilliseconds > 0) + // { + // if (mTimeOffsets.ContainsKey(time)) + // { + // mTimeOffsets[time] = new Tuple(tspan, oset, time + tspan); + // } + // else + // { + // mTimeOffsets.Add(time, new Tuple(tspan, oset, time + tspan)); + // } + // } + // tmp = time + tspan; + // } + //} + mInited = true; } } @@ -182,7 +275,7 @@ namespace Cdy.Tag /// /// /// - public Dictionary> GetFileOffsets(DateTime startTime, DateTime endTime) + public Dictionary> GetFileOffsets(DateTime startTime, DateTime endTime) { lock (mLockObj) if (!mInited) Scan(); @@ -206,13 +299,13 @@ namespace Cdy.Tag /// /// /// - public List> GetNoValueOffsets(DateTime startTime,DateTime endTime) + public List> GetNoValueOffsets(DateTime startTime, DateTime endTime) { List> re = new List>(); DateTime stime = startTime; List dtmp = new List(); DateTimeSpan ddt = new DateTimeSpan() { Start = startTime, End = endTime }; - foreach(var vv in mTimeOffsets) + foreach (var vv in mTimeOffsets) { DateTimeSpan dts = new DateTimeSpan() { Start = vv.Key, End = vv.Value.Item3 }; dts = dts.Cross(ddt); @@ -302,7 +395,7 @@ namespace Cdy.Tag { DateTime stime = Max(target.Start, this.Start); DateTime etime = Min(target.End, this.End); - if(etime /// /// - public DateTime Min(DateTime time1,DateTime time2) + public DateTime Min(DateTime time1, DateTime time2) { return time1 <= time2 ? time1 : time2; } @@ -329,7 +422,7 @@ namespace Cdy.Tag /// /// /// - public DateTime Max(DateTime time1,DateTime time2) + public DateTime Max(DateTime time1, DateTime time2) { return time1 >= time2 ? time1 : time2; } @@ -354,7 +447,7 @@ namespace Cdy.Tag } #region 读取所有值 - + /// /// 读取某时间段内的所有bool值 @@ -386,13 +479,13 @@ namespace Cdy.Tag //} } - + #endregion #region 读取指定时刻值 - + /// /// @@ -456,11 +549,11 @@ namespace Cdy.Tag } foreach (var vf in moffs) { - if(vf.Key>-1) - vff.Read(vf.Key, tid, vf.Value, type, result); + if (vf.Key > -1) + vff.Read(vf.Key, tid, vf.Value, type, result); else { - foreach(var vv in vf.Value) + foreach (var vv in vf.Value) { result.Add(default(T), vv, (byte)QualityConst.Null); } @@ -472,8 +565,17 @@ namespace Cdy.Tag #region DataFileSeriser Read - + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// public static void Read(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) { int timetick = 0; @@ -535,7 +637,7 @@ namespace Cdy.Tag data.Clear(); } - + #endregion #region DeCompressData @@ -583,7 +685,7 @@ namespace Cdy.Tag } } - + /// /// /// @@ -616,7 +718,7 @@ namespace Cdy.Tag /// /// /// - public static Dictionary CheckBlockHeadCach(this DataFileSeriserbase datafile, long offset, out int tagCount, out int fileDuration, out int blockDuration, out int timetick,out long blockPointer,out DateTime time) + public static Dictionary CheckBlockHeadCach(this DataFileSeriserbase datafile, long offset, out int tagCount, out int fileDuration, out int blockDuration, out int timetick, out long blockPointer, out DateTime time) { //文件头部结构:Pre DataRegion(8) + Next DataRegion(8) + Datatime(8)+tagcount(4)+ tagid sum(8) +file duration(4)+ block duration(4)+Time tick duration(4)+ { + tagid1+tagid2+...+tagidn }+ {[tag1 block point1(8) + tag2 block point1+ tag3 block point1+...] + [tag1 block point2(8) + tag2 block point2+ tag3 block point2+...]....} var dataoffset = offset + 16; @@ -672,7 +774,7 @@ namespace Cdy.Tag var ltmp = vcm.ToIntList(); //vcm.Dispose(); - + if (ltmp.Count > 0) { int preid = ltmp[0]; @@ -684,9 +786,9 @@ namespace Cdy.Tag preid = id; } } - TagHeadOffsetManager.manager.Add(idsum, count, dtmp,blockPointer); + TagHeadOffsetManager.manager.Add(idsum, count, dtmp, blockPointer); + - } return dtmp; } @@ -709,9 +811,9 @@ namespace Cdy.Tag /// /// /// - public static int ReadTagIndexInDataPointer(this DataFileSeriserbase datafile, int tid, long offset, out int tagCount, out int fileDuration, out int blockDuration, out int timetick,out long blockpointer,out DateTime time) + public static int ReadTagIndexInDataPointer(this DataFileSeriserbase datafile, int tid, long offset, out int tagCount, out int fileDuration, out int blockDuration, out int timetick, out long blockpointer, out DateTime time) { - var hfile = datafile.CheckBlockHeadCach(offset, out tagCount, out fileDuration, out blockDuration, out timetick,out blockpointer,out time); + var hfile = datafile.CheckBlockHeadCach(offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time); if (hfile.ContainsKey(tid)) { return hfile[tid]; @@ -731,7 +833,7 @@ namespace Cdy.Tag /// public static List ReadTargetBlockAddress(this DataFileSeriserbase datafile, List tid, long offset, out int tagCount, out int fileDuration, out int blockDuration, out int timetick, out long blockpointer, out DateTime time) { - var hfile = datafile.CheckBlockHeadCach(offset, out tagCount, out fileDuration, out blockDuration, out timetick,out blockpointer,out time); + var hfile = datafile.CheckBlockHeadCach(offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time); List re = new List(); foreach (var vv in tid) { @@ -766,7 +868,7 @@ namespace Cdy.Tag DateTime time; long blockpointer = 0; - var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick,out blockpointer,out time); + var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time); int blockcount = fileDuration * 60 / blockDuration; var startTime = datafile.ReadDateTime(16); @@ -804,7 +906,7 @@ namespace Cdy.Tag int tagCount = 0; long blockpointer = 0; DateTime time; - var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick,out blockpointer,out time); + var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time); int blockcount = fileDuration * 60 / blockDuration; var startTime = datafile.ReadDateTime(16); @@ -860,8 +962,8 @@ namespace Cdy.Tag int tagCount = 0; long blockpointer = 0; DateTime time; - var tagIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick,out blockpointer,out time); - + var tagIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time); + Dictionary rtmp = new Dictionary(); Dictionary> re = new Dictionary>(); @@ -925,9 +1027,9 @@ namespace Cdy.Tag } } } - + } - + } return re; } @@ -943,13 +1045,13 @@ namespace Cdy.Tag /// /// /// - public static Dictionary> ReadTagDataBlock2(this DataFileSeriserbase datafile,int tid, long offset, DateTime start, DateTime end, out int timetick) + public static Dictionary> ReadTagDataBlock2(this DataFileSeriserbase datafile, int tid, long offset, DateTime start, DateTime end, out int timetick) { int fileDuration, blockDuration = 0; int tagCount = 0; long blockpointer = 0; DateTime time; - var tagIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick,out blockpointer,out time); + var tagIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time); int blockcount = fileDuration * 60 / blockDuration; //读取文件开始时间 @@ -963,8 +1065,8 @@ namespace Cdy.Tag while (sstart < end) { - var ttmp = Math.Round((sstart - startTime).TotalSeconds,3); - var vv = blockDuration*60 - (ttmp %(blockDuration * 60)); + var ttmp = Math.Round((sstart - startTime).TotalSeconds, 3); + var vv = blockDuration * 60 - (ttmp % (blockDuration * 60)); send = sstart.AddSeconds(vv); @@ -984,14 +1086,14 @@ namespace Cdy.Tag throw new Exception("DataPointer index is out of total block number"); } - var dataPointer = datafile.ReadLong(offset+ blockpointer + tagIndex * 8 + blockindex * tagCount * 8); //读取DataBlock的地址 + var dataPointer = datafile.ReadLong(offset + blockpointer + tagIndex * 8 + blockindex * tagCount * 8); //读取DataBlock的地址 if (dataPointer > 0) { var datasize = datafile.ReadInt(dataPointer); //读取DataBlock 的大小 if (datasize > 0) { - var rmm = datafile.Read(dataPointer+4, (int)datasize); + var rmm = datafile.Read(dataPointer + 4, (int)datasize); if (!re.ContainsKey(rmm)) { re.Add(rmm, new Tuple(sstart, send)); diff --git a/RunTime/DBInRun/Properties/launchSettings.json b/RunTime/DBInRun/Properties/launchSettings.json index 21cb421..d74015f 100644 --- a/RunTime/DBInRun/Properties/launchSettings.json +++ b/RunTime/DBInRun/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "DBInRun": { "commandName": "Executable", - "executablePath": "C:\\Users\\cdy81\\source\\repos\\mars\\Output\\DBInRun.exe" + "executablePath": "C:\\Users\\chongdaoyang\\source\\repos\\mars\\Output\\DBInRun.exe" } } } \ No newline at end of file diff --git a/RunTime/DBRuntime/Driver/DriverManager.cs b/RunTime/DBRuntime/Driver/DriverManager.cs index 0a48a8c..2c0e2b1 100644 --- a/RunTime/DBRuntime/Driver/DriverManager.cs +++ b/RunTime/DBRuntime/Driver/DriverManager.cs @@ -94,7 +94,7 @@ namespace Cdy.Tag /// public void Start() { - LoggerService.Service.Info("DriverManager", "start to Start"); + LoggerService.Service.Info("DriverManager", "开始启动"); foreach (var vv in mDrivers.Values) { vv.Start(mTagDriverService, mHisValueDriverService); @@ -106,7 +106,7 @@ namespace Cdy.Tag /// public void Stop() { - LoggerService.Service.Info("DriverManager", "start to stop"); + LoggerService.Service.Info("DriverManager", "开始停止"); foreach (var vv in mDrivers.Values) { vv.Stop(); diff --git a/RunTime/DBRuntime/His/Compress/CompressEnginer2.cs b/RunTime/DBRuntime/His/Compress/CompressEnginer2.cs index 781bdf3..52017b2 100644 --- a/RunTime/DBRuntime/His/Compress/CompressEnginer2.cs +++ b/RunTime/DBRuntime/His/Compress/CompressEnginer2.cs @@ -153,7 +153,7 @@ namespace Cdy.Tag /// public void Start() { - LoggerService.Service.Info("CompressEnginer", "start to Start"); + LoggerService.Service.Info("CompressEnginer", "开始启动"); mIsClosed = false; //Init(); resetEvent = new ManualResetEvent(false); @@ -175,7 +175,7 @@ namespace Cdy.Tag /// public void Stop() { - LoggerService.Service.Info("CompressEnginer", "start to stop"); + LoggerService.Service.Info("CompressEnginer", "开始停止"); mIsClosed = true; resetEvent.Set(); @@ -206,6 +206,7 @@ namespace Cdy.Tag foreach(var vv in mTargetMemorys) { vv.Value.CurrentTime = mCurrentTime; + vv.Value.EndTime = dataMemory.EndDateTime; } resetEvent.Set(); } diff --git a/RunTime/DBRuntime/His/Compress/CompressMemory2.cs b/RunTime/DBRuntime/His/Compress/CompressMemory2.cs index cc7d731..123eb0d 100644 --- a/RunTime/DBRuntime/His/Compress/CompressMemory2.cs +++ b/RunTime/DBRuntime/His/Compress/CompressMemory2.cs @@ -126,6 +126,11 @@ namespace Cdy.Tag } } + /// + /// + /// + public DateTime EndTime { get; set; } + #endregion ...Properties... @@ -165,7 +170,7 @@ namespace Cdy.Tag int datasize = 0; var cdata = CompressMemory(data, out datasize); cdata.MakeMemoryBusy(); - ServiceLocator.Locator.Resolve().ManualRequestToSeriseFile(data.Id, data.Time, cdata, datasize); + ServiceLocator.Locator.Resolve().ManualRequestToSeriseFile(data.Id, data.Time,data.EndTime, cdata, datasize); data.MakeMemoryNoBusy(); ManualHisDataMemoryBlockPool.Pool.Release(data); } @@ -282,7 +287,7 @@ namespace Cdy.Tag long ltmp3 = sw.ElapsedMilliseconds; - ServiceLocator.Locator.Resolve().RequestToSeriseFile(this, mCurrentTime); + ServiceLocator.Locator.Resolve().RequestToSeriseFile(this); sw.Stop(); LoggerService.Service.Info("CompressEnginer", Id + "压缩完成 耗时:" + sw.ElapsedMilliseconds + " ltmp1:" + ltmp1 + " ltmp2:" + (ltmp2 - ltmp1) + " ltmp3:" + (ltmp3 - ltmp2) + " CPU Id:" + ThreadHelper.GetCurrentProcessorNumber(), ConsoleColor.Blue); diff --git a/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit2.cs b/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit2.cs index 6209caf..4d09560 100644 --- a/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit2.cs +++ b/RunTime/DBRuntime/His/Compress/Special/DeadAreaCompressUnit2.cs @@ -113,6 +113,8 @@ namespace Cdy.Tag byte tlen = (timerVals as HisDataMemoryBlock).TimeLen; + int rcount = 0; + for (int i = 0; i < count; i++) { if (i != ig) @@ -130,6 +132,7 @@ namespace Cdy.Tag { mVarintMemory2.WriteInt32(id - preids); } + rcount++; //dtims.Add(i, id); preids = id; } @@ -139,7 +142,10 @@ namespace Cdy.Tag // emptyIds.TryDequeue(out ig); } } - return mVarintMemory2.DataBuffer.AsMemory(0, (int)mVarintMemory.WritePosition); + + LoggerService.Service.Debug("DeadAreaCompress", "记录时间个数:"+rcount +" 空时间个数:"+ (emptyIds.WriteIndex+1)); + + return mVarintMemory2.DataBuffer.AsMemory(0, (int)mVarintMemory2.WritePosition); } /// @@ -425,7 +431,14 @@ namespace Cdy.Tag break; case TagType.Double: FindEmpityIds(source, sourceAddr, (int)count, emptys); - if (mDCompress == null) mDCompress = new DoubleCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mDCompress == null) + { + mDCompress = new DoubleCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mDCompress.CheckAndResizeTo(count); + } var ddres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); datas = CompressTimers2(source, sourceAddr, (int)count, emptys2); @@ -434,9 +447,15 @@ namespace Cdy.Tag target.WriteInt(targetAddr, rcount); rsize += 4; target.Write((int)datas.Length); - target.Write(datas); rsize += 4; + target.Write(datas); rsize += datas.Length; + + if(rcount>0 && datas.Length==0) + { + LoggerService.Service.Debug("DeadAreaCompressUnit", "压缩后数据长度为0 :"+rcount); + } + //写入数据 target.Write(ddres.Length); target.Write(ddres); @@ -460,7 +479,14 @@ namespace Cdy.Tag break; case TagType.Float: FindEmpityIds(source, sourceAddr, (int)count, emptys); - if (mFCompress == null) mFCompress = new FloatCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mFCompress == null) + { + mFCompress = new FloatCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mFCompress.CheckAndResizeTo(count); + } var fres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); datas = CompressTimers2(source, sourceAddr, (int)count, emptys2); diff --git a/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit2.cs b/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit2.cs index 10196c8..e18c18b 100644 --- a/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit2.cs +++ b/RunTime/DBRuntime/His/Compress/Special/LosslessCompressUnit2.cs @@ -993,8 +993,15 @@ namespace Cdy.Tag rsize += cqus.Length; break; case TagType.Double: - - if (mDCompress == null) mDCompress = new DoubleCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + + if (mDCompress == null) + { + mDCompress = new DoubleCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mDCompress.CheckAndResizeTo(count); + } var ddres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); target.Write(ddres.Length); @@ -1010,7 +1017,14 @@ namespace Cdy.Tag break; case TagType.Float: - if (mFCompress == null) mFCompress = new FloatCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mFCompress == null) + { + mFCompress = new FloatCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mFCompress.CheckAndResizeTo(count); + } var fres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); target.Write(fres.Length); @@ -1557,6 +1571,7 @@ namespace Cdy.Tag Dictionary re = new Dictionary(); var count = source.ReadInt(); var datasize = source.ReadInt(); + byte[] datas = source.ReadBytes(datasize); var timers = DeCompressTimers(datas, count); diff --git a/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit2.cs b/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit2.cs index 112d2e6..69cdcda 100644 --- a/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit2.cs +++ b/RunTime/DBRuntime/His/Compress/Special/SlopeCompressUnit2.cs @@ -1971,14 +1971,29 @@ namespace Cdy.Tag break; case TagType.Double: - if (mDCompress == null) mDCompress = new DoubleCompressBuffer(count * 2) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mDCompress == null) + { + mDCompress = new DoubleCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mDCompress.CheckAndResizeTo(count); + } + cval = CompressValues(source, count * 2 + sourceAddr, count, tims, type); timeData = CompressTimers(tims, usedIndex); cqus = CompressQulitys(source, count * 10 + sourceAddr, count, usedIndex); rsize = FillData(cval, cqus, timeData, target, targetAddr); break; case TagType.Float: - if (mFCompress == null) mFCompress = new FloatCompressBuffer(count * 2) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mFCompress == null) + { + mFCompress = new FloatCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mFCompress.CheckAndResizeTo(count); + } cval = CompressValues(source, count * 2 + sourceAddr, count, tims, type); timeData = CompressTimers(tims, usedIndex); cqus = CompressQulitys(source, count * 6 + sourceAddr, count, usedIndex); diff --git a/RunTime/DBRuntime/His/HisDataMemoryBlockCollection.cs b/RunTime/DBRuntime/His/HisDataMemoryBlockCollection.cs index 17b35aa..acbe5a2 100644 --- a/RunTime/DBRuntime/His/HisDataMemoryBlockCollection.cs +++ b/RunTime/DBRuntime/His/HisDataMemoryBlockCollection.cs @@ -78,6 +78,10 @@ namespace DBRuntime.His /// public DateTime CurrentDatetime { get; set; } + /// + /// + /// + public DateTime EndDateTime { get; set; } #endregion ...Properties... diff --git a/RunTime/DBRuntime/His/HisEnginer2.cs b/RunTime/DBRuntime/His/HisEnginer2.cs index fcc7be3..5f1ae08 100644 --- a/RunTime/DBRuntime/His/HisEnginer2.cs +++ b/RunTime/DBRuntime/His/HisEnginer2.cs @@ -823,7 +823,7 @@ namespace Cdy.Tag /// public void Start() { - LoggerService.Service.Info("HisEnginer", "start to Start"); + LoggerService.Service.Info("HisEnginer", "开始启动"); mIsClosed = false; mMegerProcessIsClosed = false; LoggerService.Service.Info("Record", "历史变量个数: " + this.mHisTags.Count); @@ -924,6 +924,7 @@ namespace Cdy.Tag RecordAllLastValue(); //mMergeMemory.Dump(); + mCurrentMergeMemory.EndDateTime = mSnapAllTagTime; mCurrentMergeMemory.MakeMemoryBusy(); //提交到数据压缩流程 ServiceLocator.Locator.Resolve().RequestToCompress(mCurrentMergeMemory); @@ -1053,6 +1054,8 @@ namespace Cdy.Tag if (mcc != null) { mcc.MakeMemoryBusy(); + mcc.EndDateTime = dateTime; + mWaitForMergeMemory = mcc; //通知进行内存合并 resetEvent.Set(); @@ -1227,7 +1230,7 @@ namespace Cdy.Tag /// public void Stop() { - LoggerService.Service.Info("HisEnginer", "start to stop"); + LoggerService.Service.Info("HisEnginer", "开始停止"); if(mRecordTimer!=null) { mRecordTimer.Stop(); @@ -1477,7 +1480,7 @@ namespace Cdy.Tag break; } hb.WriteInt(hb.QualityAddress + hb.CurrentCount, vv.Quality); - + hb.EndTime = vv.Time; hb.CurrentCount++; } } diff --git a/RunTime/DBRuntime/His/ManualHisDataMemoryBlock.cs b/RunTime/DBRuntime/His/ManualHisDataMemoryBlock.cs index 48706ef..d3078a6 100644 --- a/RunTime/DBRuntime/His/ManualHisDataMemoryBlock.cs +++ b/RunTime/DBRuntime/His/ManualHisDataMemoryBlock.cs @@ -47,6 +47,11 @@ namespace DBRuntime.His /// public DateTime Time { get; set; } + /// + /// + /// + public DateTime EndTime { get; set; } + /// /// /// diff --git a/RunTime/DBRuntime/His/SeriseEnginer2.cs b/RunTime/DBRuntime/His/SeriseEnginer2.cs index cb12efb..ed8e3e1 100644 --- a/RunTime/DBRuntime/His/SeriseEnginer2.cs +++ b/RunTime/DBRuntime/His/SeriseEnginer2.cs @@ -23,9 +23,9 @@ using DBRuntime.His; * [] 表示重复的一个或多个内容 * HisData File Structor - FileHead(72) + [HisDataRegion] + FileHead(84) + [HisDataRegion] - FileHead: dataTime(8)+DatabaseName(64) + FileHead: dataTime(8)(FileTime)+dateTime(8)(LastUpdateTime)+DataRegionCount(4)+DatabaseName(64) HisDataRegion Structor: RegionHead + DataBlockPoint Area + DataBlock Area @@ -55,12 +55,8 @@ namespace Cdy.Tag private bool mIsClosed = false; - //private MemoryBlock mProcessMemory; - private DateTime mCurrentTime; - //private SeriseFileItem[] mSeriseFile; - private Dictionary mWaitForProcessMemory = new Dictionary(); /// @@ -194,7 +190,7 @@ namespace Cdy.Tag /// public void Start() { - LoggerService.Service.Info("SeriseEnginer", "start to Start"); + LoggerService.Service.Info("SeriseEnginer", "开始启动"); mIsClosed = false; resetEvent = new ManualResetEvent(false); closedEvent = new ManualResetEvent(false); @@ -208,7 +204,7 @@ namespace Cdy.Tag /// public void Stop() { - LoggerService.Service.Info("SeriseEnginer", "start to stop"); + LoggerService.Service.Info("SeriseEnginer", "开始停止"); mIsClosed = true; resetEvent.Set(); closedEvent.WaitOne(); @@ -227,7 +223,7 @@ namespace Cdy.Tag /// /// /// - public void RequestToSeriseFile(CompressMemory2 dataMemory, DateTime date) + public void RequestToSeriseFile(CompressMemory2 dataMemory) { lock (mWaitForProcessMemory) { @@ -240,7 +236,7 @@ namespace Cdy.Tag mWaitForProcessMemory.Add(dataMemory.Id, dataMemory); } } - mCurrentTime = date; + mCurrentTime = dataMemory.CurrentTime; } /// @@ -294,7 +290,7 @@ namespace Cdy.Tag foreach (var vv in mtmp) { - mSeriserFiles[vv.Id].SaveToFile(vv, vv.CurrentTime); + mSeriserFiles[vv.Id].SaveToFile(vv, vv.CurrentTime,vv.EndTime); vv.Clear(); vv.MakeMemoryNoBusy(); } @@ -327,13 +323,13 @@ namespace Cdy.Tag /// /// /// - public void ManualRequestToSeriseFile(int id, DateTime time, MarshalMemoryBlock data, int size) + public void ManualRequestToSeriseFile(int id, DateTime time,DateTime endTime, MarshalMemoryBlock data, int size) { foreach(var vv in mSeriserFiles) { if( id >= vv.Value.Id* TagCountOneFile && id<(vv.Value.Id+1)* TagCountOneFile) { - vv.Value.ManualRequestToSeriseFile(id, data, size, time); + vv.Value.ManualRequestToSeriseFile(id, data, size, time,endTime); } } } @@ -382,7 +378,7 @@ namespace Cdy.Tag /// /// 文件头大小 /// - public const int FileHeadSize = 72; + public const int FileHeadSize = 84; private MemoryBlock mBlockPointMemory; @@ -498,11 +494,10 @@ namespace Cdy.Tag { DateTime date = new DateTime(time.Year, time.Month, time.Day, ((time.Hour / FileDuration) * FileDuration), 0, 0); mFileWriter.Write(date, 0); - //byte[] nameBytes = new byte[64]; byte[] nameBytes = ArrayPool.Shared.Rent(64); var ntmp = Encoding.UTF8.GetBytes(databaseName); Buffer.BlockCopy(ntmp, 0, nameBytes, 0, Math.Min(64, ntmp.Length)); - mFileWriter.Write(nameBytes, 8); + mFileWriter.Write(nameBytes, 20); ArrayPool.Shared.Return(nameBytes); } @@ -524,6 +519,8 @@ namespace Cdy.Tag mFileWriter.Append(bval, 0, datalen); mFileWriter.AppendZore(totalLen - datalen); + mFileWriter.Write(mFileWriter.ReadInt(16) + 1, 16); + mPreDataRegion = mCurrentDataRegion; mBlockPointOffset = mCurrentDataRegion + mBlockPointOffset; @@ -545,6 +542,8 @@ namespace Cdy.Tag mFileWriter.Append(bval, 0, datalen); mFileWriter.AppendZore(totalLen - datalen); + mFileWriter.Write(mFileWriter.ReadInt(16) + 1, 16); + ArrayPool.Shared.Return(bval); } @@ -633,11 +632,8 @@ namespace Cdy.Tag offset = nextaddr; } } - // mPreDataRegion = offset; - mFileWriter.GoToEnd(); mCurrentDataRegion = mFileWriter.CurrentPostion; - return offset; } @@ -695,7 +691,7 @@ namespace Cdy.Tag else { - if (mFileWriter2.Length < 72) + if (mFileWriter2.Length < FileHeadSize) { //新建文件 AppendFileHeader(time, this.DatabaseName, mFileWriter2); @@ -744,12 +740,22 @@ namespace Cdy.Tag /// /// /// - public void ManualRequestToSeriseFile(int id, MarshalMemoryBlock datablock, int size, DateTime time) + /// + public void ManualRequestToSeriseFile(int id, MarshalMemoryBlock datablock, int size, DateTime time,DateTime endTime) { lock (mFileLocker) { DataFileSeriserbase mwriter; + var heads = GetDataRegionHeadPoint(id, time, out mwriter); + + //如果更新时间,小于最后更新时间,则更新 + var vtmp = mwriter.ReadDateTime(8); + if (endTime > vtmp) + { + mwriter.Write(endTime, 8); + } + var vpointer = mwriter.GoToEnd().CurrentPostion; datablock.WriteToStream(mFileWriter.GetStream(), vpointer, size);//直接拷贝数据块 datablock.WriteLong(heads, vpointer); @@ -877,7 +883,7 @@ namespace Cdy.Tag } else { - if (mFileWriter.Length < 72) + if (mFileWriter.Length < FileHeadSize) { AppendFileHeader(time, this.DatabaseName, mFileWriter); //新建文件 @@ -915,11 +921,16 @@ namespace Cdy.Tag /// /// /// - public void SaveToFile(MarshalMemoryBlock mProcessMemory, DateTime time) + public void SaveToFile(MarshalMemoryBlock mProcessMemory, DateTime time,DateTime endTime) { - SaveToFile(mProcessMemory, 0, time); + SaveToFile(mProcessMemory, 0, time,endTime); } + /// + /// + /// + /// + /// private DateTime FormateTime(DateTime time) { return new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0); @@ -928,7 +939,7 @@ namespace Cdy.Tag /// /// 执行存储到磁盘 /// - public void SaveToFile(MarshalMemoryBlock mProcessMemory, long dataOffset, DateTime time) + public void SaveToFile(MarshalMemoryBlock mProcessMemory, long dataOffset, DateTime time,DateTime endTime) { /* 1. 检查变量ID是否变动,如果变动则重新记录变量的ID列表 @@ -956,6 +967,13 @@ namespace Cdy.Tag if (!CheckFile(time)) return; + //更新最后写入时间 + var vtmp = mFileWriter.ReadDateTime(8); + if (endTime > vtmp) + { + mFileWriter.Write(endTime, 8); + } + var ltmp2 = sw.ElapsedMilliseconds; long offset = 8 + dataOffset; diff --git a/RunTime/DBRuntime/His/obsolete/Compress/Special/DeadAreaCompressUnit.cs b/RunTime/DBRuntime/His/obsolete/Compress/Special/DeadAreaCompressUnit.cs index 83f1e79..70340fd 100644 --- a/RunTime/DBRuntime/His/obsolete/Compress/Special/DeadAreaCompressUnit.cs +++ b/RunTime/DBRuntime/His/obsolete/Compress/Special/DeadAreaCompressUnit.cs @@ -407,7 +407,14 @@ namespace Cdy.Tag break; case TagType.Double: FindEmpityIds(source, sourceAddr, (int)count, emptys); - if (mDCompress == null) mDCompress = new DoubleCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mDCompress == null) + { + mDCompress = new DoubleCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mDCompress.CheckAndResizeTo(count); + } var ddres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); datas = CompressTimers2(source, sourceAddr, (int)count, emptys2); @@ -434,7 +441,14 @@ namespace Cdy.Tag break; case TagType.Float: FindEmpityIds(source, sourceAddr, (int)count, emptys); - if (mFCompress == null) mFCompress = new FloatCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mFCompress == null) + { + mFCompress = new FloatCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mFCompress.CheckAndResizeTo(count); + } var fres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); datas = CompressTimers2(source, sourceAddr, (int)count, emptys2); diff --git a/RunTime/DBRuntime/His/obsolete/Compress/Special/DoubleCompressBuffer.cs b/RunTime/DBRuntime/His/obsolete/Compress/Special/DoubleCompressBuffer.cs index 0d0fe80..073436f 100644 --- a/RunTime/DBRuntime/His/obsolete/Compress/Special/DoubleCompressBuffer.cs +++ b/RunTime/DBRuntime/His/obsolete/Compress/Special/DoubleCompressBuffer.cs @@ -78,6 +78,19 @@ namespace DBRuntime.His.Compress #region ... Methods ... + + /// + /// + /// + /// + public void CheckAndResizeTo(int count) + { + if (count > mBuffer.Length) + { + mBuffer = new double[count]; + } + } + /// /// /// diff --git a/RunTime/DBRuntime/His/obsolete/Compress/Special/FloatCompressBuffer.cs b/RunTime/DBRuntime/His/obsolete/Compress/Special/FloatCompressBuffer.cs index fee4f5b..e8d38fb 100644 --- a/RunTime/DBRuntime/His/obsolete/Compress/Special/FloatCompressBuffer.cs +++ b/RunTime/DBRuntime/His/obsolete/Compress/Special/FloatCompressBuffer.cs @@ -78,6 +78,18 @@ namespace DBRuntime.His.Compress #region ... Methods ... + /// + /// + /// + /// + public void CheckAndResizeTo(int count) + { + if(count>mBuffer.Length) + { + mBuffer = new float[count]; + } + } + /// /// /// diff --git a/RunTime/DBRuntime/His/obsolete/Compress/Special/LosslessCompressUnit.cs b/RunTime/DBRuntime/His/obsolete/Compress/Special/LosslessCompressUnit.cs index edc78e8..3632172 100644 --- a/RunTime/DBRuntime/His/obsolete/Compress/Special/LosslessCompressUnit.cs +++ b/RunTime/DBRuntime/His/obsolete/Compress/Special/LosslessCompressUnit.cs @@ -992,8 +992,15 @@ namespace Cdy.Tag rsize += cqus.Length; break; case TagType.Double: - - if (mDCompress == null) mDCompress = new DoubleCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + + if (mDCompress == null) + { + mDCompress = new DoubleCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mDCompress.CheckAndResizeTo(count); + } var ddres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); target.Write(ddres.Length); @@ -1009,7 +1016,14 @@ namespace Cdy.Tag break; case TagType.Float: - if (mFCompress == null) mFCompress = new FloatCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mFCompress == null) + { + mFCompress = new FloatCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mFCompress.CheckAndResizeTo(count); + } var fres = CompressValues(source, count * 2 + sourceAddr, count, emptys, TagType); target.Write(fres.Length); diff --git a/RunTime/DBRuntime/His/obsolete/Compress/Special/SlopeCompressUnit.cs b/RunTime/DBRuntime/His/obsolete/Compress/Special/SlopeCompressUnit.cs index 3746383..8eb718c 100644 --- a/RunTime/DBRuntime/His/obsolete/Compress/Special/SlopeCompressUnit.cs +++ b/RunTime/DBRuntime/His/obsolete/Compress/Special/SlopeCompressUnit.cs @@ -1940,14 +1940,30 @@ namespace Cdy.Tag break; case TagType.Double: - if (mDCompress == null) mDCompress = new DoubleCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mDCompress == null) + { + mDCompress = new DoubleCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mDCompress.CheckAndResizeTo(count); + } + cval = CompressValues(source, count * 2 + sourceAddr, count, tims, type); timeData = CompressTimers(tims, usedIndex); cqus = CompressQulitys(source, count * 10 + sourceAddr, count, usedIndex); rsize = FillData(cval, cqus, timeData, target, targetAddr); break; case TagType.Float: - if (mFCompress == null) mFCompress = new FloatCompressBuffer(310) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + if (mFCompress == null) + { + mFCompress = new FloatCompressBuffer(count) { MemoryBlock = mMarshalMemory, VarintMemory = mVarintMemory }; + } + else + { + mFCompress.CheckAndResizeTo(count); + } + cval = CompressValues(source, count * 2 + sourceAddr, count, tims, type); timeData = CompressTimers(tims, usedIndex); cqus = CompressQulitys(source, count * 6 + sourceAddr, count, usedIndex); diff --git a/RunTime/DBRuntime/Interface/IDataSerialize2.cs b/RunTime/DBRuntime/Interface/IDataSerialize2.cs index ae548d9..6a74f07 100644 --- a/RunTime/DBRuntime/Interface/IDataSerialize2.cs +++ b/RunTime/DBRuntime/Interface/IDataSerialize2.cs @@ -40,7 +40,7 @@ namespace Cdy.Tag /// /// /// - void RequestToSeriseFile(CompressMemory2 dataMemory,DateTime date); + void RequestToSeriseFile(CompressMemory2 dataMemory); /// /// 手动更新历史数据 @@ -49,7 +49,7 @@ namespace Cdy.Tag /// /// /// - void ManualRequestToSeriseFile(int id, DateTime time, MarshalMemoryBlock data, int size); + void ManualRequestToSeriseFile(int id, DateTime time,DateTime enddate, MarshalMemoryBlock data, int size); /// /// diff --git a/Tools/HisDataTools/Properties/launchSettings.json b/Tools/HisDataTools/Properties/launchSettings.json index baa806c..47e9ff5 100644 --- a/Tools/HisDataTools/Properties/launchSettings.json +++ b/Tools/HisDataTools/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "HisDataTools": { "commandName": "Executable", - "executablePath": "C:\\Users\\cdy81\\source\\repos\\mars\\Output\\HisDataTools.exe" + "executablePath": "C:\\Users\\chongdaoyang\\source\\repos\\mars\\Output\\HisDataTools.exe" } } } \ No newline at end of file -- GitLab