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

tt

上级 1a5e7a8d
......@@ -26,16 +26,22 @@ namespace Cdy.Tag
/// </summary>
private byte[] mDataBuffer;
private List<byte[]> mBuffers;
/// <summary>
///
/// </summary>
private void* handle;
private List<IntPtr> mHandles;
/// <summary>
///
/// </summary>
private long mPosition = 0;
public const int BufferItemSize = 1024 * 1024 * 500;
#endregion ...Variables...
#region ... Events ...
......@@ -59,9 +65,22 @@ namespace Cdy.Tag
/// <param name="size"></param>
public MemoryBlock(long size)
{
mDataBuffer = new byte[size];
// handle = mDataBuffer.AsMemory().Pin().Pointer;
handle = (void*)System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mDataBuffer, 0);
int count = (int)(size / BufferItemSize) + 1;
mBuffers = new List<byte[]>(count);
for(int i=0;i<count;i++)
{
mBuffers.Add(new byte[BufferItemSize]);
}
mHandles = new List<IntPtr>();
for (int i = 0; i < count; i++)
{
mHandles.Add(System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mBuffers[i], 0));
}
mDataBuffer = mBuffers[0];
// handle = (void*)System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mDataBuffer, 0);
}
#endregion ...Constructor...
......@@ -71,11 +90,19 @@ namespace Cdy.Tag
/// <summary>
///
/// </summary>
public byte[] Memory
public byte[] StartMemory
{
get
{
return mBuffers[0];
}
}
public byte[] EndMemory
{
get
{
return mDataBuffer;
return mBuffers[0];
}
}
......@@ -92,7 +119,7 @@ namespace Cdy.Tag
{
get
{
return mDataBuffer.Length;
return mBuffers.Count* BufferItemSize;
}
}
......@@ -119,9 +146,12 @@ namespace Cdy.Tag
///
/// </summary>
/// <returns></returns>
public MemoryStream GetStream()
public IEnumerable<MemoryStream> GetStream()
{
return new MemoryStream(mDataBuffer);
foreach(var vv in mBuffers)
{
yield return new MemoryStream(vv);
}
}
/// <summary>
......@@ -130,7 +160,16 @@ namespace Cdy.Tag
/// <param name="size"></param>
public void ReAlloc(long size)
{
mDataBuffer = new byte[size];
int count = (int)(size / BufferItemSize) + 1;
mBuffers = new List<byte[]>(count);
for (int i = 0; i < count; i++)
{
mBuffers.Add(new byte[BufferItemSize]);
}
for (int i = 0; i < count; i++)
{
mHandles.Add(System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mBuffers[i], 0));
}
GC.Collect();
}
......@@ -140,10 +179,40 @@ namespace Cdy.Tag
/// <param name="size"></param>
public void Resize(long size)
{
var newMemory = new byte[size];
Buffer.BlockCopy(mDataBuffer, 0, newMemory, 0, Math.Min(mDataBuffer.Length, newMemory.Length));
mDataBuffer = newMemory;
handle = (void*)System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mDataBuffer, 0);
int count = (int)(size / BufferItemSize) + 1;
List<byte[]> nBuffers = new List<byte[]>(count);
if (count > mBuffers.Count)
{
int i = 0;
for (i = 0; i < mBuffers.Count; i++)
{
nBuffers[i] = mBuffers[i];
}
for(int j=i;j<count;j++)
{
mBuffers[j] = new byte[BufferItemSize];
}
}
else if (count < mBuffers.Count)
{
for(int i=0;i<count;i++)
{
nBuffers[i] = mBuffers[i];
}
}
mBuffers = nBuffers;
mHandles = new List<IntPtr>();
for (int i = 0; i < count; i++)
{
mHandles.Add(System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mBuffers[i], 0));
}
//var newMemory = new byte[size];
//Buffer.BlockCopy(mDataBuffer, 0, newMemory, 0, Math.Min(mDataBuffer.Length, newMemory.Length));
//mDataBuffer = newMemory;
//handle = (void*)System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mDataBuffer, 0);
GC.Collect();
}
......@@ -152,11 +221,59 @@ namespace Cdy.Tag
/// </summary>
public void Clear()
{
Array.Clear(mDataBuffer, 0, mDataBuffer.Length);
foreach (var vv in mBuffers)
Array.Clear(vv, 0, vv.Length);
}
#region ReadAndWrite
/// <summary>
///
/// </summary>
/// <param name="position"></param>
/// <param name="size"></param>
/// <param name="innerAddr"></param>
/// <param name="offset"></param>
/// <param name="curposition"></param>
private void GetInnerLocation(long position, int size, out IntPtr innerAddr, out long offset,out long curposition)
{
offset = position % BufferItemSize;
int id = (int)(position / BufferItemSize);
if (offset + size >= BufferItemSize)
{
//如果发现数据正好跨数据块了,则跳过块到下一个区块
id += 1;
offset = offset + size - BufferItemSize;
}
innerAddr = mHandles[id];
curposition = id * BufferItemSize + offset;
}
/// <summary>
///
/// </summary>
/// <param name="position"></param>
/// <param name="size"></param>
/// <param name="innerAddr"></param>
/// <param name="offset"></param>
private void GetDataLocation(long position, int size, out IntPtr innerAddr, out long offset)
{
offset = position % BufferItemSize;
int id = (int)(position / BufferItemSize);
innerAddr = mHandles[id];
}
/// <summary>
/// 数据是否跨数据块
/// </summary>
/// <param name="position"></param>
/// <param name="size"></param>
/// <returns></returns>
private bool IsTransDataBuffer(long position, int size)
{
return (position % BufferItemSize) + size >= BufferItemSize;
}
/// <summary>
///
/// </summary>
......@@ -296,8 +413,18 @@ namespace Cdy.Tag
/// <param name="value"></param>
public void WriteLong(long offset, long value)
{
MemoryHelper.WriteInt64(handle, offset, value);
mPosition = offset + sizeof(long);
IntPtr hd;
long ost;
if (IsTransDataBuffer(offset,8))
{
WriteBytes(offset, BitConverter.GetBytes(value));
}
else
{
GetDataLocation(offset, 8, out hd, out ost);
MemoryHelper.WriteInt64((void*)hd, ost, value);
}
mPosition = offset + 8;
}
/// <summary>
......@@ -307,8 +434,18 @@ namespace Cdy.Tag
/// <param name="value"></param>
public void WriteULong(long offset, ulong value)
{
MemoryHelper.WriteUInt64(handle, offset, value);
mPosition = offset + sizeof(ulong);
IntPtr hd;
long ost;
if (IsTransDataBuffer(offset, 8))
{
WriteBytes(offset, BitConverter.GetBytes(value));
}
else
{
GetDataLocation(offset, 8, out hd, out ost);
MemoryHelper.WriteUInt64((void*)hd, ost, value);
}
mPosition = offset + 8;
}
/// <summary>
......@@ -318,8 +455,18 @@ namespace Cdy.Tag
/// <param name="value"></param>
public void WriteFloat(long offset, float value)
{
MemoryHelper.WriteFloat(handle, offset, value);
mPosition = offset + sizeof(float);
IntPtr hd;
long ost;
if (IsTransDataBuffer(offset, 4))
{
WriteBytes(offset, BitConverter.GetBytes(value));
}
else
{
GetDataLocation(offset, 8, out hd, out ost);
MemoryHelper.WriteFloat((void*)hd, ost, value);
}
mPosition = offset + 4;
}
/// <summary>
......@@ -329,8 +476,18 @@ namespace Cdy.Tag
/// <param name="value"></param>
public void WriteDouble(long offset, double value)
{
MemoryHelper.WriteDouble(handle, offset, value);
mPosition = offset + sizeof(double);
IntPtr hd;
long ost;
if (IsTransDataBuffer(offset, 8))
{
WriteBytes(offset, BitConverter.GetBytes(value));
}
else
{
GetDataLocation(offset, 8, out hd, out ost);
MemoryHelper.WriteDouble((void*)hd, ost, value);
}
mPosition = offset + 8;
}
/// <summary>
......@@ -340,44 +497,86 @@ namespace Cdy.Tag
/// <param name="values"></param>
public void WriteBytes(long offset,byte[] values)
{
mPosition = offset + values.Length;
Buffer.BlockCopy(values, 0, this.mDataBuffer, (int)offset, values.Length);
WriteBytes(offset, values, 0, values.Length);
}
/// <summary>
///
/// </summary>
/// <param name="offset"></param>
/// <param name="value"></param>
public void WriteByte(long offset, byte value)
/// <param name="values"></param>
/// <param name="valueoffset"></param>
/// <param name="len"></param>
public void WriteBytes(long offset, byte[] values, int valueoffset, int len)
{
mPosition = offset + 1;
this.mDataBuffer[offset] = value;
int id = (int)(offset / BufferItemSize);
long ost = offset % BufferItemSize;
if (len + ost < BufferItemSize)
{
Buffer.BlockCopy(values, valueoffset, mBuffers[id], (int)ost, len);
}
else
{
int ll = BufferItemSize - (int)ost;
Buffer.BlockCopy(values, valueoffset, mBuffers[id], (int)ost, ll);
if (len - ll < BufferItemSize)
{
id++;
Buffer.BlockCopy(values, ll+ valueoffset, mBuffers[id], 0, len - ll);
}
else
{
long ltmp = len - ll;
int bcount = ll / BufferItemSize;
int i = 0;
for (i = 0; i < bcount; i++)
{
id++;
Buffer.BlockCopy(values, valueoffset+ll + i * BufferItemSize, mBuffers[id], 0, BufferItemSize);
}
int otmp = ll % BufferItemSize;
if (otmp > 0)
{
id++;
Buffer.BlockCopy(values, valueoffset+ll + i * BufferItemSize, mBuffers[id], 0, otmp);
}
}
}
mPosition = offset + len;
// Buffer.BlockCopy(values, valueoffset, this.mDataBuffer, (int)offset, len);
}
/// <summary>
///
/// </summary>
/// <param name="offset"></param>
/// <param name="value"></param>
public void WriteByte(byte value)
public void WriteByte(long offset, byte value)
{
WriteByte(mPosition, value);
IntPtr hd;
long ost;
GetDataLocation(offset, 1, out hd, out ost);
MemoryHelper.WriteByte((void*)hd, ost, value);
mPosition = offset + 1;
}
/// <summary>
///
/// </summary>
/// <param name="offset"></param>
/// <param name="values"></param>
/// <param name="valueoffset"></param>
/// <param name="len"></param>
public void WriteBytes(long offset, byte[] values,int valueoffset,int len)
/// <param name="value"></param>
public void WriteByte(byte value)
{
mPosition = offset + len;
Buffer.BlockCopy(values, valueoffset, this.mDataBuffer, (int)offset, len);
WriteByte(mPosition, value);
}
/// <summary>
///
/// </summary>
......@@ -385,8 +584,20 @@ namespace Cdy.Tag
/// <param name="value"></param>
public void WriteDatetime(long offset, DateTime value)
{
MemoryHelper.WriteDateTime(handle, offset, value);
mPosition = offset + sizeof(DateTime);
IntPtr hd;
long ost;
if (IsTransDataBuffer(offset, 8))
{
WriteBytes(offset, MemoryHelper.GetBytes(value));
}
else
{
GetDataLocation(offset, 8, out hd, out ost);
MemoryHelper.WriteDateTime((void*)hd, ost, value);
}
mPosition = offset + 8;
}
/// <summary>
///
......@@ -895,7 +1106,7 @@ namespace Cdy.Tag
public static void MakeMemoryBusy(this MemoryBlock memory)
{
memory.IsBusy = true;
memory.Memory[0] = 1;
memory.StartMemory[0] = 1;
}
/// <summary>
......@@ -905,7 +1116,7 @@ namespace Cdy.Tag
public static void MakeMemoryNoBusy(this MemoryBlock memory)
{
memory.IsBusy = false;
memory.Memory[0] = 0;
memory.StartMemory[0] = 0;
}
}
......
......@@ -310,6 +310,19 @@ namespace Cdy.Tag
}
}
/// <summary>
///
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static unsafe byte[] GetBytes(DateTime date)
{
byte[] bval = new byte[8];
var ptr = (IntPtr)System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(bval, 0);
WriteDateTime((void*)ptr, 0, date);
return bval;
}
/// <summary>
///
/// </summary>
......
......@@ -5,3 +5,4 @@ D:\Project\Galaxy\Cdy.Tag.Common\obj\Debug\netstandard2.0\Cdy.Tag.Common.Assembl
D:\Project\Galaxy\Cdy.Tag.Common\obj\Debug\netstandard2.0\Cdy.Tag.Common.AssemblyInfo.cs
D:\Project\Galaxy\Cdy.Tag.Common\obj\Debug\netstandard2.0\Cdy.Tag.Common.dll
D:\Project\Galaxy\Cdy.Tag.Common\obj\Debug\netstandard2.0\Cdy.Tag.Common.pdb
D:\Project\Galaxy\Cdy.Tag.Common\obj\Debug\netstandard2.0\Cdy.Tag.Common.csprojAssemblyReference.cache
......@@ -5,3 +5,4 @@ D:\Project\Galaxy\Cdy.Tag.CoreAPI\obj\Debug\netcoreapp3.1\Cdy.Tag.CoreAPI.Assemb
D:\Project\Galaxy\Cdy.Tag.CoreAPI\obj\Debug\netcoreapp3.1\Cdy.Tag.CoreAPI.AssemblyInfo.cs
D:\Project\Galaxy\Cdy.Tag.CoreAPI\obj\Debug\netcoreapp3.1\Cdy.Tag.CoreAPI.dll
D:\Project\Galaxy\Cdy.Tag.CoreAPI\obj\Debug\netcoreapp3.1\Cdy.Tag.CoreAPI.pdb
D:\Project\Galaxy\Cdy.Tag.CoreAPI\obj\Debug\netcoreapp3.1\Cdy.Tag.CoreAPI.csprojAssemblyReference.cache
......@@ -43,6 +43,9 @@ namespace Cdy.Tag
/// </summary>
public int MaxId { get; set; }
/// <summary>
///
/// </summary>
private Dictionary<string,Tagbase> NamedTags { get; set; }
/// <summary>
......@@ -364,17 +367,16 @@ namespace Cdy.Tag
/// <param name="groupName">组名称,多级组之间通过"."分割</param>
public TagGroup CheckAndAddGroup(string groupName)
{
if (string.IsNullOrEmpty(groupName)) return null;
if (!Groups.ContainsKey(groupName))
{
if (string.IsNullOrEmpty(groupName)) return null;
TagGroup parent = null;
if (groupName.LastIndexOf(".") > 0)
{
string sparentName = groupName.Substring(0, groupName.LastIndexOf("."));
parent = CheckAndAddGroup(sparentName);
}
TagGroup tg = new TagGroup() { Parent = parent };
TagGroup tg = new TagGroup() { Parent = parent,Name = groupName };
Groups.Add(tg.FullName, tg);
return tg;
}
......
......@@ -99,7 +99,7 @@ namespace Cdy.Tag
foreach(var vv in db.Groups.Values)
{
if(db.Groups.ContainsKey(vv.ParentName))
if(!string.IsNullOrEmpty(vv.ParentName) && db.Groups.ContainsKey(vv.ParentName))
{
vv.Parent = db.Groups[vv.ParentName];
}
......@@ -116,7 +116,7 @@ namespace Cdy.Tag
/// <param name="name"></param>
public void SaveAs(string name)
{
Save(PathHelper.helper.GetDataPath(name + ".xdb"));
Save(PathHelper.helper.GetDataPath(name + "/" + name + ".xdb"));
}
/// <summary>
......@@ -124,7 +124,7 @@ namespace Cdy.Tag
/// </summary>
public void Save()
{
Save(PathHelper.helper.GetDataPath(this.Database.Name+".xdb"));
Save(PathHelper.helper.GetDataPath(this.Database.Name + ".xdb"));
}
/// <summary>
......@@ -151,6 +151,11 @@ namespace Cdy.Tag
}
doc.Add(xe);
string sd = System.IO.Path.GetDirectoryName(sfile);
if(!System.IO.Directory.Exists(sd))
{
System.IO.Directory.CreateDirectory(sd);
}
doc.Save(sfile);
}
......
......@@ -31,7 +31,7 @@ namespace Cdy.Tag
/// <summary>
///
/// </summary>
public string FullName { get { return Parent != null ? Name : Parent.FullName + "." + Name; } }
public string FullName { get { return Parent == null ? Name : Parent.FullName + "." + Name; } }
/// <summary>
/// 用作加载时,建立父子关系
......@@ -46,7 +46,7 @@ namespace Cdy.Tag
/// <summary>
///
/// </summary>
public List<Tagbase> Tags { get; set; }
public List<Tagbase> Tags { get; set; } = new List<Tagbase>();
/// <summary>
///
......@@ -83,8 +83,9 @@ namespace Cdy.Tag
{
XElement xe = new XElement("TagGroup");
xe.SetAttributeValue("Name", group.Name);
if(group.Parent!=null)
xe.SetAttributeValue("Parent", group.Parent.FullName);
xe.SetAttributeValue("FullName", group.FullNameString);
xe.SetAttributeValue("FullName", group.FullName);
return xe;
}
......@@ -97,6 +98,7 @@ namespace Cdy.Tag
{
TagGroup group = new TagGroup();
group.Name = xe.Attribute("Name").Value;
if(xe.Attribute("Parent") !=null)
group.ParentName = xe.Attribute("Parent").Value;
group.FullNameString = xe.Attribute("FullName").Value;
return group;
......
......@@ -63,7 +63,7 @@ namespace Cdy.Tag
XElement xe = new XElement("Tag");
xe.SetAttributeValue("Id", tag.Id);
xe.SetAttributeValue("Name", tag.Name);
xe.SetAttributeValue("Type", tag.Type);
xe.SetAttributeValue("Type", (int)tag.Type);
xe.SetAttributeValue("Group", tag.Group);
xe.SetAttributeValue("Desc", tag.Desc);
xe.SetAttributeValue("LinkAddress", tag.LinkAddress);
......@@ -75,7 +75,7 @@ namespace Cdy.Tag
TagType tp = (TagType)int.Parse(xe.Attribute("Type").Value);
Tagbase re = null;
switch(tp)
switch (tp)
{
case TagType.Bool:
re = new BoolTag();
......@@ -110,9 +110,9 @@ namespace Cdy.Tag
}
re.Id = int.Parse(xe.Attribute("Id").Value);
re.Name = xe.Attribute("Name").Value;
re.Group = xe.Attribute("Group").Value;
re.Desc = xe.Attribute("Desc").Value;
re.LinkAddress = xe.Attribute("LinkAddress").Value;
re.Group = xe.Attribute("Group")!=null? xe.Attribute("Group").Value:"";
re.Desc = xe.Attribute("Desc") != null ? xe.Attribute("Desc").Value : "";
re.LinkAddress = xe.Attribute("LinkAddress") != null ? xe.Attribute("LinkAddress").Value : "";
return re;
}
}
......
......@@ -109,7 +109,7 @@ namespace Cdy.Tag
/// <param name="name"></param>
public void SaveAs(string name)
{
Save(PathHelper.helper.GetDataPath(name + ".hdb"));
Save(PathHelper.helper.GetDataPath(name+"/"+ name + ".hdb"));
}
/// <summary>
......
......@@ -43,12 +43,12 @@ namespace Cdy.Tag
/// 单个数据块保存数据的时长
/// 单位分钟
/// </summary>
public int DataBlockDuration { get; set; } = 5;
public int DataBlockDuration { get; set; } = 1;
/// <summary>
/// 数据序列化类型
/// </summary>
public string DataSeriser { get; set; }
public string DataSeriser { get; set; } = "LocalFile";
#endregion ...Properties...
......
......@@ -26,6 +26,8 @@ namespace Cdy.Tag
public static PathHelper helper = new PathHelper();
private string mDatabaseName;
#endregion ...Variables...
#region ... Events ...
......@@ -63,7 +65,11 @@ namespace Cdy.Tag
}
else
{
this.mDataPath = System.IO.Path.Combine(mDataPath, path);
if (mDatabaseName != path)
{
mDatabaseName = path;
this.mDataPath = System.IO.Path.Combine(mDataPath, path);
}
}
}
......
......@@ -5,3 +5,4 @@ D:\Project\Galaxy\Cdy.Tag\obj\Debug\netstandard2.0\Cdy.Tag.AssemblyInfoInputs.ca
D:\Project\Galaxy\Cdy.Tag\obj\Debug\netstandard2.0\Cdy.Tag.AssemblyInfo.cs
D:\Project\Galaxy\Cdy.Tag\obj\Debug\netstandard2.0\Cdy.Tag.dll
D:\Project\Galaxy\Cdy.Tag\obj\Debug\netstandard2.0\Cdy.Tag.pdb
D:\Project\Galaxy\Cdy.Tag\obj\Debug\netstandard2.0\Cdy.Tag.csprojAssemblyReference.cache
......@@ -34,7 +34,7 @@ namespace Cdy.Tag
/// 每个变量在内存中保留的历史记录历史的长度
/// 单位s
/// </summary>
public int MemoryCachTime = 60 * 5;
public int MemoryCachTime = 60 * 1;
/// <summary>
/// 历史记录时间最短间隔
......@@ -133,7 +133,7 @@ namespace Cdy.Tag
set
{
mCurrentMemory = value;
HisRunTag.HisAddr = mCurrentMemory.Memory;
HisRunTag.HisAddr = mCurrentMemory.StartMemory;
}
}
......@@ -225,7 +225,7 @@ namespace Cdy.Tag
/// 块标题大小
/// </summary>
/// <returns></returns>
private int CalHeadSize()
private long CalHeadSize()
{
//Flag + DateTime + Data Count+MemoryCachTime+MemoryTimeTick + 变量ID,数据偏移地址,数据大小
//Flag 表示 0:空闲,1:忙
......@@ -286,14 +286,14 @@ namespace Cdy.Tag
/// </summary>
private void AllocMemory()
{
int headSize = CalHeadSize();
long headSize = CalHeadSize();
int blockheadsize = CalBlockHeadSize();
int qulityoffset = 0;
foreach(var vv in mHisTags)
{
var ss = CalBlockSize(vv.Value.TagType, out qulityoffset);
vv.Value.HisValueStartAddr = headSize + blockheadsize;
vv.Value.BlockHeadStartAddr = headSize;
vv.Value.HisValueStartAddr = (int)headSize + blockheadsize;
vv.Value.BlockHeadStartAddr = (int)headSize;
vv.Value.HisQulityStartAddr = qulityoffset;
vv.Value.DataSize = ss;
headSize += ss;
......
......@@ -3145,7 +3145,7 @@ namespace Cdy.Tag
dataoffset += 4;
using (var dd = datafile.Read(dataoffset, dsize))
{
VarintCodeMemory vcm = new VarintCodeMemory(dd.Memory);
VarintCodeMemory vcm = new VarintCodeMemory(dd.StartMemory);
var ltmp = vcm.ToIntList();
var dtmp = new Dictionary<int, long>();
for (int i = 0; i < ltmp.Count; i++)
......
......@@ -122,7 +122,7 @@ namespace Cdy.Tag
{
MemoryBlock re = new MemoryBlock(len);
mStream.Position = start;
mStream.Write(re.Memory, 0, len);
mStream.Write(re.StartMemory, 0, len);
return re;
}
......
......@@ -311,7 +311,7 @@ namespace Cdy.Tag
private void AppendFileHeader()
{
GeneratorFileHeader();
mFileWriter.Append(mHeadMemory.Memory, 0, mHeadMemory.Length);
mFileWriter.Append(mHeadMemory.StartMemory, 0, mHeadMemory.Length);
var cp = mFileWriter.CurrentPostion;
if(mCurrentDataRegion>=0)
......@@ -443,7 +443,7 @@ namespace Cdy.Tag
offset = 16;
int start = count * 8 + offset;
var pos = this.mFileWriter.CurrentPostion;
this.mFileWriter.Append(mProcessMemory.Memory, start, totalsize - start);
this.mFileWriter.Append(mProcessMemory.StartMemory, start, totalsize - start);
long preaddr = 0;
for (int i = 0; i < count; i++)
......
......@@ -111,9 +111,11 @@ namespace Cdy.Tag
public void Init()
{
long msize = 0;
foreach(var vv in mConfigDatabase.Tags)
mIdAndAddr.Clear();
foreach (var vv in mConfigDatabase.Tags)
{
vv.Value.ValueAddress = msize;
mIdAndAddr.Add(vv.Value.Id, vv.Value.ValueAddress);
switch (vv.Value.Type)
{
case TagType.Bool:
......
......@@ -173,6 +173,8 @@ namespace Cdy.Tag
ServiceLocator.Locator.Registor<IDataSerialize>(seriseEnginer);
ServiceLocator.Locator.Registor<IHisQuery>(querySerivce);
ServiceLocator.Locator.Registor<ITagQuery>(mDatabase);
}
/// <summary>
......
......@@ -6,7 +6,7 @@ namespace Mars
{
static void Main(string[] args)
{
if(args[0]== "start")
if(args.Length>0 && args[0]== "start")
{
if (args.Length > 1)
{
......@@ -17,11 +17,12 @@ namespace Mars
Cdy.Tag.Runner.RunInstance.Start();
}
}
Console.WriteLine("输入h获取命令帮助信息");
while (true)
{
string cmd = Console.ReadLine();
if(cmd == "exit")
Console.Write(">");
string[] cmd = Console.ReadLine().Split(new string[] { " " },StringSplitOptions.RemoveEmptyEntries);
if(cmd[0] == "exit")
{
if(Cdy.Tag.Runner.RunInstance.IsStarted)
{
......@@ -29,22 +30,94 @@ namespace Mars
}
break;
}
else if(cmd=="start")
else if(cmd[0] == "start")
{
if (args.Length > 0)
if (cmd.Length > 1)
{
Cdy.Tag.Runner.RunInstance.StartAsync(args[0]);
Cdy.Tag.Runner.RunInstance.StartAsync(cmd[1]);
}
else
{
Cdy.Tag.Runner.RunInstance.Start();
}
}
else if(cmd == "stop")
else if(cmd[0] == "stop")
{
Cdy.Tag.Runner.RunInstance.Stop();
}
else if(cmd[0] == "gd")
{
switch(cmd.Length)
{
case 1:
GeneratorTestDatabase("local");
break;
case 2:
GeneratorTestDatabase(cmd[1]);
break;
case 3:
GeneratorTestDatabase(cmd[1], int.Parse(cmd[2]));
break;
case 4:
GeneratorTestDatabase(cmd[1], int.Parse(cmd[2]), int.Parse(cmd[3]));
break;
case 5:
GeneratorTestDatabase(cmd[1], int.Parse(cmd[2]), int.Parse(cmd[3]), int.Parse(cmd[4]));
break;
}
}
else if(cmd[0]=="h")
{
}
}
}
static void GeneratorTestDatabase(string databaseName,int dcount=100000,int icount=100000,int bcount=100000)
{
Cdy.Tag.PathHelper.helper.SetDataBasePath(databaseName);
Cdy.Tag.Database test = new Cdy.Tag.Database() { Name = databaseName };
for(int i=0;i<dcount;i++)
{
test.Append(new Cdy.Tag.DoubleTag() { Name = "Double" + i ,Group="Double"});
}
for (int i = 0; i < icount; i++)
{
test.Append(new Cdy.Tag.IntTag() { Name = "Int" + i, Group = "Int" });
}
for (int i = 0; i < bcount; i++)
{
test.Append(new Cdy.Tag.BoolTag() { Name = "Int" + i, Group = "Bool" });
}
new Cdy.Tag.DatabaseManager() { Database = test }.Save();
Cdy.Tag.HisDatabase htest = new Cdy.Tag.HisDatabase() { Name = databaseName,Setting = new Cdy.Tag.HisSettingDoc() };
int id = 0;
for (int i = 0; i < dcount; i++)
{
htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Double, Circle = 1000,Type = Cdy.Tag.RecordType.Timer });
id++;
}
for (int i = 0; i < icount; i++)
{
htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Int, Circle = 1000, Type = Cdy.Tag.RecordType.Timer });
id++;
}
for (int i = 0; i < bcount; i++)
{
htest.AddHisTags(new Cdy.Tag.HisTag() { Id = id, TagType = Cdy.Tag.TagType.Bool, Circle = 1000, Type = Cdy.Tag.RecordType.Timer });
id++;
}
new Cdy.Tag.HisDatabaseManager() { Database = htest }.Save();
}
}
}
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.0": {
"Mars/1.0.0": {
"dependencies": {
"DataRunner": "1.0.0"
},
"runtime": {
"Mars.dll": {}
}
},
"Cdy.Tag/1.0.0": {
"runtime": {
"Cdy.Tag.dll": {}
}
},
"Cdy.Tag.Common/1.0.0": {
"runtime": {
"Cdy.Tag.Common.dll": {}
}
},
"DataRunner/1.0.0": {
"dependencies": {
"Cdy.Tag": "1.0.0",
"Cdy.Tag.Common": "1.0.0"
},
"runtime": {
"DataRunner.dll": {}
}
}
}
},
"libraries": {
"Mars/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Cdy.Tag/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Cdy.Tag.Common/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"DataRunner/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\chongdaoyang\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\chongdaoyang\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.0.0"
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册