DataCollectionSysyem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using DBHelper;
  2. using Newtonsoft.Json;
  3. using ServiceCenter.Helpers;
  4. using System.ComponentModel;
  5. using WCS.Core;
  6. using WCS.Entity;
  7. using WCS.Entity.Protocol.Station;
  8. using WCS.Service.Worlds;
  9. using WCS.WorkEngineering.Extensions;
  10. namespace WCS.Service.Systems
  11. {
  12. /// <summary>
  13. /// 数据采集系统
  14. /// </summary>
  15. [BelongTo(typeof(DataCollectionWorld))]
  16. [Description("数据采集系统")]
  17. public class DataCollectionSysyem : ServiceSystem<bool, bool>
  18. {
  19. public List<Device<IStation520, IStation521>> ConvList;
  20. public DataCollectionSysyem()
  21. {
  22. ConvList = World.Devices.Where(v => v.IsConv()).Select(v => new Device<IStation520, IStation521>(v)).ToList();
  23. }
  24. protected override bool Do(bool obj)
  25. {
  26. Db.Do(db =>
  27. {
  28. //byte[] bytes = System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
  29. var plcData = new WCS_PlcData()
  30. {
  31. UPDATETIME = DateTime.Now,
  32. WAREHOUSE = "111",
  33. CONTENT = JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }),
  34. };
  35. var a = TypeConversionHelper.SerializeRedisValue(ConvList);
  36. //对bytes进行数据压缩
  37. //plcData.CONTENT = bytes.Compress();
  38. db.Default.Insertable(plcData).ExecuteCommand(); ;
  39. });
  40. return true;
  41. }
  42. }
  43. }