/// <summary> /// 读取某时间段内的所有bool值 /// </summary> /// <param name="file"></param> /// <param name="tid"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="result"></param> public static void ReadAllValue <T>(this DataFileInfo4 file, int tid, DateTime startTime, DateTime endTime, HisQueryResult <T> result) { //long ltmp = 0, ltmp1 = 0; //Stopwatch sw = new Stopwatch(); //sw.Start(); var offset = file.GetFileOffsets(startTime, endTime); var vff = file.GetFileSeriser(); //ltmp = sw.ElapsedMilliseconds; 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; ReadAllValue(vff, vv.Value.Item2, tid, stime, etime, result); } //ltmp1 = sw.ElapsedMilliseconds; //vff.Close(); vff.Dispose(); //sw.Stop(); //Debug.WriteLine("ReadAllValue:" + ltmp + " ," + (ltmp1 - ltmp) + "," + (sw.ElapsedMilliseconds - ltmp1)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="file"></param> /// <param name="tid"></param> /// <param name="times"></param> /// <param name="type"></param> /// <returns></returns> public static HisQueryResult <T> Read <T>(this DataFileInfo4 file, int tid, List <DateTime> times, QueryValueMatchType type) { HisQueryResult <T> re = new HisQueryResult <T>(times.Count); Read <T>(file, tid, times, type, re); return(re); }
/// <summary> /// /// </summary> /// <param name="startTime"></param> /// <param name="duration"></param> /// <param name="file"></param> public void AddFile(DateTime startTime, TimeSpan duration, DataFileInfo4 file) { int mon1 = startTime.Month; var endTime = startTime.Add(duration); if (mon1 == endTime.Month) { var mm = AddMonth(mon1); mm.AddFile(startTime, duration, file); } else { var startTime2 = new DateTime(endTime.Year, endTime.Month, endTime.Day); var mm = AddMonth(mon1); mm.AddFile(startTime, startTime2 - startTime, file); if ((endTime - startTime).Seconds <= 1) { return; } else { mm = AddMonth(endTime.Month); mm.AddFile(startTime2, endTime - startTime2, file); } } mMaxMonth = Math.Max(mon1, mMaxMonth); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="file"></param> /// <param name="tid"></param> /// <param name="time"></param> /// <param name="type"></param> /// <returns></returns> public static object Read <T>(this DataFileInfo4 file, int tid, DateTime time, QueryValueMatchType type) { using (var vff = file.GetFileSeriser()) { var offset = file.GetFileOffsets(time); return(Read <T>(vff, offset, tid, time, type)); } }
/// <summary> /// /// </summary> /// <param name="file"></param> /// <returns></returns> public static DataFileSeriserbase GetFileSeriser(this DataFileInfo4 file) { var re = DataFileSeriserManager.manager.GetDefaultFileSersie(); re.FileName = file.FileName; re.OpenForReadOnly(file.FileName); return(re); }
/// <summary> /// /// </summary> /// <param name="startTime"></param> /// <param name="duration"></param> /// <param name="file"></param> public void AddFile(DateTime startTime, TimeSpan duration, DataFileInfo4 file) { lock (this) { if (!mFileMaps.ContainsKey(startTime)) { var vdd = new DayFileItem() { Duration = duration, Time = startTime }; if (file is HisDataFileInfo4) { vdd.File1 = file; } else { vdd.File2 = file; } mFileMaps.Add(startTime, vdd); if (startTime > mMaxTime) { mMaxTime = startTime; } } else { var vv = mFileMaps[startTime]; vv.Duration = duration; if (file is HisDataFileInfo4) { vv.File1 = file; } else { vv.File2 = file; } mFileMaps[startTime] = vv; if (startTime > mMaxTime) { mMaxTime = startTime; } } } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="file"></param> /// <param name="tid"></param> /// <param name="times"></param> /// <param name="type"></param> /// <param name="result"></param> public static void Read <T>(this DataFileInfo4 file, int tid, List <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result) { using (var vff = file.GetFileSeriser()) { Dictionary <long, List <DateTime> > moffs = new Dictionary <long, List <DateTime> >(); foreach (var vv in times) { var ff = file.GetFileOffsets(vv); if (moffs.ContainsKey(ff)) { moffs[ff].Add(vv); } else { moffs.Add(ff, new List <DateTime>() { vv }); } } foreach (var vf in moffs) { if (vf.Key > -1) { Read <T>(vff, vf.Key, tid, vf.Value, type, result); } else { foreach (var vv in vf.Value) { result.Add(default(T), vv, (byte)QualityConst.Null); } } } } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <param name="times"></param> /// <param name="type"></param> /// <param name="result"></param> public void ReadValueByUTCTime <T>(int id, IEnumerable <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result) { List <DateTime> ltmp = new List <DateTime>(); List <DateTime> mMemoryTimes = new List <DateTime>(); //判断数据是否在内存中 if (IsCanQueryFromMemory()) { foreach (var vv in times) { if (!mMemoryService.CheckTime(id, vv)) { ltmp.Add(vv); } else { mMemoryTimes.Add(vv); } } } else { ltmp.AddRange(times); } List <DateTime> mLogTimes = new List <DateTime>(); var vfiles = GetFileManager().GetDataFiles(ltmp, mLogTimes, id); DataFileInfo4 mPreFile = null; List <DateTime> mtime = new List <DateTime>(); //从历史文件中读取数据 foreach (var vv in vfiles) { if (vv.Value == null) { if (mPreFile != null) { if (mPreFile is HisDataFileInfo4) { (mPreFile as HisDataFileInfo4).Read(id, mtime, type, result); } else { mPreFile.Read <T>(id, mtime, type, result); } mPreFile = null; mtime.Clear(); } result.Add(default(T), vv.Key, (byte)QualityConst.Null); } else if (vv.Value != mPreFile) { if (mPreFile != null) { if (mPreFile is HisDataFileInfo4) { (mPreFile as HisDataFileInfo4).Read(id, mtime, type, result); } else { mPreFile.Read <T>(id, mtime, type, result); } } mPreFile = vv.Value; mtime.Clear(); mtime.Add(vv.Key); } else { mtime.Add(vv.Key); } } if (mPreFile != null) { if (mPreFile is HisDataFileInfo4) { (mPreFile as HisDataFileInfo4).Read(id, mtime, type, result); } else { mPreFile.Read <T>(id, mtime, type, result); } } //从日志文件中读取数据 ReadLogFile(id, mLogTimes, type, result); //从内存中读取数据 ReadFromMemory(id, mMemoryTimes, type, result); }