using HBLConsole.Abstract;
using HBLConsole.Interface;
using System;
using System.Reflection;
using BPA.Message.Enum;
using HBLConsole.GVL;
using BPA.Message;
using HBLConsole.Service;
using HBLConsole.Communication;
using System.Threading;
using System.Collections.Generic;
using HBLConsole.Model;
using System.Linq;
//using BPA.Message;
namespace HBLConsole.Factory
{
public class SimpleFactory
{
private volatile static SimpleFactory _Instance;
public static SimpleFactory GetInstance => _Instance ?? (_Instance = new SimpleFactory());
private SimpleFactory() { ActionManage.GetInstance.Register(new Action(() => { GetInterfaceData(); }), "ResetProgram"); }
public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer());
private AbstractMessageServer _GetAbsMessageServer;
private string DeviceType => GeneralConfig.StartDevice;
private object debugControl;
private string GvlName = string.Empty;
public void MqttMessage(IMessage message)
{
GetAbsMessageServer.AddOrder(message);
GetAbsMessageServer.GetBatchingInfo(message);
GetAbsMessageServer.GetRecipeBom(message);
GetAbsMessageServer.Chargeback(message);
}
///
/// 获取物料信息
///
public void GetBatchingInfo()
{
//GetAbsMessageServer.GetBatchingInfo(InternetInfo.ClientId);
GetAbsMessageServer.GetBatchingInfo(InternetInfo.deviceId);
}
///
/// 订单状态更改
///
///
///
///
public bool OrderChanged(string subid, ORDER_STATUS status)
{
bool res = GetAbsMessageServer.OrderStatusChange(subid, status);
if (res)
{
ActionManage.GetInstance.Send("OrderStatusChange", new OrderStatusChange()
{
CookingStatus = status,
SuborderId = subid
});
List subOrderStatus = new List();
var result = Json.Data.orderLists.FirstOrDefault(p => p.OrderPush.SuborderId == subid);
if (result != null)
{
subOrderStatus.Add(new SubOrderStatus()
{
Status = (int)status,
SubOrderId = subid,
GoodsName = result.OrderPush.GoodsName,
SortNo = result.OrderPush.SortNum.ToString(),
});
}
//OrderStatusChangeNotify orderStatusChangeNotify = new OrderStatusChangeNotify();
//orderStatusChangeNotify.SubOrderStatuses = subOrderStatus;
//var temp = BPAPackage.Make(orderStatusChangeNotify);
//MqttHelper.GetInstance.MqttPublishAsync(TOPIC.GetInstance.GetAppTopic(GeneralConfig.DeviceType, InternetInfo.ClientId), temp.Serialize(false));
}
return res;
}
public void CreateGvl()
{
string NameSpace = $"HBLConsole.{DeviceType}";
Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.GVL_{DeviceType}");
var tempGvl = Activator.CreateInstance(type);
var FieldValue = control.GetType().GetField(GvlName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
FieldValue?.SetValue(control, null);
FieldValue?.SetValue(control, tempGvl);
GetInterfaceData();
}
private AbstractMessageServer GetAbstractMessageServer()
{
string NameSpace = "HBLConsole.Business";
Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.AbstractServer.{DeviceType}");
if (type == null)
type = Assembly.Load(NameSpace).GetType($"{NameSpace}.AbstractServer.Base");
return Activator.CreateInstance(type) as AbstractMessageServer;
}
private void GetControlBase()
{
string NameSpace = "HBLConsole.Business";
Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.AbstractServer.ControlBase");
controlAbstract = Activator.CreateInstance(type) as ControlAbstract;
if (controlAbstract != null)
{
controlAbstract.MainAction = new Action(() => { control?.Main(); });
controlAbstract.ReadDataAction = new Action(() => { control?.ReadData(); });
controlAbstract.Init();
}
}
public IControl control { get; set; }
public IGvl GVL { get; set; }
public IAlarm Alarm { get; set; }
public IHardwareStatus HardwareStatus { get; set; }
public ControlAbstract controlAbstract { get; set; }
///
/// 设备初始化
///
public void DeviceInit()
{
string NameSpace = $"HBLConsole.{DeviceType}";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类
Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{DeviceType}");
control = Activator.CreateInstance(type) as IControl;
GetBatchingInfo();
GetInterfaceData();
control?.Init();
//ActionManage.GetInstance.Register(new Action