Work.cs 824 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using WCS.Core;
  5. using WCS.Entity;
  6. namespace WCS.Service.Handlers
  7. {
  8. public abstract class Work<T> : Work
  9. {
  10. public override sealed void Execute(object obj)
  11. {
  12. Do((T)obj);
  13. }
  14. public override sealed IEnumerable<object> GetObjs()
  15. {
  16. return InitObjects().OfType<object>().ToArray();
  17. }
  18. protected abstract void Do(T obj);
  19. protected abstract bool SelectDevice(WCS_DEVICE dev);
  20. protected virtual IEnumerable<T> InitObjects()
  21. {
  22. var arr = Device.Where(v => v.ENABLED)
  23. .Where(SelectDevice).ToArray();
  24. var res = arr.Select(v => (T)Activator.CreateInstance(typeof(T), v));
  25. return res;
  26. }
  27. }
  28. }