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

优化编解码部分的程序结构

上级 c1b58397
...@@ -44,6 +44,8 @@ namespace Cdy.Tag ...@@ -44,6 +44,8 @@ namespace Cdy.Tag
public static byte[] zoreData = new byte[1024 * 10]; public static byte[] zoreData = new byte[1024 * 10];
private int mRefCount = 0;
#endregion ...Variables... #endregion ...Variables...
#region ... Events ... #region ... Events ...
...@@ -125,10 +127,10 @@ namespace Cdy.Tag ...@@ -125,10 +127,10 @@ namespace Cdy.Tag
} }
} }
/// <summary> ///// <summary>
/// 是否繁忙 ///// 是否繁忙
/// </summary> ///// </summary>
public bool IsBusy { get; set; } //public bool IsBusy { get; set; }
/// <summary> /// <summary>
...@@ -204,6 +206,34 @@ namespace Cdy.Tag ...@@ -204,6 +206,34 @@ namespace Cdy.Tag
#region ... Methods ... #region ... Methods ...
/// <summary>
///
/// </summary>
public void IncRef()
{
lock (mUserSizeLock)
Interlocked.Increment(ref mRefCount);
}
/// <summary>
///
/// </summary>
public void DecRef()
{
lock (mUserSizeLock)
mRefCount = mRefCount > 0 ? mRefCount - 1 : mRefCount;
}
/// <summary>
/// 是否繁忙
/// </summary>
/// <returns></returns>
public bool IsBusy()
{
return mRefCount > 0;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -340,7 +370,7 @@ namespace Cdy.Tag ...@@ -340,7 +370,7 @@ namespace Cdy.Tag
mUsedSize = 0; mUsedSize = 0;
mPosition = 0; mPosition = 0;
LoggerService.Service.Info("MemoryBlock", Name + " is clear !"); // LoggerService.Service.Info("MemoryBlock", Name + " is clear !");
} }
/// <summary> /// <summary>
...@@ -2164,14 +2194,17 @@ namespace Cdy.Tag ...@@ -2164,14 +2194,17 @@ namespace Cdy.Tag
return re; return re;
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="memory"></param> /// <param name="memory"></param>
public static void MakeMemoryBusy(this MarshalMemoryBlock memory) public static void MakeMemoryBusy(this MarshalMemoryBlock memory)
{ {
LoggerService.Service.Info("MemoryBlock", memory.Name + " is busy....."); memory.IncRef();
memory.IsBusy = true; LoggerService.Service.Info("MemoryBlock","make "+ memory.Name + " is busy.....");
//memory.IsBusy = true;
//memory.StartMemory[0] = 1; //memory.StartMemory[0] = 1;
} }
...@@ -2181,8 +2214,9 @@ namespace Cdy.Tag ...@@ -2181,8 +2214,9 @@ namespace Cdy.Tag
/// <param name="memory"></param> /// <param name="memory"></param>
public static void MakeMemoryNoBusy(this MarshalMemoryBlock memory) public static void MakeMemoryNoBusy(this MarshalMemoryBlock memory)
{ {
LoggerService.Service.Info("MemoryBlock", memory.Name+ " is ready !"); memory.DecRef();
memory.IsBusy = false; LoggerService.Service.Info("MemoryBlock", "make " + memory.Name+ " is ready !");
//memory.StartMemory[0] = 0; //memory.StartMemory[0] = 0;
} }
...@@ -2208,6 +2242,40 @@ namespace Cdy.Tag ...@@ -2208,6 +2242,40 @@ namespace Cdy.Tag
} }
} }
/// <summary>
///
/// </summary>
/// <param name="memory"></param>
/// <param name="stream"></param>
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);
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
......
...@@ -443,6 +443,18 @@ namespace Cdy.Tag ...@@ -443,6 +443,18 @@ namespace Cdy.Tag
} }
} }
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static unsafe float ReadFloat(byte[] value)
{
return ReadFloat(value.AsMemory(0, 4).Pin().Pointer, 0);
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -643,6 +655,18 @@ namespace Cdy.Tag ...@@ -643,6 +655,18 @@ namespace Cdy.Tag
} }
} }
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static unsafe double ReadDouble(byte[] value)
{
return ReadDouble(value.AsMemory(0, 8).Pin().Pointer, 0);
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
......
...@@ -23,7 +23,23 @@ namespace Cdy.Tag ...@@ -23,7 +23,23 @@ namespace Cdy.Tag
X = x; X = x;
Y = y; Y = y;
} }
/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public IntPointData(uint x, uint y)
{
X = (int)x;
Y = (int)y;
}
/// <summary>
///
/// </summary>
public int X { get; set; } public int X { get; set; }
/// <summary>
///
/// </summary>
public int Y { get; set; } public int Y { get; set; }
} }
/// <summary> /// <summary>
...@@ -37,6 +53,13 @@ namespace Cdy.Tag ...@@ -37,6 +53,13 @@ namespace Cdy.Tag
Y = y; Y = y;
Z = z; 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 X { get; set; }
public int Y { get; set; } public int Y { get; set; }
public int Z { get; set; } public int Z { get; set; }
...@@ -52,6 +75,12 @@ namespace Cdy.Tag ...@@ -52,6 +75,12 @@ namespace Cdy.Tag
X = x; X = x;
Y = y; Y = y;
} }
public UIntPointData(int x, int y)
{
X = (uint)x;
Y = (uint)y;
}
public uint X { get; set; } public uint X { get; set; }
public uint Y { get; set; } public uint Y { get; set; }
} }
...@@ -66,6 +95,13 @@ namespace Cdy.Tag ...@@ -66,6 +95,13 @@ namespace Cdy.Tag
Y = y; Y = y;
Z = z; 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 X { get; set; }
public uint Y { get; set; } public uint Y { get; set; }
public uint Z { get; set; } public uint Z { get; set; }
...@@ -81,6 +117,12 @@ namespace Cdy.Tag ...@@ -81,6 +117,12 @@ namespace Cdy.Tag
X = x; X = x;
Y = y; Y = y;
} }
public LongPointData(ulong x, ulong y)
{
X = (long)x;
Y = (long)y;
}
public long X { get; set; } public long X { get; set; }
public long Y { get; set; } public long Y { get; set; }
} }
...@@ -96,6 +138,13 @@ namespace Cdy.Tag ...@@ -96,6 +138,13 @@ namespace Cdy.Tag
Y = y; Y = y;
Z = z; 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 X { get; set; }
public long Y { get; set; } public long Y { get; set; }
public long Z { get; set; } public long Z { get; set; }
...@@ -111,6 +160,12 @@ namespace Cdy.Tag ...@@ -111,6 +160,12 @@ namespace Cdy.Tag
X = x; X = x;
Y = y; Y = y;
} }
public ULongPointData(long x, long y)
{
X = (ulong)x;
Y = (ulong)y;
}
public ulong X { get; set; } public ulong X { get; set; }
public ulong Y { get; set; } public ulong Y { get; set; }
} }
...@@ -127,6 +182,13 @@ namespace Cdy.Tag ...@@ -127,6 +182,13 @@ namespace Cdy.Tag
Z = z; 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 X { get; set; }
public ulong Y { get; set; } public ulong Y { get; set; }
public ulong Z { get; set; } public ulong Z { get; set; }
......
此差异已折叠。
...@@ -179,6 +179,27 @@ namespace Cdy.Tag ...@@ -179,6 +179,27 @@ namespace Cdy.Tag
/// <param name="len"></param> /// <param name="len"></param>
public abstract MarshalMemoryBlock Read(long start, int len); public abstract MarshalMemoryBlock Read(long start, int len);
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <returns></returns>
public abstract double ReadDouble(long start);
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <returns></returns>
public abstract float ReadFloat(long start);
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <param name="len"></param>
/// <returns></returns>
public abstract byte[] ReadBytes(long start,int len);
/// <summary> /// <summary>
/// ///
...@@ -236,6 +257,13 @@ namespace Cdy.Tag ...@@ -236,6 +257,13 @@ namespace Cdy.Tag
/// </summary> /// </summary>
public abstract DataFileSeriserbase Flush(); public abstract DataFileSeriserbase Flush();
/// <summary>
/// 关闭并重新打开
/// </summary>
/// <returns></returns>
public abstract DataFileSeriserbase CloseAndReOpen();
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -248,6 +276,8 @@ namespace Cdy.Tag ...@@ -248,6 +276,8 @@ namespace Cdy.Tag
/// <returns></returns> /// <returns></returns>
public abstract Stream GetStream(); public abstract Stream GetStream();
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
......
...@@ -125,7 +125,7 @@ namespace Cdy.Tag ...@@ -125,7 +125,7 @@ namespace Cdy.Tag
/// <param name="value"></param> /// <param name="value"></param>
/// <param name="time"></param> /// <param name="time"></param>
/// <param name="qulity"></param> /// <param name="qulity"></param>
public void Add<T>(T value,DateTime time,byte qulity) public void Add<TT>(TT value,DateTime time,byte qulity)
{ {
Add((object)value, time, qulity); Add((object)value, time, qulity);
} }
......
...@@ -18,142 +18,129 @@ namespace Cdy.Tag ...@@ -18,142 +18,129 @@ namespace Cdy.Tag
public interface IHisQuery public interface IHisQuery
{ {
/// <summary> void ReadValue<T>(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<T> result);
///
/// </summary>
/// <param name="id"></param>
/// <param name="times"></param>
/// <param name="type"></param>
/// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<bool> result);
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="times"></param> /// <param name="times"></param>
/// <param name="type"></param> /// <param name="type"></param>
/// <param name="result"></param> /// <returns></returns>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<byte> result); HisQueryResult<T> ReadValue<T>(int id, List<DateTime> times, QueryValueMatchType type);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="times"></param>
///// <param name="type"></param>
///// <param name="result"></param>
//void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<bool> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<short> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<byte> result);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="times"></param>
/// <param name="type"></param>
/// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<ushort> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<int> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<short> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<uint> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<ushort> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<ulong> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<int> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<long> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<uint> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="times"></param>
///// <param name="type"></param>
///// <param name="result"></param>
//void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<ulong> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<float> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<long> result);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="times"></param>
/// <param name="type"></param>
/// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<double> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<DateTime> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<float> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="times"></param> ///// <param name="times"></param>
/// <param name="type"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<string> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<double> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="times"></param>
/// <param name="endTime"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<bool> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<DateTime> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="times"></param>
/// <param name="endTime"></param> ///// <param name="type"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<byte> result); //void ReadValue(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<string> result);
/// <summary> void ReadAllValue<T>(int id, DateTime startTime, DateTime endTime, HisQueryResult<T> result);
///
/// </summary>
/// <param name="id"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<short> result);
/// <summary> /// <summary>
/// ///
...@@ -161,98 +148,120 @@ namespace Cdy.Tag ...@@ -161,98 +148,120 @@ namespace Cdy.Tag
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="startTime"></param> /// <param name="startTime"></param>
/// <param name="endTime"></param> /// <param name="endTime"></param>
/// <param name="result"></param> /// <returns></returns>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<ushort> result); HisQueryResult<T> ReadAllValue<T>(int id, DateTime startTime, DateTime endTime);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<int> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<uint> result); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<bool> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<long> result); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<byte> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<ulong> result); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<short> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<float> result); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<ushort> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<double> result); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<int> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<DateTime> result); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<uint> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <param name="result"></param> ///// <param name="result"></param>
void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<string> result); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<long> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <param name="id"></param> ///// <param name="id"></param>
/// <param name="startTime"></param> ///// <param name="startTime"></param>
/// <param name="endTime"></param> ///// <param name="endTime"></param>
/// <returns></returns> ///// <param name="result"></param>
HisQueryResult<T> ReadAllValue<T>(int id, DateTime startTime, DateTime endTime); //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<ulong> result);
/// <summary> ///// <summary>
/// /////
/// </summary> ///// </summary>
/// <typeparam name="T"></typeparam> ///// <param name="id"></param>
/// <param name="id"></param> ///// <param name="startTime"></param>
/// <param name="times"></param> ///// <param name="endTime"></param>
/// <param name="type"></param> ///// <param name="result"></param>
/// <returns></returns> //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<float> result);
HisQueryResult<T> ReadValue<T>(int id, List<DateTime> times, QueryValueMatchType type);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<double> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<DateTime> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<string> result);
} }
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
//============================================================== //==============================================================
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -23,6 +24,16 @@ namespace Cdy.Tag ...@@ -23,6 +24,16 @@ namespace Cdy.Tag
private Dictionary<int,Dictionary<int, YearTimeFile>> mTimeFileMaps = new Dictionary<int,Dictionary<int, YearTimeFile>>(); private Dictionary<int,Dictionary<int, YearTimeFile>> mTimeFileMaps = new Dictionary<int,Dictionary<int, YearTimeFile>>();
/// <summary>
///
/// </summary>
private Dictionary<string, LogFileInfo> mLogFileMaps = new Dictionary<string, LogFileInfo>();
/// <summary>
///
/// </summary>
internal static Dictionary<string, DateTime> CurrentDateTime = new Dictionary<string, DateTime>();
private string mDatabaseName; private string mDatabaseName;
/// <summary> /// <summary>
...@@ -30,8 +41,16 @@ namespace Cdy.Tag ...@@ -30,8 +41,16 @@ namespace Cdy.Tag
/// </summary> /// </summary>
public const string DataFileExtends = ".dbd"; public const string DataFileExtends = ".dbd";
public const string LogFileExtends = ".log";
/// <summary>
///
/// </summary>
public const int FileHeadSize = 72; public const int FileHeadSize = 72;
private System.IO.FileSystemWatcher hisDataWatcher;
private System.IO.FileSystemWatcher logDataWatcher;
#endregion ...Variables... #endregion ...Variables...
#region ... Events ... #region ... Events ...
...@@ -62,6 +81,9 @@ namespace Cdy.Tag ...@@ -62,6 +81,9 @@ namespace Cdy.Tag
/// </summary> /// </summary>
public string PrimaryHisDataPath { get; set; } public string PrimaryHisDataPath { get; set; }
public string PrimaryLogDataPath { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -80,6 +102,15 @@ namespace Cdy.Tag ...@@ -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); return string.IsNullOrEmpty(PrimaryHisDataPath) ? PathHelper.helper.GetDataPath(this.mDatabaseName,"HisData") : System.IO.Path.IsPathRooted(PrimaryHisDataPath) ? PrimaryHisDataPath : PathHelper.helper.GetDataPath(this.mDatabaseName,PrimaryHisDataPath);
} }
/// <summary>
///
/// </summary>
/// <returns></returns>
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);
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -95,10 +126,100 @@ namespace Cdy.Tag ...@@ -95,10 +126,100 @@ namespace Cdy.Tag
/// </summary> /// </summary>
public async Task Int() 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()); //await Scan(GetBackHisDataPath());
} }
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
/// <summary> /// <summary>
/// 搜索文件 /// 搜索文件
/// </summary> /// </summary>
...@@ -122,6 +243,66 @@ namespace Cdy.Tag ...@@ -122,6 +243,66 @@ namespace Cdy.Tag
} }
} }
/// <summary>
///
/// </summary>
/// <param name="file"></param>
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;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -179,7 +360,32 @@ namespace Cdy.Tag ...@@ -179,7 +360,32 @@ namespace Cdy.Tag
mTimeFileMaps.Add(id, new Dictionary<int, YearTimeFile>()); mTimeFileMaps.Add(id, new Dictionary<int, YearTimeFile>());
mTimeFileMaps[id].Add(yy, yt); 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 });
}
/// <summary>
///
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
private LogFileInfo GetLogDataFile(DateTime time)
{
foreach(var vv in mLogFileMaps.Values.ToArray())
{
if (vv.StartTime <= time && time < vv.EndTime) return vv;
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="time"></param>
/// <param name="id"></param>
/// <returns></returns>
private bool CheckDataInLogFile(DateTime time,int id)
{
return CurrentDateTime[mDatabaseName + id] < time;
} }
/// <summary> /// <summary>
...@@ -192,9 +398,17 @@ namespace Cdy.Tag ...@@ -192,9 +398,17 @@ namespace Cdy.Tag
{ {
int id = Id / TagCountOneFile; 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; return null;
} }
...@@ -207,9 +421,33 @@ namespace Cdy.Tag ...@@ -207,9 +421,33 @@ namespace Cdy.Tag
/// <param name="endtime"></param> /// <param name="endtime"></param>
/// <param name="Id"></param> /// <param name="Id"></param>
/// <returns></returns> /// <returns></returns>
public List<DataFileInfo> GetDataFiles(DateTime starttime, DateTime endtime, int Id) public List<DataFileInfo> GetDataFiles(DateTime starttime, DateTime endtime,out Tuple<DateTime,DateTime> logFileTimes, int Id)
{ {
return GetDataFiles(starttime,endtime-starttime,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>(DateTime.MinValue, DateTime.MinValue);
return GetDataFiles(starttime, endtime - starttime, Id);
}
} }
/// <summary> /// <summary>
...@@ -253,76 +491,58 @@ namespace Cdy.Tag ...@@ -253,76 +491,58 @@ namespace Cdy.Tag
/// <param name="times"></param> /// <param name="times"></param>
/// <param name="Id"></param> /// <param name="Id"></param>
/// <returns></returns> /// <returns></returns>
public SortedDictionary<DateTime, DataFileInfo> GetDataFiles(List<DateTime> times, int Id) public SortedDictionary<DateTime, DataFileInfo> GetDataFiles(List<DateTime> times, List<DateTime> logFileTimes,int Id)
{ {
SortedDictionary<DateTime, DataFileInfo> re = new SortedDictionary<DateTime, DataFileInfo>(); SortedDictionary<DateTime, DataFileInfo> re = new SortedDictionary<DateTime, DataFileInfo>();
foreach(var vv in times) 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;
}
/// <summary>
///
/// </summary>
/// <param name="times"></param>
/// <param name="Id"></param>
/// <returns></returns>
public SortedDictionary<DateTime, LogFileInfo> GetLogDataFiles(List<DateTime> times)
{
SortedDictionary<DateTime, LogFileInfo> re = new SortedDictionary<DateTime, LogFileInfo>();
foreach (var vvd in times)
{
re.Add(vvd, GetLogDataFile(vvd));
} }
return re; return re;
} }
///// <summary> /// <summary>
///// ///
///// </summary> /// </summary>
///// <param name="time"></param> /// <param name="startTime"></param>
///// <returns></returns> /// <param name="endtime"></param>
//public MinuteTimeFile GetFile(DateTime time,int Id) /// <param name="Id"></param>
//{ /// <returns></returns>
// int id = Id / TagCountOneFile; public List<LogFileInfo> GetLogDataFiles(DateTime startTime, DateTime endtime)
{
// if (mTimeFileMaps.ContainsKey(id) && mTimeFileMaps[id].ContainsKey(time.Year)) List<LogFileInfo> re = new List<LogFileInfo>();
// { foreach (var vv in mLogFileMaps.ToArray())
// return mTimeFileMaps[id][time.Year].GetFile(time); {
// } if ((vv.Value.StartTime >= startTime && vv.Value.StartTime < endtime) || (vv.Value.EndTime >= startTime && vv.Value.EndTime < endtime))
// return null; {
//} re.Add(vv.Value);
}
///// <summary> }
///// return re;
///// </summary> }
///// <param name="starttime"></param>
///// <param name="endtime"></param>
///// <returns></returns>
//public List<MinuteTimeFile> GetFiles(DateTime starttime,DateTime endtime,int Id)
//{
// List<MinuteTimeFile> re = new List<MinuteTimeFile>();
// DateTime sstart = starttime;
// while (sstart <= endtime)
// {
// var sfile = GetFile(sstart, Id);
// if (sfile != null)
// re.Add(sfile);
// sstart = sstart.AddMinutes(1);
// }
// return re;
//}
///// <summary>
/////
///// </summary>
///// <param name="times"></param>
///// <returns></returns>
//public Dictionary<DateTime, MinuteTimeFile> GetFiles(List<DateTime> times,int Id)
//{
// Dictionary<DateTime,MinuteTimeFile> re = new Dictionary<DateTime, MinuteTimeFile>();
// foreach(var vv in times)
// {
// re.Add(vv,GetFile(vv,Id));
// }
// return re;
//}
///// <summary>
/////
///// </summary>
///// <param name="datafile"></param>
///// <returns></returns>
//private DataFileSeriserbase GetFileSerise(string datafile)
//{
// return null;
//}
#endregion ...Methods... #endregion ...Methods...
......
//==============================================================
// 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
{
/// <summary>
///
/// </summary>
public class HisDataQuery
{
#region ... Variables ...
#endregion ...Variables...
#region ... Events ...
#endregion ...Events...
#region ... Constructor...
#endregion ...Constructor...
#region ... Properties ...
#endregion ...Properties...
#region ... Methods ...
/// <summary>
///
/// </summary>
/// <param name="tag"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public List<HisQueryResult<T>> Query<T>(List<string> tag, DateTime startTime, DateTime endTime)
{
var lid = ServiceLocator.Locator.Resolve<ITagManager>().GetTagIdByName(tag);
if (lid != null)
{
return Query<T>(lid, startTime, endTime);
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="tag"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public HisQueryResult<T> Query<T>(string tag,DateTime startTime, DateTime endTime)
{
int? lid = ServiceLocator.Locator.Resolve<ITagManager>().GetTagIdByName(tag);
if(lid!=null)
{
return Query<T>(lid.Value, startTime, endTime);
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="tagId"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public HisQueryResult<T> Query<T>(int tagId, DateTime startTime, DateTime endTime)
{
return null;
}
/// <summary>
///
/// </summary>
/// <param name="tagId"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public List<HisQueryResult<T>> Query<T>(List<int?> tagId, DateTime startTime, DateTime endTime)
{
return null;
}
#endregion ...Methods...
#region ... Interfaces ...
#endregion ...Interfaces...
}
}
此差异已折叠。
...@@ -27,7 +27,9 @@ namespace Cdy.Tag ...@@ -27,7 +27,9 @@ namespace Cdy.Tag
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
Dictionary<HeadOffsetKey,Tuple<Dictionary<int, int>,long>> mHeadOffsets = new Dictionary<HeadOffsetKey, Tuple<Dictionary<int, int>, long>>(); public Dictionary<HeadOffsetKey,Tuple<Dictionary<int, int>,long>> mHeadOffsets = new Dictionary<HeadOffsetKey, Tuple<Dictionary<int, int>, long>>();
public Dictionary<string, Dictionary<int, long>> LogHeadOffsets = new Dictionary<string, Dictionary<int, long>>();
#endregion ...Variables... #endregion ...Variables...
...@@ -45,6 +47,45 @@ namespace Cdy.Tag ...@@ -45,6 +47,45 @@ namespace Cdy.Tag
#region ... Methods ... #region ... Methods ...
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool Contains(string name)
{
return LogHeadOffsets.ContainsKey(name);
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="addrs"></param>
public void AddLogHead(string name,Dictionary<int,long> addrs)
{
if (!LogHeadOffsets.ContainsKey(name))
{
LogHeadOffsets.Add(name, addrs);
}
else
{
LogHeadOffsets[name] = addrs;
}
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
public void RemoveLogHead(string name)
{
if(LogHeadOffsets.ContainsKey(name))
{
LogHeadOffsets.Remove(name);
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -81,6 +122,16 @@ namespace Cdy.Tag ...@@ -81,6 +122,16 @@ namespace Cdy.Tag
return mHeadOffsets[key]; return mHeadOffsets[key];
} }
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Dictionary<int, long> Get(string key)
{
return LogHeadOffsets[key];
}
#endregion ...Methods... #endregion ...Methods...
#region ... Interfaces ... #region ... Interfaces ...
......
此差异已折叠。
...@@ -22,6 +22,8 @@ namespace Cdy.Tag ...@@ -22,6 +22,8 @@ namespace Cdy.Tag
private SortedDictionary<DateTime, Tuple<TimeSpan, DataFileInfo>> mFileMaps = new SortedDictionary<DateTime, Tuple<TimeSpan, DataFileInfo>>(); private SortedDictionary<DateTime, Tuple<TimeSpan, DataFileInfo>> mFileMaps = new SortedDictionary<DateTime, Tuple<TimeSpan, DataFileInfo>>();
private DateTime mMaxTime = DateTime.MinValue;
#endregion ...Variables... #endregion ...Variables...
#region ... Events ... #region ... Events ...
...@@ -43,6 +45,17 @@ namespace Cdy.Tag ...@@ -43,6 +45,17 @@ namespace Cdy.Tag
#region ... Methods ... #region ... Methods ...
/// <summary>
///
/// </summary>
public void UpdateLastDatetime()
{
if(mFileMaps.ContainsKey(mMaxTime))
{
mFileMaps[mMaxTime].Item2.UpdateLastDatetime();
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -54,6 +67,11 @@ namespace Cdy.Tag ...@@ -54,6 +67,11 @@ namespace Cdy.Tag
if(!mFileMaps.ContainsKey(startTime)) if(!mFileMaps.ContainsKey(startTime))
{ {
mFileMaps.Add(startTime, new Tuple<TimeSpan, DataFileInfo>(duration, file)); mFileMaps.Add(startTime, new Tuple<TimeSpan, DataFileInfo>(duration, file));
if(startTime>mMaxTime)
{
mMaxTime = startTime;
}
} }
} }
...@@ -106,27 +124,6 @@ namespace Cdy.Tag ...@@ -106,27 +124,6 @@ namespace Cdy.Tag
return GetDataFiles(startTime, startTime + span); return GetDataFiles(startTime, startTime + span);
} }
///// <summary>
/////
///// </summary>
///// <param name="month"></param>
///// <param name="file"></param>
//public DayTimeFile AddDay(int month, DayTimeFile file)
//{
// file.Parent = this;
// return this.AddTimefile(month, file) as DayTimeFile;
//}
///// <summary>
/////
///// </summary>
///// <param name="month"></param>
///// <returns></returns>
//public DayTimeFile AddDay(int month)
//{
// DayTimeFile mfile = new DayTimeFile() { TimeKey = month };
// return AddDay(month, mfile);
//}
#endregion ...Methods... #endregion ...Methods...
......
...@@ -20,6 +20,8 @@ namespace Cdy.Tag ...@@ -20,6 +20,8 @@ namespace Cdy.Tag
#region ... Variables ... #region ... Variables ...
private int mMaxMonth = 0;
#endregion ...Variables... #endregion ...Variables...
#region ... Events ... #region ... Events ...
...@@ -67,6 +69,18 @@ namespace Cdy.Tag ...@@ -67,6 +69,18 @@ namespace Cdy.Tag
mm.AddFile(startTime2, endTime - startTime2, file); mm.AddFile(startTime2, endTime - startTime2, file);
} }
} }
mMaxMonth = Math.Max(mon1, mMaxMonth);
}
/// <summary>
///
/// </summary>
public void UpdateLastDatetime()
{
if(this.ContainsKey(mMaxMonth))
{
(this[mMaxMonth] as MonthTimeFile).UpdateLastDatetime();
}
} }
/// <summary> /// <summary>
......
...@@ -6,6 +6,7 @@ namespace DBInRun ...@@ -6,6 +6,7 @@ namespace DBInRun
{ {
class Program class Program
{ {
//static MarshalMemoryBlock block;
static void Main(string[] args) static void Main(string[] args)
{ {
bool mIsClosed = false; bool mIsClosed = false;
...@@ -82,6 +83,10 @@ namespace DBInRun ...@@ -82,6 +83,10 @@ namespace DBInRun
case "h": case "h":
Console.WriteLine(GetHelpString()); Console.WriteLine(GetHelpString());
break; break;
//case "mtest":
// block = new MarshalMemoryBlock((long)(1024 * 1024 * 1024)*2);
// //block.Clear();
// break;
} }
} }
} }
......
...@@ -106,7 +106,7 @@ namespace DBInRun.Properties { ...@@ -106,7 +106,7 @@ namespace DBInRun.Properties {
} }
/// <summary> /// <summary>
/// 查找类似 ***************Welcome to Mars high performance real time sensor database*************** 的本地化字符串。 /// 查找类似 ***************Welcome to Mars high performance realtime iot database*************** 的本地化字符串。
/// </summary> /// </summary>
internal static string WelcomeMsg { internal static string WelcomeMsg {
get { get {
......
...@@ -133,6 +133,6 @@ ...@@ -133,6 +133,6 @@
<value>stop databse</value> <value>stop databse</value>
</data> </data>
<data name="WelcomeMsg" xml:space="preserve"> <data name="WelcomeMsg" xml:space="preserve">
<value>***************Welcome to Mars high performance real time sensor database***************</value> <value>***************Welcome to Mars high performance realtime iot database***************</value>
</data> </data>
</root> </root>
\ No newline at end of file
...@@ -133,6 +133,6 @@ ...@@ -133,6 +133,6 @@
<value>停止正在运行的数据库</value> <value>停止正在运行的数据库</value>
</data> </data>
<data name="WelcomeMsg" xml:space="preserve"> <data name="WelcomeMsg" xml:space="preserve">
<value>***************欢迎来到Mars高性能实时传感器数据库****************</value> <value>***************欢迎来到Mars高性能实时物联数据库****************</value>
</data> </data>
</root> </root>
\ No newline at end of file
...@@ -19,6 +19,21 @@ ...@@ -19,6 +19,21 @@
<ProjectReference Include="..\DBHisData\DBHisData.csproj" /> <ProjectReference Include="..\DBHisData\DBHisData.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="Config\Driver.cfg"> <None Update="Config\Driver.cfg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
......
...@@ -103,10 +103,19 @@ namespace Cdy.Tag ...@@ -103,10 +103,19 @@ namespace Cdy.Tag
} }
long psize = mTotalSize/mTargetMemorys.Count; 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.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);
//}
} }
/// <summary> /// <summary>
...@@ -170,7 +179,7 @@ namespace Cdy.Tag ...@@ -170,7 +179,7 @@ namespace Cdy.Tag
{ {
foreach(var vv in mTargetMemorys) foreach(var vv in mTargetMemorys)
{ {
if(vv.Value.IsBusy) if(vv.Value.IsBusy())
{ {
return true; return true;
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
// Version 1.0 // Version 1.0
// 种道洋 // 种道洋
//============================================================== //==============================================================
using Cdy.Tag;
using DBRuntime.His; using DBRuntime.His;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -34,6 +33,8 @@ namespace Cdy.Tag ...@@ -34,6 +33,8 @@ namespace Cdy.Tag
/// </summary> /// </summary>
private Cdy.Tag.RealEnginer mRealEnginer; private Cdy.Tag.RealEnginer mRealEnginer;
private LogManager mLogManager;
/// <summary> /// <summary>
/// 缓存内存缓存时间,单位:s /// 缓存内存缓存时间,单位:s
/// </summary> /// </summary>
...@@ -179,6 +180,25 @@ namespace Cdy.Tag ...@@ -179,6 +180,25 @@ namespace Cdy.Tag
} }
} }
/// <summary>
///
/// </summary>
public LogManager LogManager
{
get
{
return mLogManager;
}
set
{
mLogManager = value;
if(mLogManager!=null)
{
mLogManager.TimeLen = (ushort)(CachMemoryTime/60);
}
}
}
#endregion ...Properties... #endregion ...Properties...
...@@ -189,6 +209,7 @@ namespace Cdy.Tag ...@@ -189,6 +209,7 @@ namespace Cdy.Tag
/// </summary> /// </summary>
public void Init() public void Init()
{ {
if (mRealEnginer != null) if (mRealEnginer != null)
{ {
if (mManager == null) if (mManager == null)
...@@ -445,7 +466,14 @@ namespace Cdy.Tag ...@@ -445,7 +466,14 @@ namespace Cdy.Tag
mCachMemory1 = new CachMemoryBlock(cachHeadSize) { Name = "CachMemory1" }; mCachMemory1 = new CachMemoryBlock(cachHeadSize) { Name = "CachMemory1" };
mCachMemory2 = new CachMemoryBlock(cachHeadSize) { Name = "CachMemory2" }; 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; CurrentMemory = mCachMemory1;
mCachMemory1.Clear();
mCachMemory2.Clear();
mMergeMemory.Clear();
} }
...@@ -469,6 +497,13 @@ namespace Cdy.Tag ...@@ -469,6 +497,13 @@ namespace Cdy.Tag
public void Start() public void Start()
{ {
mIsClosed = false; mIsClosed = false;
if (LogManager != null)
{
LogManager.InitHeadData(this.mHisTags);
LogManager.Start();
}
foreach (var vv in mRecordTimerProcesser) foreach (var vv in mRecordTimerProcesser)
{ {
vv.Start(); vv.Start();
...@@ -509,7 +544,7 @@ namespace Cdy.Tag ...@@ -509,7 +544,7 @@ namespace Cdy.Tag
/// <param name="memory"></param> /// <param name="memory"></param>
private void CheckMemoryIsReady(MarshalMemoryBlock memory) private void CheckMemoryIsReady(MarshalMemoryBlock memory)
{ {
while (memory.IsBusy) while (memory.IsBusy())
{ {
LoggerService.Service.Info("Record", "记录出现阻塞 " + memory.Name); LoggerService.Service.Info("Record", "记录出现阻塞 " + memory.Name);
System.Threading.Thread.Sleep(1); System.Threading.Thread.Sleep(1);
...@@ -553,7 +588,7 @@ namespace Cdy.Tag ...@@ -553,7 +588,7 @@ namespace Cdy.Tag
LoggerService.Service.Info("Record", "提交内存 " + mMergeMemory.Name + " 进行压缩",ConsoleColor.Green); LoggerService.Service.Info("Record", "提交内存 " + mMergeMemory.Name + " 进行压缩",ConsoleColor.Green);
//等待压缩完成 //等待压缩完成
while(mMergeMemory.IsBusy) Thread.Sleep(1); while(mMergeMemory.IsBusy()) Thread.Sleep(1);
RecordAllFirstValue(); RecordAllFirstValue();
} }
count = 0; count = 0;
...@@ -660,6 +695,9 @@ namespace Cdy.Tag ...@@ -660,6 +695,9 @@ namespace Cdy.Tag
mWaitForMergeMemory = mcc; mWaitForMergeMemory = mcc;
//通知进行内存合并 //通知进行内存合并
resetEvent.Set(); resetEvent.Set();
mLogManager?.RequestToSave(mcc.CurrentDatetime,dateTime, mcc);
} }
} }
...@@ -821,6 +859,8 @@ namespace Cdy.Tag ...@@ -821,6 +859,8 @@ namespace Cdy.Tag
vv.Dispose(); vv.Dispose();
} }
if (LogManager != null) LogManager.Stop();
mValueChangedProcesser.Clear(); mValueChangedProcesser.Clear();
mLastValueChangedProcesser = null; mLastValueChangedProcesser = null;
......
//==============================================================
// 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
{
/// <summary>
/// 日志管理系统
/// </summary>
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...
/// <summary>
///
/// </summary>
public LogManager()
{
}
#endregion ...Constructor...
#region ... Properties ...
/// <summary>
/// 文件时长
/// </summary>
public ushort TimeLen { get; set; } = 1;
/// <summary>
///
/// </summary>
public string Database { get { return mDatabase; } set { mDatabase = value; CheckLogDirector(); } }
#endregion ...Properties...
#region ... Methods ...
/// <summary>
///
/// </summary>
public void InitHeadData(Dictionary<long,HisRunTag> 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++;
}
}
/// <summary>
///
/// </summary>
private void CheckLogDirector()
{
mLogDirector = PathHelper.helper.GetDataPath(mDatabase, "Log");
if(!System.IO.Directory.Exists(mLogDirector))
{
System.IO.Directory.CreateDirectory(mLogDirector);
}
}
/// <summary>
///
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
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"); ;
}
/// <summary>
///
/// </summary>
/// <param name="startTime"></param>
/// <param name="memory"></param>
public void RequestToSave(DateTime startTime,DateTime endTime,CachMemoryBlock memory)
{
mNeedSaveMemory1 = memory;
mStartTime = startTime;
mEndTime = endTime;
resetEvent.Set();
}
/// <summary>
///
/// </summary>
public void Start()
{
mSaveThread = new Thread(SaveProcess);
mSaveThread.IsBackground = true;
mSaveThread.Start();
}
/// <summary>
///
/// </summary>
public void Stop()
{
mIsExit = true;
resetEvent.Set();
closedEvent.WaitOne();
}
/// <summary>
///
/// </summary>
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();
}
/// <summary>
///
/// </summary>
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 );
}
/// <summary>
///
/// </summary>
private void CheckRemoveOldFiles()
{
System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(mLogDirector);
Dictionary<DateTime, string> logFiles = new Dictionary<DateTime, string>();
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...
}
}
...@@ -70,7 +70,7 @@ namespace Cdy.Tag ...@@ -70,7 +70,7 @@ namespace Cdy.Tag
/// <param name="filename"></param> /// <param name="filename"></param>
public override bool CreatOrOpenFile(string filename) public override bool CreatOrOpenFile(string filename)
{ {
this.FileName = filename;
if(System.IO.File.Exists(filename)) if(System.IO.File.Exists(filename))
{ {
mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
...@@ -234,6 +234,46 @@ namespace Cdy.Tag ...@@ -234,6 +234,46 @@ namespace Cdy.Tag
return BitConverter.ToInt32(re, 0); return BitConverter.ToInt32(re, 0);
} }
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <returns></returns>
public override float ReadFloat(long start)
{
mStream.Position = start;
byte[] re = new byte[4];
mStream.Read(re, 0, re.Length);
return MemoryHelper.ReadFloat(re);
}
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <returns></returns>
public override double ReadDouble(long start)
{
mStream.Position = start;
byte[] re = new byte[8];
mStream.Read(re, 0, re.Length);
return MemoryHelper.ReadDouble(re);
}
/// <summary>
///
/// </summary>
/// <param name="start"></param>
/// <param name="len"></param>
/// <returns></returns>
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) public override DateTime ReadDateTime(long start)
{ {
mStream.Position = start; mStream.Position = start;
...@@ -362,6 +402,15 @@ namespace Cdy.Tag ...@@ -362,6 +402,15 @@ namespace Cdy.Tag
} }
} }
public override DataFileSeriserbase CloseAndReOpen()
{
long pos = mStream.Position;
Close();
OpenFile(FileName);
mStream.Position = pos;
return this;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -371,6 +420,7 @@ namespace Cdy.Tag ...@@ -371,6 +420,7 @@ namespace Cdy.Tag
{ {
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
{ {
this.FileName = filename;
mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
return true; return true;
} }
...@@ -386,6 +436,7 @@ namespace Cdy.Tag ...@@ -386,6 +436,7 @@ namespace Cdy.Tag
{ {
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
{ {
this.FileName = filename;
mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); mStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return true; return true;
} }
...@@ -501,6 +552,7 @@ namespace Cdy.Tag ...@@ -501,6 +552,7 @@ namespace Cdy.Tag
return this; return this;
} }
} }
} }
...@@ -635,6 +635,10 @@ namespace Cdy.Tag ...@@ -635,6 +635,10 @@ namespace Cdy.Tag
var vv = ServiceLocator.Locator.Resolve<IHisEngine>(); var vv = ServiceLocator.Locator.Resolve<IHisEngine>();
var tags = vv.ListAllTags().Where(e => e.Id >= Id * TagCountOneFile && e.Id < (Id + 1) * TagCountOneFile).OrderBy(e => e.Id); 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 = 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) //foreach (var vtag in tags)
//{ //{
// mIdAddrs.Add(vtag.Id, offset); // mIdAddrs.Add(vtag.Id, offset);
...@@ -808,11 +812,12 @@ namespace Cdy.Tag ...@@ -808,11 +812,12 @@ namespace Cdy.Tag
//this.mFileWriter.Append(mProcessMemory.Buffers, (int)start, (int)(totalsize - start)); //this.mFileWriter.Append(mProcessMemory.Buffers, (int)start, (int)(totalsize - start));
mFileWriter.Write(mBlockPointMemory.Buffers, pointAddr, 0, (int)mBlockPointMemory.AllocSize); mFileWriter.Write(mBlockPointMemory.Buffers, pointAddr, 0, (int)mBlockPointMemory.AllocSize);
Flush(); Flush();
} }
sw.Stop(); sw.Stop();
LoggerService.Service.Info("SeriseFileItem" + Id, "写入数据 " + mCurrentFileName + " 数据大小:" + ((totalsize - start) + mBlockPointMemory.AllocSize) / 1024.0 / 1024 + " m" +"其他脚本耗时:"+ltmp+","+(ltmp2-ltmp)+","+(ltmp3-ltmp2)+ "存储耗时:" + (sw.ElapsedMilliseconds-ltmp3)); 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) catch(System.IO.IOException ex)
{ {
...@@ -827,6 +832,7 @@ namespace Cdy.Tag ...@@ -827,6 +832,7 @@ namespace Cdy.Tag
public void Flush() public void Flush()
{ {
mFileWriter.Flush(); mFileWriter.Flush();
mFileWriter.CloseAndReOpen();
} }
/// <summary> /// <summary>
......
...@@ -100,7 +100,7 @@ namespace Cdy.Tag ...@@ -100,7 +100,7 @@ namespace Cdy.Tag
{ {
mBusyCount++; mBusyCount++;
if(Id==0) if(Id==0)
LoggerService.Service.Warn("Record", "TimerMemoryCacheProcesser 出现阻塞:"+mBusyCount); LoggerService.Service.Warn("Record", "TimerMemoryCacheProcesser"+Id+" 出现阻塞:"+mBusyCount);
} }
else else
{ {
...@@ -126,6 +126,7 @@ namespace Cdy.Tag ...@@ -126,6 +126,7 @@ namespace Cdy.Tag
public void Stop() public void Stop()
{ {
mIsClosed = true; mIsClosed = true;
resetEvent.Set();
closedEvent.WaitOne(1000); closedEvent.WaitOne(1000);
} }
......
...@@ -128,6 +128,7 @@ namespace Cdy.Tag ...@@ -128,6 +128,7 @@ namespace Cdy.Tag
public void Stop() public void Stop()
{ {
mIsClosed = true; mIsClosed = true;
resetEvent.Set();
closedEvent.WaitOne(1000); closedEvent.WaitOne(1000);
} }
......
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace DBRuntime.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 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() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[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;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找类似 database &apos;{0}&apos; is not exist! 的本地化字符串。
/// </summary>
internal static string databasenotexist {
get {
return ResourceManager.GetString("databasenotexist", resourceCulture);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="databasenotexist" xml:space="preserve">
<value>database '{0}' is not exist!</value>
</data>
</root>
\ No newline at end of file
...@@ -174,6 +174,8 @@ namespace Cdy.Tag ...@@ -174,6 +174,8 @@ namespace Cdy.Tag
mMemory = new byte[mUsedSize]; mMemory = new byte[mUsedSize];
mMHandle = mMemory.AsMemory().Pin().Pointer; 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) foreach (var vv in mConfigDatabase.Tags)
{ {
switch (vv.Value.Type) switch (vv.Value.Type)
......
//==============================================================
// 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);
}
}
}
...@@ -105,11 +105,22 @@ namespace Cdy.Tag ...@@ -105,11 +105,22 @@ namespace Cdy.Tag
PathHelper.helper.CheckDataPathExist(); PathHelper.helper.CheckDataPathExist();
} }
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private bool CheckDatabaseExist(string name)
{
return System.IO.File.Exists(PathHelper.helper.GetDataPath(name, name + ".db"));
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
private void LoadDatabase() private void LoadDatabase()
{ {
this.mDatabase = new DatabaseSerise().Load(mDatabaseName); this.mDatabase = new DatabaseSerise().Load(mDatabaseName);
this.mRealDatabase = this.mDatabase.RealDatabase; this.mRealDatabase = this.mDatabase.RealDatabase;
this.mHisDatabase = this.mDatabase.HisDatabase; this.mHisDatabase = this.mDatabase.HisDatabase;
...@@ -119,8 +130,9 @@ namespace Cdy.Tag ...@@ -119,8 +130,9 @@ namespace Cdy.Tag
/// ///
/// </summary> /// </summary>
/// <param name="database"></param> /// <param name="database"></param>
private async Task InitAsync(string database) private async Task<bool> InitAsync(string database)
{ {
if (System.IO.Path.IsPathRooted(database)) if (System.IO.Path.IsPathRooted(database))
{ {
this.mDatabaseName = System.IO.Path.GetFileNameWithoutExtension(database); this.mDatabaseName = System.IO.Path.GetFileNameWithoutExtension(database);
...@@ -132,35 +144,47 @@ namespace Cdy.Tag ...@@ -132,35 +144,47 @@ namespace Cdy.Tag
} }
InitPath(); InitPath();
LoadDatabase(); if (CheckDatabaseExist(mDatabaseName))
{
LoadDatabase();
mHisFileManager = new DataFileManager(mDatabaseName); mHisFileManager = new DataFileManager(mDatabaseName);
mHisFileManager.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; mHisFileManager.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile;
var task = mHisFileManager.Int(); var task = mHisFileManager.Int();
realEnginer = new RealEnginer(mRealDatabase); realEnginer = new RealEnginer(mRealDatabase);
realEnginer.Init(); realEnginer.Init();
hisEnginer = new HisEnginer(mHisDatabase, realEnginer); hisEnginer = new HisEnginer(mHisDatabase, realEnginer);
hisEnginer.MergeMemoryTime = mHisDatabase.Setting.DataBlockDuration * 60; hisEnginer.MergeMemoryTime = mHisDatabase.Setting.DataBlockDuration * 60;
hisEnginer.Init(); hisEnginer.LogManager = new LogManager() { Database = mDatabaseName };
hisEnginer.Init();
compressEnginer = new CompressEnginer(hisEnginer.MegerMemorySize); compressEnginer = new CompressEnginer(hisEnginer.MegerMemorySize);
compressEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; compressEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile;
seriseEnginer = new SeriseEnginer() { DatabaseName = database }; seriseEnginer = new SeriseEnginer() { DatabaseName = database };
seriseEnginer.FileDuration = mHisDatabase.Setting.FileDataDuration; seriseEnginer.FileDuration = mHisDatabase.Setting.FileDataDuration;
seriseEnginer.BlockDuration = mHisDatabase.Setting.DataBlockDuration; seriseEnginer.BlockDuration = mHisDatabase.Setting.DataBlockDuration;
seriseEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile; seriseEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile;
seriseEnginer.DataSeriser = mHisDatabase.Setting.DataSeriser; 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 ...@@ -207,7 +231,11 @@ namespace Cdy.Tag
public async void StartAsync(string database) public async void StartAsync(string database)
{ {
LoggerService.Service.Info("Runner", " 数据库 " + database+" 开始启动"); LoggerService.Service.Info("Runner", " 数据库 " + database+" 开始启动");
await InitAsync(database); var re = await InitAsync(database);
if (!re)
{
return;
}
seriseEnginer.Start(); seriseEnginer.Start();
compressEnginer.Start(); compressEnginer.Start();
hisEnginer.Start(); hisEnginer.Start();
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
<DataGridTemplateColumn.CellEditingTemplate> <DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBox Margin="0,0" Padding="4,0" IsEnabled="{Binding IsEnableEdit}" BorderThickness="0" Text="{Binding GroupString,Mode=TwoWay,UpdateSourceTrigger=LostFocus}" VerticalAlignment="Stretch" VerticalContentAlignment="Center" /> <TextBox Margin="0,0" Padding="4,0" IsEnabled="{Binding IsEnableEdit}" MinWidth="100" BorderThickness="0" Text="{Binding GroupString,Mode=TwoWay,UpdateSourceTrigger=LostFocus}" VerticalAlignment="Stretch" VerticalContentAlignment="Center" />
<Button Margin="10,0,0,0" Content="..." IsEnabled="{Binding IsEnableEdit}" VerticalContentAlignment="Top" Command="{Binding GroupEditCommand}" /> <Button Margin="10,0,0,0" Content="..." IsEnabled="{Binding IsEnableEdit}" VerticalContentAlignment="Top" Command="{Binding GroupEditCommand}" />
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
......
...@@ -25,6 +25,8 @@ namespace SimDriver ...@@ -25,6 +25,8 @@ namespace SimDriver
private StreamWriter mWriter; private StreamWriter mWriter;
private DateTime mLastProcessTime = DateTime.Now;
#endregion ...Variables... #endregion ...Variables...
#region ... Events ... #region ... Events ...
...@@ -41,6 +43,9 @@ namespace SimDriver ...@@ -41,6 +43,9 @@ namespace SimDriver
mWriter = new StreamWriter( System.IO.File.Open(vfile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)); mWriter = new StreamWriter( System.IO.File.Open(vfile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite));
} }
#endregion ...Constructor... #endregion ...Constructor...
#region ... Properties ... #region ... Properties ...
...@@ -92,7 +97,7 @@ namespace SimDriver ...@@ -92,7 +97,7 @@ namespace SimDriver
{ {
mTagService = tagQuery; mTagService = tagQuery;
InitTagCach(tagQuery); InitTagCach(tagQuery);
mScanTimer = new System.Timers.Timer(1000); mScanTimer = new System.Timers.Timer(100);
mScanTimer.Elapsed += MScanTimer_Elapsed; mScanTimer.Elapsed += MScanTimer_Elapsed;
mScanTimer.Start(); mScanTimer.Start();
return true; return true;
...@@ -105,12 +110,19 @@ namespace SimDriver ...@@ -105,12 +110,19 @@ namespace SimDriver
/// <param name="e"></param> /// <param name="e"></param>
private void MScanTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void MScanTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
if (mIsBusy) if (mIsBusy)
{ {
LoggerService.Service.Warn("Sim Driver", "出现阻塞"); LoggerService.Service.Warn("Sim Driver", "出现阻塞");
return; return;
} }
mIsBusy = true; mIsBusy = true;
DateTime time = DateTime.Now;
if ((time - mLastProcessTime).Seconds < 1)
{
return;
}
mLastProcessTime = time;
mNumber++; mNumber++;
mNumber = mNumber > (short)360 ? (short)0 : mNumber; mNumber = mNumber > (short)360 ? (short)0 : mNumber;
...@@ -122,7 +134,7 @@ namespace SimDriver ...@@ -122,7 +134,7 @@ namespace SimDriver
double sval = Math.Sin(mNumber / 180.0 * Math.PI); double sval = Math.Sin(mNumber / 180.0 * Math.PI);
Log("Sim:Sin " + fval + " " + "Sim:Cos " + sval + " "+ "Sim:step " + mNumber +" "+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); Log("Sim:Sin " + fval + " " + "Sim:Cos " + sval + " "+ "Sim:step " + mNumber +" "+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
foreach (var vv in mTagIdCach) foreach (var vv in mTagIdCach)
{ {
if (vv.Key == "Sim:cos") if (vv.Key == "Sim:cos")
...@@ -138,6 +150,22 @@ namespace SimDriver ...@@ -138,6 +150,22 @@ namespace SimDriver
mTagService.SetTagValue(vv.Value, mNumber); mTagService.SetTagValue(vv.Value, mNumber);
} }
} }
//System.Threading.Tasks.Parallel.ForEach(mTagIdCach, (vv) => {
// if (vv.Key == "Sim:cos")
// {
// mTagService.SetTagValue(vv.Value, fval);
// }
// else if (vv.Key == "Sim:sin")
// {
// mTagService.SetTagValue(vv.Value, sval);
// }
// else if (vv.Key == "Sim:step")
// {
// mTagService.SetTagValue(vv.Value, mNumber);
// }
//});
//#if DEBUG //#if DEBUG
// sw.Stop(); // sw.Stop();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册