提交 ba87cd21 编写于 作者: cdy816's avatar cdy816

日常更新

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