EntityEx.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. public EntityEx(T entity)
  14. {
  15. this.Entity = entity;
  16. }
  17. public virtual DateTime UpdateTime { get; set; }
  18. public double Times
  19. {
  20. get
  21. {
  22. return (DateTime.Now - UpdateTime).TotalMilliseconds;
  23. }
  24. }
  25. public override string ToString()
  26. {
  27. return Entity.ToString();
  28. }
  29. }
  30. public class Device<T> : EntityEx<WCS_DEVICE> where T : IProtocol
  31. {
  32. public T Data { get; private set; }
  33. public Device(WCS_DEVICE entity) : base(entity)
  34. {
  35. Data = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T).AssemblyQualifiedName).Single().Data<T>();
  36. }
  37. }
  38. public class Device<T, T2> : Device<T> where T : IProtocol where T2 : IProtocol
  39. {
  40. public T2 Data2 { get; private set; }
  41. public Device(WCS_DEVICE entity) : base(entity)
  42. {
  43. Data2 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T2).AssemblyQualifiedName).Single().Data<T2>();
  44. }
  45. }
  46. public class Device<T, T2, T3> : Device<T, T2> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
  47. {
  48. public T3 Data3 { get; private set; }
  49. public Device(WCS_DEVICE entity) : base(entity)
  50. {
  51. Data3 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T3).AssemblyQualifiedName).Single().Data<T3>();
  52. }
  53. }
  54. public class Device<T, T2, T3, T4> : Device<T, T2, T3> where T : IProtocol where T2 : IProtocol where T3 : IProtocol where T4 : IProtocol
  55. {
  56. public T4 Data4 { get; private set; }
  57. public Device(WCS_DEVICE entity) : base(entity)
  58. {
  59. Data4 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T4).AssemblyQualifiedName).Single().Data<T4>();
  60. }
  61. }
  62. public class Group<T> : EntityEx<WCS_DEVICE> where T : EntityEx<WCS_DEVICE>
  63. {
  64. public IEnumerable<T> Items { get; private set; }
  65. public Group(WCS_DEVICE entity) : base(entity)
  66. {
  67. Items = entity.DEVICEGROUP.Select(v => Activator.CreateInstance(typeof(T), v.MEMBER)).OfType<T>().OrderBy(p => p.Entity.CODE).ToList();
  68. }
  69. }
  70. public class DeviceGroup<T> : Group<Device<T>> where T : IProtocol
  71. {
  72. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  73. {
  74. }
  75. }
  76. public class DeviceGroup<T, T2> : Group<Device<T, T2>> where T : IProtocol where T2 : IProtocol
  77. {
  78. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  79. {
  80. }
  81. }
  82. public class DeviceGroup<T, T2, T3> : Group<Device<T, T2, T3>> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
  83. {
  84. public DeviceGroup(WCS_DEVICE entity) : base(entity)
  85. {
  86. }
  87. }
  88. }