EntityEx.cs 2.8 KB

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