From b444ee2993427aacb2f0a15056a08b856f59d7d3 Mon Sep 17 00:00:00 2001 From: Candy Date: Wed, 6 May 2020 13:14:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=96=E8=A7=A3=E7=A0=81?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=9A=84=E7=A8=8B=E5=BA=8F=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cdy.Tag.Common/Common/MarshalMemoryBlock.cs | 86 +- Cdy.Tag.Common/Common/MemoryHelper.cs | 24 + Cdy.Tag.Common/Common/PointData.cs | 62 + Cdy.Tag/His/CompressUnitbase.cs | 706 +-- Cdy.Tag/His/DataFileSeriserbase.cs | 30 + Cdy.Tag/Interface/HisQueryResult.cs | 2 +- Cdy.Tag/Interface/IHisQuery.cs | 403 +- DBHisData/HisQuery/DataFileManager.cs | 356 +- DBHisData/HisQuery/HisDataQuery.cs | 102 - DBHisData/HisQuery/QuerySerivce.cs | 3605 +------------ DBHisData/HisQuery/TagHeadOffsetManager.cs | 53 +- DBHisData/HisQuery/TimeFile/DataFileInfo.cs | 4657 +++++++++-------- DBHisData/HisQuery/TimeFile/LogFileInfo.cs | 773 +++ DBHisData/HisQuery/TimeFile/MonthTimeFile.cs | 39 +- DBHisData/HisQuery/TimeFile/YearTimeFile.cs | 14 + DBInRun/Program.cs | 5 + DBInRun/Properties/Resources.Designer.cs | 2 +- DBInRun/Properties/Resources.resx | 2 +- DBInRun/Properties/Resources.zh-CN.resx | 2 +- DataRunner/DBRuntime.csproj | 15 + DataRunner/His/Compress/CompressEnginer.cs | 17 +- .../Compress/Special/LosslessCompressUnit.cs | 1852 ++----- .../His/Compress/Special/NoneCompressUnit.cs | 280 +- DataRunner/His/HisEnginer.cs | 46 +- DataRunner/His/LogManager.cs | 266 + DataRunner/His/Serise/LocalFileSeriser.cs | 56 +- DataRunner/His/Serise/SeriseEnginer.cs | 10 +- DataRunner/His/TimerMemoryCacheProcesser.cs | 3 +- .../His/ValueChangedMemoryCacheProcesser.cs | 1 + DataRunner/Properties/Resources.Designer.cs | 72 + DataRunner/Properties/Resources.resx | 123 + DataRunner/Real/RealEnginer.cs | 2 + DataRunner/Res.cs | 24 + DataRunner/Runner.cs | 72 +- .../View/PermissionDetailView.xaml | 2 +- SimDriver/Driver.cs | 32 +- 36 files changed, 5810 insertions(+), 7986 deletions(-) delete mode 100644 DBHisData/HisQuery/HisDataQuery.cs create mode 100644 DBHisData/HisQuery/TimeFile/LogFileInfo.cs create mode 100644 DataRunner/His/LogManager.cs create mode 100644 DataRunner/Properties/Resources.Designer.cs create mode 100644 DataRunner/Properties/Resources.resx create mode 100644 DataRunner/Res.cs diff --git a/Cdy.Tag.Common/Common/MarshalMemoryBlock.cs b/Cdy.Tag.Common/Common/MarshalMemoryBlock.cs index 43973c9..5910bdd 100644 --- a/Cdy.Tag.Common/Common/MarshalMemoryBlock.cs +++ b/Cdy.Tag.Common/Common/MarshalMemoryBlock.cs @@ -44,6 +44,8 @@ namespace Cdy.Tag public static byte[] zoreData = new byte[1024 * 10]; + private int mRefCount = 0; + #endregion ...Variables... #region ... Events ... @@ -125,10 +127,10 @@ namespace Cdy.Tag } } - /// - /// 是否繁忙 - /// - public bool IsBusy { get; set; } + ///// + ///// 是否繁忙 + ///// + //public bool IsBusy { get; set; } /// @@ -204,6 +206,34 @@ namespace Cdy.Tag #region ... Methods ... + /// + /// + /// + public void IncRef() + { + lock (mUserSizeLock) + Interlocked.Increment(ref mRefCount); + } + + /// + /// + /// + public void DecRef() + { + lock (mUserSizeLock) + mRefCount = mRefCount > 0 ? mRefCount - 1 : mRefCount; + } + + /// + /// 是否繁忙 + /// + /// + public bool IsBusy() + { + return mRefCount > 0; + } + + /// /// /// @@ -340,7 +370,7 @@ namespace Cdy.Tag mUsedSize = 0; mPosition = 0; - LoggerService.Service.Info("MemoryBlock", Name + " is clear !"); + // LoggerService.Service.Info("MemoryBlock", Name + " is clear !"); } /// @@ -2164,14 +2194,17 @@ namespace Cdy.Tag return re; } + /// /// /// /// public static void MakeMemoryBusy(this MarshalMemoryBlock memory) { - LoggerService.Service.Info("MemoryBlock", memory.Name + " is busy....."); - memory.IsBusy = true; + memory.IncRef(); + LoggerService.Service.Info("MemoryBlock","make "+ memory.Name + " is busy....."); + //memory.IsBusy = true; + //memory.StartMemory[0] = 1; } @@ -2181,8 +2214,9 @@ namespace Cdy.Tag /// public static void MakeMemoryNoBusy(this MarshalMemoryBlock memory) { - LoggerService.Service.Info("MemoryBlock", memory.Name+ " is ready !"); - memory.IsBusy = false; + memory.DecRef(); + LoggerService.Service.Info("MemoryBlock", "make " + memory.Name+ " is ready !"); + //memory.StartMemory[0] = 0; } @@ -2208,6 +2242,40 @@ namespace Cdy.Tag } } + /// + /// + /// + /// + /// + public static void RecordToLog(this MarshalMemoryBlock memory,Stream stream) + { + byte[] bvals = new byte[1024]; + long totalsize = memory.AllocSize; + long csize = 0; + foreach (var vv in memory.Buffers) + { + for (int i = 0; i < memory.BufferItemSize / 1024; i++) + { + Marshal.Copy(vv + i * 1024, bvals, 0, 1024); + int isize = (int)Math.Min(totalsize - csize, 1024); + csize += isize; + stream.Write(bvals, 0, isize); + if (csize >= totalsize) + break; + } + if (csize >= totalsize) + break; + } + stream.Flush(); + } + + public static void Dump(this MarshalMemoryBlock memory,DateTime time) + { + string fileName = memory.Name + "_" + time.ToString("yyyy_MM_dd_HH_mm_ss") + ".dmp"; + fileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(MarshalMemoryBlock).Assembly.Location), fileName); + Dump(memory, fileName); + } + /// /// /// diff --git a/Cdy.Tag.Common/Common/MemoryHelper.cs b/Cdy.Tag.Common/Common/MemoryHelper.cs index 29504b0..e9f4fe2 100644 --- a/Cdy.Tag.Common/Common/MemoryHelper.cs +++ b/Cdy.Tag.Common/Common/MemoryHelper.cs @@ -443,6 +443,18 @@ namespace Cdy.Tag } } + /// + /// + /// + /// + /// + /// + public static unsafe float ReadFloat(byte[] value) + { + + return ReadFloat(value.AsMemory(0, 4).Pin().Pointer, 0); + } + /// /// /// @@ -643,6 +655,18 @@ namespace Cdy.Tag } } + /// + /// + /// + /// + /// + /// + public static unsafe double ReadDouble(byte[] value) + { + + return ReadDouble(value.AsMemory(0, 8).Pin().Pointer, 0); + } + /// /// /// diff --git a/Cdy.Tag.Common/Common/PointData.cs b/Cdy.Tag.Common/Common/PointData.cs index 1432996..01438d8 100644 --- a/Cdy.Tag.Common/Common/PointData.cs +++ b/Cdy.Tag.Common/Common/PointData.cs @@ -23,7 +23,23 @@ namespace Cdy.Tag X = x; Y = y; } + /// + /// + /// + /// + /// + public IntPointData(uint x, uint y) + { + X = (int)x; + Y = (int)y; + } + /// + /// + /// public int X { get; set; } + /// + /// + /// public int Y { get; set; } } /// @@ -37,6 +53,13 @@ namespace Cdy.Tag Y = y; Z = z; } + + public IntPoint3Data(uint x, uint y, uint z) + { + X = (int)x; + Y = (int)y; + Z = (int)z; + } public int X { get; set; } public int Y { get; set; } public int Z { get; set; } @@ -52,6 +75,12 @@ namespace Cdy.Tag X = x; Y = y; } + + public UIntPointData(int x, int y) + { + X = (uint)x; + Y = (uint)y; + } public uint X { get; set; } public uint Y { get; set; } } @@ -66,6 +95,13 @@ namespace Cdy.Tag Y = y; Z = z; } + + public UIntPoint3Data(int x, int y, int z) + { + X = (uint)x; + Y = (uint)y; + Z = (uint)z; + } public uint X { get; set; } public uint Y { get; set; } public uint Z { get; set; } @@ -81,6 +117,12 @@ namespace Cdy.Tag X = x; Y = y; } + + public LongPointData(ulong x, ulong y) + { + X = (long)x; + Y = (long)y; + } public long X { get; set; } public long Y { get; set; } } @@ -96,6 +138,13 @@ namespace Cdy.Tag Y = y; Z = z; } + + public LongPoint3Data(ulong x, ulong y, ulong z) + { + X = (long)x; + Y = (long)y; + Z = (long)z; + } public long X { get; set; } public long Y { get; set; } public long Z { get; set; } @@ -111,6 +160,12 @@ namespace Cdy.Tag X = x; Y = y; } + + public ULongPointData(long x, long y) + { + X = (ulong)x; + Y = (ulong)y; + } public ulong X { get; set; } public ulong Y { get; set; } } @@ -127,6 +182,13 @@ namespace Cdy.Tag Z = z; } + public ULongPoint3Data(long x, long y, long z) + { + X = (ulong)x; + Y = (ulong)y; + Z = (ulong)z; + } + public ulong X { get; set; } public ulong Y { get; set; } public ulong Z { get; set; } diff --git a/Cdy.Tag/His/CompressUnitbase.cs b/Cdy.Tag/His/CompressUnitbase.cs index 1949ee7..40b21e2 100644 --- a/Cdy.Tag/His/CompressUnitbase.cs +++ b/Cdy.Tag/His/CompressUnitbase.cs @@ -103,379 +103,379 @@ namespace Cdy.Tag public abstract long Compress(MarshalMemoryBlock source, long sourceAddr, MarshalMemoryBlock target, long targetAddr, long size); - /// - /// - /// - /// - /// - /// - /// - /// - public abstract bool? DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr,DateTime time,int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract bool? DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr,DateTime time,int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// 解压缩某个事件段内所有值 - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime,DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// 解压缩某个事件段内所有值 + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime,DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract byte? DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract byte? DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract short? DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract short? DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract ushort? DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract ushort? DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract int? DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int? DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract uint? DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract uint? DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract long? DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract long? DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract ulong? DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract ulong? DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - public abstract float? DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract float? DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - public abstract double? DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract double? DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract DateTime? DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract DateTime? DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract string DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract string DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); /// /// /// + /// /// /// /// @@ -483,7 +483,7 @@ namespace Cdy.Tag /// /// /// - public abstract int DeCompressAllPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); /// /// @@ -494,8 +494,9 @@ namespace Cdy.Tag /// /// /// + /// /// - public abstract T DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + public abstract int DeCompressValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); /// /// @@ -506,9 +507,46 @@ namespace Cdy.Tag /// /// /// - /// /// - public abstract int DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); + public abstract object DeCompressValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressAllPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result); + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract T DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type); + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public abstract int DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result); public abstract CompressUnitbase Clone(); diff --git a/Cdy.Tag/His/DataFileSeriserbase.cs b/Cdy.Tag/His/DataFileSeriserbase.cs index 95f4c31..e4642a1 100644 --- a/Cdy.Tag/His/DataFileSeriserbase.cs +++ b/Cdy.Tag/His/DataFileSeriserbase.cs @@ -179,6 +179,27 @@ namespace Cdy.Tag /// public abstract MarshalMemoryBlock Read(long start, int len); + /// + /// + /// + /// + /// + public abstract double ReadDouble(long start); + + /// + /// + /// + /// + /// + public abstract float ReadFloat(long start); + + /// + /// + /// + /// + /// + /// + public abstract byte[] ReadBytes(long start,int len); /// /// @@ -236,6 +257,13 @@ namespace Cdy.Tag /// public abstract DataFileSeriserbase Flush(); + + /// + /// 关闭并重新打开 + /// + /// + public abstract DataFileSeriserbase CloseAndReOpen(); + /// /// /// @@ -248,6 +276,8 @@ namespace Cdy.Tag /// public abstract Stream GetStream(); + + /// /// /// diff --git a/Cdy.Tag/Interface/HisQueryResult.cs b/Cdy.Tag/Interface/HisQueryResult.cs index 0901e7e..2f6b934 100644 --- a/Cdy.Tag/Interface/HisQueryResult.cs +++ b/Cdy.Tag/Interface/HisQueryResult.cs @@ -125,7 +125,7 @@ namespace Cdy.Tag /// /// /// - public void Add(T value,DateTime time,byte qulity) + public void Add(TT value,DateTime time,byte qulity) { Add((object)value, time, qulity); } diff --git a/Cdy.Tag/Interface/IHisQuery.cs b/Cdy.Tag/Interface/IHisQuery.cs index 635aad6..691bc0c 100644 --- a/Cdy.Tag/Interface/IHisQuery.cs +++ b/Cdy.Tag/Interface/IHisQuery.cs @@ -18,142 +18,129 @@ namespace Cdy.Tag public interface IHisQuery { - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); /// /// /// + /// /// /// /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + /// + HisQueryResult ReadValue(int id, List times, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); /// /// @@ -161,98 +148,120 @@ namespace Cdy.Tag /// /// /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + /// + HisQueryResult ReadAllValue(int id, DateTime startTime, DateTime endTime); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - HisQueryResult ReadAllValue(int id, DateTime startTime, DateTime endTime); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - /// - /// - /// - /// - /// - /// - /// - /// - HisQueryResult ReadValue(int id, List times, QueryValueMatchType type); + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + + + + } } diff --git a/DBHisData/HisQuery/DataFileManager.cs b/DBHisData/HisQuery/DataFileManager.cs index bb38368..05ca06c 100644 --- a/DBHisData/HisQuery/DataFileManager.cs +++ b/DBHisData/HisQuery/DataFileManager.cs @@ -8,6 +8,7 @@ //============================================================== using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,6 +24,16 @@ namespace Cdy.Tag private Dictionary> mTimeFileMaps = new Dictionary>(); + /// + /// + /// + private Dictionary mLogFileMaps = new Dictionary(); + + /// + /// + /// + internal static Dictionary CurrentDateTime = new Dictionary(); + private string mDatabaseName; /// @@ -30,8 +41,16 @@ namespace Cdy.Tag /// public const string DataFileExtends = ".dbd"; + public const string LogFileExtends = ".log"; + + /// + /// + /// public const int FileHeadSize = 72; + private System.IO.FileSystemWatcher hisDataWatcher; + + private System.IO.FileSystemWatcher logDataWatcher; #endregion ...Variables... #region ... Events ... @@ -62,6 +81,9 @@ namespace Cdy.Tag /// public string PrimaryHisDataPath { get; set; } + + public string PrimaryLogDataPath { get; set; } + /// /// /// @@ -80,6 +102,15 @@ namespace Cdy.Tag return string.IsNullOrEmpty(PrimaryHisDataPath) ? PathHelper.helper.GetDataPath(this.mDatabaseName,"HisData") : System.IO.Path.IsPathRooted(PrimaryHisDataPath) ? PrimaryHisDataPath : PathHelper.helper.GetDataPath(this.mDatabaseName,PrimaryHisDataPath); } + /// + /// + /// + /// + private string GetPrimaryLogDataPath() + { + return string.IsNullOrEmpty(PrimaryLogDataPath)?PathHelper.helper.GetDataPath(this.mDatabaseName, "Log"): System.IO.Path.IsPathRooted(PrimaryLogDataPath) ? PrimaryLogDataPath : PathHelper.helper.GetDataPath(this.mDatabaseName, PrimaryLogDataPath); + } + /// /// /// @@ -95,10 +126,100 @@ namespace Cdy.Tag /// public async Task Int() { - await Scan(GetPrimaryHisDataPath()); + + + string datapath = GetPrimaryHisDataPath(); + await Scan(datapath); + if (System.IO.Directory.Exists(datapath)) + { + hisDataWatcher = new System.IO.FileSystemWatcher(GetPrimaryHisDataPath()); + hisDataWatcher.Changed += HisDataWatcher_Changed; + hisDataWatcher.EnableRaisingEvents = true; + } + + string logpath = GetPrimaryLogDataPath(); + if (System.IO.Directory.Exists(logpath)) + { + logDataWatcher = new System.IO.FileSystemWatcher(logpath); + logDataWatcher.Changed += LogDataWatcher_Changed; + + logDataWatcher.EnableRaisingEvents = true; + } + //await Scan(GetBackHisDataPath()); } + /// + /// + /// + /// + /// + private void LogDataWatcher_Changed(object sender, System.IO.FileSystemEventArgs e) + { + if (e.ChangeType == System.IO.WatcherChangeTypes.Deleted) + { + if(mLogFileMaps.ContainsKey(e.FullPath)) + { + mLogFileMaps.Remove(e.FullPath); + } + } + else + { + LoggerService.Service.Info("DataFileMananger", "LogFile "+ e.Name + " add to FileCach!", ConsoleColor.Cyan); + ParseLogFile(e.FullPath); + } + } + + private void HisDataWatcher_Changed(object sender, System.IO.FileSystemEventArgs e) + { + if(e.ChangeType == System.IO.WatcherChangeTypes.Created) + { + LoggerService.Service.Info("DataFileMananger", "HisDataFile " + e.Name + " is Created & will be add to dataFileCach!", ConsoleColor.Cyan); + var vifno = new System.IO.FileInfo(e.FullPath); + if(vifno.Extension == DataFileExtends) + { + ParseFileName(vifno); + } + } + else if(e.ChangeType == System.IO.WatcherChangeTypes.Changed) + { + LoggerService.Service.Info("DataFileMananger", "HisDataFile "+ e.Name + " is changed & will be processed!", ConsoleColor.Cyan); + var vtmp = new System.IO.FileInfo(e.FullPath); + if(vtmp.Extension == DataFileExtends) + { + var vfile = CheckAndGetDataFile(e.Name); + if (vfile != null) + { + vfile.UpdateLastDatetime(); + } + else + { + ParseFileName(vtmp); + } + } + + } + } + + public async Task ScanLogFile(string path) + { + System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path); + if (dir.Exists) + { + foreach (var vv in dir.GetFiles()) + { + if (vv.Extension == LogFileExtends) + { + ParseLogFile(vv.FullName); + } + } + foreach (var vv in dir.GetDirectories()) + { + await ScanLogFile(vv.FullName); + } + } + } + /// /// 搜索文件 /// @@ -122,6 +243,66 @@ namespace Cdy.Tag } } + /// + /// + /// + /// + private void ParseLogFile(string sfileName) + { + + var vname = System.IO.Path.GetFileNameWithoutExtension(sfileName); + + DateTime dt = new DateTime(int.Parse(vname.Substring(0, 4)), int.Parse(vname.Substring(4, 2)), int.Parse(vname.Substring(6, 2)), int.Parse(vname.Substring(8, 2)), int.Parse(vname.Substring(10, 2)), int.Parse(vname.Substring(12, 2))); + int timelen = int.Parse(vname.Substring(14, 3)); + + if(!mLogFileMaps.ContainsKey(sfileName)) + { + mLogFileMaps.Add(sfileName, new LogFileInfo() { FileName = sfileName, StartTime = dt, EndTime = dt.AddSeconds(timelen) }); + } + } + + private DataFileInfo CheckAndGetDataFile(string file) + { + string sname = file.Replace(DataFileExtends, ""); + string stime = sname.Substring(sname.Length - 12, 12); + int yy = 0, mm = 0, dd = 0; + + int id = -1; + int.TryParse(sname.Substring(sname.Length - 15, 3), out id); + + if (id == -1) + return null; + + if (!int.TryParse(stime.Substring(0, 4), out yy)) + { + return null; + } + + if (!int.TryParse(stime.Substring(4, 2), out mm)) + { + return null; + } + + if (!int.TryParse(stime.Substring(6, 2), out dd)) + { + return null; + } + int hhspan = int.Parse(stime.Substring(8, 2)); + + int hhind = int.Parse(stime.Substring(10, 2)); + + int hh = hhspan * hhind; + + + DateTime startTime = new DateTime(yy, mm, dd, hh, 0, 0); + + if (mTimeFileMaps.ContainsKey(id)) + { + return mTimeFileMaps[id][yy].GetDataFile(startTime); + } + return null; + } + /// /// /// @@ -179,7 +360,32 @@ namespace Cdy.Tag mTimeFileMaps.Add(id, new Dictionary()); mTimeFileMaps[id].Add(yy, yt); } - yt.AddFile(startTime, new TimeSpan(hhspan, 0, 0), new DataFileInfo() { Duration = new TimeSpan(hhspan, 0, 0), StartTime = startTime, FileName = file.FullName }); + yt.AddFile(startTime, new TimeSpan(hhspan, 0, 0), new DataFileInfo() { Duration = new TimeSpan(hhspan, 0, 0), StartTime = startTime, FileName = file.FullName,FId= mDatabaseName + id }); + } + + /// + /// + /// + /// + /// + private LogFileInfo GetLogDataFile(DateTime time) + { + foreach(var vv in mLogFileMaps.Values.ToArray()) + { + if (vv.StartTime <= time && time < vv.EndTime) return vv; + } + return null; + } + + /// + /// + /// + /// + /// + /// + private bool CheckDataInLogFile(DateTime time,int id) + { + return CurrentDateTime[mDatabaseName + id] < time; } /// @@ -192,9 +398,17 @@ namespace Cdy.Tag { int id = Id / TagCountOneFile; - if (mTimeFileMaps.ContainsKey(id) && mTimeFileMaps[id].ContainsKey(time.Year)) + if (CheckDataInLogFile(time,id)) + { + //如果查询时间,比最近更新的时间还要新,则需要查询日志文件 + return null; + } + else { - return mTimeFileMaps[id][time.Year].GetDataFile(time); + if (mTimeFileMaps.ContainsKey(id) && mTimeFileMaps[id].ContainsKey(time.Year)) + { + return mTimeFileMaps[id][time.Year].GetDataFile(time); + } } return null; } @@ -207,9 +421,33 @@ namespace Cdy.Tag /// /// /// - public List GetDataFiles(DateTime starttime, DateTime endtime, int Id) + public List GetDataFiles(DateTime starttime, DateTime endtime,out Tuple logFileTimes, int Id) { - return GetDataFiles(starttime,endtime-starttime,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(DateTime.MinValue, DateTime.MinValue); + return GetDataFiles(starttime, endtime - starttime, Id); + } + } /// @@ -253,76 +491,58 @@ namespace Cdy.Tag /// /// /// - public SortedDictionary GetDataFiles(List times, int Id) + public SortedDictionary GetDataFiles(List times, List logFileTimes,int Id) { SortedDictionary re = new SortedDictionary(); foreach(var vv in times) { - re.Add(vv, GetDataFile(vv, Id)); + if (CheckDataInLogFile(vv, Id)) + { + logFileTimes.Add(vv); + } + else + { + re.Add(vv, GetDataFile(vv, Id)); + } + } + return re; + } + + /// + /// + /// + /// + /// + /// + public SortedDictionary GetLogDataFiles(List times) + { + SortedDictionary re = new SortedDictionary(); + foreach (var vvd in times) + { + re.Add(vvd, GetLogDataFile(vvd)); } return re; } - ///// - ///// - ///// - ///// - ///// - //public MinuteTimeFile GetFile(DateTime time,int Id) - //{ - // int id = Id / TagCountOneFile; - - // if (mTimeFileMaps.ContainsKey(id) && mTimeFileMaps[id].ContainsKey(time.Year)) - // { - // return mTimeFileMaps[id][time.Year].GetFile(time); - // } - // return null; - //} - - ///// - ///// - ///// - ///// - ///// - ///// - //public List GetFiles(DateTime starttime,DateTime endtime,int Id) - //{ - // List re = new List(); - // DateTime sstart = starttime; - // while (sstart <= endtime) - // { - // var sfile = GetFile(sstart, Id); - // if (sfile != null) - // re.Add(sfile); - // sstart = sstart.AddMinutes(1); - // } - // return re; - //} - - ///// - ///// - ///// - ///// - ///// - //public Dictionary GetFiles(List times,int Id) - //{ - // Dictionary re = new Dictionary(); - // foreach(var vv in times) - // { - // re.Add(vv,GetFile(vv,Id)); - // } - // return re; - //} - - ///// - ///// - ///// - ///// - ///// - //private DataFileSeriserbase GetFileSerise(string datafile) - //{ - // return null; - //} + /// + /// + /// + /// + /// + /// + /// + public List GetLogDataFiles(DateTime startTime, DateTime endtime) + { + List re = new List(); + foreach (var vv in mLogFileMaps.ToArray()) + { + if ((vv.Value.StartTime >= startTime && vv.Value.StartTime < endtime) || (vv.Value.EndTime >= startTime && vv.Value.EndTime < endtime)) + { + re.Add(vv.Value); + } + } + return re; + } #endregion ...Methods... diff --git a/DBHisData/HisQuery/HisDataQuery.cs b/DBHisData/HisQuery/HisDataQuery.cs deleted file mode 100644 index 2b43eca..0000000 --- a/DBHisData/HisQuery/HisDataQuery.cs +++ /dev/null @@ -1,102 +0,0 @@ -//============================================================== -// Copyright (C) 2019 Inc. All rights reserved. -// -//============================================================== -// Create by 种道洋 at 2019/12/27 18:45:02. -// Version 1.0 -// 种道洋 -//============================================================== -using System; -using System.Collections.Generic; -using System.Text; - -namespace Cdy.Tag -{ - /// - /// - /// - public class HisDataQuery - { - #region ... Variables ... - - #endregion ...Variables... - - #region ... Events ... - - #endregion ...Events... - - #region ... Constructor... - - #endregion ...Constructor... - - #region ... Properties ... - - #endregion ...Properties... - - #region ... Methods ... - - /// - /// - /// - /// - /// - /// - /// - public List> Query(List tag, DateTime startTime, DateTime endTime) - { - var lid = ServiceLocator.Locator.Resolve().GetTagIdByName(tag); - if (lid != null) - { - return Query(lid, startTime, endTime); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - public HisQueryResult Query(string tag,DateTime startTime, DateTime endTime) - { - int? lid = ServiceLocator.Locator.Resolve().GetTagIdByName(tag); - if(lid!=null) - { - return Query(lid.Value, startTime, endTime); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - public HisQueryResult Query(int tagId, DateTime startTime, DateTime endTime) - { - return null; - } - - /// - /// - /// - /// - /// - /// - /// - public List> Query(List tagId, DateTime startTime, DateTime endTime) - { - return null; - } - - #endregion ...Methods... - - #region ... Interfaces ... - - #endregion ...Interfaces... - } -} diff --git a/DBHisData/HisQuery/QuerySerivce.cs b/DBHisData/HisQuery/QuerySerivce.cs index 8f0c059..1f85b5f 100644 --- a/DBHisData/HisQuery/QuerySerivce.cs +++ b/DBHisData/HisQuery/QuerySerivce.cs @@ -50,80 +50,37 @@ namespace Cdy.Tag /// /// /// + /// /// /// /// /// - public void ReadValue(int id,List times, QueryValueMatchType type, HisQueryResult result) + public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) { - var vfiles = GetFileManager().GetDataFiles(times, id); - - DataFileInfo mPreFile = null; - - List mtime = new List(); - - foreach(var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadBool(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - result.Add(false, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadBool(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if(mPreFile!=null) - { - mPreFile.ReadBool(id, mtime, type, result); - } - } + List mLogTimes = new List(); + var vfiles = GetFileManager().GetDataFiles(times, mLogTimes, id); - /// - /// - /// - /// - /// - /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(times, id); DataFileInfo mPreFile = null; + List mtime = new List(); + foreach (var vv in vfiles) { if (vv.Value == null) { if (mPreFile != null) { - mPreFile.ReadByte(id, mtime, type, result); + mPreFile.Read(id, mtime, type, result); mPreFile = null; mtime.Clear(); } - result.Add((byte)0, vv.Key, (byte)QualityConst.Null); + result.Add(false, vv.Key, (byte)QualityConst.Null); } else if (vv.Value != mPreFile) { if (mPreFile != null) { - mPreFile.ReadByte(id, mtime, type, result); + mPreFile.Read(id, mtime, type, result); } mPreFile = vv.Value; mtime.Clear(); @@ -136,3533 +93,139 @@ namespace Cdy.Tag } if (mPreFile != null) { - mPreFile.ReadByte(id, mtime, type, result); + mPreFile.Read(id, mtime, type, result); } + + ReadLogFile(id, mLogTimes, type, result); } /// /// /// + /// /// - /// - /// + /// /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) + private void ReadLogFile(int id,List mLogTimes, QueryValueMatchType type, HisQueryResult result) { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) + if (mLogTimes.Count > 0) { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadShort(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - result.Add((short)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) + List mtime = new List(); + var lfiles = GetFileManager().GetLogDataFiles(mLogTimes); + + LogFileInfo mPlFile = null; + + foreach (var vv in lfiles) { - if (mPreFile != null) + if (vv.Value == null) { - mPreFile.ReadShort(id, mtime, type, result); + if (mPlFile != null) + { + mPlFile.Read(id, mtime, type, result); + mPlFile = null; + mtime.Clear(); + } + result.Add(default(T), vv.Key, (byte)QualityConst.Null); } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadShort(id, mtime, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) + else if (vv.Value != mPlFile) { - mPreFile.ReadUShort(id, mtime, type, result); - mPreFile = null; + if (mPlFile != null) + { + mPlFile.Read(id, mtime, type, result); + } + mPlFile = vv.Value; mtime.Clear(); + mtime.Add(vv.Key); } - result.Add((ushort)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) + else { - mPreFile.ReadUShort(id, mtime, type, result); + mtime.Add(vv.Key); } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); } - else + if (mPlFile != null) { - mtime.Add(vv.Key); + mPlFile.Read(id, mtime, type, result); } } - if (mPreFile != null) - { - mPreFile.ReadUShort(id, mtime, type, result); - } } + + /// /// /// + /// /// - /// - /// + /// + /// /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) + private void ReadLogFileAllValue(int id,DateTime startTime,DateTime endTime,HisQueryResult result) { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadInt(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - result.Add((int)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadInt(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadInt(id, mtime, type, result); - } + var vfiles = GetFileManager().GetLogDataFiles(startTime,endTime); + vfiles.ForEach(e => { + DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; + DateTime eend = e.EndTime > endTime ? endTime : endTime; + e.ReadAllValue(id, sstart, eend, result); + }); } /// /// /// + /// /// - /// - /// + /// + /// /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) + public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadUInt(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - result.Add((uint)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadUInt(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) + Tuple mLogFileTimes; + var vfiles = GetFileManager().GetDataFiles(startTime, endTime, out mLogFileTimes, id); + vfiles.ForEach(e => { + DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; + DateTime eend = e.EndTime > endTime ? endTime : endTime; + e.ReadAllValue(id, sstart, eend, result); + }); + + if (mLogFileTimes.Item1 != DateTime.MinValue) { - mPreFile.ReadUInt(id, mtime, type, result); + ReadLogFileAllValue(id, mLogFileTimes.Item1, mLogFileTimes.Item2, result); } } + /// /// /// + /// /// - /// - /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) + /// + /// + /// + public HisQueryResult ReadAllValue(int id, DateTime startTime, DateTime endTime) { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadULong(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - result.Add((ulong)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadULong(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadULong(id, mtime, type, result); - } + int valueCount = (int)(endTime - startTime).TotalSeconds; + var result = new HisQueryResult(valueCount); + ReadAllValue(id, startTime, endTime, result); + return result as HisQueryResult; } /// /// /// + /// /// /// /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) + /// + public HisQueryResult ReadValue(int id, List times, QueryValueMatchType type) { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadLong(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } + int valueCount = times.Count; - result.Add((long)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadLong(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadLong(id, mtime, type, result); - } - } - - - /// - /// - /// - /// - /// - /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadFloat(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - - result.Add((float)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadFloat(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadFloat(id, mtime, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadDouble(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - - result.Add((double)0, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadDouble(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadDouble(id, mtime, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadDateTime(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - result.Add(DateTime.Now, vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadDateTime(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadDateTime(id, mtime, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(times, id); - DataFileInfo mPreFile = null; - List mtime = new List(); - foreach (var vv in vfiles) - { - if (vv.Value == null) - { - if (mPreFile != null) - { - mPreFile.ReadString(id, mtime, type, result); - mPreFile = null; - mtime.Clear(); - } - result.Add("", vv.Key, (byte)QualityConst.Null); - } - else if (vv.Value != mPreFile) - { - if (mPreFile != null) - { - mPreFile.ReadString(id, mtime, type, result); - } - mPreFile = vv.Value; - mtime.Clear(); - mtime.Add(vv.Key); - } - else - { - mtime.Add(vv.Key); - } - } - if (mPreFile != null) - { - mPreFile.ReadString(id, mtime, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id,DateTime startTime,DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime,id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime>startTime?e.StartTime:startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - public void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vfiles = GetFileManager().GetDataFiles(startTime, endTime, id); - vfiles.ForEach(e => { - DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime; - DateTime eend = e.EndTime > endTime ? endTime : endTime; - e.ReadAllValue(id, sstart, eend, result); - }); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public HisQueryResult ReadAllValue(int id, DateTime startTime, DateTime endTime) - { - int valueCount = (int)(endTime - startTime).TotalSeconds; - if (typeof(T) == typeof(double)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(float)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(bool) || typeof(T) == typeof(Boolean)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(long) || typeof(T) == typeof(Int64)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(ulong) || typeof(T) == typeof(UInt64)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(int) || typeof(T) == typeof(Int32)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(uint) || typeof(T) == typeof(UInt32)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(short) || typeof(T) == typeof(Int16)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(ushort) || typeof(T) == typeof(UInt16)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(byte)) - { - - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(string) || typeof(T) == typeof(String)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(DateTime)) - { - var result = new HisQueryResult(valueCount); - ReadAllValue(id, startTime, endTime, result); - return result as HisQueryResult; - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public HisQueryResult ReadValue(int id, List times, QueryValueMatchType type) - { - int valueCount = times.Count; - if (typeof(T) == typeof(double)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(float)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(bool) || typeof(T) == typeof(Boolean)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(long) || typeof(T) == typeof(Int64)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(ulong) || typeof(T) == typeof(UInt64)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(int) || typeof(T) == typeof(Int32)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(uint) || typeof(T) == typeof(UInt32)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(short) || typeof(T) == typeof(Int16)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(ushort) || typeof(T) == typeof(UInt16)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(byte)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(string) || typeof(T) == typeof(String)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - else if (typeof(T) == typeof(DateTime)) - { - var result = new HisQueryResult(valueCount); - ReadValue(id, times, type, result); - return result as HisQueryResult; - } - return null; + var result = new HisQueryResult(valueCount); + ReadValue(id, times, type, result); + return result; } } - - - //public static class MinuteTimeFileExtend - //{ - - // /// - // /// - // /// - // /// - // /// - // public static DataFileSeriserbase GetFileSeriser(this MinuteTimeFile file) - // { - // return DataFileSeriserManager.manager.GetDefaultFileSersie(); - // } - - // #region 读取所有值 - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void GeneratorTime(Dictionary> times, DateTime start, DateTime end, MinuteTimeFile file) - // { - // file.GetTimeSpan(out start, out end); - - // int icount = 0; - // long laddr = 0; - // foreach (var vv in file.SecondOffset) - // { - // var vend = start.AddSeconds(vv.Key); - // if (icount > 0) - // { - // times.Add(vv.Value.Item1, new Tuple(start, vend)); - // } - // laddr = vv.Value.Item1; - // start = vend; - // } - - // if (start < end) - // { - // times.Add(laddr, new Tuple(start, end)); - // } - // } - - // /// - // /// 读取某时间段内的所有bool值 - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// 读取某时间段内的所有byte值 - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this MinuteTimeFile file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - - // GeneratorTime(moffs, startTime, endTime, file); - - // foreach (var vf in moffs) - // { - // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - // } - // } - - // #endregion - - // #region 读取指定时刻值 - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static bool? ReadBool(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadBool(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadBool(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadBool(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadBool(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadBool(vf.Key, tid, vf.Value, type, result); - // } - // } - - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static byte? ReadByte(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadByte(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadByte(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadByte(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadByte(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadByte(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static short? ReadShort(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadShort(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadShort(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadShort(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadShort(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - // foreach (var vf in moffs) - // { - // vff.ReadShort(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static ushort? ReadUShort(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadUShort(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadUShort(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadUShort(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadUShort(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadUShort(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static int? ReadInt(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadInt(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadInt(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadInt(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadInt(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadInt(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static uint? ReadUInt(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadUInt(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadUInt(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadUInt(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadUInt(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - // foreach (var vf in moffs) - // { - // vff.ReadUInt(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static long? ReadLong(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadLong(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadLong(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadLong(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadLong(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadLong(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static ulong? ReadULong(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadULong(offset, tid, time, type); - // } - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadULong(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadULong(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadULong(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadULong(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static float? ReadFloat(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadFloat(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadFloat(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadFloat(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadFloat(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadFloat(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static double? ReadDouble(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadDouble(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadDouble(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadDouble(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadDouble(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - - // foreach (var vf in moffs) - // { - // vff.ReadDouble(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static DateTime? ReadDateTime(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadDateTime(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadDateTime(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadDateTime(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadDateTime(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - // foreach (var vf in moffs) - // { - // vff.ReadDateTime(vf.Key, tid, vf.Value, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static string ReadString(this MinuteTimeFile file, int tid, DateTime time, QueryValueMatchType type) - // { - // var vff = file.GetFileSeriser(); - // var offset = file.GetOffset(time.Second); - // return vff.ReadString(offset, tid, time, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadString(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type) - // { - // HisQueryResult re = new HisQueryResult(times.Count); - // ReadString(file, tid, times, type, re); - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadString(this MinuteTimeFile file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - // { - // var vff = file.GetFileSeriser(); - // Dictionary> moffs = new Dictionary>(); - // foreach (var vv in times) - // { - // var ff = file.GetOffset(vv.Second); - // if (moffs.ContainsKey(ff)) - // { - // moffs[ff].Add(vv); - // } - // else - // { - // moffs.Add(ff, new List() { vv }); - // } - // } - // foreach (var vf in moffs) - // { - // vff.ReadString(vf.Key, tid, vf.Value, type, result); - // } - // } - // #endregion - - // #region DataFileSeriser Read - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static bool? ReadBool(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToBoolValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static HisQueryResult ReadBool(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToBoolValue(vv.Key, vv.Value, timetick, type, res); - // } - // return res; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static byte? ReadByte(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToByteValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadByte(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToByteValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static short? ReadShort(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToShortValue(data, dataTime, timetick, type); - // } - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadShort(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToShortValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static ushort? ReadUShort(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToUShortValue(data, dataTime, timetick, type); - // } - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadUShort(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToUShortValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static int? ReadInt(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToIntValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadInt(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToIntValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static uint? ReadUInt(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToUIntValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadUInt(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToUIntValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static long? ReadLong(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToLongValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadLong(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToLongValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static ulong? ReadULong(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToULongValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadULong(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToULongValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static string ReadString(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToStringValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadString(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToStringValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static DateTime? ReadDateTime(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToDateTimeValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadDateTime(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToDateTimeValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static float? ReadFloat(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToFloatValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadFloat(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToFloatValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static double? ReadDouble(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - // return DeCompressDataBlockToDoubleValue(data, dataTime, timetick, type); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadDouble(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockToDoubleValue(vv.Key, vv.Value, timetick, type, res); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime,DateTime endTime, HisQueryResult result) - // { - // int timetick = 0; - // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - // foreach (var vv in data) - // { - // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - // } - // } - // #endregion - - // #region DeCompressData - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static bool? DeCompressDataBlockToBoolValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressBoolValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToBoolValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressBoolValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static byte? DeCompressDataBlockToByteValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressByteValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToByteValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressByteValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static short? DeCompressDataBlockToShortValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressShortValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToShortValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressShortValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static ushort? DeCompressDataBlockToUShortValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressUShortValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToUShortValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressUShortValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static int? DeCompressDataBlockToIntValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressIntValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToIntValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressIntValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static uint? DeCompressDataBlockToUIntValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressUIntValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToUIntValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressUIntValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static long? DeCompressDataBlockToLongValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressLongValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // private static void DeCompressDataBlockToLongValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressLongValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static ulong? DeCompressDataBlockToULongValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressULongValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // private static void DeCompressDataBlockToULongValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressULongValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static float? DeCompressDataBlockToFloatValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressFloatValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToFloatValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressFloatValue(memory, 1, datatime, timeTick, type, result); - // } - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static Double? DeCompressDataBlockToDoubleValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressDoubleValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToDoubleValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressDoubleValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static string DeCompressDataBlockToStringValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressStringValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToStringValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressStringValue(memory, 1, datatime, timeTick, type, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static DateTime? DeCompressDataBlockToDateTimeValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // return tp.DeCompressDateTimeValue(memory, 1, datatime, timeTick, type); - // } - // return null; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockToDateTimeValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressDateTimeValue(memory, 1, datatime, timeTick, type, result); - // } - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory,DateTime startTime,DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - // { - // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - // //读取压缩类型 - // var ctype = memory.ReadByte(); - // var tp = CompressUnitManager.Manager.GetCompress(ctype); - // if (tp != null) - // { - // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - // } - // } - // #endregion - - // #region 读取数据区域头数据 - // /// - // /// 检测数据头部指针区域数据是否被缓存 - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static Dictionary CheckBlockHeadCach(this DataFileSeriserbase datafile, long offset,out int tagCount, out int fileDuration, out int blockDuration, out int timetick) - // { - // //文件头部结构: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 + 24; - // //读取变量个数 - // int count = datafile.ReadInit(dataoffset); - // dataoffset += 4; - - // tagCount = count; - - // //读取校验和 - // long idsum = datafile.ReadLong(dataoffset); - // dataoffset += 8; - - // //读取单个文件的时长 - // fileDuration = datafile.ReadInit(dataoffset); - // dataoffset += 4; - // //读取数据块时长 - // blockDuration = datafile.ReadInit(dataoffset); - // dataoffset += 4; - // //读取时钟周期 - // timetick = datafile.ReadInit(dataoffset); - // dataoffset += 4; - - // lock (TagHeadOffsetManager.manager) - // { - // if (!TagHeadOffsetManager.manager.Contains(idsum, count)) - // { - // //Tag id 列表经过压缩,内容格式为:DataSize + Data - // var dsize = datafile.ReadInit(dataoffset); - // dataoffset += 4; - // using (var dd = datafile.Read(dataoffset, dsize)) - // { - // MarshalVarintCodeMemory vcm = new MarshalVarintCodeMemory(dd.StartMemory); - // var ltmp = vcm.ToIntList(); - - // var dtmp = new Dictionary(); - // if (ltmp.Count > 0) - // { - // int preid = ltmp[0]; - // dtmp.Add(preid,0); - // for (int i = 1; i < ltmp.Count; i++) - // { - // var id = ltmp[i] + preid; - // dtmp.Add(id, i); - // preid = id; - // } - // } - // TagHeadOffsetManager.manager.Add(idsum, count, dtmp); - - // return dtmp; - // } - // } - // else - // { - // return TagHeadOffsetManager.manager.Get(idsum, count); - // } - // } - // } - - // /// - // /// 读取某个变量在头部文件种的序号 - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static int ReadTagIndexInDataPointer(this DataFileSeriserbase datafile, int tid, long offset, out int tagCount,out int fileDuration, out int blockDuration, out int timetick) - // { - // var hfile = datafile.CheckBlockHeadCach(offset,out tagCount ,out fileDuration, out blockDuration, out timetick); - // if (hfile.ContainsKey(tid)) - // { - // return hfile[tid]; - // } - // return -1; - // } - - // /// - // /// 读取数据区域的数据头数据 - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static List ReadTargetBlockAddress(this DataFileSeriserbase datafile, List tid ,long offset,out int tagCount, out int fileDuration, out int blockDuration, out int timetick) - // { - // var hfile = datafile.CheckBlockHeadCach(offset,out tagCount, out fileDuration, out blockDuration, out timetick); - // List re = new List(); - // foreach (var vv in tid) - // { - // if (hfile.ContainsKey(vv)) - // { - // re.Add(hfile[vv]); - // } - // else - // { - // re.Add(-1); - // } - // } - // return re; - // } - // #endregion - - // #region 读取数据块 - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static MarshalMemoryBlock ReadTagDataBlock(this DataFileSeriserbase datafile, int tid, long offset, DateTime dataTime, out int timetick) - // { - // int fileDuration, blockDuration = 0; - // int tagCount = 0; - // var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick); - // int blockcount = fileDuration * 60 / blockDuration; - - // var startTime = datafile.ReadDateTime(16); - // var ttmp = (dataTime - startTime).TotalMinutes; - // int dindex = (int)(ttmp / blockDuration); - // if (ttmp % blockDuration > 0) - // { - // dindex++; - // } - - // if (dindex > blockcount) - // { - // throw new Exception("DataPointer index is out of total block number"); - // } - - // var dataPointer = datafile.ReadLong(blockIndex * 8 + dindex * tagCount * 8); //读取DataBlock的地址 - - // var datasize = datafile.ReadInit(dataPointer); //读取DataBlock 的大小 - - // return datafile.Read(dataPointer + 4, datasize); - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static Dictionary ReadTagDataBlock(this DataFileSeriserbase datafile, int tid, long offset, List dataTimes, out int timetick) - // { - // int fileDuration, blockDuration = 0; - // int tagCount = 0; - // var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick); - // int blockcount = fileDuration * 60 / blockDuration; - - // var startTime = datafile.ReadDateTime(16); - - // Dictionary rtmp = new Dictionary(); - - // Dictionary re = new Dictionary(); - - // foreach (var vdd in dataTimes) - // { - // var ttmp = (vdd - startTime).TotalMinutes; - // int dindex = (int)(ttmp / blockDuration); - // if (ttmp % blockDuration > 0) - // { - // dindex++; - // } - - // if (dindex > blockcount) - // { - // throw new Exception("DataPointer index is out of total block number"); - // } - - // var dataPointer = datafile.ReadLong(blockIndex * 8 + dindex * tagCount * 8); //读取DataBlock的地址 - - // var datasize = datafile.ReadInit(dataPointer); //读取DataBlock 的大小 - - // if (!rtmp.ContainsKey(dataPointer)) - // { - // var rmm = datafile.Read(dataPointer + 4, datasize); - // re.Add(vdd, rmm); - // rtmp.Add(dataPointer, rmm); - // } - // else - // { - // re.Add(vdd, rtmp[dataPointer]); - // } - // } - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // public static Dictionary> ReadTagDataBlock2(this DataFileSeriserbase datafile, int tid, long offset, List dataTimes, out int timetick) - // { - // int fileDuration, blockDuration = 0; - // int tagCount = 0; - // var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset,out tagCount, out fileDuration, out blockDuration, out timetick); - // int blockcount = fileDuration * 60 / blockDuration; - - // var startTime = datafile.ReadDateTime(16); - - // Dictionary rtmp = new Dictionary(); - - // Dictionary> re = new Dictionary>(); - - // foreach (var vdd in dataTimes) - // { - // var ttmp = (vdd - startTime).TotalMinutes; - // int dindex = (int)(ttmp / blockDuration); - // if (ttmp % blockDuration > 0) - // { - // dindex++; - // } - - // if (dindex > blockcount) - // { - // throw new Exception("DataPointer index is out of total block number"); - // } - - // var dataPointer = datafile.ReadLong(blockIndex * 8 + dindex * tagCount * 8); //读取DataBlock的地址 - - // var datasize = datafile.ReadInit(dataPointer); //读取DataBlock 的大小 - - // if (!rtmp.ContainsKey(dataPointer)) - // { - // var rmm = datafile.Read(dataPointer, datasize); - // if (!re.ContainsKey(rmm)) - // { - // re.Add(rmm, new List() { vdd }); - // } - // else - // { - // re[rmm].Add(vdd); - // } - // rtmp.Add(dataPointer, rmm); - // } - // else - // { - // var rmm = rtmp[dataPointer]; - // if (!re.ContainsKey(rmm)) - // { - // re.Add(rmm, new List() { vdd }); - // } - // else - // { - // re[rmm].Add(vdd); - // } - // } - // } - // return re; - // } - - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // /// - // 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; - // var blockIndex = datafile.ReadTagIndexInDataPointer(tid, offset,out tagCount, out fileDuration, out blockDuration, out timetick); - // int blockcount = fileDuration * 60 / blockDuration; - - // var startTime = datafile.ReadDateTime(16); - - // Dictionary> re = new Dictionary>(); - - // DateTime sstart = start; - // DateTime send = end; - - // while(sstartend) - // { - // send = end; - // } - // int dindex = (int)(ttmp / blockDuration); - // if (ttmp % blockDuration > 0) - // { - // dindex++; - // } - - // if (dindex > blockcount) - // { - // throw new Exception("DataPointer index is out of total block number"); - // } - - // var dataPointer = datafile.ReadLong(blockIndex * 8 + dindex * tagCount * 8); //读取DataBlock的地址 - - // var datasize = datafile.ReadInit(dataPointer); //读取DataBlock 的大小 - - // var rmm = datafile.Read(dataPointer, datasize); - // if (!re.ContainsKey(rmm)) - // { - // re.Add(rmm, new Tuple(sstart, end)); - // } - - // sstart = send; - // } - // return re; - // } - // #endregion - //} } diff --git a/DBHisData/HisQuery/TagHeadOffsetManager.cs b/DBHisData/HisQuery/TagHeadOffsetManager.cs index c1d1fa2..46f049c 100644 --- a/DBHisData/HisQuery/TagHeadOffsetManager.cs +++ b/DBHisData/HisQuery/TagHeadOffsetManager.cs @@ -27,7 +27,9 @@ namespace Cdy.Tag /// /// /// - Dictionary,long>> mHeadOffsets = new Dictionary, long>>(); + public Dictionary,long>> mHeadOffsets = new Dictionary, long>>(); + + public Dictionary> LogHeadOffsets = new Dictionary>(); #endregion ...Variables... @@ -45,6 +47,45 @@ namespace Cdy.Tag #region ... Methods ... + /// + /// + /// + /// + /// + public bool Contains(string name) + { + return LogHeadOffsets.ContainsKey(name); + } + + /// + /// + /// + /// + /// + public void AddLogHead(string name,Dictionary addrs) + { + if (!LogHeadOffsets.ContainsKey(name)) + { + LogHeadOffsets.Add(name, addrs); + } + else + { + LogHeadOffsets[name] = addrs; + } + } + + /// + /// + /// + /// + public void RemoveLogHead(string name) + { + if(LogHeadOffsets.ContainsKey(name)) + { + LogHeadOffsets.Remove(name); + } + } + /// /// /// @@ -81,6 +122,16 @@ namespace Cdy.Tag return mHeadOffsets[key]; } + /// + /// + /// + /// + /// + public Dictionary Get(string key) + { + return LogHeadOffsets[key]; + } + #endregion ...Methods... #region ... Interfaces ... diff --git a/DBHisData/HisQuery/TimeFile/DataFileInfo.cs b/DBHisData/HisQuery/TimeFile/DataFileInfo.cs index da5dc2e..be2b1b6 100644 --- a/DBHisData/HisQuery/TimeFile/DataFileInfo.cs +++ b/DBHisData/HisQuery/TimeFile/DataFileInfo.cs @@ -27,6 +27,8 @@ namespace Cdy.Tag private object mLockObj = new object(); + private DateTime mLastTime; + #endregion ...Variables... #region ... Events ... @@ -39,6 +41,11 @@ namespace Cdy.Tag #region ... Properties ... + /// + /// + /// + public string FId { get; set; } + /// /// /// @@ -72,6 +79,23 @@ namespace Cdy.Tag #region ... Methods ... + /// + /// + /// + public void UpdateLastDatetime() + { + + lock (mLockObj) + { + mTimeOffsets.Clear(); + Scan(); + } + + DataFileManager.CurrentDateTime.Add(FId, mLastTime); + + } + + /// /// /// @@ -80,10 +104,10 @@ namespace Cdy.Tag { using (var ss = DataFileSeriserManager.manager.GetDefaultFileSersie()) { - ss.OpenFile(FileName); + ss.OpenForReadOnly(FileName); long offset = DataFileManager.FileHeadSize; DateTime time; - + do { time = ss.ReadDateTime(offset + 16); @@ -94,12 +118,14 @@ namespace Cdy.Tag { var dt2 = ss.ReadDateTime(offset + 16); mTimeOffsets.Add(time, new Tuple(dt2 - time, oset)); + mLastTime = dt2; } else { var tspan = StartTime + Duration - time; if(tspan.TotalMilliseconds>0) - mTimeOffsets.Add(time, new Tuple(StartTime + Duration - time, oset)); + mTimeOffsets.Add(time, new Tuple(tspan, oset)); + mLastTime = time + tspan; } } while (offset != 0); @@ -169,40 +195,40 @@ namespace Cdy.Tag { var re = DataFileSeriserManager.manager.GetDefaultFileSersie(); re.FileName = file.FileName; - re.OpenFile(file.FileName); + re.OpenForReadOnly(file.FileName); return re; } #region 读取所有值 - /// - /// - /// - /// - /// - /// - /// - private static void GeneratorTime(Dictionary> times, DateTime start, DateTime end, DataFileInfo file) - { - //file.GetTimeSpan(out start, out end); - - //int icount = 0; - //long laddr = 0; - //foreach (var vv in file.SecondOffset) - //{ - // var vend = start.AddSeconds(vv.Key); - // if (icount > 0) - // { - // times.Add(vv.Value.Item1, new Tuple(start, vend)); - // } - // laddr = vv.Value.Item1; - // start = vend; - //} - - //if (start < end) - //{ - // times.Add(laddr, new Tuple(start, end)); - //} - } + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void GeneratorTime(Dictionary> times, DateTime start, DateTime end, DataFileInfo file) + //{ + // //file.GetTimeSpan(out start, out end); + + // //int icount = 0; + // //long laddr = 0; + // //foreach (var vv in file.SecondOffset) + // //{ + // // var vend = start.AddSeconds(vv.Key); + // // if (icount > 0) + // // { + // // times.Add(vv.Value.Item1, new Tuple(start, vend)); + // // } + // // laddr = vv.Value.Item1; + // // start = vend; + // //} + + // //if (start < end) + // //{ + // // times.Add(laddr, new Tuple(start, end)); + // //} + //} /// /// 读取某时间段内的所有bool值 @@ -212,2307 +238,2450 @@ namespace Cdy.Tag /// /// /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) { var vff = file.GetFileSeriser(); Dictionary> moffs = new Dictionary>(); - GeneratorTime(moffs, startTime, endTime, file); + var offset = file.GetFileOffsets(startTime, endTime); - foreach (var vf in moffs) + foreach (var vv in offset) { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + DateTime stime = vv.Key > startTime ? vv.Key : startTime; + DateTime etime = vv.Key + vv.Value.Item1 > endTime ? endTime : vv.Key + vv.Value.Item1; + vff.ReadAllValue(vv.Value.Item2, tid, stime, etime, result); } - } - /// - /// 读取某时间段内的所有byte值 - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - Dictionary> moffs = new Dictionary>(); - using (var vff = file.GetFileSeriser()) - { - GeneratorTime(moffs, startTime, endTime, file); + //GeneratorTime(moffs, startTime, endTime, file); - foreach (var vf in moffs) - { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - } - } + //foreach (var vf in moffs) + //{ + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + //} } - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); + ///// + ///// 读取某时间段内的所有byte值 + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // Dictionary> moffs = new Dictionary>(); + // using (var vff = file.GetFileSeriser()) + // { + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + + // var offset = file.GetFileOffsets(startTime,endTime); + + // foreach (var vv in offset) + // { + // DateTime stime = vv.Key > startTime ? vv.Key : startTime; + // DateTime etime = vv.Key + vv.Value.Item1 > endTime ? endTime : vv.Key + vv.Value.Item1; + // vff.ReadAllValue(vv.Value.Item2, tid, stime, etime, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + + // GeneratorTime(moffs, startTime, endTime, file); + + // foreach (var vf in moffs) + // { + // vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + // } + //} - GeneratorTime(moffs, startTime, endTime, file); + #endregion - foreach (var vf in moffs) - { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - } - } + #region 读取指定时刻值 - /// - /// - /// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static bool? ReadBool(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadBool(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadBool(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadBool(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadBool(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadBool(vf.Key, tid, vf.Value, type, result); + // } + //} + + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static byte? ReadByte(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadByte(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadByte(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadByte(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadByte(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadByte(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static short? ReadShort(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadShort(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadShort(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + // foreach (var vf in moffs) + // { + // vff.ReadShort(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static ushort? ReadUShort(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadUShort(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadUShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadUShort(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadUShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadUShort(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static int? ReadInt(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadInt(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadInt(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadInt(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static uint? ReadUInt(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadUInt(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadUInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadUInt(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadUInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + // foreach (var vf in moffs) + // { + // vff.ReadUInt(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static long? ReadLong(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadLong(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadLong(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadLong(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadLong(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadLong(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static ulong? ReadULong(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadULong(offset, tid, time, type); + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadULong(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadULong(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadULong(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadULong(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static float? ReadFloat(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadFloat(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadFloat(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadFloat(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadFloat(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadFloat(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static double? ReadDouble(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadDouble(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadDouble(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadDouble(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadDouble(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (ff <= 0) continue; + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + + // foreach (var vf in moffs) + // { + // vff.ReadDouble(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static DateTime? ReadDateTime(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadDateTime(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadDateTime(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadDateTime(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadDateTime(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + // foreach (var vf in moffs) + // { + // vff.ReadDateTime(vf.Key, tid, vf.Value, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static string ReadString(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) + //{ + // var vff = file.GetFileSeriser(); + // var offset = file.GetFileOffsets(time); + // return vff.ReadString(offset, tid, time, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadString(this DataFileInfo file, int tid, List times, QueryValueMatchType type) + //{ + // HisQueryResult re = new HisQueryResult(times.Count); + // ReadString(file, tid, times, type, re); + // return re; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadString(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + //{ + // var vff = file.GetFileSeriser(); + // Dictionary> moffs = new Dictionary>(); + // foreach (var vv in times) + // { + // var ff = file.GetFileOffsets(vv); + // if (moffs.ContainsKey(ff)) + // { + // moffs[ff].Add(vv); + // } + // else + // { + // moffs.Add(ff, new List() { vv }); + // } + // } + // foreach (var vf in moffs) + // { + // vff.ReadString(vf.Key, tid, vf.Value, type, result); + // } + //} + + /// + /// + /// + /// /// /// - /// - /// - /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + /// + /// + /// + public static object Read(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) { var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - - GeneratorTime(moffs, startTime, endTime, file); - - foreach (var vf in moffs) - { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - } + var offset = file.GetFileOffsets(time); + return vff.Read(offset, tid, time, type); } /// /// /// + /// /// /// - /// - /// - /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + /// + /// + /// + public static HisQueryResult Read(this DataFileInfo file, int tid, List times, QueryValueMatchType type) { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - - GeneratorTime(moffs, startTime, endTime, file); - - foreach (var vf in moffs) - { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - } + HisQueryResult re = new HisQueryResult(times.Count); + Read(file, tid, times, type, re); + return re; } /// /// /// + /// /// /// - /// - /// + /// + /// /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + public static void Read(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) { var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - - GeneratorTime(moffs, startTime, endTime, file); - + Dictionary> moffs = new Dictionary>(); + foreach (var vv in times) + { + var ff = file.GetFileOffsets(vv); + if (moffs.ContainsKey(ff)) + { + moffs[ff].Add(vv); + } + else + { + moffs.Add(ff, new List() { vv }); + } + } foreach (var vf in moffs) { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + vff.Read(vf.Key, tid, vf.Value, type, result); } } - /// - /// - /// - /// - /// - /// - /// - /// - - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); + #endregion - GeneratorTime(moffs, startTime, endTime, file); + #region DataFileSeriser Read - foreach (var vf in moffs) + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static bool? ReadBool(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToBoolValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static HisQueryResult ReadBool(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToBoolValue(vv.Key, vv.Value, timetick, type, res); + // } + // return res; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static byte? ReadByte(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToByteValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadByte(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToByteValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static short? ReadShort(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToShortValue(data, dataTime, timetick, type); + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadShort(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToShortValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static ushort? ReadUShort(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToUShortValue(data, dataTime, timetick, type); + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadUShort(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToUShortValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static int? ReadInt(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToIntValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadInt(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToIntValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static uint? ReadUInt(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToUIntValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadUInt(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToUIntValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static long? ReadLong(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToLongValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadLong(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToLongValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static ulong? ReadULong(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToULongValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadULong(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToULongValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static string ReadString(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToStringValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadString(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToStringValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static DateTime? ReadDateTime(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToDateTimeValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadDateTime(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToDateTimeValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static float? ReadFloat(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToFloatValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadFloat(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToFloatValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static double? ReadDouble(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + // return DeCompressDataBlockToDoubleValue(data, dataTime, timetick, type); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadDouble(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockToDoubleValue(vv.Key, vv.Value, timetick, type, res); + // } + //} + + public static void Read(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) + { + int timetick = 0; + var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); + foreach (var vv in data) { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + DeCompressDataBlockValue(vv.Key, vv.Value, timetick, type, res); } } /// /// /// - /// + /// + /// + /// /// - /// - /// - /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + /// + /// + /// + public static object Read(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - - GeneratorTime(moffs, startTime, endTime, file); - - foreach (var vf in moffs) - { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - } + int timetick = 0; + var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); + return DeCompressDataBlockValue(data, dataTime, timetick, type); } /// /// /// - /// + /// + /// /// /// /// /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - - GeneratorTime(moffs, startTime, endTime, file); - - foreach (var vf in moffs) + int timetick = 0; + var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + foreach (var vv in data) { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); } } + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + //{ + // int timetick = 0; + // var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); + // foreach (var vv in data) + // { + // DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); + // } + //} + #endregion + + #region DeCompressData + /// /// /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + /// + /// + /// + /// + /// + /// + private static object DeCompressDataBlockValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) { - var vff = file.GetFileSeriser(); - - var offset = file.GetFileOffsets(startTime,endTime); - - foreach (var vv in offset) + MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + //读取压缩类型 + var ctype = memory.ReadByte(); + var tp = CompressUnitManager.Manager.GetCompress(ctype); + if (tp != null) { - DateTime stime = vv.Key > startTime ? vv.Key : startTime; - DateTime etime = vv.Key + vv.Value.Item1 > endTime ? endTime : vv.Key + vv.Value.Item1; - vff.ReadAllValue(vv.Value.Item2, tid, stime, etime, result); + return tp.DeCompressValue(memory, 1, datatime, timeTick, type); } + return null; } /// /// /// - /// - /// - /// - /// + /// + /// + /// + /// + /// /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + private static void DeCompressDataBlockValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - - GeneratorTime(moffs, startTime, endTime, file); - - foreach (var vf in moffs) + MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + //读取压缩类型 + var ctype = memory.ReadByte(); + var tp = CompressUnitManager.Manager.GetCompress(ctype); + if (tp != null) { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); - } - } - + tp.DeCompressValue(memory, 1, datatime, timeTick, type, result); + } + } + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static bool? DeCompressDataBlockToBoolValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressBoolValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToBoolValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressBoolValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static byte? DeCompressDataBlockToByteValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressByteValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToByteValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressByteValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static short? DeCompressDataBlockToShortValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressShortValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToShortValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressShortValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static ushort? DeCompressDataBlockToUShortValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressUShortValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToUShortValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressUShortValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static int? DeCompressDataBlockToIntValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressIntValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToIntValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressIntValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static uint? DeCompressDataBlockToUIntValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressUIntValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToUIntValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressUIntValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static long? DeCompressDataBlockToLongValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressLongValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + //private static void DeCompressDataBlockToLongValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressLongValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static ulong? DeCompressDataBlockToULongValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressULongValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + //private static void DeCompressDataBlockToULongValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressULongValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static float? DeCompressDataBlockToFloatValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressFloatValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToFloatValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressFloatValue(memory, 1, datatime, timeTick, type, result); + // } + //} + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static Double? DeCompressDataBlockToDoubleValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressDoubleValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToDoubleValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressDoubleValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static string DeCompressDataBlockToStringValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressStringValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToStringValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressStringValue(memory, 1, datatime, timeTick, type, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static DateTime? DeCompressDataBlockToDateTimeValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // return tp.DeCompressDateTimeValue(memory, 1, datatime, timeTick, type); + // } + // return null; + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockToDateTimeValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressDateTimeValue(memory, 1, datatime, timeTick, type, result); + // } + //} + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + + // } + //} /// /// /// - /// - /// + /// /// /// + /// /// - public static void ReadAllValue(this DataFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - - GeneratorTime(moffs, startTime, endTime, file); - - foreach (var vf in moffs) + MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + //读取压缩类型 + var ctype = memory.ReadByte(); + var tp = CompressUnitManager.Manager.GetCompress(ctype); + if (tp != null) { - vff.ReadAllValue(vf.Key, tid, vf.Value.Item1, vf.Value.Item2, result); + tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); } } - #endregion - - #region 读取指定时刻值 - - /// - /// - /// - /// - /// - /// - /// - /// - public static bool? ReadBool(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadBool(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadBool(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadBool(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadBool(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadBool(vf.Key, tid, vf.Value, type, result); - } - } - - - - /// - /// - /// - /// - /// - /// - /// - public static byte? ReadByte(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadByte(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadByte(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadByte(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadByte(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadByte(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static short? ReadShort(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadShort(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadShort(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - foreach (var vf in moffs) - { - vff.ReadShort(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static ushort? ReadUShort(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadUShort(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadUShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadUShort(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadUShort(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadUShort(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static int? ReadInt(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadInt(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadInt(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadInt(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static uint? ReadUInt(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadUInt(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadUInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadUInt(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadUInt(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - foreach (var vf in moffs) - { - vff.ReadUInt(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static long? ReadLong(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadLong(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadLong(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - - HisQueryResult re = new HisQueryResult(times.Count); - ReadLong(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadLong(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadLong(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static ulong? ReadULong(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadULong(offset, tid, time, type); - } - - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadULong(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadULong(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadULong(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadULong(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static float? ReadFloat(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadFloat(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadFloat(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadFloat(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadFloat(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadFloat(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static double? ReadDouble(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadDouble(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadDouble(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadDouble(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadDouble(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (ff <= 0) continue; - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - - foreach (var vf in moffs) - { - vff.ReadDouble(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static DateTime? ReadDateTime(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadDateTime(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadDateTime(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadDateTime(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadDateTime(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - foreach (var vf in moffs) - { - vff.ReadDateTime(vf.Key, tid, vf.Value, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - public static string ReadString(this DataFileInfo file, int tid, DateTime time, QueryValueMatchType type) - { - var vff = file.GetFileSeriser(); - var offset = file.GetFileOffsets(time); - return vff.ReadString(offset, tid, time, type); - } - - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadString(this DataFileInfo file, int tid, List times, QueryValueMatchType type) - { - HisQueryResult re = new HisQueryResult(times.Count); - ReadString(file, tid, times, type, re); - return re; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadString(this DataFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) - { - var vff = file.GetFileSeriser(); - Dictionary> moffs = new Dictionary>(); - foreach (var vv in times) - { - var ff = file.GetFileOffsets(vv); - if (moffs.ContainsKey(ff)) - { - moffs[ff].Add(vv); - } - else - { - moffs.Add(ff, new List() { vv }); - } - } - foreach (var vf in moffs) - { - vff.ReadString(vf.Key, tid, vf.Value, type, result); - } - } - #endregion - - #region DataFileSeriser Read - - /// - /// - /// - /// - /// - /// - /// - /// - public static bool? ReadBool(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToBoolValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static HisQueryResult ReadBool(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToBoolValue(vv.Key, vv.Value, timetick, type, res); - } - return res; - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static byte? ReadByte(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToByteValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadByte(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToByteValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static short? ReadShort(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToShortValue(data, dataTime, timetick, type); - } - - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadShort(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToShortValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static ushort? ReadUShort(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToUShortValue(data, dataTime, timetick, type); - } - - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadUShort(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToUShortValue(vv.Key, vv.Value, timetick, type, res); - } - } - - - /// - /// - /// - /// - /// - /// - /// - /// - public static int? ReadInt(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToIntValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadInt(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToIntValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static uint? ReadUInt(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToUIntValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadUInt(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToUIntValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static long? ReadLong(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToLongValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadLong(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToLongValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static ulong? ReadULong(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToULongValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadULong(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToULongValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static string ReadString(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToStringValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadString(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToStringValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static DateTime? ReadDateTime(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToDateTimeValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadDateTime(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToDateTimeValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static float? ReadFloat(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToFloatValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadFloat(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToFloatValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static double? ReadDouble(this DataFileSeriserbase datafile, long offset, int tid, DateTime dataTime, QueryValueMatchType type) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock(tid, offset, dataTime, out timetick); - return DeCompressDataBlockToDoubleValue(data, dataTime, timetick, type); - } - - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadDouble(this DataFileSeriserbase datafile, long offset, int tid, List dataTimes, QueryValueMatchType type, HisQueryResult res) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, dataTimes, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockToDoubleValue(vv.Key, vv.Value, timetick, type, res); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - - - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void ReadAllValue(this DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) - { - int timetick = 0; - var data = datafile.ReadTagDataBlock2(tid, offset, startTime, endTime, out timetick); - foreach (var vv in data) - { - DeCompressDataBlockAllValue(vv.Key, vv.Value.Item1, vv.Value.Item2, timetick, result); - } - } - #endregion - - #region DeCompressData - - /// - /// - /// - /// - /// - /// - /// - private static bool? DeCompressDataBlockToBoolValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressBoolValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToBoolValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressBoolValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static byte? DeCompressDataBlockToByteValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressByteValue(memory, 1, datatime, timeTick, type); - } - return null; - } - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToByteValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressByteValue(memory, 1, datatime, timeTick, type, result); - } - } - - - /// - /// - /// - /// - /// - /// - /// - private static short? DeCompressDataBlockToShortValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressShortValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToShortValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressShortValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static ushort? DeCompressDataBlockToUShortValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressUShortValue(memory, 1, datatime, timeTick, type); - } - return null; - } - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToUShortValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressUShortValue(memory, 1, datatime, timeTick, type, result); - } - } - - - - /// - /// - /// - /// - /// - /// - /// - private static int? DeCompressDataBlockToIntValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressIntValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToIntValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressIntValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static uint? DeCompressDataBlockToUIntValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressUIntValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToUIntValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressUIntValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static long? DeCompressDataBlockToLongValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressLongValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - private static void DeCompressDataBlockToLongValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressLongValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static ulong? DeCompressDataBlockToULongValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressULongValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - private static void DeCompressDataBlockToULongValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressULongValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static float? DeCompressDataBlockToFloatValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressFloatValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToFloatValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressFloatValue(memory, 1, datatime, timeTick, type, result); - } - } - /// - /// - /// - /// - /// - /// - /// - private static Double? DeCompressDataBlockToDoubleValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressDoubleValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToDoubleValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressDoubleValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static string DeCompressDataBlockToStringValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressStringValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToStringValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressStringValue(memory, 1, datatime, timeTick, type, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - private static DateTime? DeCompressDataBlockToDateTimeValue(MarshalMemoryBlock memory, DateTime datatime, int timeTick, QueryValueMatchType type) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - return tp.DeCompressDateTimeValue(memory, 1, datatime, timeTick, type); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockToDateTimeValue(MarshalMemoryBlock memory, List datatime, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressDateTimeValue(memory, 1, datatime, timeTick, type, result); - } - } - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } - - /// - /// - /// - /// - /// - /// - /// - /// - private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); - //读取压缩类型 - var ctype = memory.ReadByte(); - var tp = CompressUnitManager.Manager.GetCompress(ctype); - if (tp != null) - { - tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); - } - } + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //private static void DeCompressDataBlockAllValue(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length); + // //读取压缩类型 + // var ctype = memory.ReadByte(); + // var tp = CompressUnitManager.Manager.GetCompress(ctype); + // if (tp != null) + // { + // tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result); + // } + //} #endregion #region 读取数据区域头数据 diff --git a/DBHisData/HisQuery/TimeFile/LogFileInfo.cs b/DBHisData/HisQuery/TimeFile/LogFileInfo.cs new file mode 100644 index 0000000..dc6320c --- /dev/null +++ b/DBHisData/HisQuery/TimeFile/LogFileInfo.cs @@ -0,0 +1,773 @@ +//============================================================== +// Copyright (C) 2020 Inc. All rights reserved. +// +//============================================================== +// Create by 种道洋 at 2020/5/4 16:40:03. +// Version 1.0 +// 种道洋 +//============================================================== + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace Cdy.Tag +{ + /// + /// 从日志文件种读取 + /// + public class LogFileInfo + { + + #region ... Variables ... + + #endregion ...Variables... + + #region ... Events ... + + #endregion ...Events... + + #region ... Constructor... + + #endregion ...Constructor... + + #region ... Properties ... + + /// + /// + /// + public DateTime StartTime { get; set; } + + /// + /// + /// + public DateTime EndTime { get; set; } + + /// + /// + /// + public string FileName { get; set; } + + #endregion ...Properties... + + #region ... Methods ... + + /// + /// + /// + public void Init() + { + + } + + #endregion ...Methods... + + #region ... Interfaces ... + + #endregion ...Interfaces... + } + + public static class LogFileInfoExtend + { + + /// + /// + /// + /// + /// + public static DataFileSeriserbase GetFileSeriser(this LogFileInfo file) + { + var re = DataFileSeriserManager.manager.GetDefaultFileSersie(); + re.FileName = file.FileName; + re.OpenForReadOnly(file.FileName); + return re; + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static void ReadAllValue(this LogFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult result) + { + file.GetFileSeriser().ReadAllValue(tid,startTime,endTime,file.StartTime,result); + } + + + /// + /// + /// + /// + /// + /// + /// + /// + public static void Read(this LogFileInfo file, int tid, List times, QueryValueMatchType type, HisQueryResult result) + { + file.GetFileSeriser().Read(tid, times, type, file.StartTime, result); + } + + /// + /// + /// + /// + /// + private static long ReadTagIndex(this DataFileSeriserbase datafile,int tid,out long offset,out short len) + { + len = datafile.ReadShort(0); + var vsize = datafile.ReadInt(2); + offset = vsize; + + lock (TagHeadOffsetManager.manager.LogHeadOffsets) + { + if (!TagHeadOffsetManager.manager.Contains(datafile.FileName)) + { + var data = datafile.Read(6, vsize); + MarshalVarintCodeMemory vcm = new MarshalVarintCodeMemory(data.StartMemory, vsize); + var ltmp = vcm.ToLongList(); + int addroffset = (ltmp.Count - 1) / 2; + List ids = new List(); + List addrs = new List(); + + long lp = ltmp[1]; + for (int i = 1; i < ltmp[0]; i++) + { + var lp2 = ltmp[i + 1] + lp; + ids.Add((int)lp2); + lp = lp2; + } + + lp = ltmp[1 + addroffset]; + for (int i = 1; i < ltmp[0]; i++) + { + var lp2 = ltmp[i + 1 + addroffset] + lp; + addrs.Add(lp2); + lp = lp2; + } + + Dictionary idaddrs = new Dictionary(); + for(int i=0;i + /// + /// + /// + /// + /// + /// + /// + /// + private static Dictionary ReadTimeIndex(this DataFileSeriserbase datafile,long offset,long timeraddr,DateTime starttime,DateTime endtime,DateTime time,int count) + { + Dictionary re = new Dictionary(); + for (int i = 0; i < count; i++) + { + var vf = time .AddMilliseconds(datafile.ReadShort(offset + timeraddr + i * 2) * 100); + if (vf >= starttime && vf < endtime) + { + if(vf!=time|| i==0) + re.Add(i,vf); + } + } + return re; + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + private static Dictionary> ReadTimeIndex(this DataFileSeriserbase datafile, long offset, long timeraddr, DateTime time, int count) + { + Dictionary> re = new Dictionary>(); + for (int i = 0; i < count; i++) + { + var vf = time.AddMilliseconds(datafile.ReadShort(offset + timeraddr + i * 2) * 100); + if (vf != time || i == 0) + { + re.Add(i, new Tuple(vf, true)); + } + else + { + re.Add(i, new Tuple(vf, false)); + } + } + return re; + } + + /// + /// + /// + /// + /// + /// + /// + /// + private static List ReadValueInner(this DataFileSeriserbase datafile,List valIndex,long offset,long valueaddr,out int datasize) + { + List re = new List(); + if (typeof(T) == typeof(bool)) + { + foreach (var vv in valIndex) + { + re.Add(Convert.ToBoolean(datafile.ReadByte(offset + valueaddr + vv))); + } + datasize = 1; + } + else if (typeof(T) == typeof(byte)) + { + foreach (var vv in valIndex) + { + re.Add(datafile.ReadByte(offset + valueaddr + vv)); + } + datasize = 1; + } + else if (typeof(T) == typeof(short)) + { + foreach (var vv in valIndex) + { + re.Add(datafile.ReadShort(offset + valueaddr + vv*2)); + } + datasize = 2; + } + else if (typeof(T) == typeof(ushort)) + { + foreach (var vv in valIndex) + { + re.Add((ushort)datafile.ReadShort(offset + valueaddr + vv * 2)); + } + datasize = 2; + } + else if (typeof(T) == typeof(int)) + { + foreach (var vv in valIndex) + { + re.Add(datafile.ReadInt(offset + valueaddr + vv * 4)); + } + datasize = 4; + } + else if (typeof(T) == typeof(uint)) + { + foreach (var vv in valIndex) + { + re.Add((uint)datafile.ReadInt(offset + valueaddr + vv * 4)); + } + datasize = 4; + } + else if (typeof(T) == typeof(long)) + { + foreach (var vv in valIndex) + { + re.Add((long)datafile.ReadLong(offset + valueaddr + vv * 8)); + } + datasize = 8; + } + else if (typeof(T) == typeof(ulong)) + { + foreach (var vv in valIndex) + { + re.Add((ulong)datafile.ReadLong(offset + valueaddr + vv * 8)); + } + datasize = 8; + } + else if (typeof(T) == typeof(double)) + { + foreach (var vv in valIndex) + { + re.Add(datafile.ReadDouble(offset + valueaddr + vv * 8)); + } + datasize = 8; + } + else if (typeof(T) == typeof(float)) + { + foreach (var vv in valIndex) + { + re.Add(datafile.ReadFloat(offset + valueaddr + vv * 4)); + } + datasize = 4; + } + else if (typeof(T) == typeof(string)) + { + foreach (var vv in valIndex) + { + var str = Encoding.Unicode.GetString(datafile.ReadBytes(offset + valueaddr + vv * Const.StringSize, Const.StringSize)); + re.Add(str); + } + datasize = Const.StringSize; + } + else if (typeof(T) == typeof(DateTime)) + { + foreach (var vv in valIndex) + { + re.Add(datafile.ReadDateTime(offset + valueaddr + vv * 8)); + } + datasize = 8; + } + else if (typeof(T) == typeof(IntPointData)) + { + foreach (var vv in valIndex) + { + var x = datafile.ReadInt(offset + valueaddr + vv * 8); + var y = datafile.ReadInt(offset + valueaddr + vv * 8+4); + re.Add(new IntPointData() { X = x, Y = y }); + } + datasize = 8; + } + else if (typeof(T) == typeof(UIntPointData)) + { + foreach (var vv in valIndex) + { + var x = (uint)datafile.ReadInt(offset + valueaddr + vv * 8); + var y = (uint)datafile.ReadInt(offset + valueaddr + vv * 8 + 4); + re.Add(new UIntPointData() { X = x, Y = y }); + } + datasize = 8; + } + else if (typeof(T) == typeof(LongPointData)) + { + foreach (var vv in valIndex) + { + var x = (long)datafile.ReadLong(offset + valueaddr + vv * 16); + var y = (long)datafile.ReadLong(offset + valueaddr + vv * 16 + 8); + re.Add(new LongPointData() { X = x, Y = y }); + } + datasize = 16; + } + else if (typeof(T) == typeof(ULongPointData)) + { + foreach (var vv in valIndex) + { + var x = (ulong)datafile.ReadLong(offset + valueaddr + vv * 16); + var y = (ulong)datafile.ReadLong(offset + valueaddr + vv * 16 + 8); + re.Add(new ULongPointData() { X = x, Y = y }); + } + datasize = 16; + } + else if (typeof(T) == typeof(IntPoint3Data)) + { + foreach (var vv in valIndex) + { + var x = datafile.ReadInt(offset + valueaddr + vv * 12); + var y = datafile.ReadInt(offset + valueaddr + vv * 12 + 4); + var z = datafile.ReadInt(offset + valueaddr + vv * 12 + 8); + re.Add(new IntPoint3Data() { X = x, Y = y,Z=z }); + } + datasize = 12; + } + else if (typeof(T) == typeof(UIntPoint3Data)) + { + foreach (var vv in valIndex) + { + var x = (uint)datafile.ReadInt(offset + valueaddr + vv * 12); + var y = (uint)datafile.ReadInt(offset + valueaddr + vv * 12 + 4); + var z = (uint)datafile.ReadInt(offset + valueaddr + vv * 12 + 8); + re.Add(new UIntPoint3Data() { X = x, Y = y, Z = z }); + } + datasize = 12; + } + else if (typeof(T) == typeof(LongPoint3Data)) + { + foreach (var vv in valIndex) + { + var x = (long)datafile.ReadLong(offset + valueaddr + vv * 24); + var y = (long)datafile.ReadLong(offset + valueaddr + vv * 24 + 8); + var z = (long)datafile.ReadLong(offset + valueaddr + vv * 24 + 168); + re.Add(new LongPoint3Data() { X = x, Y = y, Z = z }); + } + datasize = 24; + } + else if (typeof(T) == typeof(ULongPoint3Data)) + { + foreach (var vv in valIndex) + { + var x = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24); + var y = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24 + 8); + var z = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24 + 168); + re.Add(new ULongPoint3Data() { X = x, Y = y, Z = z }); + } + datasize = 24; + } + datasize = 0; + return re; + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static void ReadAllValue(this DataFileSeriserbase datafile, int tid, DateTime startTime, DateTime endTime,DateTime time, HisQueryResult result) + { + long addroffset = 0; + short len = 0; + int datasize = 0; + var aid = datafile.ReadTagIndex(tid,out addroffset,out len); + if(aid>=0) + { + int tagcount = len * 60; + var tindex = ReadTimeIndex(datafile, addroffset, aid, startTime, endTime,time, tagcount); + var vals = ReadValueInner(datafile,tindex.Keys.ToList(), addroffset, aid + tagcount * 2,out datasize); + var qus = datafile.ReadBytes(aid + addroffset + tagcount * (2 + datasize), tagcount); + int i = 0; + foreach(var vv in tindex) + { + result.Add(vals[i], vv.Value, qus[vv.Key]); + } + } + } + + private static int GetValueSize() + { + if (typeof(T) == typeof(bool)) + { + return 1; + } + else if (typeof(T) == typeof(byte)) + { + return 1; + } + else if (typeof(T) == typeof(short)) + { + return 2; + } + else if (typeof(T) == typeof(ushort)) + { + return 2; + } + else if (typeof(T) == typeof(int)) + { + return 4; + } + else if (typeof(T) == typeof(uint)) + { + return 4; + } + else if (typeof(T) == typeof(long)) + { + return 8; + } + else if (typeof(T) == typeof(ulong)) + { + return 8; + } + else if (typeof(T) == typeof(double)) + { + return 8; + } + else if (typeof(T) == typeof(float)) + { + return 4; + } + else if (typeof(T) == typeof(string)) + { + return Const.StringSize; + } + else if (typeof(T) == typeof(DateTime)) + { + return 8; + + } + else if (typeof(T) == typeof(IntPointData)) + { + return 8; + } + else if (typeof(T) == typeof(UIntPointData)) + { + return 8; + } + else if (typeof(T) == typeof(LongPointData)) + { + return 16; + } + else if (typeof(T) == typeof(ULongPointData)) + { + return 16; + } + else if (typeof(T) == typeof(IntPoint3Data)) + { + + return 12; + } + else if (typeof(T) == typeof(UIntPoint3Data)) + { + return 12; + } + else if (typeof(T) == typeof(LongPoint3Data)) + { + return 24; + } + else if (typeof(T) == typeof(ULongPoint3Data)) + { + return 24; + } + return 0; + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + private static object LinerValue(DateTime startTime, DateTime endTime, DateTime time, T value1, T value2) + { + var pval1 = (time - startTime).TotalMilliseconds; + var tval1 = (endTime - startTime).TotalMilliseconds; + + if (typeof(T) == typeof(IntPointData)) + { + var sval1 = (IntPointData)((object)value1); + var sval2 = (IntPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new IntPointData((int)val1, (int)val2); + } + else if (typeof(T) == typeof(UIntPointData)) + { + var sval1 = (UIntPointData)((object)value1); + var sval2 = (UIntPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new UIntPointData((uint)val1, (uint)val2); + } + else if (typeof(T) == typeof(LongPointData)) + { + var sval1 = (LongPointData)((object)value1); + var sval2 = (LongPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new LongPointData((long)val1, (long)val2); + } + else if (typeof(T) == typeof(ULongPointData)) + { + var sval1 = (ULongPointData)((object)value1); + var sval2 = (ULongPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new ULongPointData((ulong)val1, (ulong)val2); + } + else if (typeof(T) == typeof(IntPoint3Data)) + { + var sval1 = (IntPoint3Data)((object)value1); + var sval2 = (IntPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new IntPoint3Data((int)val1, (int)val2, (int)val3); + } + else if (typeof(T) == typeof(UIntPoint3Data)) + { + var sval1 = (UIntPoint3Data)((object)value1); + var sval2 = (UIntPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new UIntPoint3Data((uint)val1, (uint)val2, (uint)val3); + } + else if (typeof(T) == typeof(LongPoint3Data)) + { + var sval1 = (LongPoint3Data)((object)value1); + var sval2 = (LongPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new LongPoint3Data((long)val1, (long)val2, (long)val3); + } + else if (typeof(T) == typeof(ULongPoint3Data)) + { + var sval1 = (ULongPoint3Data)((object)value1); + var sval2 = (ULongPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new ULongPoint3Data((ulong)val1, (ulong)val2, (ulong)val3); + } + + return default(T); + } + + /// + /// + /// + /// + /// + private static bool CheckTypeIsPointData(Type type) + { + return type == typeof(IntPointData) || type == typeof(UIntPointData) || type == typeof(LongPointData) || type == typeof(ULongPointData) || type == typeof(IntPoint3Data) || type == typeof(UIntPoint3Data) || type == typeof(LongPoint3Data) || type == typeof(ULongPoint3Data); + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static void Read(this DataFileSeriserbase datafile, int tid, List times, QueryValueMatchType type, DateTime startTime,HisQueryResult result) + { + long addroffset = 0; + short len = 0; + int datasize = 0; + var aid = datafile.ReadTagIndex(tid, out addroffset, out len); + if(aid>0) + { + int tagcount = len * 60; + var qs = ReadTimeIndex(datafile, addroffset, aid, startTime, tagcount); + + var vals = ReadValueInner(datafile, qs.Keys.ToList(), addroffset, aid + tagcount * 2, out datasize); + var qq = datafile.ReadBytes(aid + addroffset + tagcount * (datasize + 2), tagcount); + + var vv = qs.ToArray(); + long valaddr = addroffset + tagcount * 2; + int count = 0; + foreach (var time1 in times) + { + for (int i = 0; i < vv.Length - 1; i++) + { + var skey = vv[i]; + + var snext = vv[i + 1]; + + if (time1 == skey.Value.Item1) + { + result.Add(vals[i], time1, qq[skey.Key]); + count++; + break; + } + else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1) + { + + switch (type) + { + case QueryValueMatchType.Previous: + result.Add(vals[i], time1, qq[skey.Key]); + count++; + break; + case QueryValueMatchType.After: + result.Add(vals[i+1], time1, qq[snext.Key]); + count++; + break; + case QueryValueMatchType.Linear: + if (typeof(T) == typeof(bool) || typeof(T) == typeof(string) || typeof(T) == typeof(DateTime)) + { + var ppval = (time1 - skey.Value.Item1).TotalMilliseconds; + var ffval = (snext.Value.Item1 - time1).TotalMilliseconds; + + if (ppval < ffval) + { + result.Add(vals[i], time1, qq[skey.Key]); + } + else + { + result.Add(vals[i + 1], time1, qq[snext.Key]); + } + count++; + } + else + { + + if (qq[skey.Key] < 20 && qq[snext.Key] < 20) + { + if (CheckTypeIsPointData(typeof(T))) + { + result.Add(LinerValue(skey.Value.Item1, snext.Value.Item1, time1, vals[i], vals[i + 1]), time1, 0); + } + else + { + var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds; + var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds; + var sval1 = (double)vals[i]; + var sval2 = (double)vals[i + 1]; + var val1 = pval1 / tval1 * (sval2 - sval1) + sval1; + result.Add((object)val1, time1, 0); + } + } + else if (qq[skey.Key] < 20) + { + result.Add(vals[i], time1, qq[skey.Key]); + } + else if (qq[snext.Key] < 20) + { + result.Add(vals[i + 1], time1, qq[snext.Key]); + } + else + { + result.Add(default(T), time1, (byte)QualityConst.Null); + } + } + count++; + break; + case QueryValueMatchType.Closed: + var pval = (time1 - skey.Value.Item1).TotalMilliseconds; + var fval = (snext.Value.Item1 - time1).TotalMilliseconds; + + if (pval < fval) + { + result.Add(vals[i], time1, qq[skey.Key]); + } + else + { + result.Add(vals[i + 1], time1, qq[snext.Key]); + } + count++; + break; + } + + break; + } + else if (time1 == snext.Value.Item1) + { + result.Add(vals[i + 1], time1, qq[snext.Key]); + count++; + break; + } + + } + } + } + } + } + +} diff --git a/DBHisData/HisQuery/TimeFile/MonthTimeFile.cs b/DBHisData/HisQuery/TimeFile/MonthTimeFile.cs index 1f55bb2..f78f9ea 100644 --- a/DBHisData/HisQuery/TimeFile/MonthTimeFile.cs +++ b/DBHisData/HisQuery/TimeFile/MonthTimeFile.cs @@ -22,6 +22,8 @@ namespace Cdy.Tag private SortedDictionary> mFileMaps = new SortedDictionary>(); + private DateTime mMaxTime = DateTime.MinValue; + #endregion ...Variables... #region ... Events ... @@ -43,6 +45,17 @@ namespace Cdy.Tag #region ... Methods ... + /// + /// + /// + public void UpdateLastDatetime() + { + if(mFileMaps.ContainsKey(mMaxTime)) + { + mFileMaps[mMaxTime].Item2.UpdateLastDatetime(); + } + } + /// /// /// @@ -54,6 +67,11 @@ namespace Cdy.Tag if(!mFileMaps.ContainsKey(startTime)) { mFileMaps.Add(startTime, new Tuple(duration, file)); + + if(startTime>mMaxTime) + { + mMaxTime = startTime; + } } } @@ -106,27 +124,6 @@ namespace Cdy.Tag return GetDataFiles(startTime, startTime + span); } - ///// - ///// - ///// - ///// - ///// - //public DayTimeFile AddDay(int month, DayTimeFile file) - //{ - // file.Parent = this; - // return this.AddTimefile(month, file) as DayTimeFile; - //} - - ///// - ///// - ///// - ///// - ///// - //public DayTimeFile AddDay(int month) - //{ - // DayTimeFile mfile = new DayTimeFile() { TimeKey = month }; - // return AddDay(month, mfile); - //} #endregion ...Methods... diff --git a/DBHisData/HisQuery/TimeFile/YearTimeFile.cs b/DBHisData/HisQuery/TimeFile/YearTimeFile.cs index a2ae573..db9e296 100644 --- a/DBHisData/HisQuery/TimeFile/YearTimeFile.cs +++ b/DBHisData/HisQuery/TimeFile/YearTimeFile.cs @@ -20,6 +20,8 @@ namespace Cdy.Tag #region ... Variables ... + private int mMaxMonth = 0; + #endregion ...Variables... #region ... Events ... @@ -67,6 +69,18 @@ namespace Cdy.Tag mm.AddFile(startTime2, endTime - startTime2, file); } } + mMaxMonth = Math.Max(mon1, mMaxMonth); + } + + /// + /// + /// + public void UpdateLastDatetime() + { + if(this.ContainsKey(mMaxMonth)) + { + (this[mMaxMonth] as MonthTimeFile).UpdateLastDatetime(); + } } /// diff --git a/DBInRun/Program.cs b/DBInRun/Program.cs index 0ebadbf..a74481b 100644 --- a/DBInRun/Program.cs +++ b/DBInRun/Program.cs @@ -6,6 +6,7 @@ namespace DBInRun { class Program { + //static MarshalMemoryBlock block; static void Main(string[] args) { bool mIsClosed = false; @@ -82,6 +83,10 @@ namespace DBInRun case "h": Console.WriteLine(GetHelpString()); break; + //case "mtest": + // block = new MarshalMemoryBlock((long)(1024 * 1024 * 1024)*2); + // //block.Clear(); + // break; } } } diff --git a/DBInRun/Properties/Resources.Designer.cs b/DBInRun/Properties/Resources.Designer.cs index df269a0..dee3869 100644 --- a/DBInRun/Properties/Resources.Designer.cs +++ b/DBInRun/Properties/Resources.Designer.cs @@ -106,7 +106,7 @@ namespace DBInRun.Properties { } /// - /// 查找类似 ***************Welcome to Mars high performance real time sensor database*************** 的本地化字符串。 + /// 查找类似 ***************Welcome to Mars high performance realtime iot database*************** 的本地化字符串。 /// internal static string WelcomeMsg { get { diff --git a/DBInRun/Properties/Resources.resx b/DBInRun/Properties/Resources.resx index ac25d7c..684fddd 100644 --- a/DBInRun/Properties/Resources.resx +++ b/DBInRun/Properties/Resources.resx @@ -133,6 +133,6 @@ stop databse - ***************Welcome to Mars high performance real time sensor database*************** + ***************Welcome to Mars high performance realtime iot database*************** \ No newline at end of file diff --git a/DBInRun/Properties/Resources.zh-CN.resx b/DBInRun/Properties/Resources.zh-CN.resx index ac35f5e..09d9c36 100644 --- a/DBInRun/Properties/Resources.zh-CN.resx +++ b/DBInRun/Properties/Resources.zh-CN.resx @@ -133,6 +133,6 @@ 停止正在运行的数据库 - ***************欢迎来到Mars高性能实时传感器数据库**************** + ***************欢迎来到Mars高性能实时物联数据库**************** \ No newline at end of file diff --git a/DataRunner/DBRuntime.csproj b/DataRunner/DBRuntime.csproj index e8d7ebb..7d92eda 100644 --- a/DataRunner/DBRuntime.csproj +++ b/DataRunner/DBRuntime.csproj @@ -19,6 +19,21 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + Always diff --git a/DataRunner/His/Compress/CompressEnginer.cs b/DataRunner/His/Compress/CompressEnginer.cs index 8f4f418..b97df5a 100644 --- a/DataRunner/His/Compress/CompressEnginer.cs +++ b/DataRunner/His/Compress/CompressEnginer.cs @@ -103,10 +103,19 @@ namespace Cdy.Tag } long psize = mTotalSize/mTargetMemorys.Count; - foreach(var vv in mTargetMemorys) - { + + System.Threading.Tasks.Parallel.ForEach(mTargetMemorys, (vv) => { vv.Value.ReAlloc(vv.Value.HeadSize + psize); - } + vv.Value.Clear(); + LoggerService.Service.Info("CompressEnginer", "Cal CompressMemory memory size:" + (vv.Value.HeadSize + psize) / 1024.0 / 1024 + "M", ConsoleColor.Cyan); + }); + + //foreach(var vv in mTargetMemorys) + //{ + // vv.Value.ReAlloc(vv.Value.HeadSize + psize); + // vv.Value.Clear(); + // LoggerService.Service.Info("CompressEnginer", "Cal CompressMemory memory size:" + (vv.Value.HeadSize + psize) / 1024.0 / 1024 + "M", ConsoleColor.Cyan); + //} } /// @@ -170,7 +179,7 @@ namespace Cdy.Tag { foreach(var vv in mTargetMemorys) { - if(vv.Value.IsBusy) + if(vv.Value.IsBusy()) { return true; } diff --git a/DataRunner/His/Compress/Special/LosslessCompressUnit.cs b/DataRunner/His/Compress/Special/LosslessCompressUnit.cs index 3b85e40..649bf10 100644 --- a/DataRunner/His/Compress/Special/LosslessCompressUnit.cs +++ b/DataRunner/His/Compress/Special/LosslessCompressUnit.cs @@ -1144,11 +1144,11 @@ namespace Cdy.Tag List re = new List(); using (VarintCodeMemory memory = new VarintCodeMemory(value)) { - var vv = (ushort)memory.ReadInt32(); - re.Add(vv); + var vv = (short)memory.ReadInt32(); + re.Add((ushort)vv); for (int i = 1; i < count; i++) { - var vss = (ushort)memory.ReadSInt32(); + var vss = (short)memory.ReadSInt32(); re.Add((ushort)(vv + vss)); vv = vss; } @@ -1177,12 +1177,12 @@ namespace Cdy.Tag List re = new List(); using (VarintCodeMemory memory = new VarintCodeMemory(value)) { - var vv = (uint)memory.ReadInt32(); - re.Add(vv); + var vv = memory.ReadInt32(); + re.Add((uint)vv); for (int i = 1; i < count; i++) { - var vss = (uint)memory.ReadSInt32(); - re.Add((uint)(vv + vss)); + var vss = memory.ReadSInt32(); + re.Add((uint)((uint)vv + vss)); vv = vss; } } @@ -1209,11 +1209,11 @@ namespace Cdy.Tag List re = new List(); using (VarintCodeMemory memory = new VarintCodeMemory(value)) { - var vv = (ulong)memory.ReadInt64(); - re.Add(vv); + var vv = memory.ReadInt64(); + re.Add((ulong)vv); for (int i = 1; i < count; i++) { - var vss = (ulong)memory.ReadSInt64(); + var vss = memory.ReadSInt64(); re.Add((ulong)(vv + vss)); vv = vss; } @@ -1276,6 +1276,170 @@ namespace Cdy.Tag return re as List; } } + else if (typeof(T) == typeof(IntPointData)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = (int)memory.ReadInt32(); + var vv2 = (int)memory.ReadInt32(); + re.Add(new IntPointData(vv,vv2)); + for (int i = 2; i < count-1; i=i+2) + { + var vss = (int)memory.ReadSInt32(); + var vss2 = (int)memory.ReadSInt32(); + re.Add(new IntPointData((int)(vv + vss), (int)(vv2 + vss2))); + vv = vss; + vv2 = vss2; + } + } + return re as List; + } + else if (typeof(T) == typeof(UIntPointData)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = (int)memory.ReadInt32(); + var vv2 = (int)memory.ReadInt32(); + re.Add(new UIntPointData((uint)vv, (uint)vv2)); + for (int i = 2; i < count - 1; i = i + 2) + { + var vss = (int)memory.ReadSInt32(); + var vss2 = (int)memory.ReadSInt32(); + re.Add(new UIntPointData((uint)(vv + vss), (uint)(vv2 + vss2))); + vv = vss; + vv2 = vss2; + } + } + return re as List; + } + else if (typeof(T) == typeof(LongPointData)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = (long)memory.ReadInt64(); + var vv2 = (long)memory.ReadInt64(); + re.Add(new LongPointData(vv, vv2)); + for (int i = 2; i < count - 1; i = i + 2) + { + var vss = memory.ReadSInt64(); + var vss2 = memory.ReadSInt64(); + re.Add(new LongPointData((vv + vss), (vv2 + vss2))); + vv = vss; + vv2 = vss2; + } + } + return re as List; + } + else if (typeof(T) == typeof(ULongPointData)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = memory.ReadInt64(); + var vv2 = memory.ReadInt64(); + re.Add(new ULongPointData((ulong)vv, (ulong)vv2)); + for (int i = 2; i < count - 1; i = i + 2) + { + var vss = memory.ReadSInt64(); + var vss2 = memory.ReadSInt64(); + re.Add(new ULongPointData((ulong)(vv + vss), (ulong)(vv2 + vss2))); + vv = vss; + vv2 = vss2; + } + } + return re as List; + } + else if (typeof(T) == typeof(IntPoint3Data)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = (int)memory.ReadInt32(); + var vv2 = (int)memory.ReadInt32(); + var vv3 = (int)memory.ReadInt32(); + re.Add(new IntPoint3Data(vv, vv2,vv3)); + for (int i = 3; i < count - 2; i = i + 3) + { + var vss = (int)memory.ReadSInt32(); + var vss2 = (int)memory.ReadSInt32(); + var vss3 = (int)memory.ReadSInt32(); + re.Add(new IntPoint3Data((int)(vv + vss), (int)(vv2 + vss2), (int)(vv3 + vss3))); + vv = vss; + vv2 = vss2; + vv3 = vss3; + } + } + return re as List; + } + else if (typeof(T) == typeof(UIntPoint3Data)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = (int)memory.ReadInt32(); + var vv2 = (int)memory.ReadInt32(); + var vv3 = (int)memory.ReadInt32(); + re.Add(new UIntPoint3Data((uint)vv, (uint)vv2, (uint)vv3)); + for (int i = 3; i < count - 2; i = i + 3) + { + var vss = (int)memory.ReadSInt32(); + var vss2 = (int)memory.ReadSInt32(); + var vss3 = (int)memory.ReadSInt32(); + re.Add(new UIntPoint3Data((uint)(vv + vss), (uint)(vv2 + vss2), (uint)(vv3 + vss3))); + vv = vss; + vv2 = vss2; + vv3 = vss3; + } + } + return re as List; + } + else if (typeof(T) == typeof(LongPoint3Data)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = (long)memory.ReadInt64(); + var vv2 = (long)memory.ReadInt64(); + var vv3 = (long)memory.ReadInt64(); + re.Add(new LongPoint3Data((long)vv, (long)vv2, (long)vv3)); + for (int i = 3; i < count - 2; i = i + 3) + { + var vss = memory.ReadInt64(); + var vss2 = memory.ReadInt64(); + var vss3 = memory.ReadInt64(); + re.Add(new LongPoint3Data((long)(vv + vss), (long)(vv2 + vss2), (long)(vv3 + vss3))); + vv = vss; + vv2 = vss2; + vv3 = vss3; + } + } + return re as List; + } + else if (typeof(T) == typeof(ULongPoint3Data)) + { + List re = new List(); + using (VarintCodeMemory memory = new VarintCodeMemory(value)) + { + var vv = (long)memory.ReadInt64(); + var vv2 = (long)memory.ReadInt64(); + var vv3 = (long)memory.ReadInt64(); + re.Add(new ULongPoint3Data((ulong)vv, (ulong)vv2, (ulong)vv3)); + for (int i = 3; i < count - 2; i = i + 3) + { + var vss = memory.ReadInt64(); + var vss2 = memory.ReadInt64(); + var vss3 = memory.ReadInt64(); + re.Add(new ULongPoint3Data((ulong)(vv + vss), (ulong)(vv2 + vss2), (ulong)(vv3 + vss3))); + vv = vss; + vv2 = vss2; + vv3 = vss3; + } + } + return re as List; + } return null; } @@ -1325,6 +1489,15 @@ namespace Cdy.Tag return re; } + /// + /// + /// + /// + /// + private bool CheckTypeIsPointData(Type type) + { + return type == typeof(IntPointData) || type == typeof(UIntPointData) || type == typeof(LongPointData) || type == typeof(ULongPointData) || type == typeof(IntPoint3Data) || type == typeof(UIntPoint3Data) || type == typeof(LongPoint3Data) || type == typeof(ULongPoint3Data); + } /// /// /// @@ -1336,108 +1509,109 @@ namespace Cdy.Tag /// /// /// - public virtual int DeCompressALlValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { int count = 0; - var timers = GetTimers(source, sourceAddr, startTime, endTime, timeTick,out count); + var timers = GetTimers(source, sourceAddr, startTime, endTime, timeTick, out count); var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize),count); + var value = DeCompressValue(source.ReadBytes(valuesize), count); var qusize = source.ReadInt(); var qulityes = DeCompressQulity(source.ReadBytes(qusize)); int resultCount = 0; - for(int i=0;i( value[i],timers[i],qulityes[i] ); + result.Add(value[i], timers[i], qulityes[i]); resultCount++; } } return resultCount; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); } - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - return DeCompressALlValue(source, sourceAddr, startTime, endTime, timeTick, result); - } + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} + + //public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + //{ + // return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result); + //} /// /// @@ -1450,8 +1624,13 @@ namespace Cdy.Tag /// /// /// - public virtual int DeCompressValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public override int DeCompressValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { + if (CheckTypeIsPointData(typeof(T))) + { + return DeCompressPointValue(source, sourceAddr, time, timeTick, type, result); + } + int count = 0; var timers = GetTimers(source, sourceAddr + 8,timeTick, out count); @@ -1538,7 +1717,7 @@ namespace Cdy.Tag } else { - result.Add(0, time1, (byte)QualityConst.Null); + result.Add(default(T), time1, (byte)QualityConst.Null); } resultCount++; } @@ -1589,8 +1768,13 @@ namespace Cdy.Tag /// /// /// - public virtual object DeCompressValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public override object DeCompressValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { + if (CheckTypeIsPointData(typeof(T))) + { + return DeCompressPointValue(source, sourceAddr, time, timeTick, type); + } + int count = 0; var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); @@ -1723,1285 +1907,187 @@ namespace Cdy.Tag return null; } - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override bool? DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as bool?; - } + /// /// /// + /// /// /// /// /// /// - /// /// - public override int DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public object DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time1, int timeTick, QueryValueMatchType type) { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } - - public override byte? DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as byte?; - } - - public override int DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } + int count = 0; + var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - public override DateTime? DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as DateTime?; - } + var valuesize = source.ReadInt(); + var value = DeCompressValue(source.ReadBytes(valuesize), count); - public override int DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } + var qusize = source.ReadInt(); - public override double? DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as double?; - } + var qulityes = DeCompressQulity(source.ReadBytes(qusize)); + + for (int i = 0; i < timers.Count - 1; i++) + { + var skey = timers[i]; - public override int DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } + var snext = timers[i + 1]; - public override float? DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as float?; - } + if (time1 == skey) + { + return value[i]; - public override int DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } + } + else if (time1 > skey && time1 < snext) + { + switch (type) + { + case QueryValueMatchType.Previous: + return value[i]; + case QueryValueMatchType.After: + return value[i+1]; + case QueryValueMatchType.Linear: + if (qulityes[i] < 20 && qulityes[i + 1] < 20) + { + return (T)LinerValue(skey, snext, time1, value[i], value[i + 1]); + } + else if (qulityes[i] < 20) + { + return value[i]; + } + else if (qulityes[i + 1] < 20) + { + return value[i+1]; + } + return null; + case QueryValueMatchType.Closed: + var pval = (time1 - skey).TotalMilliseconds; + var fval = (snext - time1).TotalMilliseconds; - public override int? DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as int?; - } + if (pval < fval) + { + return value[i]; + } + else + { + return value[i + 1]; + } + + } + break; + } + else if (time1 == snext) + { + return value[i + 1]; + } - public override int DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } + } - public override long? DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as long?; + return null; + } - public override int DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } - public override short? DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as short?; - } + #region + /// /// /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override string DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as string; - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override uint? DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as uint?; - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override ulong? DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as ulong?; - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override ushort? DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type) as ushort?; - } - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - return DeCompressValue(source, sourceAddr, time, timeTick, type, result); - } - - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressAllPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) - { - throw new NotImplementedException(); - } - - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private int DeCompressIntPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - var time1 = time; - - for (int i = j; i < timers.Count - 2; i = i + 2) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval2 = value[i + 2]; - - var sval21 = value[i + 1]; - var sval22 = value[i + 3]; - - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - - result.AddPoint((int)val1, (int)val2, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - resultCount++; - break; - } - - } - - - return resultCount; - } - - private int DeCompressUIntPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - var time1 = time; - - for (int i = j; i < timers.Count - 2; i = i + 2) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval2 = value[i + 2]; - - var sval21 = value[i + 1]; - var sval22 = value[i + 3]; - - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - - result.AddPoint((uint)val1, (uint)val2, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - resultCount++; - break; - } - - } - - - return resultCount; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override T DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) - { - throw new NotImplementedException(); - } - - #region - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private int DeCompressIntPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - - foreach (var time1 in time) - { - for (int i = j; i < timers.Count - 2; i = i + 2) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval2 = value[i + 2]; - - var sval21 = value[i + 1]; - var sval22 = value[i + 3]; - - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - - result.AddPoint((int)val1, (int)val2, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - resultCount++; - break; - } - - } - } - - - return resultCount; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private int DeCompressUIntPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - - foreach (var time1 in time) - { - for (int i = j; i < timers.Count - 2; i = i + 2) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval2 = value[i + 2]; - - var sval21 = value[i + 1]; - var sval22 = value[i + 3]; - - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - - result.AddPoint((uint)val1, (uint)val2, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - resultCount++; - break; - } - - } - } - - - return resultCount; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private int DeCompressLongPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - - foreach (var time1 in time) - { - for (int i = j; i < timers.Count - 2; i = i + 2) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval2 = value[i + 2]; - - var sval21 = value[i + 1]; - var sval22 = value[i + 3]; - - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - - result.AddPoint((long)val1, (long)val2, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - resultCount++; - break; - } - - } - } - - - return resultCount; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private int DeCompressULongPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - - foreach (var time1 in time) - { - for (int i = j; i < timers.Count - 2; i = i + 2) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval2 = value[i + 2]; - - var sval21 = value[i + 1]; - var sval22 = value[i + 3]; - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - - result.AddPoint((ulong)val1, (ulong)val2, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 2], value[i + 3], time1, qulityes[i]); - resultCount++; - break; - } - - } - } - return resultCount; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private int DeCompressIntPoint3Value(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - - foreach (var time1 in time) - { - for (int i = j; i < timers.Count - 3; i = i + 3) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - resultCount++; - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval21 = value[i + 1]; - var sval31 = value[i + 2]; - - var sval2 = value[i + 3]; - var sval22 = value[i + 4]; - var sval32 = value[i + 5]; - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - var val3 = pval1 / tval1 * (Convert.ToDouble(sval32) - Convert.ToDouble(sval31)) + Convert.ToDouble(sval31); - - result.AddPoint((int)val1, (int)val2, (int)val3, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - resultCount++; - break; - } - - } - } - - - return resultCount; - } - - /// - /// - /// - /// - /// + /// + /// + /// /// - /// - /// - /// + /// + /// /// - private int DeCompressUIntPoint3Value(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + private object LinerValue(DateTime startTime,DateTime endTime,DateTime time,T value1,T value2) { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; + var pval1 = (time - startTime).TotalMilliseconds; + var tval1 = (endTime - startTime).TotalMilliseconds; - foreach (var time1 in time) + if (typeof(T) == typeof(IntPointData)) { - for (int i = j; i < timers.Count - 3; i = i + 3) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - resultCount++; - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval21 = value[i + 1]; - var sval31 = value[i + 2]; - - var sval2 = value[i + 3]; - var sval22 = value[i + 4]; - var sval32 = value[i + 5]; - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - var val3 = pval1 / tval1 * (Convert.ToDouble(sval32) - Convert.ToDouble(sval31)) + Convert.ToDouble(sval31); - - result.AddPoint((uint)val1, (uint)val2, (uint)val3, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - resultCount++; - break; - } - - } + var sval1 = (IntPointData)((object)value1); + var sval2 = (IntPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new IntPointData((int)val1, (int)val2); } - - - return resultCount; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private int DeCompressLongPoint3Value(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - int count = 0; - var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); - - var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); - - var qusize = source.ReadInt(); - - var qulityes = DeCompressQulity(source.ReadBytes(qusize)); - int resultCount = 0; - - int j = 0; - - foreach (var time1 in time) + else if (typeof(T) == typeof(UIntPointData)) { - for (int i = j; i < timers.Count - 3; i = i + 3) - { - var skey = timers[i]; - - var snext = timers[i + 1]; - - if (time1 == skey) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - resultCount++; - break; - } - else if (time1 > skey && time1 < snext) - { - switch (type) - { - case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.After: - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - resultCount++; - break; - case QueryValueMatchType.Linear: - if (qulityes[i] < 20 && qulityes[i + 1] < 20) - { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval21 = value[i + 1]; - var sval31 = value[i + 2]; - - var sval2 = value[i + 3]; - var sval22 = value[i + 4]; - var sval32 = value[i + 5]; - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - var val3 = pval1 / tval1 * (Convert.ToDouble(sval32) - Convert.ToDouble(sval31)) + Convert.ToDouble(sval31); - - result.AddPoint((long)val1, (long)val2, (long)val3, time1, 0); - } - else if (qulityes[i] < 20) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - } - else if (qulityes[i + 1] < 20) - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - } - else - { - result.Add(0, time1, (byte)QualityConst.Null); - } - resultCount++; - break; - case QueryValueMatchType.Closed: - var pval = (time1 - skey).TotalMilliseconds; - var fval = (snext - time1).TotalMilliseconds; - - if (pval < fval) - { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); - } - else - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - } - resultCount++; - break; - } - break; - } - else if (time1 == snext) - { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); - resultCount++; - break; - } - - } + var sval1 = (UIntPointData)((object)value1); + var sval2 = (UIntPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new UIntPointData((uint)val1, (uint)val2); + } + else if (typeof(T) == typeof(LongPointData)) + { + var sval1 = (LongPointData)((object)value1); + var sval2 = (LongPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new LongPointData((long)val1, (long)val2); + } + else if (typeof(T) == typeof(ULongPointData)) + { + var sval1 = (ULongPointData)((object)value1); + var sval2 = (ULongPointData)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + return new ULongPointData((ulong)val1, (ulong)val2); + } + else if (typeof(T) == typeof(IntPoint3Data)) + { + var sval1 = (IntPoint3Data)((object)value1); + var sval2 = (IntPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new IntPoint3Data((int)val1, (int)val2, (int)val3); + } + else if (typeof(T) == typeof(UIntPoint3Data)) + { + var sval1 = (UIntPoint3Data)((object)value1); + var sval2 = (UIntPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new UIntPoint3Data((uint)val1, (uint)val2, (uint)val3); + } + else if (typeof(T) == typeof(LongPoint3Data)) + { + var sval1 = (LongPoint3Data)((object)value1); + var sval2 = (LongPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new LongPoint3Data((long)val1, (long)val2, (long)val3); + } + else if (typeof(T) == typeof(ULongPoint3Data)) + { + var sval1 = (ULongPoint3Data)((object)value1); + var sval2 = (ULongPoint3Data)((object)value2); + var val1 = pval1 / tval1 * (Convert.ToDouble(sval2.X) - Convert.ToDouble(sval1.X)) + Convert.ToDouble(sval1.X); + var val2 = pval1 / tval1 * (Convert.ToDouble(sval2.Y) - Convert.ToDouble(sval1.Y)) + Convert.ToDouble(sval1.Y); + var val3 = pval1 / tval1 * (Convert.ToDouble(sval2.Z) - Convert.ToDouble(sval1.Z)) + Convert.ToDouble(sval1.Z); + return new ULongPoint3Data((ulong)val1, (ulong)val2, (ulong)val3); } - - return resultCount; + return default(T); } + + /// /// /// + /// /// /// /// @@ -3009,13 +2095,13 @@ namespace Cdy.Tag /// /// /// - private int DeCompressULongPoint3Value(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { int count = 0; var timers = GetTimers(source, sourceAddr + 8, timeTick, out count); var valuesize = source.ReadInt(); - var value = DeCompressValue(source.ReadBytes(valuesize), count); + var value = DeCompressValue(source.ReadBytes(valuesize), count); var qusize = source.ReadInt(); @@ -3026,7 +2112,7 @@ namespace Cdy.Tag foreach (var time1 in time) { - for (int i = j; i < timers.Count - 3; i = i + 3) + for (int i = j; i < timers.Count - 1; i++) { var skey = timers[i]; @@ -3034,8 +2120,10 @@ namespace Cdy.Tag if (time1 == skey) { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); + var val = value[i]; + result.Add(val, time1, qulityes[i]); resultCount++; + break; } else if (time1 > skey && time1 < snext) @@ -3043,39 +2131,29 @@ namespace Cdy.Tag switch (type) { case QueryValueMatchType.Previous: - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); + var val = value[i]; + result.Add(val, time1, qulityes[i]); resultCount++; break; case QueryValueMatchType.After: - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); + val = value[i + 1]; + result.Add(val, time1, qulityes[i + 1]); resultCount++; break; case QueryValueMatchType.Linear: if (qulityes[i] < 20 && qulityes[i + 1] < 20) { - var pval1 = (time1 - skey).TotalMilliseconds; - var tval1 = (snext - skey).TotalMilliseconds; - var sval1 = value[i]; - var sval21 = value[i + 1]; - var sval31 = value[i + 2]; - - var sval2 = value[i + 3]; - var sval22 = value[i + 4]; - var sval32 = value[i + 5]; - - var val1 = pval1 / tval1 * (Convert.ToDouble(sval2) - Convert.ToDouble(sval1)) + Convert.ToDouble(sval1); - var val2 = pval1 / tval1 * (Convert.ToDouble(sval22) - Convert.ToDouble(sval21)) + Convert.ToDouble(sval21); - var val3 = pval1 / tval1 * (Convert.ToDouble(sval32) - Convert.ToDouble(sval31)) + Convert.ToDouble(sval31); - - result.AddPoint((ulong)val1, (ulong)val2, (ulong)val3, time1, 0); + result.Add(LinerValue(skey, snext, time1, value[i], value[i + 1]), time1, 0); } else if (qulityes[i] < 20) { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); + val = value[i]; + result.Add(val, time1, qulityes[i]); } else if (qulityes[i + 1] < 20) { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); + val = value[i + 1]; + result.Add(val, time1, qulityes[i + 1]); } else { @@ -3089,11 +2167,13 @@ namespace Cdy.Tag if (pval < fval) { - result.AddPoint(value[i], value[i + 1], value[i + 2], time1, qulityes[i]); + val = value[i]; + result.Add(val, time1, qulityes[i]); } else { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); + val = value[i + 1]; + result.Add(val, time1, qulityes[i + 1]); } resultCount++; break; @@ -3102,7 +2182,8 @@ namespace Cdy.Tag } else if (time1 == snext) { - result.AddPoint(value[i + 3], value[i + 4], value[i + 5], time1, qulityes[i]); + var val = value[i + 1]; + result.Add(val, time1, qulityes[i + 1]); resultCount++; break; } @@ -3110,56 +2191,9 @@ namespace Cdy.Tag } } - return resultCount; } - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override int DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) - { - if (typeof(T) == typeof(IntPointData)) - { - return DeCompressIntPointValue(source, sourceAddr, time, timeTick, type, result); - } - else if (typeof(T) == typeof(UIntPointData)) - { - return DeCompressUIntPointValue(source, sourceAddr, time, timeTick, type, result); - } - else if (typeof(T) == typeof(LongPointData)) - { - return DeCompressLongPointValue(source, sourceAddr, time, timeTick, type, result); - } - else if (typeof(T) == typeof(ULongPointData)) - { - return DeCompressULongPointValue(source, sourceAddr, time, timeTick, type, result); - } - else if (typeof(T) == typeof(IntPoint3Data)) - { - return DeCompressIntPoint3Value(source, sourceAddr, time, timeTick, type, result); - } - else if (typeof(T) == typeof(UIntPoint3Data)) - { - return DeCompressUIntPoint3Value(source, sourceAddr, time, timeTick, type, result); - } - else if (typeof(T) == typeof(LongPoint3Data)) - { - return DeCompressLongPoint3Value(source, sourceAddr, time, timeTick, type, result); - } - else if (typeof(T) == typeof(ULongPoint3Data)) - { - return DeCompressULongPoint3Value(source, sourceAddr, time, timeTick, type, result); - } - return 0; - } + #endregion diff --git a/DataRunner/His/Compress/Special/NoneCompressUnit.cs b/DataRunner/His/Compress/Special/NoneCompressUnit.cs index 8cab602..0ca6a1e 100644 --- a/DataRunner/His/Compress/Special/NoneCompressUnit.cs +++ b/DataRunner/His/Compress/Special/NoneCompressUnit.cs @@ -116,7 +116,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -158,7 +158,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -224,7 +224,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -290,7 +290,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -356,7 +356,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -422,7 +422,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -487,7 +487,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -552,7 +552,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -618,7 +618,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -683,7 +683,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -722,7 +722,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -788,7 +788,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; int valuecount = 0; @@ -848,7 +848,7 @@ namespace Cdy.Tag /// /// /// - public override bool? DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public bool? DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -909,7 +909,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -997,7 +997,7 @@ namespace Cdy.Tag /// /// /// - public override byte? DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public byte? DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -1057,7 +1057,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -1144,7 +1144,7 @@ namespace Cdy.Tag /// /// /// - public override DateTime? DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public DateTime? DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -1204,7 +1204,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -1292,7 +1292,7 @@ namespace Cdy.Tag /// /// /// - public override double? DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public double? DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -1375,7 +1375,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -1477,7 +1477,7 @@ namespace Cdy.Tag } - public override float? DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public float? DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -1558,7 +1558,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -1668,7 +1668,7 @@ namespace Cdy.Tag /// /// /// - public override int? DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public int? DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -1749,7 +1749,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -1859,7 +1859,7 @@ namespace Cdy.Tag /// /// /// - public override long? DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public long? DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -1940,7 +1940,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -2052,7 +2052,7 @@ namespace Cdy.Tag /// /// /// - public override short? DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public short? DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -2133,7 +2133,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; @@ -2246,7 +2246,7 @@ namespace Cdy.Tag /// /// /// - public override string DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public string DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -2314,7 +2314,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; @@ -2409,7 +2409,7 @@ namespace Cdy.Tag /// /// /// - public override uint? DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public uint? DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -2491,7 +2491,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -2601,7 +2601,7 @@ namespace Cdy.Tag /// /// /// - public override ulong? DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public ulong? DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -2684,7 +2684,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -2793,7 +2793,7 @@ namespace Cdy.Tag /// /// /// - public override ushort? DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public ushort? DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -2876,7 +2876,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; @@ -2988,7 +2988,209 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressAllPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + public override int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) + { + if (typeof(T) == typeof(bool)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(short)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(ushort)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(int)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(uint)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(long)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(ulong)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(double)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(float)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(byte)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(string)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else if (typeof(T) == typeof(DateTime)) + { + return DeCompressAllValue(source, sourceAddr, startTime, endTime, timeTick, result as HisQueryResult); + } + else + { + return DeCompressAllPointValue(source, sourceAddr, startTime, endTime, timeTick, result); + } + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public override object DeCompressValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + { + if (typeof(T) == typeof(bool)) + { + return ((object)DeCompressBoolValue(source, sourceAddr, time, timeTick, type)); + } + else if (typeof(T) == typeof(byte)) + { + return ((object)DeCompressByteValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(short)) + { + return ((object)DeCompressShortValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(ushort)) + { + return ((object)DeCompressUShortValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(int)) + { + return ((object)DeCompressIntValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(uint)) + { + return ((object)DeCompressUIntValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(long)) + { + return ((object)DeCompressLongValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(ulong)) + { + return ((object)DeCompressULongValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(DateTime)) + { + return ((object)DeCompressDateTimeValue(source, sourceAddr, time, timeTick, type)); + + } + else if (typeof(T) == typeof(string)) + { + return ((object)DeCompressStringValue(source, sourceAddr, time, timeTick, type)); + } + else + { + return DeCompressPointValue(source, sourceAddr, time, timeTick, type); + } + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public override int DeCompressValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + { + if (typeof(T) == typeof(bool)) + { + return DeCompressBoolValue(source, sourceAddr, time, timeTick,type, result as HisQueryResult); + } + else if (typeof(T) == typeof(byte)) + { + return DeCompressByteValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(short)) + { + return DeCompressShortValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(ushort)) + { + return DeCompressUShortValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(int)) + { + return DeCompressIntValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(uint)) + { + return DeCompressUIntValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(long)) + { + return DeCompressLongValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(ulong)) + { + return DeCompressULongValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(DateTime)) + { + return DeCompressDateTimeValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + + } + else if (typeof(T) == typeof(string)) + { + return DeCompressStringValue(source, sourceAddr, time, timeTick, type, result as HisQueryResult); + } + else + { + return DeCompressPointValue(source, sourceAddr, time,timeTick,type, result); + } + + } + + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public int DeCompressAllPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult result) { DateTime time; @@ -3157,7 +3359,7 @@ namespace Cdy.Tag /// /// /// - public override T DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) + public T DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type) { DateTime time1; int valuecount = 0; @@ -3764,7 +3966,7 @@ namespace Cdy.Tag /// /// /// - public override int DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) + public int DeCompressPointValue(MarshalMemoryBlock source, int sourceAddr, List time, int timeTick, QueryValueMatchType type, HisQueryResult result) { DateTime stime; int valuecount = 0; diff --git a/DataRunner/His/HisEnginer.cs b/DataRunner/His/HisEnginer.cs index c241471..0f04b75 100644 --- a/DataRunner/His/HisEnginer.cs +++ b/DataRunner/His/HisEnginer.cs @@ -6,7 +6,6 @@ // Version 1.0 // 种道洋 //============================================================== -using Cdy.Tag; using DBRuntime.His; using System; using System.Collections.Generic; @@ -34,6 +33,8 @@ namespace Cdy.Tag /// private Cdy.Tag.RealEnginer mRealEnginer; + private LogManager mLogManager; + /// /// 缓存内存缓存时间,单位:s /// @@ -179,6 +180,25 @@ namespace Cdy.Tag } } + /// + /// + /// + public LogManager LogManager + { + get + { + return mLogManager; + } + set + { + mLogManager = value; + if(mLogManager!=null) + { + mLogManager.TimeLen = (ushort)(CachMemoryTime/60); + } + } + } + #endregion ...Properties... @@ -189,6 +209,7 @@ namespace Cdy.Tag /// public void Init() { + if (mRealEnginer != null) { if (mManager == null) @@ -445,7 +466,14 @@ namespace Cdy.Tag mCachMemory1 = new CachMemoryBlock(cachHeadSize) { Name = "CachMemory1" }; mCachMemory2 = new CachMemoryBlock(cachHeadSize) { Name = "CachMemory2" }; + LoggerService.Service.Info("HisEnginer", "Cal MergeMemory memory size:" + (storeHeadSize/1024.0/1024)+"M", ConsoleColor.Cyan); + LoggerService.Service.Info("HisEnginer", "Cal CachMemoryBlock memory size:" + (cachHeadSize / 1024.0 / 1024 *2) + "M", ConsoleColor.Cyan); + CurrentMemory = mCachMemory1; + + mCachMemory1.Clear(); + mCachMemory2.Clear(); + mMergeMemory.Clear(); } @@ -469,6 +497,13 @@ namespace Cdy.Tag public void Start() { mIsClosed = false; + + if (LogManager != null) + { + LogManager.InitHeadData(this.mHisTags); + LogManager.Start(); + } + foreach (var vv in mRecordTimerProcesser) { vv.Start(); @@ -509,7 +544,7 @@ namespace Cdy.Tag /// private void CheckMemoryIsReady(MarshalMemoryBlock memory) { - while (memory.IsBusy) + while (memory.IsBusy()) { LoggerService.Service.Info("Record", "记录出现阻塞 " + memory.Name); System.Threading.Thread.Sleep(1); @@ -553,7 +588,7 @@ namespace Cdy.Tag LoggerService.Service.Info("Record", "提交内存 " + mMergeMemory.Name + " 进行压缩",ConsoleColor.Green); //等待压缩完成 - while(mMergeMemory.IsBusy) Thread.Sleep(1); + while(mMergeMemory.IsBusy()) Thread.Sleep(1); RecordAllFirstValue(); } count = 0; @@ -660,6 +695,9 @@ namespace Cdy.Tag mWaitForMergeMemory = mcc; //通知进行内存合并 resetEvent.Set(); + + mLogManager?.RequestToSave(mcc.CurrentDatetime,dateTime, mcc); + } } @@ -821,6 +859,8 @@ namespace Cdy.Tag vv.Dispose(); } + if (LogManager != null) LogManager.Stop(); + mValueChangedProcesser.Clear(); mLastValueChangedProcesser = null; diff --git a/DataRunner/His/LogManager.cs b/DataRunner/His/LogManager.cs new file mode 100644 index 0000000..28ebeff --- /dev/null +++ b/DataRunner/His/LogManager.cs @@ -0,0 +1,266 @@ +//============================================================== +// Copyright (C) 2020 Inc. All rights reserved. +// +//============================================================== +// Create by 种道洋 at 2020/5/4 12:16:14. +// Version 1.0 +// 种道洋 +//============================================================== + +using DBRuntime.His; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; + +namespace Cdy.Tag +{ + /// + /// 日志管理系统 + /// + public class LogManager + { + + #region ... Variables ... + private Thread mSaveThread; + private bool mIsExit = false; + + private DateTime mStartTime; + private DateTime mEndTime; + + private ManualResetEvent resetEvent = new ManualResetEvent(false); + + private ManualResetEvent closedEvent = new ManualResetEvent(false); + + private CachMemoryBlock mNeedSaveMemory1; + + private string mLogDirector = string.Empty; + + private string mDatabase = string.Empty; + + private VarintCodeMemory memory; + + #endregion ...Variables... + + #region ... Events ... + + #endregion ...Events... + + #region ... Constructor... + /// + /// + /// + public LogManager() + { + + } + #endregion ...Constructor... + + #region ... Properties ... + + /// + /// 文件时长 + /// + public ushort TimeLen { get; set; } = 1; + + + /// + /// + /// + public string Database { get { return mDatabase; } set { mDatabase = value; CheckLogDirector(); } } + + + + #endregion ...Properties... + + #region ... Methods ... + + /// + /// + /// + public void InitHeadData(Dictionary mtags) + { + memory = new VarintCodeMemory(mtags.Count * 16); + memory.WriteInt64(mtags.Count); + var vtags = mtags.ToArray(); + long prev = mtags.First().Key; + int i = 0; + foreach(var vv in mtags) + { + if (i == 0) memory.WriteInt64(prev); + else + { + memory.WriteInt64((vv.Key - prev)); + prev = vv.Key; + } + i++; + } + + prev = mtags.First().Value.TimerValueStartAddr; + i = 0; + foreach (var vv in mtags) + { + if (i == 0) + { + memory.WriteInt64(prev); + } + else + { + memory.WriteInt64(vv.Value.TimerValueStartAddr - prev); + prev = vv.Value.TimerValueStartAddr; + } + i++; + } + } + + /// + /// + /// + private void CheckLogDirector() + { + mLogDirector = PathHelper.helper.GetDataPath(mDatabase, "Log"); + if(!System.IO.Directory.Exists(mLogDirector)) + { + System.IO.Directory.CreateDirectory(mLogDirector); + } + } + + /// + /// + /// + /// + /// + private string GetLogFilePath(DateTime starttime,DateTime endtime) + { + return System.IO.Path.Combine(mLogDirector, starttime.ToString("yyyyMMddHHmmss")+ ((int)Math.Floor((mEndTime - starttime).TotalSeconds)).ToString("D3")+".log"); ; + } + + /// + /// + /// + /// + /// + public void RequestToSave(DateTime startTime,DateTime endTime,CachMemoryBlock memory) + { + mNeedSaveMemory1 = memory; + mStartTime = startTime; + mEndTime = endTime; + resetEvent.Set(); + } + + /// + /// + /// + public void Start() + { + mSaveThread = new Thread(SaveProcess); + mSaveThread.IsBackground = true; + mSaveThread.Start(); + } + + /// + /// + /// + public void Stop() + { + mIsExit = true; + resetEvent.Set(); + closedEvent.WaitOne(); + } + + /// + /// + /// + private void SaveProcess() + { + while(!mIsExit) + { + resetEvent.WaitOne(); + resetEvent.Reset(); + if (mIsExit) break; + + Stopwatch sw = new Stopwatch(); + sw.Start(); + if(mNeedSaveMemory1!=null) + { + mNeedSaveMemory1.MakeMemoryBusy(); + RecordToFile(); + mNeedSaveMemory1.MakeMemoryNoBusy(); + } + CheckRemoveOldFiles(); + sw.Stop(); + LoggerService.Service.Info("LogManager", "记录"+ mNeedSaveMemory1.Name +"到日志文件 耗时" + sw.ElapsedMilliseconds + " "); + } + closedEvent.Set(); + } + + /// + /// + /// + private void RecordToFile() + { + //TimeSpan + HeadLength+HeadData+Data + + string fileName = GetLogFilePath(mStartTime,mEndTime); + using (var stream = System.IO.File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + stream.Write(BitConverter.GetBytes(TimeLen)); + stream.Write(BitConverter.GetBytes(memory.Position)); + stream.Write(memory.Buffer, 0, memory.Position); + mNeedSaveMemory1.RecordToLog(stream); + } + LoggerService.Service.Info("LogManager", "日志文件:"+ fileName + " 记录完成!",ConsoleColor.Cyan ); + + } + + + + /// + /// + /// + private void CheckRemoveOldFiles() + { + System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(mLogDirector); + Dictionary logFiles = new Dictionary(); + if(dinfo.Exists) + { + foreach(var vv in dinfo.EnumerateFileSystemInfos()) + { + string sfileName = vv.Name; + DateTime dt = new DateTime(int.Parse(sfileName.Substring(0, 4)), int.Parse(sfileName.Substring(4, 2)), int.Parse(sfileName.Substring(6, 2)), int.Parse(sfileName.Substring(8, 2)), int.Parse(sfileName.Substring(10, 2)), int.Parse(sfileName.Substring(12, 2))); + logFiles.Add(dt, vv.FullName); + } + } + + + if(logFiles.Count>9) + { + foreach(var vv in logFiles.OrderBy(e=>e.Key).Take(5)) + { + if(System.IO.File.Exists(vv.Value)) + { + try + { + if(System.IO.File.GetAttributes(vv.Value) != FileAttributes.ReadOnly) + System.IO.File.Delete(vv.Value); + } + catch + { + + } + } + } + } + + } + + #endregion ...Methods... + + #region ... Interfaces ... + + #endregion ...Interfaces... + } +} diff --git a/DataRunner/His/Serise/LocalFileSeriser.cs b/DataRunner/His/Serise/LocalFileSeriser.cs index 07769e7..d12be3a 100644 --- a/DataRunner/His/Serise/LocalFileSeriser.cs +++ b/DataRunner/His/Serise/LocalFileSeriser.cs @@ -70,7 +70,7 @@ namespace Cdy.Tag /// public override bool CreatOrOpenFile(string filename) { - + this.FileName = filename; if(System.IO.File.Exists(filename)) { mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); @@ -234,6 +234,46 @@ namespace Cdy.Tag return BitConverter.ToInt32(re, 0); } + /// + /// + /// + /// + /// + public override float ReadFloat(long start) + { + mStream.Position = start; + byte[] re = new byte[4]; + mStream.Read(re, 0, re.Length); + return MemoryHelper.ReadFloat(re); + } + + /// + /// + /// + /// + /// + public override double ReadDouble(long start) + { + mStream.Position = start; + byte[] re = new byte[8]; + mStream.Read(re, 0, re.Length); + return MemoryHelper.ReadDouble(re); + } + + /// + /// + /// + /// + /// + /// + public override byte[] ReadBytes(long start, int len) + { + mStream.Position = start; + byte[] re = new byte[len]; + mStream.Read(re, 0, re.Length); + return re; + } + public override DateTime ReadDateTime(long start) { mStream.Position = start; @@ -362,6 +402,15 @@ namespace Cdy.Tag } } + public override DataFileSeriserbase CloseAndReOpen() + { + long pos = mStream.Position; + Close(); + OpenFile(FileName); + mStream.Position = pos; + return this; + } + /// /// /// @@ -371,6 +420,7 @@ namespace Cdy.Tag { if (System.IO.File.Exists(filename)) { + this.FileName = filename; mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); return true; } @@ -386,6 +436,7 @@ namespace Cdy.Tag { if (System.IO.File.Exists(filename)) { + this.FileName = filename; mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); return true; } @@ -501,6 +552,7 @@ namespace Cdy.Tag return this; } - + + } } diff --git a/DataRunner/His/Serise/SeriseEnginer.cs b/DataRunner/His/Serise/SeriseEnginer.cs index 53b7e1a..2f3235d 100644 --- a/DataRunner/His/Serise/SeriseEnginer.cs +++ b/DataRunner/His/Serise/SeriseEnginer.cs @@ -635,6 +635,10 @@ namespace Cdy.Tag var vv = ServiceLocator.Locator.Resolve(); var tags = vv.ListAllTags().Where(e => e.Id >= Id * TagCountOneFile && e.Id < (Id + 1) * TagCountOneFile).OrderBy(e => e.Id); mBlockPointMemory = new MemoryBlock(tags.Count() * 8,1024*1024); + mBlockPointMemory.Clear(); + + LoggerService.Service.Info("SeriseEnginer", "Cal BlockPointMemory memory size:" + (mBlockPointMemory.AllocSize) / 1024.0 / 1024 + "M", ConsoleColor.Cyan); + //foreach (var vtag in tags) //{ // mIdAddrs.Add(vtag.Id, offset); @@ -808,11 +812,12 @@ namespace Cdy.Tag //this.mFileWriter.Append(mProcessMemory.Buffers, (int)start, (int)(totalsize - start)); mFileWriter.Write(mBlockPointMemory.Buffers, pointAddr, 0, (int)mBlockPointMemory.AllocSize); Flush(); + } sw.Stop(); - + LoggerService.Service.Info("SeriseFileItem" + Id, "写入数据 " + mCurrentFileName + " 数据大小:" + ((totalsize - start) + mBlockPointMemory.AllocSize) / 1024.0 / 1024 + " m" +"其他脚本耗时:"+ltmp+","+(ltmp2-ltmp)+","+(ltmp3-ltmp2)+ "存储耗时:" + (sw.ElapsedMilliseconds-ltmp3)); - + } catch(System.IO.IOException ex) { @@ -827,6 +832,7 @@ namespace Cdy.Tag public void Flush() { mFileWriter.Flush(); + mFileWriter.CloseAndReOpen(); } /// diff --git a/DataRunner/His/TimerMemoryCacheProcesser.cs b/DataRunner/His/TimerMemoryCacheProcesser.cs index 414a76d..9c27bcf 100644 --- a/DataRunner/His/TimerMemoryCacheProcesser.cs +++ b/DataRunner/His/TimerMemoryCacheProcesser.cs @@ -100,7 +100,7 @@ namespace Cdy.Tag { mBusyCount++; if(Id==0) - LoggerService.Service.Warn("Record", "TimerMemoryCacheProcesser 出现阻塞:"+mBusyCount); + LoggerService.Service.Warn("Record", "TimerMemoryCacheProcesser"+Id+" 出现阻塞:"+mBusyCount); } else { @@ -126,6 +126,7 @@ namespace Cdy.Tag public void Stop() { mIsClosed = true; + resetEvent.Set(); closedEvent.WaitOne(1000); } diff --git a/DataRunner/His/ValueChangedMemoryCacheProcesser.cs b/DataRunner/His/ValueChangedMemoryCacheProcesser.cs index 4467913..b2cc6b3 100644 --- a/DataRunner/His/ValueChangedMemoryCacheProcesser.cs +++ b/DataRunner/His/ValueChangedMemoryCacheProcesser.cs @@ -128,6 +128,7 @@ namespace Cdy.Tag public void Stop() { mIsClosed = true; + resetEvent.Set(); closedEvent.WaitOne(1000); } diff --git a/DataRunner/Properties/Resources.Designer.cs b/DataRunner/Properties/Resources.Designer.cs new file mode 100644 index 0000000..7b7f7f5 --- /dev/null +++ b/DataRunner/Properties/Resources.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace DBRuntime.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DBRuntime.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找类似 database '{0}' is not exist! 的本地化字符串。 + /// + internal static string databasenotexist { + get { + return ResourceManager.GetString("databasenotexist", resourceCulture); + } + } + } +} diff --git a/DataRunner/Properties/Resources.resx b/DataRunner/Properties/Resources.resx new file mode 100644 index 0000000..355cbf0 --- /dev/null +++ b/DataRunner/Properties/Resources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + database '{0}' is not exist! + + \ No newline at end of file diff --git a/DataRunner/Real/RealEnginer.cs b/DataRunner/Real/RealEnginer.cs index 46ada58..c2e9d03 100644 --- a/DataRunner/Real/RealEnginer.cs +++ b/DataRunner/Real/RealEnginer.cs @@ -174,6 +174,8 @@ namespace Cdy.Tag mMemory = new byte[mUsedSize]; mMHandle = mMemory.AsMemory().Pin().Pointer; + LoggerService.Service.Info("RealEnginer","Cal memory size:"+ mUsedSize/1024.0/1024+"M",ConsoleColor.Cyan); + foreach (var vv in mConfigDatabase.Tags) { switch (vv.Value.Type) diff --git a/DataRunner/Res.cs b/DataRunner/Res.cs new file mode 100644 index 0000000..60a1bab --- /dev/null +++ b/DataRunner/Res.cs @@ -0,0 +1,24 @@ +//============================================================== +// Copyright (C) 2020 Inc. All rights reserved. +// +//============================================================== +// Create by 种道洋 at 2020/3/29 11:05:05. +// Version 1.0 +// 种道洋 +//============================================================== + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace DBRuntime +{ + public class Res + { + public static string Get(string name) + { + return DBRuntime.Properties.Resources.ResourceManager.GetString(name, Thread.CurrentThread.CurrentCulture); + } + } +} diff --git a/DataRunner/Runner.cs b/DataRunner/Runner.cs index 2a26a7d..6bcfed9 100644 --- a/DataRunner/Runner.cs +++ b/DataRunner/Runner.cs @@ -105,11 +105,22 @@ namespace Cdy.Tag PathHelper.helper.CheckDataPathExist(); } + /// + /// + /// + /// + /// + private bool CheckDatabaseExist(string name) + { + return System.IO.File.Exists(PathHelper.helper.GetDataPath(name, name + ".db")); + } + /// /// /// private void LoadDatabase() { + this.mDatabase = new DatabaseSerise().Load(mDatabaseName); this.mRealDatabase = this.mDatabase.RealDatabase; this.mHisDatabase = this.mDatabase.HisDatabase; @@ -119,8 +130,9 @@ namespace Cdy.Tag /// /// /// - private async Task InitAsync(string database) + private async Task InitAsync(string database) { + if (System.IO.Path.IsPathRooted(database)) { this.mDatabaseName = System.IO.Path.GetFileNameWithoutExtension(database); @@ -132,35 +144,47 @@ namespace Cdy.Tag } InitPath(); - LoadDatabase(); + if (CheckDatabaseExist(mDatabaseName)) + { + LoadDatabase(); - mHisFileManager = new DataFileManager(mDatabaseName); - mHisFileManager.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; + mHisFileManager = new DataFileManager(mDatabaseName); + mHisFileManager.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; - var task = mHisFileManager.Int(); - realEnginer = new RealEnginer(mRealDatabase); - realEnginer.Init(); + var task = mHisFileManager.Int(); + realEnginer = new RealEnginer(mRealDatabase); + realEnginer.Init(); - hisEnginer = new HisEnginer(mHisDatabase, realEnginer); - hisEnginer.MergeMemoryTime = mHisDatabase.Setting.DataBlockDuration * 60; - hisEnginer.Init(); + hisEnginer = new HisEnginer(mHisDatabase, realEnginer); + hisEnginer.MergeMemoryTime = mHisDatabase.Setting.DataBlockDuration * 60; + hisEnginer.LogManager = new LogManager() { Database = mDatabaseName }; + hisEnginer.Init(); - compressEnginer = new CompressEnginer(hisEnginer.MegerMemorySize); - compressEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; + compressEnginer = new CompressEnginer(hisEnginer.MegerMemorySize); + compressEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; - seriseEnginer = new SeriseEnginer() { DatabaseName = database }; - seriseEnginer.FileDuration = mHisDatabase.Setting.FileDataDuration; - seriseEnginer.BlockDuration = mHisDatabase.Setting.DataBlockDuration; - seriseEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; - seriseEnginer.DataSeriser = mHisDatabase.Setting.DataSeriser; + seriseEnginer = new SeriseEnginer() { DatabaseName = database }; + seriseEnginer.FileDuration = mHisDatabase.Setting.FileDataDuration; + seriseEnginer.BlockDuration = mHisDatabase.Setting.DataBlockDuration; + seriseEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; + seriseEnginer.DataSeriser = mHisDatabase.Setting.DataSeriser; - querySerivce = new QuerySerivce(this.mDatabaseName); + querySerivce = new QuerySerivce(this.mDatabaseName); - RegistorInterface(); + RegistorInterface(); - DriverManager.Manager.Init(realEnginer); + DriverManager.Manager.Init(realEnginer); - await task; + await task; + + return true; + } + else + { + LoggerService.Service.Erro("Runner", string.Format(DBRuntime.Res.Get("databasenotexist"), mDatabaseName)); + return false; + } + } @@ -207,7 +231,11 @@ namespace Cdy.Tag public async void StartAsync(string database) { LoggerService.Service.Info("Runner", " 数据库 " + database+" 开始启动"); - await InitAsync(database); + var re = await InitAsync(database); + if (!re) + { + return; + } seriseEnginer.Start(); compressEnginer.Start(); hisEnginer.Start(); diff --git a/DbManager.Desktop/View/PermissionDetailView.xaml b/DbManager.Desktop/View/PermissionDetailView.xaml index be55fdf..963ef2b 100644 --- a/DbManager.Desktop/View/PermissionDetailView.xaml +++ b/DbManager.Desktop/View/PermissionDetailView.xaml @@ -84,7 +84,7 @@ - +