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.
 
 

86 lines
2.9 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. namespace HBLConsole.Factory
  10. {
  11. public class SimpleFactory
  12. {
  13. private volatile static SimpleFactory _Instance;
  14. public static SimpleFactory GetInstance => _Instance ?? (_Instance = new SimpleFactory());
  15. private SimpleFactory() { }
  16. public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer());
  17. private AbstractMessageServer _GetAbsMessageServer;
  18. private string DeviceType => GeneralConfig.GetInstance.DeviceType.ToString();
  19. public void MqttMessage(IMessage message)
  20. {
  21. GetAbsMessageServer.AddOrder(message);
  22. GetAbsMessageServer.GetBatchingInfo(message);
  23. GetAbsMessageServer.GetRecipeBom(message);
  24. }
  25. /// <summary>
  26. /// 获取物料信息
  27. /// </summary>
  28. public void GetBatchingInfo()
  29. {
  30. GetAbsMessageServer.GetBatchingInfo(InternetInfo.GetInstance.ClientId);
  31. }
  32. /// <summary>
  33. /// 订单状态更改
  34. /// </summary>
  35. /// <param name="subid"></param>
  36. /// <param name="status"></param>
  37. /// <returns></returns>
  38. public bool OrderChanged(string subid, ORDER_STATUS status)
  39. {
  40. bool res = GetAbsMessageServer.OrderStatusChange(subid, status);
  41. if (res)
  42. {
  43. ActionManagerment.GetInstance.Send("OrderStatusChange", new OrderStatusChange()
  44. {
  45. CookingStatus = status,
  46. SuborderId = subid
  47. });
  48. }
  49. return res;
  50. }
  51. private AbstractMessageServer GetAbstractMessageServer()
  52. {
  53. string NameSpace = "HBLConsole.Business";
  54. Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.{DeviceType}");
  55. if (type == null)
  56. type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.Base");
  57. return (AbstractMessageServer)Activator.CreateInstance(type);
  58. }
  59. /// <summary>
  60. /// 设备初始化
  61. /// </summary>
  62. public void DeviceInit()
  63. {
  64. string NameSpace = "HBLConsole.Business";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类
  65. Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Devices.{DeviceType}");
  66. IBusiness business = (IBusiness)type?.GetProperty("GetInstance").GetValue(null);
  67. business?.Init();
  68. }
  69. public IGvl GetGvl()
  70. {
  71. Type type = Assembly.Load("HBLConsole.GVL").GetType($"HBLConsole.GVL.{DeviceType}");
  72. return (IGvl)Activator.CreateInstance(type);
  73. }
  74. }
  75. }