ProtocolProxy.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using WCS.Core;
  2. using WCS.Entity.Protocol.DataStructure;
  3. using WCS.WorkEngineering.Worlds;
  4. namespace WCS.WorkEngineering;
  5. public class ProtocolProxy : ProtocolProxyBase
  6. {
  7. public ProtocolProxy(Device dev, ProtocolInfo info, Type protocolType, World world) : base(dev, info, protocolType,world)
  8. {
  9. }
  10. public static DeviceDataPack DataPack { get; set; } = new();
  11. protected override void DataChanged()
  12. {
  13. MainWorld.DataQueue.Enqueue(this);
  14. }
  15. private Type GetProtocolType(Type source)
  16. {
  17. var t = source.GetInterfaces().FirstOrDefault(v => v.GetInterfaces().Any(d => d.Name == "IProtocol"));
  18. return t;
  19. }
  20. public object DictionaryToEntity(Type type, Dictionary<string, PlcItem> items)
  21. {
  22. var a = Activator.CreateInstance(type);
  23. foreach (var ty in type.GetProperties())
  24. foreach (var item in items.Where(item => ty.Name == item.Key))
  25. {
  26. ty.SetValue(a, item.Value.Value);
  27. break;
  28. }
  29. return a;
  30. }
  31. public string GetString(string value)
  32. {
  33. return value.Replace("INSERT INTO ", "")
  34. .Replace(",N'", ",'")
  35. .Replace("\0", "")
  36. .Replace("wcs_", "")
  37. .Replace("(N'", "('") + "\r";
  38. }
  39. }