You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

120 lines
4.2 KiB

  1. using HBLConsole.Abstract;
  2. using HBLConsole.Interface;
  3. using System;
  4. using System.Reflection;
  5. using BPA.Message.Enum;
  6. using HBLConsole.GVL;
  7. using BPA.Message;
  8. using HBLConsole.Service;
  9. using HBLConsole.Communication;
  10. namespace HBLConsole.Factory
  11. {
  12. public class SimpleFactory
  13. {
  14. private volatile static SimpleFactory _Instance;
  15. public static SimpleFactory GetInstance => _Instance ?? (_Instance = new SimpleFactory());
  16. private SimpleFactory() { }
  17. public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer());
  18. private AbstractMessageServer _GetAbsMessageServer;
  19. private string DeviceType => GeneralConfig.DeviceType.ToString();
  20. private object debugControl;
  21. public void MqttMessage(IMessage message)
  22. {
  23. GetAbsMessageServer.AddOrder(message);
  24. GetAbsMessageServer.GetBatchingInfo(message);
  25. GetAbsMessageServer.GetRecipeBom(message);
  26. }
  27. /// <summary>
  28. /// 获取物料信息
  29. /// </summary>
  30. public void GetBatchingInfo()
  31. {
  32. GetAbsMessageServer.GetBatchingInfo(InternetInfo.ClientId);
  33. }
  34. /// <summary>
  35. /// 订单状态更改
  36. /// </summary>
  37. /// <param name="subid"></param>
  38. /// <param name="status"></param>
  39. /// <returns></returns>
  40. public bool OrderChanged(string subid, ORDER_STATUS status)
  41. {
  42. bool res = GetAbsMessageServer.OrderStatusChange(subid, status);
  43. if (res)
  44. {
  45. ActionOperate.GetInstance.Send("OrderStatusChange", new OrderStatusChange()
  46. {
  47. CookingStatus = status,
  48. SuborderId = subid
  49. });
  50. }
  51. return res;
  52. }
  53. private AbstractMessageServer GetAbstractMessageServer()
  54. {
  55. string NameSpace = "HBLConsole.Business";
  56. Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.{DeviceType}");
  57. if (type == null)
  58. type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.Base");
  59. return Activator.CreateInstance(type) as AbstractMessageServer;
  60. }
  61. IControl control;
  62. /// <summary>
  63. /// 设备初始化
  64. /// </summary>
  65. public void DeviceInit()
  66. {
  67. return;
  68. string NameSpace = $"HBLConsole.{DeviceType}";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类
  69. Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{DeviceType}");
  70. control = Activator.CreateInstance(type) as IControl;
  71. //IControl business = (IControl)type?.GetProperty("GetInstance").GetValue(null);
  72. GetBatchingInfo();
  73. control?.Init();
  74. ActionOperate.GetInstance.Register(new Action<object>((o) => { control?.DataParse(o); }), "DataParse");
  75. ActionOperate.GetInstance.Register(new Action(() => { control?.ConnectOk(); }), "ConnectOk");
  76. ActionOperate.GetInstance.Register(new Action<object>((o) => { control?.SimOrder(o); }), "SimOrder");
  77. ConnectHelper.GetInstance.Init();
  78. }
  79. public IGvl GetGvl()
  80. {
  81. Type type = control?.GetType();
  82. foreach (var item in type?.GetProperties())
  83. {
  84. var interfaces = item.PropertyType.GetInterfaces();
  85. if (interfaces != null)
  86. {
  87. foreach (var inters in interfaces)
  88. {
  89. if (inters.Name.Equals("IGvl"))
  90. {
  91. return (type?.GetProperty(item.Name).GetValue(control, null)) as IGvl;
  92. }
  93. }
  94. }
  95. }
  96. return default;
  97. }
  98. public object GetDebugControl()
  99. {
  100. if (null == debugControl)
  101. {
  102. debugControl = Assembly.Load("HBLConsole.Debug").CreateInstance($"HBLConsole.Debug.Debug_{DeviceType}");
  103. }
  104. return debugControl;
  105. }
  106. }
  107. }