diff --git a/Cdy.Tag.Common/Common/FixedMemoryBlock.cs b/Cdy.Tag.Common/Common/FixedMemoryBlock.cs
new file mode 100644
index 0000000000000000000000000000000000000000..0aff14249a4bc1429600eb9a6472c815f2831b2b
--- /dev/null
+++ b/Cdy.Tag.Common/Common/FixedMemoryBlock.cs
@@ -0,0 +1,1085 @@
+//==============================================================
+// 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.IO;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading;
+
+namespace Cdy.Tag
+{
+ ///
+ /// 划分内存
+ ///
+ public unsafe class FixedMemoryBlock : IDisposable
+ {
+
+ #region ... Variables ...
+
+ /////
+ /////
+ /////
+ //private byte[] mDataBuffer;
+
+ private byte[] mBuffers;
+
+ ///
+ ///
+ ///
+ private IntPtr mHandles;
+
+ ///
+ ///
+ ///
+ private int mPosition = 0;
+
+ //private long mUsedSize = 0;
+
+ private long mAllocSize = 0;
+
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+
+ ///
+ ///
+ ///
+ public FixedMemoryBlock()
+ {
+
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public FixedMemoryBlock(long size)
+ {
+ Init(size);
+ }
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+
+ ///
+ ///
+ ///
+ public string Name { get; set; }
+
+ ///
+ ///
+ ///
+ public byte[] Buffers
+ {
+ get
+ {
+ return mBuffers;
+ }
+ internal set
+ {
+ mBuffers = value;
+ }
+ }
+
+
+ ///
+ /// 是否繁忙
+ ///
+ public bool IsBusy { get; set; }
+
+
+ ///
+ ///
+ ///
+ public long Length
+ {
+ get
+ {
+ return mBuffers.Length;
+ }
+ }
+
+ ///
+ ///
+ ///
+ public int Position
+ {
+ get
+ {
+ return mPosition;
+ }
+ set
+ {
+ mPosition = value;
+ }
+ }
+
+
+ ///
+ ///
+ ///
+ public long AllocSize
+ {
+ get
+ {
+ return mAllocSize;
+ }
+ }
+
+
+ ///
+ ///
+ ///
+ internal IntPtr Handles
+ {
+ get
+ {
+ return mHandles;
+ }
+ set
+ {
+ mHandles = value;
+ }
+
+ }
+
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+ ///
+ ///
+ ///
+ ///
+ private void Init(long size)
+ {
+ mBuffers = new byte[size];
+ mHandles = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(mBuffers, 0);
+ mAllocSize = size;
+ }
+
+ /////
+ /////
+ /////
+ /////
+ //public IEnumerable GetStream()
+ //{
+ // foreach(var vv in mBuffers)
+ // {
+ // yield return new MemoryStream(vv);
+ // }
+ //}
+
+ ///
+ /// 重新分配对象
+ ///
+ ///
+ public void ReAlloc(long size)
+ {
+ Init(size);
+ GC.Collect();
+ }
+
+ ///
+ /// 清空内存
+ ///
+ public void Clear()
+ {
+ mBuffers.AsSpan().Fill(0);
+
+ LoggerService.Service.Info("FixedMemoryBlock", Name + " is clear !");
+ }
+
+
+ #region ReadAndWrite
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(DateTime value)
+ {
+ WriteDatetime(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(long value)
+ {
+ WriteLong(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+
+ public void Write(ulong value)
+ {
+ WriteULong(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(int value)
+ {
+ WriteInt(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(uint value)
+ {
+ WriteUInt(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(short value)
+ {
+ WriteShort(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(ushort value)
+ {
+ WriteUShort(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(float value)
+ {
+ WriteFloat(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(double value)
+ {
+ WriteDouble(mPosition, value);
+ }
+
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void Write(string value,Encoding encoding)
+ {
+ WriteString(mPosition, value, encoding);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(string value)
+ {
+ WriteString(mPosition, value, Encoding.Unicode);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(byte value)
+ {
+ WriteByte(mPosition, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void Write(byte[] values)
+ {
+ WriteBytes(mPosition, values);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void Write(byte[] values,int offset,int len)
+ {
+ WriteBytes(mPosition, values,offset,len);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteLong(int offset, long value)
+ {
+ MemoryHelper.WriteInt64((void*)mHandles, offset, value);
+ Position = offset + 8;
+
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void WriteLongDirect(int offset, long value)
+ {
+ MemoryHelper.WriteInt64((void*)mHandles, offset, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteULong(int offset, ulong value)
+ {
+ MemoryHelper.WriteUInt64((void*)mHandles, offset, value);
+ Position = offset + 8;
+
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteFloat(int offset, float value)
+ {
+ MemoryHelper.WriteFloat((void*)mHandles, offset, value);
+ Position = offset + 4;
+
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteDouble(int offset, double value)
+ {
+ MemoryHelper.WriteDouble((void*)mHandles, offset, value);
+ Position = offset + 8;
+
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteBytes(int offset,byte[] values)
+ {
+ WriteBytes(offset, values, 0, values.Length);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteBytesDirect(int offset, byte[] values)
+ {
+ WriteBytesDirect(offset, values, 0, values.Length);
+ }
+
+ ///
+ /// 清空值
+ ///
+ ///
+ ///
+ public virtual void Clear(int offset,int len)
+ {
+ mBuffers.AsSpan(offset, len).Fill(0);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteBytes(int offset, byte[] values, int valueoffset, int len)
+ {
+ Array.Copy(values, valueoffset, mBuffers,offset , len);
+ Position = offset + len;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void WriteBytesDirect(int offset, byte[] values, int valueoffset, int len)
+ {
+ Array.Copy(values, valueoffset, mBuffers, offset, len);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteByte(int offset, byte value)
+ {
+ mBuffers[offset] = value;
+ Position = offset + 1;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void WriteByteDirect(int offset, byte value)
+ {
+ mBuffers[offset] = value;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public void WriteByte(byte value)
+ {
+ WriteByte(mPosition, value);
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteDatetime(int offset, DateTime value)
+ {
+ MemoryHelper.WriteDateTime((void*)mHandles, offset, value);
+ Position = offset + 8;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteInt(int offset, int value)
+ {
+ MemoryHelper.WriteInt32((void*)mHandles, offset, value);
+ Position = offset + 4;
+ }
+
+
+ public void WriteIntDirect(int offset, int value)
+ {
+ MemoryHelper.WriteInt32((void*)mHandles, offset, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteUInt(int offset, uint value)
+ {
+ MemoryHelper.WriteUInt32((void*)mHandles, offset, value);
+ Position = offset + 4;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void WriteUIntDirect(int offset, uint value)
+ {
+ MemoryHelper.WriteUInt32((void*)mHandles, offset, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteShort(int offset, short value)
+ {
+ MemoryHelper.WriteShort((void*)mHandles, offset, value);
+ Position = offset + 2;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void WriteShortDirect(int offset, short value)
+ {
+ MemoryHelper.WriteShort((void*)mHandles, offset, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteUShort(int offset, ushort value)
+ {
+ MemoryHelper.WriteUShort((void*)mHandles, offset, value);
+ Position = offset + 2;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void WriteUShortDirect(int offset, ushort value)
+ {
+ MemoryHelper.WriteUShort((void*)mHandles, offset, value);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual void WriteString(int offset, string value, Encoding encode)
+ {
+ var sdata = encode.GetBytes(value);
+ WriteByte(offset, (byte)sdata.Length);
+ WriteBytes(offset+1, sdata);
+ Position = offset + sdata.Length + 1;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void WriteStringDirect(int offset, string value, Encoding encode)
+ {
+ var sdata = encode.GetBytes(value);
+ WriteByte(offset, (byte)sdata.Length);
+ WriteBytes(offset + 1, sdata);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual DateTime ReadDateTime(int offset)
+ {
+ mPosition = offset + sizeof(DateTime);
+
+ return MemoryHelper.ReadDateTime((void*)mHandles, offset);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+
+ public virtual int ReadInt(int offset)
+ {
+ mPosition = offset + sizeof(int);
+ return MemoryHelper.ReadInt32((void*)mHandles, offset);
+ }
+
+
+ public virtual uint ReadUInt(int offset)
+ {
+ mPosition = offset + 4;
+ return MemoryHelper.ReadUInt32((void*)mHandles, offset);
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual short ReadShort(int offset)
+ {
+ mPosition = offset + 2;
+ return MemoryHelper.ReadShort((void*)mHandles, offset);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual ushort ReadUShort(int offset)
+ {
+ mPosition = offset + 2;
+ return MemoryHelper.ReadUShort((void*)mHandles, offset);
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual float ReadFloat(int offset)
+ {
+ mPosition = offset + 4;
+ return MemoryHelper.ReadFloat((void*)mHandles, offset);
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual double ReadDouble(int offset)
+ {
+ mPosition = offset + 8;
+ return MemoryHelper.ReadDouble((void*)mHandles, offset);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual long ReadLong(int offset)
+ {
+ mPosition = offset + 8;
+ return MemoryHelper.ReadInt64((void*)mHandles, offset);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual ulong ReadULong(int offset)
+ {
+ mPosition = offset + 8;
+ return MemoryHelper.ReadUInt64((void*)mHandles, offset);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual byte ReadByte(int offset)
+ {
+ mPosition = offset + 1;
+ return MemoryHelper.ReadByte((void*)mHandles, offset);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual string ReadString(int offset, Encoding encoding)
+ {
+ var len = ReadByte(offset);
+ mPosition = offset + len + 1;
+ return new string((sbyte*)mHandles, (int)offset + 1, len, encoding);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual string ReadString(int offset)
+ {
+ return ReadString(offset, Encoding.Unicode);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private byte[] ReadBytesInner(int offset,int len)
+ {
+ byte[] re = new byte[len];
+ Array.Copy(mBuffers, offset, re, 0, len);
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual byte[] ReadBytes(int offset,int len)
+ {
+ byte[] re = ReadBytesInner(offset, len);
+ mPosition += len;
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public byte ReadByte()
+ {
+ return ReadByte(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public long ReadLong()
+ {
+ return ReadLong(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public ulong ReadULong()
+ {
+ return ReadULong(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public int ReadInt()
+ {
+ return ReadInt(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public uint ReadUInt()
+ {
+ return ReadUInt(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public float ReadFloat()
+ {
+ return ReadFloat(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public double ReadDouble()
+ {
+ return ReadDouble(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public short ReadShort()
+ {
+ return ReadShort(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public ushort ReadUShort()
+ {
+ return ReadUShort(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public DateTime ReadDateTime()
+ {
+ return ReadDateTime(mPosition);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public string ReadString(Encoding encoding)
+ {
+ return ReadString(mPosition,encoding);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public string ReadString()
+ {
+ return ReadString(mPosition, Encoding.Unicode);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public byte[] ReadBytes(int len)
+ {
+ return ReadBytes(mPosition, len);
+ }
+
+ #endregion
+
+ ///
+ ///
+ ///
+ public virtual void Dispose()
+ {
+ //mDataBuffer = null;
+ mBuffers = null;
+ LoggerService.Service.Erro("FixedMemoryBlock", Name + " Disposed ");
+ GC.Collect();
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public byte this[long index]
+ {
+ get
+ {
+ return this.mBuffers[index];
+ }
+ set
+ {
+ this.mBuffers[index] = value;
+ }
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void CopyTo(FixedMemoryBlock target,long sourceStart, long targetStart, long len)
+ {
+ if (target == null) return;
+ Array.Copy(mBuffers, sourceStart, target.mBuffers, targetStart, len);
+ }
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+
+ public static class FixedMemoryBlockExtends
+ {
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToLongList(this FixedMemoryBlock memory)
+ {
+ List re = new List((int)(memory.AllocSize / 8));
+ memory.Position = 0;
+ while (memory.Position < memory.AllocSize)
+ {
+ re.Add(memory.ReadLong());
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToIntList(this FixedMemoryBlock memory)
+ {
+ List re = new List((int)(memory.Length / 4));
+ memory.Position = 0;
+ while (memory.Position < memory.Length)
+ {
+ re.Add(memory.ReadInt());
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToDoubleList(this FixedMemoryBlock memory)
+ {
+ List re = new List((int)(memory.Length / 8));
+ memory.Position = 0;
+ while (memory.Position < memory.Length)
+ {
+ re.Add(memory.ReadDouble());
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToFloatList(this FixedMemoryBlock memory)
+ {
+ List re = new List((int)(memory.Length / 4));
+ memory.Position = 0;
+ while (memory.Position < memory.Length)
+ {
+ re.Add(memory.ReadFloat());
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToShortList(this FixedMemoryBlock memory)
+ {
+ List re = new List((int)(memory.Length / 2));
+ memory.Position = 0;
+ while (memory.Position < memory.Length)
+ {
+ re.Add(memory.ReadShort());
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToDatetimeList(this FixedMemoryBlock memory)
+ {
+ List re = new List((int)(memory.Length / 8));
+ memory.Position = 0;
+ while (memory.Position < memory.Length)
+ {
+ re.Add(memory.ReadDateTime());
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToffsetringList(this FixedMemoryBlock memory, Encoding encoding)
+ {
+ List re = new List();
+ memory.Position = 0;
+ while (memory.Position < memory.Length)
+ {
+ re.Add(memory.ReadString(encoding));
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static List ToffsetringList(this FixedMemoryBlock memory,int offset, Encoding encoding)
+ {
+ List re = new List();
+ memory.Position = offset;
+ while (memory.Position < memory.Length)
+ {
+ re.Add(memory.ReadString(encoding));
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public static void MakeMemoryBusy(this FixedMemoryBlock memory)
+ {
+ LoggerService.Service.Info("FixedMemoryBlock", memory.Name + " is busy.....");
+ memory.IsBusy = true;
+ //memory.StartMemory[0] = 1;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public static void MakeMemoryNoBusy(this FixedMemoryBlock memory)
+ {
+ LoggerService.Service.Info("FixedMemoryBlock", memory.Name+ " is ready !");
+ memory.IsBusy = false;
+ //memory.StartMemory[0] = 0;
+ }
+ }
+}
diff --git a/Cdy.Tag.Common/Common/MarshalFixedMemoryBlock.cs b/Cdy.Tag.Common/Common/MarshalFixedMemoryBlock.cs
index 1e63985228152094246fb5e1769843cf00bc0f45..34fded3edc0991c82ccaffb8e030aee1e4acec53 100644
--- a/Cdy.Tag.Common/Common/MarshalFixedMemoryBlock.cs
+++ b/Cdy.Tag.Common/Common/MarshalFixedMemoryBlock.cs
@@ -1470,7 +1470,7 @@ namespace Cdy.Tag
using (var stream = System.IO.File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
byte[] bvals = new byte[1024];
- for (long i = 0; i < memory.Position / 1024; i++)
+ for (long i = 0; i < memory.Length / 1024; i++)
{
Marshal.Copy(new IntPtr(memory.Handles.ToInt64() + i * 1024), bvals, 0, 1024);
stream.Write(bvals, 0, 1024);
@@ -1489,7 +1489,7 @@ namespace Cdy.Tag
byte[] bvals = new byte[1024];
long totalsize = memory.AllocSize;
long csize = 0;
- for (long i = 0; i < memory.Position / 1024; i++)
+ for (long i = 0; i < memory.Length / 1024; i++)
{
Marshal.Copy(new IntPtr(memory.Handles.ToInt64() + i * 1024), bvals, 0, 1024);
int isize = (int)Math.Min(totalsize - csize, 1024);
diff --git a/Cdy.Tag.Common/Common/PointData.cs b/Cdy.Tag.Common/Common/PointData.cs
index 4456476acf240adc566edbade0ec75470dcdef67..f160760011209d63e8581e436cedd5378ab1c833 100644
--- a/Cdy.Tag.Common/Common/PointData.cs
+++ b/Cdy.Tag.Common/Common/PointData.cs
@@ -62,6 +62,11 @@ namespace Cdy.Tag
return Empty;
}
+ public override string ToString()
+ {
+ return X+","+Y;
+ }
+
}
///
///
@@ -84,6 +89,11 @@ namespace Cdy.Tag
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
+
+ public override string ToString()
+ {
+ return X + "," + Y+","+Z;
+ }
}
///
@@ -104,6 +114,11 @@ namespace Cdy.Tag
}
public uint X { get; set; }
public uint Y { get; set; }
+
+ public override string ToString()
+ {
+ return X + "," + Y;
+ }
}
///
///
@@ -126,6 +141,12 @@ namespace Cdy.Tag
public uint X { get; set; }
public uint Y { get; set; }
public uint Z { get; set; }
+
+
+ public override string ToString()
+ {
+ return X + "," + Y + "," + Z;
+ }
}
///
@@ -146,6 +167,11 @@ namespace Cdy.Tag
}
public long X { get; set; }
public long Y { get; set; }
+
+ public override string ToString()
+ {
+ return X + "," + Y;
+ }
}
///
@@ -169,6 +195,11 @@ namespace Cdy.Tag
public long X { get; set; }
public long Y { get; set; }
public long Z { get; set; }
+
+ public override string ToString()
+ {
+ return X + "," + Y + "," + Z;
+ }
}
///
@@ -189,6 +220,11 @@ namespace Cdy.Tag
}
public ulong X { get; set; }
public ulong Y { get; set; }
+
+ public override string ToString()
+ {
+ return X + "," + Y;
+ }
}
///
@@ -213,6 +249,11 @@ namespace Cdy.Tag
public ulong X { get; set; }
public ulong Y { get; set; }
public ulong Z { get; set; }
+
+ public override string ToString()
+ {
+ return X + "," + Y + "," + Z;
+ }
}
}
diff --git a/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj b/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj
index 9f5c4f4abb611103e8d62ab979dda9bfcb5a7fc2..5978e61eaab05e2088593d2195c50ef2194829b4 100644
--- a/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj
+++ b/Cdy.Tag.Consume/Cdy.Tag.Consume.csproj
@@ -1,7 +1,15 @@
- netstandard2.0
+ netstandard2.1
+
+
+
+
+
+
+
+
diff --git a/Cdy.Tag.Consume/IRuntimeSecurity.cs b/Cdy.Tag.Consume/IRuntimeSecurity.cs
new file mode 100644
index 0000000000000000000000000000000000000000..3a29fb4b180d90fcdbb160c072c862abf3a598a3
--- /dev/null
+++ b/Cdy.Tag.Consume/IRuntimeSecurity.cs
@@ -0,0 +1,90 @@
+//==============================================================
+// Copyright (C) 2020 Inc. All rights reserved.
+//
+//==============================================================
+// Create by 种道洋 at 2020/5/9 21:48:50.
+// Version 1.0
+// 种道洋
+//==============================================================
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Cdy.Tag
+{
+ ///
+ ///
+ ///
+ public interface IRuntimeSecurity
+ {
+
+ #region ... Variables ...
+
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ bool CheckLogin(string id);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ bool FreshUserId(string id);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ string Login(string user, string pass);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ bool Logout(string id);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ string GetUserByLoginId(string id);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ List GetPermission(string user);
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+}
diff --git a/Cdy.Tag.Driver/IRealTagProducter.cs b/Cdy.Tag.Driver/IRealTagProducter.cs
index 27dbf52b716b0a981cd204dc17f4efbebb78c24c..0fc5da3c4d4ae9098605566914a1a4cb76bb423f 100644
--- a/Cdy.Tag.Driver/IRealTagProducter.cs
+++ b/Cdy.Tag.Driver/IRealTagProducter.cs
@@ -45,6 +45,14 @@ namespace Cdy.Tag.Driver
///
object GetTagValueForProductor(int id);
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ bool SetTagByGroup(string group, params object[] values);
+
///
///
///
diff --git a/Cdy.Tag.Network/Cdy.Tag.Network.csproj b/Cdy.Tag.Network/Cdy.Tag.Network.csproj
new file mode 100644
index 0000000000000000000000000000000000000000..7a5a5d104dc8b9547cb53abe9a5a7ada42481444
--- /dev/null
+++ b/Cdy.Tag.Network/Cdy.Tag.Network.csproj
@@ -0,0 +1,11 @@
+
+
+
+ netstandard2.1
+
+
+
+
+
+
+
diff --git a/Cdy.Tag.Network/ServerProcessItem.cs b/Cdy.Tag.Network/ServerProcessItem.cs
new file mode 100644
index 0000000000000000000000000000000000000000..679e19163edd23aae3853f716eedec62f3cadf9b
--- /dev/null
+++ b/Cdy.Tag.Network/ServerProcessItem.cs
@@ -0,0 +1,88 @@
+//==============================================================
+// Copyright (C) 2020 Inc. All rights reserved.
+//
+//==============================================================
+// Create by 种道洋 at 2020/5/11 11:34:18.
+// Version 1.0
+// 种道洋
+//==============================================================
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net.Sockets;
+
+namespace Cdy.Tag
+{
+ public class ServerProcessItem
+ {
+
+ #region ... Variables ...
+ private System.Net.Sockets.Socket mSocket;
+ private SocketBuffer mSendBuffer;
+ private SocketBuffer mReceiveBuffer;
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+ ///
+ ///
+ ///
+ ///
+ public ServerProcessItem(Socket socket)
+ {
+ mSocket = socket;
+
+ }
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+ private void Init()
+ {
+ mSendBuffer = new SocketBuffer(1024 * 10);
+ mReceiveBuffer = new SocketBuffer(1024 * 10);
+ }
+
+ ///
+ ///
+ ///
+ public void Receive()
+ {
+ int count = mSocket.Receive(mReceiveBuffer.Buffers, mReceiveBuffer.ReceiveAddr, mSocket.Available, SocketFlags.None);
+ mReceiveBuffer.ReceiveAddr += count;
+
+ }
+
+ ///
+ ///
+ ///
+ public void Send()
+ {
+
+ }
+
+ ///
+ ///
+ ///
+ public void Close()
+ {
+ mSocket.Close();
+ }
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+}
diff --git a/Cdy.Tag.Network/SocketBuffer.cs b/Cdy.Tag.Network/SocketBuffer.cs
new file mode 100644
index 0000000000000000000000000000000000000000..272fe3c834528fadd814b97e9411f6e78d36851e
--- /dev/null
+++ b/Cdy.Tag.Network/SocketBuffer.cs
@@ -0,0 +1,77 @@
+//==============================================================
+// Copyright (C) 2020 Inc. All rights reserved.
+//
+//==============================================================
+// Create by 种道洋 at 2020/5/11 12:09:03.
+// Version 1.0
+// 种道洋
+//==============================================================
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Cdy.Tag
+{
+ ///
+ ///
+ ///
+ public class SocketBuffer:FixedMemoryBlock
+ {
+
+ #region ... Variables ...
+ private int mReceiveAddr = 0;
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+ ///
+ ///
+ ///
+ ///
+ public SocketBuffer(int size):base(size)
+ {
+
+ }
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+
+ ///
+ ///
+ ///
+ public int ReceiveAddr
+ {
+ get { return mReceiveAddr; }
+ set
+ {
+ if (value > this.Length)
+ {
+ mReceiveAddr = (int)(value - Length);
+ }
+ else
+ {
+ mReceiveAddr = value;
+ }
+ }
+ }
+
+ ///
+ ///
+ ///
+ public int SendAddr { get; set; }
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+}
diff --git a/Cdy.Tag.Network/SocketServer.cs b/Cdy.Tag.Network/SocketServer.cs
new file mode 100644
index 0000000000000000000000000000000000000000..6331107b2ef21f72019b92c91a0990c2bd6912e2
--- /dev/null
+++ b/Cdy.Tag.Network/SocketServer.cs
@@ -0,0 +1,125 @@
+using System;
+using System.Net;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace Cdy.Tag
+{
+ ///
+ ///
+ ///
+ public class SocketServer
+ {
+
+ #region ... Variables ...
+ private string mIp;
+ private System.Net.Sockets.Socket mServerSocket;
+
+ private Dictionary mClients = new Dictionary();
+
+ private Thread mAcceptThread;
+
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void Start(string ip,int port)
+ {
+ mIp = ip;
+ StartInner(port);
+ }
+
+ ///
+ ///
+ ///
+ public void Start(int port)
+ {
+ mIp = "0.0.0.0";
+ StartInner(port);
+ }
+
+ public void StartIpv6(string ip,int port)
+ {
+ mIp = ip;
+ StartInnerV6(port);
+ }
+
+ private void StartInner(int port)
+ {
+ mServerSocket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
+ mServerSocket.Bind(new IPEndPoint(IPAddress.Parse(mIp), port));
+ mServerSocket.Listen(1024);
+ StartScan();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ private void StartInnerV6(int port)
+ {
+ mServerSocket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetworkV6, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
+ mServerSocket.Bind(new IPEndPoint(IPAddress.Parse(mIp), port));
+ mServerSocket.Listen(1024);
+ StartScan();
+ }
+
+ ///
+ ///
+ ///
+ private void StartScan()
+ {
+ mAcceptThread = new Thread(AcceptThreadPro);
+ mAcceptThread.IsBackground = true;
+ mAcceptThread.Start();
+ }
+
+ ///
+ ///
+ ///
+ private void AcceptThreadPro()
+ {
+ while(true)
+ {
+ var socket = mServerSocket.Accept();
+ mClients.Add(socket.RemoteEndPoint, new ServerProcessItem(socket));
+ }
+ }
+
+ ///
+ ///
+ ///
+ public void Stop()
+ {
+ foreach(var vv in mClients)
+ {
+ vv.Value.Close();
+ }
+ mAcceptThread.Abort();
+ }
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+}
diff --git a/Cdy.Tag/Interface/HisQueryResult.cs b/Cdy.Tag/Interface/HisQueryResult.cs
index 2f6b9344f5bf688f6dcf2740343eb4b479cd1b92..d8069bcfbfe5199be8187b41372da2c02b213aaf 100644
--- a/Cdy.Tag/Interface/HisQueryResult.cs
+++ b/Cdy.Tag/Interface/HisQueryResult.cs
@@ -790,13 +790,13 @@ namespace Cdy.Tag
re = MemoryHelper.ReadInt32((void*)handle, index * 4);
break;
case 5:
- re = MemoryHelper.ReadInt32((void*)handle, index * 4);
+ re = MemoryHelper.ReadUInt32((void*)handle, index * 4);
break;
case 6:
- re = MemoryHelper.ReadInt32((void*)handle, index * 8);
+ re = MemoryHelper.ReadInt64((void*)handle, index * 8);
break;
case 7:
- re = MemoryHelper.ReadInt32((void*)handle, index * 8);
+ re = MemoryHelper.ReadUInt64((void*)handle, index * 8);
break;
case 8:
re = MemoryHelper.ReadFloat((void*)handle, index * 4);
@@ -823,6 +823,32 @@ namespace Cdy.Tag
}
re = new string((char*)handle, pos+1, MemoryHelper.ReadByte((void*)handle, pos));
break;
+ case 12:
+ var x = MemoryHelper.ReadInt32((void*)handle, index * 8);
+ var y = MemoryHelper.ReadInt32((void*)handle, index * 8+4);
+ re = new IntPointData(x, y);
+ break;
+ case 13:
+ re = new UIntPointData(MemoryHelper.ReadUInt32((void*)handle, index * 8), MemoryHelper.ReadUInt32((void*)handle, index * 8 + 4));
+ break;
+ case 14:
+ re = new IntPoint3Data(MemoryHelper.ReadInt32((void*)handle, index * 12), MemoryHelper.ReadInt32((void*)handle, index * 12 + 4), MemoryHelper.ReadInt32((void*)handle, index * 12 + 8));
+ break;
+ case 15:
+ re = new UIntPoint3Data(MemoryHelper.ReadUInt32((void*)handle, index * 12), MemoryHelper.ReadUInt32((void*)handle, index * 12 + 4), MemoryHelper.ReadUInt32((void*)handle, index * 12 + 8));
+ break;
+ case 16:
+ re = new LongPointData(MemoryHelper.ReadInt64((void*)handle, index * 16), MemoryHelper.ReadInt64((void*)handle, index * 16 + 8));
+ break;
+ case 17:
+ re = new ULongPointData(MemoryHelper.ReadUInt64((void*)handle, index * 16), MemoryHelper.ReadUInt64((void*)handle, index * 16 + 8));
+ break;
+ case 18:
+ re = new LongPoint3Data(MemoryHelper.ReadInt64((void*)handle, index * 24), MemoryHelper.ReadInt64((void*)handle, index * 24 + 8), MemoryHelper.ReadInt64((void*)handle, index * 24 + 16));
+ break;
+ case 19:
+ re = new ULongPoint3Data(MemoryHelper.ReadUInt64((void*)handle, index * 24), MemoryHelper.ReadUInt64((void*)handle, index * 24 + 8), MemoryHelper.ReadUInt64((void*)handle, index * 24 + 16));
+ break;
}
time = MemoryHelper.ReadDateTime((void*)handle, index * 8 + mTimeAddr);
@@ -905,28 +931,28 @@ namespace Cdy.Tag
case "string":
mDataType = 11;
return Const.StringSize;
- case "IntPointdata":
+ case "intpointdata":
mDataType = 12;
return 8;
- case "UIntPointdata":
+ case "uintpointdata":
mDataType = 13;
return 8;
- case "IntPoint3data":
+ case "intpoint3data":
mDataType = 14;
return 12;
- case "UIntPoint3data":
+ case "uintpoint3data":
mDataType = 15;
return 12;
- case "LongPointdata":
+ case "longpointdata":
mDataType = 16;
return 16;
- case "ULongPointdata":
+ case "ulongpointdata":
mDataType = 17;
return 16;
- case "LongPoint3data":
+ case "longpoint3data":
mDataType = 18;
return 24;
- case "ULongPoint3data":
+ case "ulongpoint3data":
mDataType = 19;
return 24;
}
diff --git a/Cdy.Tag/Interface/IValueConvert.cs b/Cdy.Tag/Interface/IValueConvert.cs
index d126deb88d705236170bb2feb03a7e86cc9855a8..780ee4c97c95089577a7295b39e51f6149e4227f 100644
--- a/Cdy.Tag/Interface/IValueConvert.cs
+++ b/Cdy.Tag/Interface/IValueConvert.cs
@@ -81,4 +81,35 @@ namespace Cdy.Tag
#endregion ...Interfaces...
}
+
+ public static class IValueConvertExtend
+ {
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string SeriseToString(this IValueConvert convert)
+ {
+ return convert.Name + ":" + convert.SaveToString();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static IValueConvert DeSeriseToValueConvert(this string convert)
+ {
+ string[] sval = convert.Split(new char[] { ':' });
+ var vtmp = ValueConvertManager.manager.GetConvert(sval[0]);
+ if (vtmp != null)
+ {
+ return vtmp.LoadFromString(convert.Replace(sval[0] + ":", ""));
+ }
+ return null;
+ }
+
+ }
+
}
diff --git a/Cdy.Tag/Real/Tagbase.cs b/Cdy.Tag/Real/Tagbase.cs
index c94245c32aea4e95ff5b9c962580d85f37f111d7..449a2bd1633112c043f8e2c944979312bb0c0857 100644
--- a/Cdy.Tag/Real/Tagbase.cs
+++ b/Cdy.Tag/Real/Tagbase.cs
@@ -163,7 +163,7 @@ namespace Cdy.Tag
///
/// 小数位数
///
- public byte Precision { get; set; } = 3;
+ public byte Precision { get; set; } = 6;
#endregion ...Properties...
#region ... Methods ...
@@ -193,7 +193,7 @@ namespace Cdy.Tag
xe.SetAttributeValue("ReadWriteType", (int)tag.ReadWriteType);
if(tag.Conveter!=null)
{
- xe.SetAttributeValue("Conveter", tag.Conveter+":"+ tag.Conveter.SaveToString());
+ xe.SetAttributeValue("Conveter", tag.Conveter.Name+":"+ tag.Conveter.SaveToString());
}
if(tag is NumberTagBase)
{
diff --git a/Cdy.Tag/Real/ValueConvert/ValueConvertManager.cs b/Cdy.Tag/Real/ValueConvert/ValueConvertManager.cs
index b1ae323b080678bed0c13089e38000d0e3f34b83..f3ea9e2a915470adf3c179183060566dfc3ce5d8 100644
--- a/Cdy.Tag/Real/ValueConvert/ValueConvertManager.cs
+++ b/Cdy.Tag/Real/ValueConvert/ValueConvertManager.cs
@@ -73,6 +73,9 @@ namespace Cdy.Tag
return null;
}
+
+
+
#endregion ...Methods...
#region ... Interfaces ...
diff --git a/Cdy.Tag/Security/PermissionDocument.cs b/Cdy.Tag/Security/PermissionDocument.cs
index 7a1c74f126af5b85edd9d7d8a99a24459a303fdb..913fe0c795634c1cdc884389cc8613b3ab3a1f90 100644
--- a/Cdy.Tag/Security/PermissionDocument.cs
+++ b/Cdy.Tag/Security/PermissionDocument.cs
@@ -33,7 +33,7 @@ namespace Cdy.Tag
public PermissionDocument()
{
- var superPermission = new PermissionItem() { Name = "Super", SuperPermission = true, EnableWrite = true,Desc="Super Permission" };
+ var superPermission = new UserPermission() { Name = "Super", SuperPermission = true, EnableWrite = true,Desc="Super Permission" };
Permissions.Add(superPermission.Name, superPermission);
}
@@ -44,7 +44,7 @@ namespace Cdy.Tag
///
///
///
- public Dictionary Permissions { get; set; } = new Dictionary();
+ public Dictionary Permissions { get; set; } = new Dictionary();
@@ -56,7 +56,7 @@ namespace Cdy.Tag
///
///
///
- public void Add(PermissionItem permission)
+ public void Add(UserPermission permission)
{
if(!Permissions.ContainsKey(permission.Name))
{
diff --git a/Cdy.Tag/Security/SecuritySerise.cs b/Cdy.Tag/Security/SecuritySerise.cs
index 4e82d0368eb9cf87a962b362e05a1c938cb0c74b..0cd9d6902f31b200a40755690befeb1e2027e7d8 100644
--- a/Cdy.Tag/Security/SecuritySerise.cs
+++ b/Cdy.Tag/Security/SecuritySerise.cs
@@ -147,7 +147,7 @@ namespace Cdy.Tag
public PermissionDocument LoadPermission(XElement element)
{
PermissionDocument re = new PermissionDocument();
- re.Permissions = new Dictionary();
+ re.Permissions = new Dictionary();
foreach(var vv in element.Elements())
{
var pp = LoadPermissionItem(vv);
@@ -260,7 +260,7 @@ namespace Cdy.Tag
return xe;
}
- private XElement Save(PermissionItem permission)
+ private XElement Save(UserPermission permission)
{
XElement re = new XElement("PermissionItem");
re.SetAttributeValue("Name", permission.Name);
@@ -280,9 +280,9 @@ namespace Cdy.Tag
return re;
}
- private PermissionItem LoadPermissionItem(XElement xe)
+ private UserPermission LoadPermissionItem(XElement xe)
{
- PermissionItem re = new PermissionItem();
+ UserPermission re = new UserPermission();
if(xe.Attribute("Name") !=null)
{
re.Name = xe.Attribute("Name").Value;
diff --git a/Cdy.Tag/Security/PermissionItem.cs b/Cdy.Tag/Security/UserPermission.cs
similarity index 97%
rename from Cdy.Tag/Security/PermissionItem.cs
rename to Cdy.Tag/Security/UserPermission.cs
index 663a714b97b3d75e7c7c09ca5c9e4ded88091987..8fb109f2261cffe64855d9f64a942437e52cf5d8 100644
--- a/Cdy.Tag/Security/PermissionItem.cs
+++ b/Cdy.Tag/Security/UserPermission.cs
@@ -16,7 +16,7 @@ namespace Cdy.Tag
///
///
///
- public class PermissionItem
+ public class UserPermission
{
///
///
diff --git a/DBDevelopClientApi/DevelopServiceHelper.cs b/DBDevelopClientApi/DevelopServiceHelper.cs
index e6ee173133e9c7b6ab872a837edc93efa78f881b..f415de3dde5dc829184ee408f571fb3343272418 100644
--- a/DBDevelopClientApi/DevelopServiceHelper.cs
+++ b/DBDevelopClientApi/DevelopServiceHelper.cs
@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Linq;
+using Cdy.Tag;
namespace DBDevelopClientApi
{
@@ -308,14 +309,14 @@ namespace DBDevelopClientApi
///
///
///
- public List GetAllDatabasePermission(string database)
+ public List GetAllDatabasePermission(string database)
{
- List re = new List();
+ List re = new List();
if (mCurrentClient != null && !string.IsNullOrEmpty(mLoginId))
{
foreach (var vv in mCurrentClient.GetAllDatabasePermission(new DBDevelopService.GetAllDatabasePermissionRequest() { Database = database, LoginId = mLoginId }).Permission)
{
- Cdy.Tag.PermissionItem user = new Cdy.Tag.PermissionItem() { Name = vv.Name, Group = vv.Group.ToList(),Desc=vv.Desc,EnableWrite=vv.EnableWrite,SuperPermission=vv.SuperPermission };
+ Cdy.Tag.UserPermission user = new Cdy.Tag.UserPermission() { Name = vv.Name, Group = vv.Group.ToList(),Desc=vv.Desc,EnableWrite=vv.EnableWrite,SuperPermission=vv.SuperPermission };
re.Add(user);
}
}
@@ -343,7 +344,7 @@ namespace DBDevelopClientApi
///
///
///
- public bool UpdateDatabasePermission(string database,Cdy.Tag.PermissionItem permission)
+ public bool UpdateDatabasePermission(string database,Cdy.Tag.UserPermission permission)
{
if (mCurrentClient != null && !string.IsNullOrEmpty(mLoginId))
{
@@ -491,6 +492,18 @@ namespace DBDevelopClientApi
tag.Name = vv.Name;
tag.Desc = vv.Desc;
tag.Group = vv.Group;
+ tag.ReadWriteType = (Cdy.Tag.ReadWriteMode)vv.ReadWriteMode;
+ tag.Conveter = !string.IsNullOrEmpty(vv.Convert) ? vv.Convert.DeSeriseToValueConvert():null;
+ if (tag is Cdy.Tag.NumberTagBase)
+ {
+ (tag as Cdy.Tag.NumberTagBase).MaxValue = vv.MaxValue;
+ (tag as Cdy.Tag.NumberTagBase).MinValue = vv.MinValue;
+ }
+
+ if (tag is Cdy.Tag.FloatingTagBase)
+ {
+ (tag as Cdy.Tag.FloatingTagBase).Precision = (byte)vv.Precision;
+ }
mRealTag.Add(tag.Id, tag);
}
@@ -558,6 +571,18 @@ namespace DBDevelopClientApi
tag.Name = vv.Name;
tag.Desc = vv.Desc;
tag.Group = vv.Group;
+ tag.ReadWriteType = (Cdy.Tag.ReadWriteMode)vv.ReadWriteMode;
+ tag.Conveter = !string.IsNullOrEmpty(vv.Convert) ? vv.Convert.DeSeriseToValueConvert() : null;
+ if (tag is Cdy.Tag.NumberTagBase)
+ {
+ (tag as Cdy.Tag.NumberTagBase).MaxValue = vv.MaxValue;
+ (tag as Cdy.Tag.NumberTagBase).MinValue = vv.MinValue;
+ }
+
+ if (tag is Cdy.Tag.FloatingTagBase)
+ {
+ (tag as Cdy.Tag.FloatingTagBase).Precision = (byte)vv.Precision;
+ }
mRealTag.Add(tag.Id, tag);
}
@@ -628,6 +653,18 @@ namespace DBDevelopClientApi
tag.Name = vv.Name;
tag.Desc = vv.Desc;
tag.Group = vv.Group;
+ tag.ReadWriteType = (Cdy.Tag.ReadWriteMode)vv.ReadWriteMode;
+ tag.Conveter = !string.IsNullOrEmpty(vv.Convert) ? vv.Convert.DeSeriseToValueConvert() : null;
+ if (tag is Cdy.Tag.NumberTagBase)
+ {
+ (tag as Cdy.Tag.NumberTagBase).MaxValue = vv.MaxValue;
+ (tag as Cdy.Tag.NumberTagBase).MinValue = vv.MinValue;
+ }
+
+ if (tag is Cdy.Tag.FloatingTagBase)
+ {
+ (tag as Cdy.Tag.FloatingTagBase).Precision = (byte)vv.Precision;
+ }
mRealTag.Add(tag.Id, tag);
}
@@ -788,6 +825,18 @@ namespace DBDevelopClientApi
re.TagType = (uint)tag.Type;
re.Group = tag.Group;
re.Desc = tag.Desc;
+ re.Convert = tag.Conveter != null ? tag.Conveter.SeriseToString() : string.Empty;
+ re.ReadWriteMode = (int)tag.ReadWriteType;
+ if(tag is NumberTagBase)
+ {
+ re.MaxValue = (tag as NumberTagBase).MaxValue;
+ re.MinValue = (tag as NumberTagBase).MinValue;
+ }
+
+ if (tag is FloatingTagBase)
+ {
+ re.Precision = (tag as FloatingTagBase).Precision;
+ }
return re;
}
diff --git a/DBDevelopClientApi/developService.proto b/DBDevelopClientApi/developService.proto
index 584ca8025be6414caf25ade9da82e0890996db65..20d28f840810b0daa1730866970afa23d57b4397 100644
--- a/DBDevelopClientApi/developService.proto
+++ b/DBDevelopClientApi/developService.proto
@@ -505,6 +505,11 @@ message RealTagMessage
string Group = 4;
string Desc = 5;
string LinkAddress = 6;
+ string Convert=7;
+ int32 ReadWriteMode=8;
+ double MaxValue=9;
+ double MinValue=10;
+ int32 Precision=11;
}
//ʷ
diff --git a/DBDevelopService/Protos/developService.proto b/DBDevelopService/Protos/developService.proto
index 584ca8025be6414caf25ade9da82e0890996db65..20d28f840810b0daa1730866970afa23d57b4397 100644
--- a/DBDevelopService/Protos/developService.proto
+++ b/DBDevelopService/Protos/developService.proto
@@ -505,6 +505,11 @@ message RealTagMessage
string Group = 4;
string Desc = 5;
string LinkAddress = 6;
+ string Convert=7;
+ int32 ReadWriteMode=8;
+ double MaxValue=9;
+ double MinValue=10;
+ int32 Precision=11;
}
//ʷ
diff --git a/DBDevelopService/Services/DevelopServerService.cs b/DBDevelopService/Services/DevelopServerService.cs
index 47ed9c664aa86de801e0b4ce54eaaa961555568c..949e94ebe343a12fc2396d7c1ba657557f6c24b3 100644
--- a/DBDevelopService/Services/DevelopServerService.cs
+++ b/DBDevelopService/Services/DevelopServerService.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Extensions.Logging;
-
+using Cdy.Tag;
namespace DBDevelopService
{
public class DevelopServerService : DevelopServer.DevelopServerBase
@@ -119,7 +119,7 @@ namespace DBDevelopService
var db = DbManager.Instance.GetDatabase(request.Database);
if (db != null)
{
- var pers = new Cdy.Tag.PermissionItem() { Name = request.Permission.Name, Desc = request.Permission.Desc, EnableWrite = request.Permission.EnableWrite};
+ var pers = new Cdy.Tag.UserPermission() { Name = request.Permission.Name, Desc = request.Permission.Desc, EnableWrite = request.Permission.EnableWrite};
pers.Group.AddRange(request.Permission.Group);
db.Security.Permission.Add(pers);
}
@@ -171,7 +171,7 @@ namespace DBDevelopService
}
else
{
- var pp = new Cdy.Tag.PermissionItem() { Name = request.Permission.Name, Desc = request.Permission.Desc, EnableWrite = request.Permission.EnableWrite };
+ var pp = new Cdy.Tag.UserPermission() { Name = request.Permission.Name, Desc = request.Permission.Desc, EnableWrite = request.Permission.EnableWrite };
pp.Group.AddRange(request.Permission.Group);
db.Security.Permission.Add(pp);
}
@@ -735,7 +735,7 @@ namespace DBDevelopService
{
if (cc >= from && cc < (from + PageCount))
{
- rre.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc, Group = vv.Group, LinkAddress = vv.LinkAddress, TagType = (uint)vv.Type });
+ rre.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc, Group = vv.Group, LinkAddress = vv.LinkAddress, TagType = (uint)vv.Type, Convert = vv.Conveter != null ? vv.Conveter.SeriseToString() : string.Empty, ReadWriteMode = (int)vv.ReadWriteType, MaxValue = (vv is Cdy.Tag.NumberTagBase) ? (vv as Cdy.Tag.NumberTagBase).MaxValue : 0, MinValue = (vv is Cdy.Tag.NumberTagBase) ? (vv as Cdy.Tag.NumberTagBase).MinValue : 0, Precision = (vv is Cdy.Tag.FloatingTagBase) ? (vv as Cdy.Tag.FloatingTagBase).Precision : 0 });
if (db.HisDatabase.HisTags.ContainsKey(vv.Id))
{
@@ -791,7 +791,7 @@ namespace DBDevelopService
{
if (cc >= from && cc < (from + PageCount))
{
- rre.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc, Group = vv.Group, LinkAddress = vv.LinkAddress, TagType = (uint)vv.Type });
+ rre.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc, Group = vv.Group, LinkAddress = vv.LinkAddress, TagType = (uint)vv.Type, Convert = vv.Conveter != null ? vv.Conveter.SeriseToString() : string.Empty, ReadWriteMode = (int)vv.ReadWriteType, MaxValue = (vv is Cdy.Tag.NumberTagBase) ? (vv as Cdy.Tag.NumberTagBase).MaxValue : 0, MinValue = (vv is Cdy.Tag.NumberTagBase) ? (vv as Cdy.Tag.NumberTagBase).MinValue : 0, Precision = (vv is Cdy.Tag.FloatingTagBase) ? (vv as Cdy.Tag.FloatingTagBase).Precision : 0 });
if (db.HisDatabase.HisTags.ContainsKey(vv.Id))
{
@@ -869,7 +869,7 @@ namespace DBDevelopService
{
foreach (var vv in db.RealDatabase.ListAllTags())
{
- re.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc,Group = vv.Group, LinkAddress = vv.LinkAddress,TagType=(uint)vv.Type });
+ re.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc,Group = vv.Group, LinkAddress = vv.LinkAddress,TagType=(uint)vv.Type,Convert=vv.Conveter!=null?vv.Conveter.SeriseToString():string.Empty,ReadWriteMode=(int)vv.ReadWriteType,MaxValue=(vv is Cdy.Tag.NumberTagBase)?(vv as Cdy.Tag.NumberTagBase).MaxValue:0,MinValue = (vv is Cdy.Tag.NumberTagBase) ? (vv as Cdy.Tag.NumberTagBase).MinValue:0, Precision = (vv is Cdy.Tag.FloatingTagBase) ? (vv as Cdy.Tag.FloatingTagBase).Precision:0 });
}
}
var msg = new GetRealTagMessageReply() { Result = true };
@@ -982,7 +982,7 @@ namespace DBDevelopService
List re = new List();
foreach (var vv in htags)
{
- re.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc, Group = vv.Group, LinkAddress = vv.LinkAddress, TagType = (uint)vv.Type });
+ re.Add(new RealTagMessage() { Id = (uint)vv.Id, Name = vv.Name, Desc = vv.Desc, Group = vv.Group, LinkAddress = vv.LinkAddress, TagType = (uint)vv.Type, Convert = vv.Conveter != null ? vv.Conveter.SeriseToString() : string.Empty, ReadWriteMode = (int)vv.ReadWriteType, MaxValue = (vv is Cdy.Tag.NumberTagBase) ? (vv as Cdy.Tag.NumberTagBase).MaxValue : 0, MinValue = (vv is Cdy.Tag.NumberTagBase) ? (vv as Cdy.Tag.NumberTagBase).MinValue : 0, Precision = (vv is Cdy.Tag.FloatingTagBase) ? (vv as Cdy.Tag.FloatingTagBase).Precision : 0 });
}
var msg = new GetRealTagMessageReply() { Result = true };
msg.Messages.AddRange(re);
@@ -1158,6 +1158,22 @@ namespace DBDevelopService
re.Group = tmsg.Group;
re.Desc = tmsg.Desc;
re.Id = (int)tmsg.Id;
+ re.ReadWriteType = (Cdy.Tag.ReadWriteMode)tmsg.ReadWriteMode;
+ if(!string.IsNullOrEmpty(tmsg.Convert))
+ {
+ re.Conveter = tmsg.Convert.DeSeriseToValueConvert();
+ }
+ if(re is Cdy.Tag.NumberTagBase)
+ {
+ (re as Cdy.Tag.NumberTagBase).MaxValue = tmsg.MaxValue;
+ (re as Cdy.Tag.NumberTagBase).MinValue = tmsg.MinValue;
+ }
+
+ if (re is Cdy.Tag.FloatingTagBase)
+ {
+ (re as Cdy.Tag.FloatingTagBase).Precision = (byte)tmsg.Precision;
+ }
+
}
return re;
diff --git a/DBStudio/Program.cs b/DBStudio/Program.cs
index 9423bdbaf9be88c14563b0ad7452f8cd772b5fcb..e777d5e794b87a2fd86c1d04087eff4e9af1071f 100644
--- a/DBStudio/Program.cs
+++ b/DBStudio/Program.cs
@@ -4,6 +4,7 @@ using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.IO;
+using System.Diagnostics;
namespace DBStudio
{
@@ -36,7 +37,7 @@ namespace DBStudio
if (cmsg == "exit")
{
- OutByLine("","确定要退出?输入y确定,输入其他任意字符取消");
+ OutByLine("", "确定要退出?输入y确定,输入其他任意字符取消");
cmd = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
if (cmd.Length == 0) continue;
if (cmd[0].ToLower() == "y")
@@ -53,7 +54,7 @@ namespace DBStudio
}
else if (cmsg == "h")
{
- OutByLine("",GetHelpString());
+ OutByLine("", GetHelpString());
}
}
DBDevelopService.Service.Instanse.Stop();
@@ -65,9 +66,9 @@ namespace DBStudio
///
///
///
- private static void OutByLine(string prechar,string msg)
+ private static void OutByLine(string prechar, string msg)
{
- Console.WriteLine(prechar+">" + msg);
+ Console.WriteLine(prechar + ">" + msg);
}
///
@@ -89,9 +90,9 @@ namespace DBStudio
DBDevelopService.DbManager.Instance.Load();
StringBuilder sb = new StringBuilder();
- foreach(var vdd in DBDevelopService.DbManager.Instance.ListDatabase())
+ foreach (var vdd in DBDevelopService.DbManager.Instance.ListDatabase())
{
- sb.Append(vdd+",");
+ sb.Append(vdd + ",");
}
sb.Length = sb.Length > 1 ? sb.Length - 1 : sb.Length;
OutByLine("", sb.ToString());
@@ -102,7 +103,7 @@ namespace DBStudio
///
///
///
- private static void ProcessDatabaseCommand(Database db,string msg)
+ private static void ProcessDatabaseCommand(Database db, string msg)
{
try
{
@@ -135,7 +136,7 @@ namespace DBStudio
}
catch
{
-
+
}
}
@@ -149,13 +150,13 @@ namespace DBStudio
DBDevelopService.DbManager.Instance.Load();
Database db = DBDevelopService.DbManager.Instance.GetDatabase(name);
-
+
if (db == null)
{
db = Database.New(name);
}
- OutByLine(name,Res.Get("HelpMsg"));
+ OutByLine(name, Res.Get("HelpMsg"));
while (true)
{
OutInLine(name, "");
@@ -184,6 +185,11 @@ namespace DBStudio
{
UpdateTag(db, cmd[1].ToLower(), cmd[2], cmd[3]);
}
+ else if (cmsg == "start")
+ {
+
+ StartDb(db.Name);
+ }
else if (cmsg == "updatehis")
{
UpdateHisTag(db, cmd[1].ToLower(), cmd[2], cmd[3]);
@@ -199,11 +205,11 @@ namespace DBStudio
}
else if (cmsg == "export")
{
- if(cmd.Length>1)
- ExportToCSV(db, cmd[1].ToLower());
+ if (cmd.Length > 1)
+ ExportToCSV(db, cmd[1].ToLower());
else
{
- ExportToCSV(db, name+".csv");
+ ExportToCSV(db, name + ".csv");
}
}
else if (cmsg == "list")
@@ -213,11 +219,15 @@ namespace DBStudio
}
else if (cmsg == "h")
{
- if(cmd.Length==1)
+ if (cmd.Length == 1)
{
Console.WriteLine(GetDbManagerHelpString());
}
}
+ else if (cmsg == "sp")
+ {
+ Sp(db, cmd.Skip(1).ToArray());
+ }
else if (cmsg == "exit")
{
break;
@@ -225,7 +235,124 @@ namespace DBStudio
}
catch
{
- OutByLine(name ,Res.Get("ErroParameter"));
+ OutByLine(name, Res.Get("ErroParameter"));
+ }
+ }
+ }
+
+ ///
+ ///
+ ///
+ ///
+ private static void StartDb(string name)
+ {
+ var info = new ProcessStartInfo() { FileName = "DbInRun.exe" };
+ info.UseShellExecute = true;
+ info.Arguments = "start "+name;
+ info.WorkingDirectory = System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location);
+ Process.Start(info);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private static void Sp(Database db, params string[] paras)
+ {
+ Cdy.Tag.RealDatabase test = db.RealDatabase;
+ db.RealDatabase = test;
+ Cdy.Tag.HisDatabase htest = db.HisDatabase;
+
+ string address = "";
+ if (paras.Length > 0)
+ {
+ int dcount = int.Parse(paras[0]);
+ for (int i = 0; i < dcount; i++)
+ {
+ if (i % 3 == 0)
+ {
+ address = "Sim:sin";
+ }
+ else if (i % 3 == 1)
+ {
+ address = "Sim:cos";
+ }
+ else
+ {
+ address = "Sim:step";
+ }
+ var vtag = new Cdy.Tag.DoubleTag() { Name = "Double" + i, Group = "Double", LinkAddress = address };
+ test.Append(vtag);
+ htest.AddHisTags(new Cdy.Tag.HisTag() { Id = vtag.Id, TagType = Cdy.Tag.TagType.Double, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 });
+ }
+ }
+
+ if (paras.Length > 1)
+ {
+ int fcount = int.Parse(paras[1]);
+ for (int i = 0; i < fcount; i++)
+ {
+ if (i % 3 == 0)
+ {
+ address = "Sim:sin";
+ }
+ else if (i % 3 == 1)
+ {
+ address = "Sim:cos";
+ }
+ else
+ {
+ address = "Sim:step";
+ }
+ var vtag = new Cdy.Tag.FloatTag() { Name = "Float" + i, Group = "Float", LinkAddress = address };
+ test.Append(vtag);
+ htest.AddHisTags(new Cdy.Tag.HisTag() { Id = vtag.Id, TagType = Cdy.Tag.TagType.Float, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 });
+ }
+ }
+
+ if (paras.Length > 2)
+ {
+ int fcount = int.Parse(paras[2]);
+ for (int i = 0; i < fcount; i++)
+ {
+ var vtag = new Cdy.Tag.LongTag() { Name = "Long" + i, Group = "Long", LinkAddress = "Sim:step" };
+ test.Append(vtag);
+ htest.AddHisTags(new Cdy.Tag.HisTag() { Id = vtag.Id, TagType = Cdy.Tag.TagType.Long, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 });
+ }
+ }
+
+ if (paras.Length > 3)
+ {
+ int fcount = int.Parse(paras[3]);
+ for (int i = 0; i < fcount; i++)
+ {
+ var vtag = new Cdy.Tag.IntTag() { Name = "Int" + i, Group = "Int", LinkAddress = "Sim:step" };
+ test.Append(vtag);
+ htest.AddHisTags(new Cdy.Tag.HisTag() { Id = vtag.Id, TagType = Cdy.Tag.TagType.Int, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 });
+ }
+ }
+
+ if (paras.Length > 4)
+ {
+ int fcount = int.Parse(paras[4]);
+ for (int i = 0; i < fcount; i++)
+ {
+ var vtag = new Cdy.Tag.BoolTag() { Name = "Bool" + i, Group = "Bool", LinkAddress = "Sim:square" };
+ test.Append(vtag);
+ htest.AddHisTags(new Cdy.Tag.HisTag() { Id = vtag.Id, TagType = Cdy.Tag.TagType.Bool, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 });
+ }
+ }
+
+
+ if (paras.Length > 5)
+ {
+ int fcount = int.Parse(paras[5]);
+ for (int i = 0; i < fcount; i++)
+ {
+ var vtag = new Cdy.Tag.IntPointTag() { Name = "IntPoint" + i, Group = "IntPoint", LinkAddress = "Sim:steppoint" };
+ test.Append(vtag);
+ htest.AddHisTags(new Cdy.Tag.HisTag() { Id = vtag.Id, TagType = Cdy.Tag.TagType.IntPoint, Circle = 1000, Type = Cdy.Tag.RecordType.Timer, CompressType = 0 });
}
}
}
@@ -246,6 +373,7 @@ namespace DBStudio
re.AppendLine("import [filename] //import tags from a csvfile");
re.AppendLine("export [filename] //export tags to a csvfile");
re.AppendLine("list [tagtype] //the sumery info of specical type tags or all tags");
+ re.AppendLine("sp [double tag number] [float tag number] [long tag number] [int tag number] [bool tag number] [intpoint tag number] //Quickly generate a specified number of tags for test purposes");
re.AppendLine("exit //exit and back to parent");
return re.ToString();
@@ -319,6 +447,32 @@ namespace DBStudio
sb.Append(mRealTagMode.Group + ",");
sb.Append(mRealTagMode.Type + ",");
sb.Append(mRealTagMode.LinkAddress + ",");
+ sb.Append((int)mRealTagMode.ReadWriteType + ",");
+ if(mRealTagMode.Conveter!=null)
+ sb.Append(mRealTagMode.Conveter.SeriseToString() + ",");
+ else
+ {
+ sb.Append(",");
+ }
+ if (mRealTagMode is NumberTagBase)
+ {
+ sb.Append((mRealTagMode as NumberTagBase).MaxValue.ToString() + ",");
+ sb.Append((mRealTagMode as NumberTagBase).MinValue.ToString() + ",");
+ }
+ else
+ {
+ sb.Append(",");
+ sb.Append(",");
+ }
+ if(mRealTagMode is FloatingTagBase)
+ {
+ sb.Append((mRealTagMode as FloatingTagBase).Precision + ",");
+ }
+ else
+ {
+ sb.Append(",");
+ }
+
if (mHisTagMode != null)
{
sb.Append(mHisTagMode.Type + ",");
@@ -352,19 +506,35 @@ namespace DBStudio
realtag.Desc = stmp[2];
realtag.Group = stmp[3];
realtag.LinkAddress = stmp[5];
+ realtag.ReadWriteType = (ReadWriteMode)(int.Parse(stmp[6]));
+ if(stmp[7]!=null)
+ {
+ realtag.Conveter = stmp[7].DeSeriseToValueConvert();
+ }
+
+ if(realtag is NumberTagBase)
+ {
+ (realtag as NumberTagBase).MaxValue = double.Parse(stmp[8], System.Globalization.NumberStyles.Any);
+ (realtag as NumberTagBase).MinValue = double.Parse(stmp[9], System.Globalization.NumberStyles.Any);
+ }
+
+ if (realtag is FloatingTagBase)
+ {
+ (realtag as FloatingTagBase).Precision = byte.Parse(stmp[10]);
+ }
- if (stmp.Length > 6)
+ if (stmp.Length > 11)
{
Cdy.Tag.HisTag histag = new HisTag();
- histag.Type = (Cdy.Tag.RecordType)Enum.Parse(typeof(Cdy.Tag.RecordType), stmp[6]);
+ histag.Type = (Cdy.Tag.RecordType)Enum.Parse(typeof(Cdy.Tag.RecordType), stmp[11]);
- histag.Circle = long.Parse(stmp[7]);
- histag.CompressType = int.Parse(stmp[8]);
+ histag.Circle = long.Parse(stmp[12]);
+ histag.CompressType = int.Parse(stmp[13]);
histag.Parameters = new Dictionary();
histag.TagType = realtag.Type;
histag.Id = realtag.Id;
- for (int i = 9; i < stmp.Length; i++)
+ for (int i = 14; i < stmp.Length; i++)
{
string skey = stmp[i];
if (string.IsNullOrEmpty(skey))
@@ -522,6 +692,7 @@ namespace DBStudio
private static void ClearTag(Database database)
{
database.RealDatabase.Tags.Clear();
+ database.RealDatabase.MaxId = 0;
database.HisDatabase.HisTags.Clear();
}
diff --git a/DataRunner/DBRuntime.csproj b/DataRunner/DBRuntime.csproj
index 7d92eda2376c94d0315d6b7de8ac3e1350ef4e19..f31767c97c986a9c63592599a35650fb005f1ed9 100644
--- a/DataRunner/DBRuntime.csproj
+++ b/DataRunner/DBRuntime.csproj
@@ -14,6 +14,7 @@
+
diff --git a/DataRunner/His/Compress/CompressMemory.cs b/DataRunner/His/Compress/CompressMemory.cs
index 33a78dcd86c5250bf47d6f07d59c1ef6cb04668a..89b8225f54ba281982288a548580b1b1c44a9acd 100644
--- a/DataRunner/His/Compress/CompressMemory.cs
+++ b/DataRunner/His/Compress/CompressMemory.cs
@@ -160,7 +160,7 @@ namespace Cdy.Tag
Stopwatch sw = new Stopwatch();
sw.Start();
- CheckTagAddress(source);
+ CheckTagAddress(source);
long datasize = 0;
int headOffset = 4 + 4;
long Offset = headOffset + this.mTagAddress.Count * 8;
@@ -234,8 +234,10 @@ namespace Cdy.Tag
tp.Parameters = histag.Parameters;
var size = tp.Compress(mSourceMemory, addr, this, targetPosition + 5, len) + 1;
this.WriteInt(targetPosition, (int)size);
+ //this.Dump();
return size + 5;
}
+
return 0;
}
diff --git a/DataRunner/His/Compress/Special/NoneCompressUnit.cs b/DataRunner/His/Compress/Special/NoneCompressUnit.cs
index 0ca6a1e138818662b89b13bd4b7ce27526c28614..af70a1312133f4eea977e2530d8d99fd88147e19 100644
--- a/DataRunner/His/Compress/Special/NoneCompressUnit.cs
+++ b/DataRunner/His/Compress/Special/NoneCompressUnit.cs
@@ -48,6 +48,7 @@ namespace Cdy.Tag
///
public override long Compress(MarshalMemoryBlock source, long sourceAddr, MarshalMemoryBlock target, long targetAddr, long size)
{
+ // LoggerService.Service.Erro("NoneCompressUnit", "目标地址:"+targetAddr +" 数值地址: " + (targetAddr+10) +" 变量个数: "+ (size - this.QulityOffset));
target.WriteDatetime(targetAddr,this.StartTime);
target.Write((ushort)(size - this.QulityOffset));//写入值的个数
if (size > 0)
@@ -3211,11 +3212,12 @@ namespace Cdy.Tag
var vals = source.ReadInts(valaddr, valuecount * 2);
- for (i = 0; i < valuecount; i=i+2)
+ for (i = 0; i < vals.Count; i=i+2)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 2;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1] , qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1] , qs[j].Item1, qq[j]);
rcount++;
}
}
@@ -3229,11 +3231,12 @@ namespace Cdy.Tag
var vals = source.ReadUInts(valaddr, valuecount * 2);
- for (i = 0; i < valuecount; i = i + 2)
+ for (i = 0; i < vals.Count; i = i + 2)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 2;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1], qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1], qs[j].Item1, qq[j]);
rcount++;
}
}
@@ -3247,11 +3250,12 @@ namespace Cdy.Tag
var vals = source.ReadInts(valaddr, valuecount * 3);
- for (i = 0; i < valuecount; i = i + 3)
+ for (i = 0; i < vals.Count; i = i + 3)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 3;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1],vals[i + 2], qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1],vals[i + 2], qs[j].Item1, qq[j]);
rcount++;
}
}
@@ -3265,11 +3269,12 @@ namespace Cdy.Tag
var vals = source.ReadUInts(valaddr, valuecount * 3);
- for (i = 0; i < valuecount; i = i + 3)
+ for (i = 0; i < vals.Count; i = i + 3)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 3;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1], vals[i + 2], qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1], vals[i + 2], qs[j].Item1, qq[j]);
rcount++;
}
}
@@ -3283,11 +3288,12 @@ namespace Cdy.Tag
var vals = source.ReadLongs(valaddr, valuecount * 2);
- for (i = 0; i < valuecount; i = i + 2)
+ for (i = 0; i < vals.Count; i = i + 2)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 2;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1], qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1], qs[j].Item1, qq[j]);
rcount++;
}
}
@@ -3301,11 +3307,12 @@ namespace Cdy.Tag
var vals = source.ReadULongs(valaddr, valuecount * 2);
- for (i = 0; i < valuecount; i = i + 2)
+ for (i = 0; i < vals.Count; i = i + 2)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 2;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1], qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1], qs[j].Item1, qq[j]);
rcount++;
}
}
@@ -3319,11 +3326,12 @@ namespace Cdy.Tag
var vals = source.ReadLongs(valaddr, valuecount * 3);
- for (i = 0; i < valuecount; i = i + 3)
+ for (i = 0; i < vals.Count; i = i + 3)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 3;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1], vals[i + 2], qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1], vals[i + 2], qs[j].Item1, qq[j]);
rcount++;
}
}
@@ -3337,11 +3345,12 @@ namespace Cdy.Tag
var vals = source.ReadULongs(valaddr, valuecount * 3);
- for (i = 0; i < valuecount; i = i + 3)
+ for (i = 0; i < vals.Count; i = i + 3)
{
- if (qs[i].Item2 && qq[i] < 100 && qs[i].Item1 >= startTime && qs[i].Item1 < endTime)
+ int j = i / 3;
+ if (qs[j].Item2 && qq[j] < 100 && qs[j].Item1 >= startTime && qs[j].Item1 < endTime)
{
- result.AddPoint(vals[i], vals[i + 1], vals[i + 2], qs[i].Item1, qq[i]);
+ result.AddPoint(vals[i], vals[i + 1], vals[i + 2], qs[j].Item1, qq[j]);
rcount++;
}
}
diff --git a/DataRunner/His/HisEnginer.cs b/DataRunner/His/HisEnginer.cs
index aca5c2a6e4599d1f9f8ff7316a4f41fb719cc5fe..2cee371fb11e05cc7e45b82b07a8ef9e4ddfc5a1 100644
--- a/DataRunner/His/HisEnginer.cs
+++ b/DataRunner/His/HisEnginer.cs
@@ -414,8 +414,24 @@ namespace Cdy.Tag
case Cdy.Tag.TagType.ULong:
case Cdy.Tag.TagType.Double:
case Cdy.Tag.TagType.DateTime:
+ case TagType.UIntPoint:
+ case TagType.IntPoint:
qulityOffset = dataOffset + count * 8;
return qulityOffset + count;
+ case Cdy.Tag.TagType.IntPoint3:
+ case Cdy.Tag.TagType.UIntPoint3:
+ qulityOffset = dataOffset + count * 12;
+ return qulityOffset + count;
+
+ case Cdy.Tag.TagType.LongPoint:
+ case Cdy.Tag.TagType.ULongPoint:
+ qulityOffset = dataOffset + count * 16;
+ return qulityOffset + count;
+
+ case Cdy.Tag.TagType.LongPoint3:
+ case Cdy.Tag.TagType.ULongPoint3:
+ qulityOffset = dataOffset + count * 24;
+ return qulityOffset + count;
case Cdy.Tag.TagType.String:
qulityOffset = dataOffset + count * Const.StringSize;
return qulityOffset + count;
@@ -559,6 +575,19 @@ namespace Cdy.Tag
}
}
+ ///
+ ///
+ ///
+ ///
+ private void CheckMemoryIsReady(MarshalMemoryBlock memory)
+ {
+ while (memory.IsBusy())
+ {
+ LoggerService.Service.Info("Record", "记录出现阻塞 " + memory.Name);
+ System.Threading.Thread.Sleep(1);
+ }
+ }
+
///
///
///
@@ -589,6 +618,7 @@ namespace Cdy.Tag
if (mMergeMemory != null)
{
RecordAllLastValue();
+ //mMergeMemory.Dump();
mMergeMemory.MakeMemoryBusy();
//提交到数据压缩流程
@@ -632,13 +662,17 @@ namespace Cdy.Tag
//拷贝时间
var tcount = (tag.Value.HisValueStartAddr - tag.Value.TimerValueStartAddr);
var vtimeaddr = addrbase + tcount * count + 2;
- mMergeMemory.CopyFrom(mcc, tag.Value.TimerValueStartAddr, vtimeaddr, tcount);
+ // mcc.CopyTo(mMergeMemory, tag.Value.TimerValueStartAddr, vtimeaddr, tcount);
+
+ mMergeMemory.CopyFrom(mcc, tag.Value.TimerValueStartAddr, vtimeaddr, tcount);
//LoggerService.Service.Info("HisEnginer","拷贝时间数据:"+count+"," + tag.Value.TimerValueStartAddr +","+ vtimeaddr + "," + tcount);
//拷贝数值
tcount = tag.Value.HisQulityStartAddr - tag.Value.HisValueStartAddr;
vtimeaddr = addrbase + vaddrs.Item2 + tcount * count+tag.Value.SizeOfValue;
- mMergeMemory.CopyFrom(mcc, tag.Value.HisValueStartAddr, vtimeaddr, tcount);
+ //mcc.CopyTo(mMergeMemory, tag.Value.HisValueStartAddr, vtimeaddr, tcount);
+
+ mMergeMemory.CopyFrom(mcc, tag.Value.HisValueStartAddr, vtimeaddr, tcount);
//LoggerService.Service.Info("HisEnginer", "拷贝数值数据:" + count + "," + tag.Value.HisValueStartAddr + "," + vtimeaddr + "," + tcount);
@@ -646,15 +680,19 @@ namespace Cdy.Tag
//拷贝质量戳
tcount = tag.Value.DataSize - tag.Value.HisQulityStartAddr + tag.Value.BlockHeadStartAddr;
vtimeaddr = addrbase + vaddrs.Item3 + tcount * count+1;
+ // mcc.CopyTo(mMergeMemory, tag.Value.HisQulityStartAddr, vtimeaddr, tcount);
mMergeMemory.CopyFrom(mcc, tag.Value.HisQulityStartAddr, vtimeaddr, tcount);
//LoggerService.Service.Info("HisEnginer", "拷贝质量戳数据:" + count + "," + tag.Value.HisQulityStartAddr + "," + vtimeaddr + "," + tcount);
}
//});
+ // mMergeMemory.Dump();
//mcc.Dump();
- ClearMemoryHisData(mcc);
+
mcc.MakeMemoryNoBusy();
+ //ClearMemoryHisData(mcc);
+
sw.Stop();
LoggerService.Service.Info("Record", "合并完成 " + mcc.Name+" 次数:"+(count+1)+" 耗时:"+sw.ElapsedMilliseconds);
}
@@ -828,19 +866,16 @@ namespace Cdy.Tag
LoggerService.Service.Info("Record", "*************************************************************************", ConsoleColor.Green);
}
- //else
- //{
- foreach (var vv in mRecordTimerProcesser)
- {
- vv.Notify(dt);
- }
+ foreach (var vv in mRecordTimerProcesser)
+ {
+ vv.Notify(dt);
+ }
- //值改变的变量,也受内部定时逻辑处理。这样值改变频路高于MemoryTimeTick 的值时,无效。
- foreach (var vv in mValueChangedProcesser)
- {
- vv.Notify(dt);
- }
- //}
+ //值改变的变量,也受内部定时逻辑处理。这样值改变频路高于MemoryTimeTick 的值时,无效。
+ foreach (var vv in mValueChangedProcesser)
+ {
+ vv.Notify(dt);
+ }
mIsBusy = false;
}
@@ -909,6 +944,7 @@ namespace Cdy.Tag
{
Stopwatch sw = new Stopwatch();
sw.Start();
+ while (memory.IsBusy()) ;
memory.Clear();
sw.Stop();
LoggerService.Service.Info("Record", memory.Name + "清空数据区耗时:" + sw.ElapsedMilliseconds);
diff --git a/DataRunner/His/LogManager.cs b/DataRunner/His/LogManager.cs
index 4857b0cac959b6427c6b8f189774eb98de5a99e9..6db73348f77ea09948eabd7d9455db4dc71392b3 100644
--- a/DataRunner/His/LogManager.cs
+++ b/DataRunner/His/LogManager.cs
@@ -189,6 +189,7 @@ namespace Cdy.Tag
mNeedSaveMemory1.MakeMemoryBusy();
RecordToFile();
mNeedSaveMemory1.MakeMemoryNoBusy();
+ ClearMemoryHisData(mNeedSaveMemory1);
}
CheckRemoveOldFiles();
sw.Stop();
@@ -199,6 +200,20 @@ namespace Cdy.Tag
}
+ ///
+ ///
+ ///
+ ///
+ public void ClearMemoryHisData(MarshalFixedMemoryBlock memory)
+ {
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ while (memory.IsBusy()) ;
+ memory.Clear();
+ sw.Stop();
+ LoggerService.Service.Info("Record", memory.Name + "清空数据区耗时:" + sw.ElapsedMilliseconds);
+ }
+
///
///
///
@@ -233,6 +248,7 @@ namespace Cdy.Tag
{
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)));
+ if(!logFiles.ContainsKey(dt))
logFiles.Add(dt, vv.FullName);
}
}
diff --git a/DataRunner/His/Serise/SeriseEnginer.cs b/DataRunner/His/Serise/SeriseEnginer.cs
index be6700eee8c89093386991da720b53b06084e559..bb6f93457422597a84ebe74af40f923bacde24a3 100644
--- a/DataRunner/His/Serise/SeriseEnginer.cs
+++ b/DataRunner/His/Serise/SeriseEnginer.cs
@@ -743,7 +743,7 @@ namespace Cdy.Tag
Stopwatch sw = new Stopwatch();
sw.Start();
- var totalsize = mProcessMemory.ReadInt(dataOffset);
+ var datasize = mProcessMemory.ReadInt(dataOffset);
var count = mProcessMemory.ReadInt(dataOffset + 4);
mTagCount = count;
mCurrentTime = time;
@@ -808,10 +808,17 @@ namespace Cdy.Tag
{
mFileWriter.GoToEnd();
long lpp = mFileWriter.CurrentPostion;
- mProcessMemory.WriteToStream(mFileWriter.GetStream(), start, totalsize - start);//直接拷贝数据块
- // LoggerService.Service.Info("SeriseFileItem", "数据写入地址:" + lpp + ",更新指针地址:" + pointAddr+" block index:"+bid+" tagcount:"+count+" block point Start Addr:"+ mBlockPointOffset+" point values:"+sb.ToString());
-
+
+ mProcessMemory.WriteToStream(mFileWriter.GetStream(), start, datasize);//直接拷贝数据块
+ // mProcessMemory.WriteToStream(mFileWriter.GetStream(), start, totalsize - start);//直接拷贝数据块
+
+
+ LoggerService.Service.Info("SeriseFileItem", "数据写入地址:" + lpp + " 数据大小: "+(datasize) +" 最后地址: "+mFileWriter.CurrentPostion+ ",更新指针地址:" + pointAddr + " block index:" + bid + " tagcount:" + count + " block point Start Addr:" + mBlockPointOffset, ConsoleColor.Red);
+
+ // LoggerService.Service.Info("SeriseFileItem", "数据写入地址:" + lpp + ",更新指针地址:" + pointAddr+" block index:"+bid+" tagcount:"+count+" block point Start Addr:"+ mBlockPointOffset+" point values:"+sb.ToString());
+
+
//this.mFileWriter.Append(mProcessMemory.Buffers, (int)start, (int)(totalsize - start));
mFileWriter.Write(mBlockPointMemory.Buffers, pointAddr, 0, (int)mBlockPointMemory.AllocSize);
@@ -820,7 +827,7 @@ namespace Cdy.Tag
}
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 + " 数据大小:" + ((datasize) + mBlockPointMemory.AllocSize) / 1024.0 / 1024 + " m" +"其他脚本耗时:"+ltmp+","+(ltmp2-ltmp)+","+(ltmp3-ltmp2)+ "存储耗时:" + (sw.ElapsedMilliseconds-ltmp3));
}
catch(System.IO.IOException ex)
diff --git a/DataRunner/His/Tag/HisRunTag.cs b/DataRunner/His/Tag/HisRunTag.cs
index da2bd48ed9b1b8be7aae5ae8f055267eb558964e..122e8192e8196d3a862d8a361ca1f0b8a248564a 100644
--- a/DataRunner/His/Tag/HisRunTag.cs
+++ b/DataRunner/His/Tag/HisRunTag.cs
@@ -176,9 +176,9 @@ namespace Cdy.Tag
//实时数据内存结构为:实时值+时间戳+质量戳,时间戳2个字节,质量戳1个字节
HisAddr.WriteUShortDirect(TimerValueStartAddr + vcount * 2, (ushort)(tim));
- //写入数值
- //HisAddr.WriteBytesDirect(HisValueStartAddr + vcount * SizeOfValue, RealMemoryAddr, RealValueAddr, SizeOfValue);
-
+ //写入数值
+ //HisAddr.WriteBytesDirect(HisValueStartAddr + vcount * SizeOfValue, RealMemoryAddr, RealValueAddr, SizeOfValue);
+ //LoggerService.Service.Erro("HisTag","read from realmemory:"+ MemoryHelper.ReadDouble((void*)RealMemoryPtr, RealValueAddr));
HisAddr.WriteBytesDirect(HisValueStartAddr + vcount * SizeOfValue, RealMemoryPtr, RealValueAddr, SizeOfValue);
//更新质量戳
diff --git a/DataRunner/Real/RealEnginer.cs b/DataRunner/Real/RealEnginer.cs
index 82af0c5bab88f2bcd2c09f6662f510e63372b175..09b9d115d24914df4dc3585706cfb6d38bb1a19c 100644
--- a/DataRunner/Real/RealEnginer.cs
+++ b/DataRunner/Real/RealEnginer.cs
@@ -446,6 +446,7 @@ namespace Cdy.Tag
///
public void SetValueByAddr(long addr, double value, byte quality, DateTime time)
{
+ //LoggerService.Service.Warn("RealEnginer", " write value:"+ value.ToString() + "");
MemoryHelper.WriteDouble(mMHandle, addr, value);
MemoryHelper.WriteDateTime(mMHandle, addr + 8, time);
MemoryHelper.WriteByte(mMHandle, addr + 16, quality); ;
@@ -518,7 +519,7 @@ namespace Cdy.Tag
MemoryHelper.WriteInt32(mMHandle, addr, value1);
MemoryHelper.WriteInt32(mMHandle, addr+4, value2);
MemoryHelper.WriteDateTime(mMHandle, addr + 8, time);
- MemoryHelper.WriteByte(mMHandle, addr + 16, quality); ;
+ MemoryHelper.WriteByte(mMHandle, addr + 16, quality);
}
///
@@ -534,7 +535,7 @@ namespace Cdy.Tag
MemoryHelper.WriteUInt32(mMHandle, addr, value1);
MemoryHelper.WriteUInt32(mMHandle, addr + 4, value2);
MemoryHelper.WriteDateTime(mMHandle, addr + 8, time);
- MemoryHelper.WriteByte(mMHandle, addr + 16, quality); ;
+ MemoryHelper.WriteByte(mMHandle, addr + 16, quality);
}
///
@@ -603,7 +604,7 @@ namespace Cdy.Tag
MemoryHelper.WriteInt64(mMHandle, addr, value1);
MemoryHelper.WriteInt64(mMHandle, addr + 8, value2);
MemoryHelper.WriteDateTime(mMHandle, addr + 16, time);
- MemoryHelper.WriteByte(mMHandle, addr + 24, quality); ;
+ MemoryHelper.WriteByte(mMHandle, addr + 24, quality);
}
///
@@ -621,7 +622,7 @@ namespace Cdy.Tag
MemoryHelper.WriteInt64(mMHandle, addr + 8, value2);
MemoryHelper.WriteInt64(mMHandle, addr + 16, value3);
MemoryHelper.WriteDateTime(mMHandle, addr + 24, time);
- MemoryHelper.WriteByte(mMHandle, addr + 32, quality); ;
+ MemoryHelper.WriteByte(mMHandle, addr + 32, quality);
}
///
@@ -639,7 +640,7 @@ namespace Cdy.Tag
MemoryHelper.WriteUInt64(mMHandle, addr + 8, value2);
MemoryHelper.WriteUInt64(mMHandle, addr + 16, value3);
MemoryHelper.WriteDateTime(mMHandle, addr + 24, time);
- MemoryHelper.WriteByte(mMHandle, addr + 32, quality); ;
+ MemoryHelper.WriteByte(mMHandle, addr + 32, quality);
}
#endregion
@@ -2972,6 +2973,62 @@ namespace Cdy.Tag
#endregion
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool SetTagByGroup(string group, params object[] values)
+ {
+ var vatg = mConfigDatabase.GetTagsByGroup(group);
+ DateTime time = DateTime.Now;
+ for(int i=0;i
///
///
@@ -3792,8 +3849,12 @@ namespace Cdy.Tag
return true;
}
+
+
#endregion
+
+
#endregion ...Interfaces...
}
}
diff --git a/DataRunner/Runner.cs b/DataRunner/Runner.cs
index 6bcfed9762a50dcb9e3561bcaec643512e90e45a..d2c5e8e55ffb6a593078b270fe4b6693a5d13ba8 100644
--- a/DataRunner/Runner.cs
+++ b/DataRunner/Runner.cs
@@ -49,6 +49,8 @@ namespace Cdy.Tag
private QuerySerivce querySerivce;
+ private SecurityRunner mSecurityRunner;
+
private bool mIsStarted = false;
#endregion ...Variables...
@@ -171,6 +173,9 @@ namespace Cdy.Tag
querySerivce = new QuerySerivce(this.mDatabaseName);
+ mSecurityRunner = new SecurityRunner() { Document = mDatabase.Security };
+
+
RegistorInterface();
DriverManager.Manager.Init(realEnginer);
@@ -204,6 +209,8 @@ namespace Cdy.Tag
ServiceLocator.Locator.Registor(querySerivce);
ServiceLocator.Locator.Registor(mRealDatabase);
+
+ ServiceLocator.Locator.Registor(mSecurityRunner);
}
///
@@ -239,6 +246,7 @@ namespace Cdy.Tag
seriseEnginer.Start();
compressEnginer.Start();
hisEnginer.Start();
+ mSecurityRunner.Start();
DriverManager.Manager.Start();
mIsStarted = true;
LoggerService.Service.Info("Runner", " 数据库 " + database + " 启动完成");
@@ -253,6 +261,8 @@ namespace Cdy.Tag
hisEnginer.Stop();
compressEnginer.Stop();
seriseEnginer.Stop();
+ mSecurityRunner.Stop();
+ DriverManager.Manager.Stop();
mIsStarted = false;
}
diff --git a/DataRunner/Security/SecurityRunner.cs b/DataRunner/Security/SecurityRunner.cs
new file mode 100644
index 0000000000000000000000000000000000000000..8723f772bddd43945037fba7fee1700036af7209
--- /dev/null
+++ b/DataRunner/Security/SecurityRunner.cs
@@ -0,0 +1,224 @@
+//==============================================================
+// Copyright (C) 2020 Inc. All rights reserved.
+//
+//==============================================================
+// Create by 种道洋 at 2020/5/9 21:36:54.
+// Version 1.0
+// 种道洋
+//==============================================================
+
+using Cdy.Tag;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+
+namespace Cdy.Tag
+{
+ ///
+ ///
+ ///
+ public class SecurityRunner: IRuntimeSecurity
+ {
+
+ #region ... Variables ...
+ private SecurityDocument mDocument;
+
+ private Dictionary mLastLogin = new Dictionary();
+
+ private Dictionary mUseIdMap = new Dictionary();
+
+ public const int Timeout = 10;
+
+ private bool mIsClosed = false;
+
+ private Thread mScanThread;
+
+ private object mLockObj = new object();
+
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+ ///
+ ///
+ ///
+ public SecurityDocument Document
+ {
+ get
+ {
+ return mDocument;
+ }
+ set
+ {
+ mDocument = value;
+ }
+ }
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+ ///
+ ///
+ ///
+ public void Start()
+ {
+ mScanThread = new Thread(ProcessTimeOut);
+ mScanThread.IsBackground = true;
+ mScanThread.Start();
+ }
+
+ ///
+ ///
+ ///
+ public void Stop()
+ {
+ mIsClosed = true;
+
+ }
+
+ ///
+ ///
+ ///
+ private void ProcessTimeOut()
+ {
+ List ltmp = new List();
+ while(!mIsClosed)
+ {
+ ltmp.Clear();
+ DateTime dt = DateTime.Now;
+ lock (mLockObj)
+ {
+ foreach (var vv in mLastLogin)
+ {
+ if ((dt - vv.Value).TotalMinutes >= Timeout)
+ {
+ ltmp.Add(vv.Key);
+ }
+ }
+ foreach (var vv in ltmp)
+ {
+ mLastLogin.Remove(vv);
+ if (mUseIdMap.ContainsKey(vv)) mUseIdMap.Remove(vv);
+ }
+ }
+
+ Thread.Sleep(500);
+ }
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool CheckLogin(string id)
+ {
+ return mLastLogin.ContainsKey(id);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public string Login(string user, string pass)
+ {
+ if(mDocument!=null&&mDocument.User.Users.ContainsKey(user)&&mDocument.User.Users[user].Password == pass)
+ {
+ string sid = Guid.NewGuid().ToString().Replace("-", "");
+ lock(mLockObj)
+ {
+ mLastLogin.Add(sid, DateTime.Now);
+ mUseIdMap.Add(sid, user);
+ }
+
+ }
+ return string.Empty;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool Logout(string id)
+ {
+ if(mLastLogin.ContainsKey(id))
+ {
+ mLastLogin.Remove(id);
+ }
+ if (mUseIdMap.ContainsKey(id)) return mUseIdMap.Remove(id);
+ return true;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public string GetUserByLoginId(string id)
+ {
+ if(mUseIdMap.ContainsKey(id))
+ {
+ return mUseIdMap[id];
+ }
+ return string.Empty;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public List GetPermission(string id)
+ {
+ List re = new List();
+ if (mDocument.User.Users.ContainsKey(id))
+ {
+ var vtmp = mDocument.User.Users[id].Permissions;
+ if (vtmp != null)
+ {
+ foreach (var vv in vtmp)
+ {
+ if(mDocument.Permission.Permissions.ContainsKey(vv))
+ {
+ re.Add(mDocument.Permission.Permissions[vv]);
+ }
+ }
+ }
+ }
+ return re;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool FreshUserId(string id)
+ {
+ if(mLastLogin.ContainsKey(id))
+ {
+ mLastLogin[id] = DateTime.Now;
+ }
+ return true;
+ }
+
+
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+}
diff --git a/DataRunner/obj/project.assets.json b/DataRunner/obj/project.assets.json
index 0af4ba7296a02f1ef969213e1315ae3538760dc5..befd02de5acf51851592f16170df578f84a96a08 100644
--- a/DataRunner/obj/project.assets.json
+++ b/DataRunner/obj/project.assets.json
@@ -25,6 +25,19 @@
"bin/placeholder/Cdy.Tag.Common.dll": {}
}
},
+ "Cdy.Tag.Consume/1.0.0": {
+ "type": "project",
+ "framework": ".NETStandard,Version=v2.1",
+ "dependencies": {
+ "Cdy.Tag": "1.0.0"
+ },
+ "compile": {
+ "bin/placeholder/Cdy.Tag.Consume.dll": {}
+ },
+ "runtime": {
+ "bin/placeholder/Cdy.Tag.Consume.dll": {}
+ }
+ },
"Cdy.Tag.Driver/1.0.0": {
"type": "project",
"framework": ".NETStandard,Version=v2.1",
@@ -65,6 +78,11 @@
"path": "../Cdy.Tag.Common/Cdy.Tag.Common.csproj",
"msbuildProject": "../Cdy.Tag.Common/Cdy.Tag.Common.csproj"
},
+ "Cdy.Tag.Consume/1.0.0": {
+ "type": "project",
+ "path": "../Cdy.Tag.Consume/Cdy.Tag.Consume.csproj",
+ "msbuildProject": "../Cdy.Tag.Consume/Cdy.Tag.Consume.csproj"
+ },
"Cdy.Tag.Driver/1.0.0": {
"type": "project",
"path": "../Cdy.Tag.Driver/Cdy.Tag.Driver.csproj",
@@ -80,6 +98,7 @@
".NETCoreApp,Version=v3.1": [
"Cdy.Tag >= 1.0.0",
"Cdy.Tag.Common >= 1.0.0",
+ "Cdy.Tag.Consume >= 1.0.0",
"Cdy.Tag.Driver >= 1.0.0",
"DBHisData >= 1.0.0"
]
@@ -117,6 +136,9 @@
"D:\\Project\\Galaxy\\Cdy.Tag.Common\\Cdy.Tag.Common.csproj": {
"projectPath": "D:\\Project\\Galaxy\\Cdy.Tag.Common\\Cdy.Tag.Common.csproj"
},
+ "D:\\Project\\Galaxy\\Cdy.Tag.Consume\\Cdy.Tag.Consume.csproj": {
+ "projectPath": "D:\\Project\\Galaxy\\Cdy.Tag.Consume\\Cdy.Tag.Consume.csproj"
+ },
"D:\\Project\\Galaxy\\Cdy.Tag.Driver\\Cdy.Tag.Driver.csproj": {
"projectPath": "D:\\Project\\Galaxy\\Cdy.Tag.Driver\\Cdy.Tag.Driver.csproj"
},
diff --git a/DbInRunWebApi/Controllers/LoginController.cs b/DbInRunWebApi/Controllers/LoginController.cs
index 298714e612ca1aa6d5b053b2ca764fb3edfb8331..e109b92f37521cf04f9ae5e01e967dbfdb0829b7 100644
--- a/DbInRunWebApi/Controllers/LoginController.cs
+++ b/DbInRunWebApi/Controllers/LoginController.cs
@@ -13,10 +13,33 @@ namespace DbInRunWebApi.Controllers
public class LoginController : ControllerBase
{
// POST: Login
- [HttpPost]
- public string Post([FromBody] LoginUser user)
+ [HttpPost("Login")]
+ public LoginResponse Login([FromBody] LoginUser user)
{
- return Guid.NewGuid().ToString();
+ return new LoginResponse() { Token = Cdy.Tag.ServiceLocator.Locator.Resolve().Login(user.UserName, user.Password),Time=DateTime.Now };
}
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("Hart")]
+ public bool Hart([FromBody] Requestbase token)
+ {
+ return Cdy.Tag.ServiceLocator.Locator.Resolve().FreshUserId(token.Token);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("Logout")]
+ public bool Logout([FromBody] Requestbase token)
+ {
+ return Cdy.Tag.ServiceLocator.Locator.Resolve().Logout(token.Token);
+ }
+
}
}
diff --git a/DbInRunWebApi/Controllers/RealDataController.cs b/DbInRunWebApi/Controllers/RealDataController.cs
index b41d28f9b881d176b6dd3a86a8898efe5b7f2cf8..ffe8e11ec4e7144013626ab2b5e9ae33dc916594 100644
--- a/DbInRunWebApi/Controllers/RealDataController.cs
+++ b/DbInRunWebApi/Controllers/RealDataController.cs
@@ -21,7 +21,23 @@ namespace DbInRunWebApi.Controllers
[HttpGet()]
public RealValueQueryResponse Get([FromBody] RealDataRequest request)
{
-
+ if(DbInRunWebApi.SecurityManager.Manager.IsLogin(request.Token)&&DbInRunWebApi.SecurityManager.Manager.CheckReaderPermission(request.Token,request.Group))
+ {
+ RealValueQueryResponse response = new RealValueQueryResponse() { Result = true, Datas = new List(request.TagNames.Count) };
+ var service = ServiceLocator.Locator.Resolve();
+ var ids = service.GetTagIdByName(request.TagNames);
+ for(int i=0;i().GetTagValue()
return new RealValueQueryResponse() { Result = false };
}
diff --git a/DbInRunWebApi/DbInRunWebApi.csproj b/DbInRunWebApi/DbInRunWebApi.csproj
index 987afe6581d85abac9e85a187776e41b41b48adb..54f1c8bf61bb8735f2c718f646dde63761285a7b 100644
--- a/DbInRunWebApi/DbInRunWebApi.csproj
+++ b/DbInRunWebApi/DbInRunWebApi.csproj
@@ -9,6 +9,7 @@
+
diff --git a/DbInRunWebApi/Model/Requestbase.cs b/DbInRunWebApi/Model/Requestbase.cs
index 8e0ce9c1a6336cdccedc337f6e223dad608e7466..d2147bde9fe0f301e3f48ebd0febda94d4738e39 100644
--- a/DbInRunWebApi/Model/Requestbase.cs
+++ b/DbInRunWebApi/Model/Requestbase.cs
@@ -6,6 +6,73 @@ using System.Threading.Tasks;
namespace DbInRunWebApi.Model
{
+ public class ReponseBase
+ {
+
+ #region ... Variables ...
+
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+ ///
+ ///
+ ///
+ public string Token { get; set; }
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+
+ public class LoginResponse:ReponseBase
+ {
+
+ #region ... Variables ...
+
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+ ///
+ ///
+ ///
+ public DateTime Time { get; set; }
+
+
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+
+
+
///
///
///
@@ -58,7 +125,12 @@ namespace DbInRunWebApi.Model
#endregion ...Constructor...
#region ... Properties ...
-
+
+ ///
+ ///
+ ///
+ public string Group { get; set; }
+
///
///
///
diff --git a/DbInRunWebApi/SecurityManager.cs b/DbInRunWebApi/SecurityManager.cs
new file mode 100644
index 0000000000000000000000000000000000000000..a7aff9f66126a1460b7f20bd0be233b054757ab1
--- /dev/null
+++ b/DbInRunWebApi/SecurityManager.cs
@@ -0,0 +1,138 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Cdy.Tag;
+
+namespace DbInRunWebApi
+{
+ public class SecurityManager
+ {
+
+ #region ... Variables ...
+ ///
+ ///
+ ///
+ public static SecurityManager Manager = new SecurityManager();
+
+ private Dictionary> mUserReaderPermissionCach = new Dictionary>();
+
+
+ private Dictionary> mUserWriterPermissionCach = new Dictionary>();
+
+ ///
+ ///
+ ///
+ private Dictionary mSuperUsers = new Dictionary();
+
+ #endregion ...Variables...
+
+ #region ... Events ...
+
+ #endregion ...Events...
+
+ #region ... Constructor...
+
+ #endregion ...Constructor...
+
+ #region ... Properties ...
+
+ #endregion ...Properties...
+
+ #region ... Methods ...
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool IsLogin(string token)
+ {
+ return ServiceLocator.Locator.Resolve().CheckLogin(token);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool CheckWritePermission(string token,string group)
+ {
+ var securityService = ServiceLocator.Locator.Resolve();
+
+ var user = securityService.GetUserByLoginId(token);
+
+ if (mUserWriterPermissionCach.ContainsKey(user))
+ {
+ return mSuperUsers[user] || (mUserWriterPermissionCach[user].Contains(group));
+ }
+ else
+ {
+ var pps = securityService.GetPermission(user);
+ bool issuerper = false;
+ List mgroups = new List();
+ foreach (var vv in pps)
+ {
+ issuerper = issuerper | vv.SuperPermission;
+ if (vv.Group != null && vv.EnableWrite)
+ mgroups.AddRange(vv.Group);
+ }
+ if (mSuperUsers.ContainsKey(user)) mSuperUsers[user] = issuerper;
+ else mSuperUsers.Add(user, issuerper);
+ mUserWriterPermissionCach.Add(user, mgroups);
+
+ return mSuperUsers[user] || (mUserReaderPermissionCach[user].Contains(group));
+ }
+
+ //var pps = securityService.GetPermission(user);
+ //foreach(var vv in pps)
+ //if (vv.SuperPermission || (vv.Group.Contains(group)&& vv.EnableWrite )) return true;
+ //return false;
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool CheckReaderPermission(string token, string group)
+ {
+ var securityService = ServiceLocator.Locator.Resolve();
+ var user = securityService.GetUserByLoginId(token);
+
+ if (mUserReaderPermissionCach.ContainsKey(user))
+ {
+ return mSuperUsers[user] || (mUserReaderPermissionCach[user].Contains(group));
+ }
+ else
+ {
+ var pps = securityService.GetPermission(user);
+ bool issuerper = false;
+ List mgroups = new List();
+ foreach(var vv in pps)
+ {
+ issuerper = issuerper | vv.SuperPermission;
+ if(vv.Group!=null)
+ mgroups.AddRange(vv.Group);
+ }
+
+ if (mSuperUsers.ContainsKey(user)) mSuperUsers[user] = issuerper;
+ else mSuperUsers.Add(user, issuerper);
+
+ mUserReaderPermissionCach.Add(user, mgroups);
+
+ return mSuperUsers[user] || (mUserReaderPermissionCach[user].Contains(group));
+ }
+ }
+
+ #endregion ...Methods...
+
+ #region ... Interfaces ...
+
+ #endregion ...Interfaces...
+ }
+}
diff --git a/DbManager.Desktop/Properties/Resources.Designer.cs b/DbManager.Desktop/Properties/Resources.Designer.cs
index 5afa5e28c5ad347a1e656e15296bc1989aab863d..1a1a8413af9ac2a028993f128a8719cb0616f6a9 100644
--- a/DbManager.Desktop/Properties/Resources.Designer.cs
+++ b/DbManager.Desktop/Properties/Resources.Designer.cs
@@ -114,6 +114,15 @@ namespace DBInStudio.Desktop.Properties {
}
}
+ ///
+ /// 查找类似 Convert 的本地化字符串。
+ ///
+ internal static string Convert {
+ get {
+ return ResourceManager.GetString("Convert", resourceCulture);
+ }
+ }
+
///
/// 查找类似 Database select 的本地化字符串。
///
@@ -267,6 +276,24 @@ namespace DBInStudio.Desktop.Properties {
}
}
+ ///
+ /// 查找类似 MaxValue 的本地化字符串。
+ ///
+ internal static string MaxValue {
+ get {
+ return ResourceManager.GetString("MaxValue", resourceCulture);
+ }
+ }
+
+ ///
+ /// 查找类似 MinValue 的本地化字符串。
+ ///
+ internal static string MinValue {
+ get {
+ return ResourceManager.GetString("MinValue", resourceCulture);
+ }
+ }
+
///
/// 查找类似 Name 的本地化字符串。
///
@@ -357,6 +384,42 @@ namespace DBInStudio.Desktop.Properties {
}
}
+ ///
+ /// 查找类似 Precision 的本地化字符串。
+ ///
+ internal static string Precision {
+ get {
+ return ResourceManager.GetString("Precision", resourceCulture);
+ }
+ }
+
+ ///
+ /// 查找类似 Read 的本地化字符串。
+ ///
+ internal static string Read {
+ get {
+ return ResourceManager.GetString("Read", resourceCulture);
+ }
+ }
+
+ ///
+ /// 查找类似 ReadWrite 的本地化字符串。
+ ///
+ internal static string ReadWrite {
+ get {
+ return ResourceManager.GetString("ReadWrite", resourceCulture);
+ }
+ }
+
+ ///
+ /// 查找类似 ReadWriteMode 的本地化字符串。
+ ///
+ internal static string ReadWriteMode {
+ get {
+ return ResourceManager.GetString("ReadWriteMode", resourceCulture);
+ }
+ }
+
///
/// 查找类似 Record 的本地化字符串。
///
@@ -536,5 +599,14 @@ namespace DBInStudio.Desktop.Properties {
return ResourceManager.GetString("UserName", resourceCulture);
}
}
+
+ ///
+ /// 查找类似 Write 的本地化字符串。
+ ///
+ internal static string Write {
+ get {
+ return ResourceManager.GetString("Write", resourceCulture);
+ }
+ }
}
}
diff --git a/DbManager.Desktop/Properties/Resources.resx b/DbManager.Desktop/Properties/Resources.resx
index e3e5136f105154567416649cb6fb6542801dd881..a80263703a839b624fbeed7fbfdbc2188dbb2e87 100644
--- a/DbManager.Desktop/Properties/Resources.resx
+++ b/DbManager.Desktop/Properties/Resources.resx
@@ -135,6 +135,9 @@
CompressType
+
+ Convert
+
Database select
List database View Title
@@ -188,6 +191,12 @@
Mars database developer
+
+ MaxValue
+
+
+ MinValue
+
Name
@@ -218,6 +227,18 @@
Permission list
+
+ Precision
+
+
+ Read
+
+
+ ReadWrite
+
+
+ ReadWriteMode
+
Record
@@ -279,4 +300,7 @@
UserName
+
+ Write
+
\ No newline at end of file
diff --git a/DbManager.Desktop/View/Convert/IndexConverter.cs b/DbManager.Desktop/View/Convert/IndexConverter.cs
index 5a522fe934ce2c4efd0986734a6723b4226ff86b..f824115a4853ab6dfb2ec125515ac86573baaea5 100644
--- a/DbManager.Desktop/View/Convert/IndexConverter.cs
+++ b/DbManager.Desktop/View/Convert/IndexConverter.cs
@@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Text;
using System.Windows.Data;
@@ -79,4 +80,34 @@ namespace DBInStudio.Desktop
#endregion ...Interfaces ...
}
+
+ public class BoolInvertConvert : IValueConverter
+ {
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return !(bool)value;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
}
diff --git a/DbManager.Desktop/View/TagGroupDetailView.xaml b/DbManager.Desktop/View/TagGroupDetailView.xaml
index df481829dc7cb9092f4d4834331c29707c1ad033..4652a8c4567505f9bf7d256ff4e20aae7552cfb9 100644
--- a/DbManager.Desktop/View/TagGroupDetailView.xaml
+++ b/DbManager.Desktop/View/TagGroupDetailView.xaml
@@ -9,6 +9,7 @@
+
@@ -55,6 +56,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DbManager.Desktop/View/TagGroupDetailView.xaml.cs b/DbManager.Desktop/View/TagGroupDetailView.xaml.cs
index ea7f0fc597611d8f7b087d74a5a9bb751d9efd10..7d07f26e9edb12dad328080ed9d983b27e28a322 100644
--- a/DbManager.Desktop/View/TagGroupDetailView.xaml.cs
+++ b/DbManager.Desktop/View/TagGroupDetailView.xaml.cs
@@ -32,4 +32,6 @@ namespace DBInStudio.Desktop.View
}
}
}
+
+
}
diff --git a/DbManager.Desktop/ViewModel/PermissionDetailViewModel.cs b/DbManager.Desktop/ViewModel/PermissionDetailViewModel.cs
index efeb9d0260a0c1196602c364a421d451d3106be2..328ad223e4d535303c29743530cfc2f1cb5d8948 100644
--- a/DbManager.Desktop/ViewModel/PermissionDetailViewModel.cs
+++ b/DbManager.Desktop/ViewModel/PermissionDetailViewModel.cs
@@ -153,7 +153,7 @@ namespace DBInStudio.Desktop.ViewModel
private void Add()
{
string sname = GetAvaiabelName("Permission");
- Cdy.Tag.PermissionItem pitem = new Cdy.Tag.PermissionItem() { Name = sname };
+ Cdy.Tag.UserPermission pitem = new Cdy.Tag.UserPermission() { Name = sname };
//if(DBDevelopClientApi.DevelopServiceHelper.Helper.UpdateDatabasePermission(this.Database,pitem))
//{
this.Permissions.Add(new PermissionItemViewModel(pitem) { IsNew = true });
@@ -195,7 +195,7 @@ namespace DBInStudio.Desktop.ViewModel
#region ... Variables ...
- private Cdy.Tag.PermissionItem mModel;
+ private Cdy.Tag.UserPermission mModel;
private string mGroupString;
@@ -222,7 +222,7 @@ namespace DBInStudio.Desktop.ViewModel
///
///
///
- public PermissionItemViewModel(Cdy.Tag.PermissionItem mode)
+ public PermissionItemViewModel(Cdy.Tag.UserPermission mode)
{
mModel = mode;
MakeGroupString();
@@ -291,7 +291,7 @@ namespace DBInStudio.Desktop.ViewModel
///
///
///
- public Cdy.Tag.PermissionItem Model
+ public Cdy.Tag.UserPermission Model
{
get
{
diff --git a/DbManager.Desktop/ViewModel/TagViewModel.cs b/DbManager.Desktop/ViewModel/TagViewModel.cs
index 917d0f78dc2335e5beff24391f89515458251800..fef416f7a7bdfc3dfdc4528ac29da05223559886 100644
--- a/DbManager.Desktop/ViewModel/TagViewModel.cs
+++ b/DbManager.Desktop/ViewModel/TagViewModel.cs
@@ -31,6 +31,7 @@ namespace DBInStudio.Desktop
private static string[] mTagTypeList;
private static string[] mRecordTypeList;
private static string[] mCompressTypeList;
+ private static string[] mReadWriteModeList;
///
///
@@ -46,6 +47,8 @@ namespace DBInStudio.Desktop
private string[] mRegistorList;
+ private ICommand mConvertEditCommand;
+
#endregion ...Variables...
#region ... Events ...
@@ -203,6 +206,18 @@ namespace DBInStudio.Desktop
}
}
+ ///
+ ///
+ ///
+ public string[] ReadWriteModeList
+ {
+ get
+ {
+ return mReadWriteModeList;
+ }
+ }
+
+
///
///
///
@@ -454,6 +469,179 @@ namespace DBInStudio.Desktop
}
}
+ ///
+ ///
+ ///
+ public string ConvertString
+ {
+ get
+ {
+ return mRealTagMode.Conveter != null ? mRealTagMode.Conveter.ToString() : string.Empty;
+ }
+ }
+
+ ///
+ ///
+ ///
+ public IValueConvert Convert
+ {
+ get
+ {
+ return mRealTagMode.Conveter;
+ }
+ set
+ {
+ if (mRealTagMode.Conveter != value)
+ {
+ mRealTagMode.Conveter = value;
+ OnPropertyChanged("Convert");
+ OnPropertyChanged("ConvertString");
+ }
+ }
+ }
+
+ ///
+ ///
+ ///
+ public ICommand ConvertEditCommand
+ {
+ get
+ {
+ if(mConvertEditCommand==null)
+ {
+ mConvertEditCommand = new RelayCommand(() => {
+ // to do here
+ });
+ }
+ return mConvertEditCommand;
+ }
+ }
+
+
+
+
+ ///
+ ///
+ ///
+ public int ReadWriteMode
+ {
+ get
+ {
+ return (int)mRealTagMode.ReadWriteType;
+ }
+ set
+ {
+ if ((int)mRealTagMode.ReadWriteType != value)
+ {
+ mRealTagMode.ReadWriteType = (Cdy.Tag.ReadWriteMode)value;
+ OnPropertyChanged("ReadWriteMode");
+ OnPropertyChanged("ReadWriteModeString");
+ }
+ }
+ }
+
+ ///
+ ///
+ ///
+ public double AllowMaxValue
+ {
+ get
+ {
+ return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).AllowMaxValue : 0;
+ }
+ }
+
+
+ ///
+ ///
+ ///
+ public double AllowMinValue
+ {
+ get
+ {
+ return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).AllowMinValue : 0;
+ }
+ }
+
+ ///
+ ///
+ ///
+ public double MaxValue
+ {
+ get
+ {
+ return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).MaxValue : 0;
+ }
+ set
+ {
+ if (mRealTagMode is Cdy.Tag.NumberTagBase)
+ {
+ if (value <= AllowMaxValue)
+ {
+ (mRealTagMode as Cdy.Tag.NumberTagBase).MaxValue = value;
+ }
+ OnPropertyChanged("MaxValue");
+ }
+ }
+ }
+
+
+ ///
+ ///
+ ///
+ public double MinValue
+ {
+ get
+ {
+ return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).MinValue : 0;
+ }
+ set
+ {
+ if (mRealTagMode is Cdy.Tag.NumberTagBase)
+ {
+ if(value>=AllowMinValue)
+ (mRealTagMode as Cdy.Tag.NumberTagBase).MinValue = value;
+ OnPropertyChanged("MinValue");
+ }
+ }
+ }
+
+ public bool IsNumberTag
+ {
+ get
+ {
+ return mRealTagMode is Cdy.Tag.NumberTagBase;
+ }
+ }
+
+
+ ///
+ ///
+ ///
+ public byte Precision
+ {
+ get
+ {
+ return mRealTagMode is Cdy.Tag.FloatingTagBase ? (mRealTagMode as Cdy.Tag.FloatingTagBase).Precision : (byte)0;
+ }
+ set
+ {
+ if (mRealTagMode is Cdy.Tag.FloatingTagBase)
+ {
+ (mRealTagMode as Cdy.Tag.FloatingTagBase).Precision = value;
+ OnPropertyChanged("Precision");
+ }
+ }
+ }
+
+ public bool IsFloatingTag
+ {
+ get
+ {
+ return mRealTagMode is Cdy.Tag.FloatingTagBase;
+ }
+ }
+
///
///
@@ -466,6 +654,18 @@ namespace DBInStudio.Desktop
}
}
+ ///
+ ///
+ ///
+ public string ReadWriteModeString
+ {
+ get
+ {
+ return Res.Get(((Cdy.Tag.ReadWriteMode)ReadWriteMode).ToString());
+ }
+ }
+
+
///
///
@@ -541,6 +741,7 @@ namespace DBInStudio.Desktop
{
mTagTypeList = Enum.GetNames(typeof(Cdy.Tag.TagType));
mRecordTypeList = Enum.GetNames(typeof(Cdy.Tag.RecordType));
+ mReadWriteModeList = Enum.GetNames(typeof(Cdy.Tag.ReadWriteMode));
}
///
@@ -763,7 +964,32 @@ namespace DBInStudio.Desktop
sb.Append(mRealTagMode.Group + ",");
sb.Append(mRealTagMode.Type + ",");
sb.Append(mRealTagMode.LinkAddress + ",");
- if(this.mHisTagMode!=null)
+ sb.Append((int)mRealTagMode.ReadWriteType + ",");
+ if (mRealTagMode.Conveter != null)
+ sb.Append(mRealTagMode.Conveter.SeriseToString() + ",");
+ else
+ {
+ sb.Append(",");
+ }
+ if (mRealTagMode is NumberTagBase)
+ {
+ sb.Append((mRealTagMode as NumberTagBase).MaxValue.ToString() + ",");
+ sb.Append((mRealTagMode as NumberTagBase).MinValue.ToString() + ",");
+ }
+ else
+ {
+ sb.Append(",");
+ sb.Append(",");
+ }
+ if (mRealTagMode is FloatingTagBase)
+ {
+ sb.Append((mRealTagMode as FloatingTagBase).Precision + ",");
+ }
+ else
+ {
+ sb.Append(",");
+ }
+ if (this.mHisTagMode!=null)
{
sb.Append(mHisTagMode.Type + ",");
sb.Append(mHisTagMode.Circle + ",");
@@ -796,19 +1022,34 @@ namespace DBInStudio.Desktop
realtag.Desc = stmp[2];
realtag.Group = stmp[3];
realtag.LinkAddress = stmp[5];
+ realtag.ReadWriteType = (ReadWriteMode)(int.Parse(stmp[6]));
+ if (stmp[7] != null)
+ {
+ realtag.Conveter = stmp[7].DeSeriseToValueConvert();
+ }
- if (stmp.Length > 6)
+ if (realtag is NumberTagBase)
+ {
+ (realtag as NumberTagBase).MaxValue = double.Parse(stmp[8], System.Globalization.NumberStyles.Any);
+ (realtag as NumberTagBase).MinValue = double.Parse(stmp[9], System.Globalization.NumberStyles.Any);
+ }
+
+ if (realtag is FloatingTagBase)
+ {
+ (realtag as FloatingTagBase).Precision = byte.Parse(stmp[10]);
+ }
+ if (stmp.Length > 11)
{
Cdy.Tag.HisTag histag = new HisTag();
- histag.Type = (Cdy.Tag.RecordType)Enum.Parse(typeof(Cdy.Tag.RecordType), stmp[6]);
+ histag.Type = (Cdy.Tag.RecordType)Enum.Parse(typeof(Cdy.Tag.RecordType), stmp[11]);
- histag.Circle = long.Parse(stmp[7]);
- histag.CompressType = int.Parse(stmp[8]);
+ histag.Circle = long.Parse(stmp[12]);
+ histag.CompressType = int.Parse(stmp[13]);
histag.Parameters = new Dictionary();
histag.TagType = realtag.Type;
histag.Id = realtag.Id;
- for (int i=9;i(id, sTime, eTime);
break;
+ case (byte)Cdy.Tag.TagType.IntPoint:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
+ case (byte)Cdy.Tag.TagType.UIntPoint:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
+ case (byte)Cdy.Tag.TagType.IntPoint3:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
+ case (byte)Cdy.Tag.TagType.UIntPoint3:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
+ case (byte)Cdy.Tag.TagType.LongPoint:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
+ case (byte)Cdy.Tag.TagType.ULongPoint:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
+ case (byte)Cdy.Tag.TagType.LongPoint3:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
+ case (byte)Cdy.Tag.TagType.ULongPoint3:
+ ProcessDataQuery(id, sTime, eTime);
+ break;
}
mIsBusy = false;
}
@@ -616,12 +642,14 @@ namespace HisDataTools.ViewModel
minx = minx > i ? i : minx;
maxx = maxx < i ? i : maxx;
- miny = miny > Convert.ToDouble(value) ? Convert.ToDouble(value) : miny;
- maxy = maxy < Convert.ToDouble(value) ? Convert.ToDouble(value) : maxy;
+ var dtmp = ConvertValue(vv);
+
+ miny = miny > dtmp ? dtmp : miny;
+ maxy = maxy < dtmp ? dtmp : maxy;
PointC point = new PointC();
point.X = i;
- point.Y = Convert.ToDouble(value);
+ point.Y = dtmp;
point.Text = time.ToString("dd HH:mm:ss");
entity.Source.Add(point);
@@ -654,6 +682,15 @@ namespace HisDataTools.ViewModel
YLineItems = yitems;
}
+ private double ConvertValue(object value)
+ {
+ if((value is UIntPointData)|| (value is IntPointData)|| (value is IntPoint3Data)|| (value is UIntPoint3Data)|| (value is LongPointData) || (value is ULongPointData) || (value is LongPoint3Data) || (value is ULongPoint3Data))
+ {
+ return Convert.ToDouble(((dynamic)value).X);
+ }
+ return Convert.ToDouble(value);
+ }
+
///
///
///
@@ -694,12 +731,14 @@ namespace HisDataTools.ViewModel
minx = minx > i ? i : minx;
maxx = maxx < i ? i : maxx;
- miny = miny > Convert.ToDouble(value) ? Convert.ToDouble(value) : miny;
- maxy =maxy < Convert.ToDouble(value) ? Convert.ToDouble(value) : maxy;
+ double dtmp = ConvertValue(value);
+
+ miny = miny > dtmp ? dtmp : miny;
+ maxy =maxy < dtmp ? dtmp : maxy;
PointC point = new PointC();
point.X = i;
- point.Y = Convert.ToDouble(value);
+ point.Y = dtmp;
point.Text = time.ToString("dd HH:mm:ss");
entity.Source.Add(point);
diff --git a/Mars.sln b/Mars.sln
index 5ed5b60d3590d4b64be066aa3cf27ae3221e6126..833f1ffd3bc4e954f76eef6933c157dcf8f23afe 100644
--- a/Mars.sln
+++ b/Mars.sln
@@ -43,7 +43,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{2C1049
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cdy.Tag.Consume", "Cdy.Tag.Consume\Cdy.Tag.Consume.csproj", "{1B99F842-E366-43E8-8FAF-A14A10740B9E}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbInRunWebApi", "DbInRunWebApi\DbInRunWebApi.csproj", "{5D7F9E22-D683-4E27-8952-4A36EE8AB123}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbInRunWebApi", "DbInRunWebApi\DbInRunWebApi.csproj", "{5D7F9E22-D683-4E27-8952-4A36EE8AB123}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cdy.Tag.Network", "Cdy.Tag.Network\Cdy.Tag.Network.csproj", "{3B08487A-442F-4ACF-BFC1-7A4EE5FD4AE2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -119,6 +121,10 @@ Global
{5D7F9E22-D683-4E27-8952-4A36EE8AB123}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D7F9E22-D683-4E27-8952-4A36EE8AB123}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D7F9E22-D683-4E27-8952-4A36EE8AB123}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3B08487A-442F-4ACF-BFC1-7A4EE5FD4AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3B08487A-442F-4ACF-BFC1-7A4EE5FD4AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3B08487A-442F-4ACF-BFC1-7A4EE5FD4AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3B08487A-442F-4ACF-BFC1-7A4EE5FD4AE2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -141,6 +147,7 @@ Global
{F6B8840F-9F8C-4194-923F-BCF0BA1D9BF3} = {95F6A9D4-42A9-483A-80F8-EADDD6CEFEDE}
{1B99F842-E366-43E8-8FAF-A14A10740B9E} = {2C104906-798F-4EEB-931C-F01600EA9F7F}
{5D7F9E22-D683-4E27-8952-4A36EE8AB123} = {95F6A9D4-42A9-483A-80F8-EADDD6CEFEDE}
+ {3B08487A-442F-4ACF-BFC1-7A4EE5FD4AE2} = {2C104906-798F-4EEB-931C-F01600EA9F7F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {577CCEC3-4CDB-458A-B93D-F8579C2C3D8F}
diff --git a/SimDriver/Driver.cs b/SimDriver/Driver.cs
index 1963e849004c5e750e57178666c8f75ba7906cd9..5d7eb548c9ddfb56bd18cf476202f030cd168970 100644
--- a/SimDriver/Driver.cs
+++ b/SimDriver/Driver.cs
@@ -5,6 +5,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Threading;
namespace SimDriver
{
@@ -19,6 +20,8 @@ namespace SimDriver
private short mNumber = 0;
+ private bool mBoolNumber = false;
+
private IRealTagProducter mTagService;
private bool mIsBusy = false;
@@ -29,6 +32,14 @@ namespace SimDriver
private int mBusyCount = 0;
+ private bool mIsSecond = false;
+
+ private int mTickCount = 0;
+
+ private Thread mScanThread;
+
+ private bool mIsClosed = false;
+
#endregion ...Variables...
#region ... Events ...
@@ -64,7 +75,7 @@ namespace SimDriver
{
get
{
- return new string[] { "cos", "sin", "step","steppoint" };
+ return new string[] { "cos", "sin", "step","steppoint", "square" };
}
}
@@ -79,6 +90,7 @@ namespace SimDriver
private void Log(string sval)
{
mWriter.WriteLine(sval);
+ mWriter.Flush();
}
///
@@ -87,7 +99,7 @@ namespace SimDriver
///
private void InitTagCach(IRealTagProducter tagQuery)
{
- mTagIdCach = tagQuery.GetTagsByLinkAddress(new List() { "Sim:cos", "Sim:sin", "Sim:step", "Sim:steppoint" });
+ mTagIdCach = tagQuery.GetTagsByLinkAddress(new List() { "Sim:cos", "Sim:sin", "Sim:step", "Sim:steppoint", "Sim:square" });
}
///
@@ -99,12 +111,96 @@ namespace SimDriver
{
mTagService = tagQuery;
InitTagCach(tagQuery);
- mScanTimer = new System.Timers.Timer(100);
- mScanTimer.Elapsed += MScanTimer_Elapsed;
- mScanTimer.Start();
+ mScanThread = new Thread(ScanThreadPro);
+ mScanThread.IsBackground = true;
+ mScanThread.Start();
+ //mScanTimer = new System.Timers.Timer(100);
+ //mScanTimer.Elapsed += MScanTimer_Elapsed;
+ //mScanTimer.Start();
return true;
}
+ private void ScanThreadPro()
+ {
+ while (!mIsClosed)
+ {
+ mTickCount++;
+ DateTime time = DateTime.Now;
+ if (mTickCount < 5)
+ {
+ mIsBusy = false;
+ Thread.Sleep(100);
+ continue;
+ }
+ else
+ {
+ mTickCount = 0;
+ }
+
+ if((mLastProcessTime-time).TotalSeconds>1000)
+ {
+ LoggerService.Service.Warn("Sim Driver", "出现阻塞");
+ }
+ mLastProcessTime = time;
+ if (!mIsSecond)
+ {
+ mNumber++;
+ mNumber = mNumber > (short)360 ? (short)0 : mNumber;
+ mIsSecond = true;
+ }
+ else
+ {
+ mIsSecond = false;
+ }
+
+
+ if (mNumber % 100 == 0) mBoolNumber = !mBoolNumber;
+
+ double fval = Math.Cos(mNumber / 180.0 * Math.PI);
+ double sval = Math.Sin(mNumber / 180.0 * Math.PI);
+
+//#if DEBUG
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ Log("Sim:Sin " + fval + " " + "Sim:Cos " + sval + " " + "Sim:step " + mNumber + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
+
+//#endif
+
+
+ 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);
+ }
+ else if (vv.Key == "Sim:steppoint")
+ {
+ mTagService.SetPointValue(vv.Value, mNumber, mNumber, mNumber);
+ }
+ else if (vv.Key == "Sim:square")
+ {
+ mTagService.SetPointValue(vv.Value, mBoolNumber);
+ }
+ });
+
+//#if DEBUG
+ sw.Stop();
+
+ LoggerService.Service.Info("Sim Driver", "set value elapsed:" + sw.ElapsedMilliseconds);
+//#endif
+
+ Thread.Sleep(100);
+ }
+ }
+
///
///
///
@@ -112,50 +208,55 @@ namespace SimDriver
///
private void MScanTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
-
+ mTickCount++;
if (mIsBusy)
{
mBusyCount++;
- if(mBusyCount>=10)
- LoggerService.Service.Warn("Sim Driver", "出现阻塞");
+ if (mBusyCount >= 10)
+ {
+ mBusyCount = 0;
+ LoggerService.Service.Warn("Sim Driver", "出现阻塞");
+ }
return;
}
mBusyCount = 0;
mIsBusy = true;
DateTime time = DateTime.Now;
- if ((time - mLastProcessTime).Seconds < 1)
+ if (mTickCount <5)
{
mIsBusy = false;
return;
}
+ else
+ {
+ mTickCount = 0;
+ }
+
mLastProcessTime = time;
+ if(!mIsSecond)
+ {
+ mNumber++;
+ mNumber = mNumber > (short)360 ? (short)0 : mNumber;
+ mIsSecond = true;
+ }
+ else
+ {
+ mIsSecond = false;
+ }
+
+
+ if (mNumber % 100 == 0) mBoolNumber = !mBoolNumber;
- mNumber++;
- mNumber = mNumber > (short)360 ? (short)0 : mNumber;
-//#if DEBUG
-// Stopwatch sw = new Stopwatch();
-// sw.Start();
-//#endif
double fval = Math.Cos(mNumber / 180.0 * Math.PI);
double sval = Math.Sin(mNumber / 180.0 * Math.PI);
+#if DEBUG
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
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)
- //{
- // 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);
- // }
- //}
+#endif
+
System.Threading.Tasks.Parallel.ForEach(mTagIdCach, (vv) =>
{
@@ -175,13 +276,17 @@ namespace SimDriver
{
mTagService.SetPointValue(vv.Value,mNumber,mNumber,mNumber);
}
+ else if (vv.Key == "Sim:square")
+ {
+ mTagService.SetPointValue(vv.Value, mBoolNumber);
+ }
});
-//#if DEBUG
-// sw.Stop();
+#if DEBUG
+ sw.Stop();
-// LoggerService.Service.Info("Sim Driver", "set value elapsed:" + sw.ElapsedMilliseconds + " total count:" + mNumber + " cos:" + Math.Cos(mNumber / 180.0 * Math.PI) + " sin:" + Math.Sin(mNumber / 180.0 * Math.PI));
-//#endif
+ LoggerService.Service.Info("Sim Driver", "set value elapsed:" + sw.ElapsedMilliseconds + " total count:" + mNumber + " cos:" + Math.Cos(mNumber / 180.0 * Math.PI) + " sin:" + Math.Sin(mNumber / 180.0 * Math.PI));
+#endif
mIsBusy = false;
}
@@ -191,7 +296,9 @@ namespace SimDriver
///
public bool Stop()
{
- mScanTimer.Stop();
+ //mScanTimer.Stop();
+ mIsClosed = true;
+ // mScanThread.Abort();
mWriter.Close();
return true;
}