123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using WCS.Entity;
- namespace WCS.Core
- {
- public abstract class EntityEx<T>
- {
- public T Entity
- {
- get; private set;
- }
- public EntityEx(T entity)
- {
- this.Entity = entity;
- }
- public virtual DateTime UpdateTime { get; set; }
- public double Times
- {
- get
- {
- return (DateTime.Now - UpdateTime).TotalMilliseconds;
- }
- }
- public override string ToString()
- {
- return Entity.ToString();
- }
- }
- public class Device<T> : EntityEx<WCS_DEVICE> where T : IProtocol
- {
- public T Data { get; private set; }
- public Device(WCS_DEVICE entity) : base(entity)
- {
- Data = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T).AssemblyQualifiedName).Single().Data<T>();
- }
- }
- public class Device<T, T2> : Device<T> where T : IProtocol where T2 : IProtocol
- {
- public T2 Data2 { get; private set; }
- public Device(WCS_DEVICE entity) : base(entity)
- {
- Data2 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T2).AssemblyQualifiedName).Single().Data<T2>();
- }
- }
- public class Device<T, T2, T3> : Device<T, T2> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
- {
- public T3 Data3 { get; private set; }
- public Device(WCS_DEVICE entity) : base(entity)
- {
- Data3 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T3).AssemblyQualifiedName).Single().Data<T3>();
- }
- }
- public class Device<T, T2, T3, T4> : Device<T, T2, T3> where T : IProtocol where T2 : IProtocol where T3 : IProtocol where T4 : IProtocol
- {
- public T4 Data4 { get; private set; }
- public Device(WCS_DEVICE entity) : base(entity)
- {
- Data4 = entity.PROTOCOLS.Where(v => v.DB.PROTOCOL == typeof(T4).AssemblyQualifiedName).Single().Data<T4>();
- }
- }
- public class Group<T> : EntityEx<WCS_DEVICE> where T : EntityEx<WCS_DEVICE>
- {
- public IEnumerable<T> Items { get; private set; }
- public Group(WCS_DEVICE entity) : base(entity)
- {
- Items = entity.DEVICEGROUP.Select(v => Activator.CreateInstance(typeof(T), v.MEMBER)).OfType<T>().OrderBy(p => p.Entity.CODE).ToList();
- }
- }
- public class DeviceGroup<T> : Group<Device<T>> where T : IProtocol
- {
- public DeviceGroup(WCS_DEVICE entity) : base(entity)
- {
- }
- }
- public class DeviceGroup<T, T2> : Group<Device<T, T2>> where T : IProtocol where T2 : IProtocol
- {
- public DeviceGroup(WCS_DEVICE entity) : base(entity)
- {
- }
- }
- public class DeviceGroup<T, T2, T3> : Group<Device<T, T2, T3>> where T : IProtocol where T2 : IProtocol where T3 : IProtocol
- {
- public DeviceGroup(WCS_DEVICE entity) : base(entity)
- {
- }
- }
- }
|