EntityEx.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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; private set;
  12. }
  13. /// <summary>
  14. /// 执行中的设备
  15. /// </summary>
  16. public static List<string> ExDevice { get; set; } = new List<string>();
  17. /// <summary>
  18. /// 添加锁
  19. /// </summary>
  20. private static readonly object Addobj = new object();
  21. /// <summary>
  22. /// 移除锁
  23. /// </summary>
  24. private static readonly object removeobj = new object();
  25. /// <summary>
  26. /// 添加进行中的设备
  27. /// </summary>
  28. /// <param name="e"></param>
  29. public void AddExDevice(string e)
  30. {
  31. //lock (Addobj)
  32. //{
  33. ExDevice.Add(e);
  34. //}
  35. }
  36. /// <summary>
  37. /// 移除进行中的设备
  38. /// </summary>
  39. /// <param name="e"></param>
  40. public void RemoveExDevice(string e)
  41. {
  42. //lock (removeobj)
  43. //{
  44. ExDevice.Remove(e);
  45. //}
  46. }
  47. public EntityEx(T entity)
  48. {
  49. this.Entity = entity;
  50. }
  51. public virtual DateTime UpdateTime { get; set; }
  52. public double Times
  53. {
  54. get
  55. {
  56. return (DateTime.Now - UpdateTime).TotalMilliseconds;
  57. }
  58. }
  59. public override string ToString()
  60. {
  61. return Entity.ToString();
  62. }
  63. }
  64. public class Device<T> : EntityEx<WCS_DEVICE> where T : IProtocol
  65. {
  66. public T Data { get; private set; }
  67. public Device(WCS_DEVICE entity) : base(entity)
  68. {
  69. Data = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T).AssemblyQualifiedName).Single().Data<T>();
  70. }
  71. }
  72. public class Device<T, T2> : Device<T> where T : IProtocol where T2 : IProtocol
  73. {
  74. public T2 Data2 { get; private set; }
  75. public Device(WCS_DEVICE entity) : base(entity)
  76. {
  77. Data2 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T2).AssemblyQualifiedName).Single().Data<T2>();
  78. }
  79. }
  80. public class Device<T, T2, T3> : Device<T, T2> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
  81. {
  82. public T3 Data3 { get; private set; }
  83. public Device(WCS_DEVICE entity) : base(entity)
  84. {
  85. Data3 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T3).AssemblyQualifiedName).Single().Data<T3>();
  86. }
  87. }
  88. public class Device<T, T2, T3, T4> : Device<T, T2, T3> where T : IProtocol where T2 : IProtocol where T3 : IProtocol where T4 : IProtocol
  89. {
  90. public T4 Data4 { get; private set; }
  91. public Device(WCS_DEVICE entity) : base(entity)
  92. {
  93. Data4 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T4).AssemblyQualifiedName).Single().Data<T4>();
  94. }
  95. }
  96. public class Group<T> : EntityEx<WCS_DEVICE> where T : EntityEx<WCS_DEVICE>
  97. {
  98. public IEnumerable<T> Items { get; private set; }
  99. public Group(WCS_DEVICE entity) : base(entity)
  100. {
  101. Items = entity.DEVICEGROUP.Select(v => Activator.CreateInstance(typeof(T), v.MEMBER)).OfType<T>().OrderBy(p => p.Entity.CODE).ToList();
  102. }
  103. }
  104. public class DeviceGroup<T> : Group<Device<T>> where T : IProtocol
  105. {
  106. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  107. {
  108. }
  109. }
  110. public class DeviceGroup<T, T2> : Group<Device<T, T2>> where T : IProtocol where T2 : IProtocol
  111. {
  112. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  113. {
  114. }
  115. }
  116. public class DeviceGroup<T, T2, T3> : Group<Device<T, T2, T3>> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
  117. {
  118. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  119. {
  120. }
  121. }
  122. }