EntityEx.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using WCS.Core.DataTrans;
  5. using WCS.Entity;
  6. namespace WCS.Core
  7. {
  8. public abstract class EntityEx<T>
  9. {
  10. public T Entity
  11. {
  12. get;
  13. }
  14. protected EntityEx(T entity)
  15. {
  16. Entity = entity;
  17. }
  18. public virtual DateTime UpdateTime { get; set; }
  19. public double Times => (DateTime.Now - UpdateTime).TotalMilliseconds;
  20. public override string ToString()
  21. {
  22. return Entity.ToString();
  23. }
  24. }
  25. public class Device<T> : EntityEx<WCS_DEVICE> where T : IProtocol
  26. {
  27. public T Data { get; }
  28. public Device(WCS_DEVICE entity) : base(entity)
  29. {
  30. //新增一个报错
  31. var data = entity.DEVICEPROTOCOLS.FirstOrDefault(v => v.DB.PROTOCOL == typeof(T).AssemblyQualifiedName) ?? throw new Exception($"设备{entity.CODE}对应PROTOCOL有误,请检查相关配置");
  32. Data = data.Data<T>();
  33. }
  34. }
  35. public class Device<T, T2> : Device<T> where T : IProtocol where T2 : IProtocol
  36. {
  37. public T2 Data2 { get; }
  38. public Device(WCS_DEVICE entity) : base(entity)
  39. {
  40. Data2 = entity.DEVICEPROTOCOLS.Single(v => v.DB.PROTOCOL == typeof(T2).AssemblyQualifiedName).Data<T2>();
  41. }
  42. }
  43. public class Device<T, T2, T3> : Device<T, T2> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
  44. {
  45. public T3 Data3 { get; }
  46. public Device(WCS_DEVICE entity) : base(entity)
  47. {
  48. Data3 = entity.DEVICEPROTOCOLS.Single(v => v.DB.PROTOCOL == typeof(T3).AssemblyQualifiedName).Data<T3>();
  49. }
  50. }
  51. public class Device<T, T2, T3, T4> : Device<T, T2, T3> where T : IProtocol where T2 : IProtocol where T3 : IProtocol where T4 : IProtocol
  52. {
  53. public T4 Data4 { get; }
  54. public Device(WCS_DEVICE entity) : base(entity)
  55. {
  56. Data4 = entity.DEVICEPROTOCOLS.Single(v => v.DB.PROTOCOL == typeof(T4).AssemblyQualifiedName).Data<T4>();
  57. }
  58. }
  59. public class Group<T> : EntityEx<WCS_DEVICE> where T : EntityEx<WCS_DEVICE>
  60. {
  61. public IEnumerable<T> Items { get; }
  62. public Group(WCS_DEVICE entity) : base(entity)
  63. {
  64. Items = entity.DEVICEGROUP.Select(v => Device.Find(v.MEMBER.CODE).Create<T>()).OrderBy(p => p.Entity.CODE).ToList();
  65. }
  66. }
  67. public class DeviceGroup<T> : Group<Device<T>> where T : IProtocol
  68. {
  69. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  70. {
  71. }
  72. }
  73. public class DeviceGroup<T, T2> : Group<Device<T, T2>> where T : IProtocol where T2 : IProtocol
  74. {
  75. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  76. {
  77. }
  78. }
  79. public class DeviceGroup<T, T2, T3> : Group<Device<T, T2, T3>> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
  80. {
  81. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  82. {
  83. }
  84. }
  85. }