Kaynağa Gözat

反射工厂修改

master
pry 2 yıl önce
ebeveyn
işleme
dc5bb3d66c
7 değiştirilmiş dosya ile 127 ekleme ve 118 silme
  1. +17
    -14
      HBLConsole.Business/IotReport.cs
  2. +47
    -13
      HBLConsole.Factory/SimpleFactory.cs
  3. +1
    -1
      HBLConsole.Interface/IControl.cs
  4. +28
    -27
      HBLConsole.MORKD/Control_MORKD.cs
  5. +1
    -20
      HBLConsole.MORKIC/Control_MORKIC.cs
  6. +2
    -23
      HBLConsole.MORKS/Control_MORKS.cs
  7. +31
    -20
      HBLConsole/ViewModel/ProcessMonitoringViewModel.cs

+ 17
- 14
HBLConsole.Business/IotReport.cs Dosyayı Görüntüle

@@ -10,6 +10,7 @@ using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HBLConsole.Factory;

namespace HBLConsole.Business
{
@@ -24,11 +25,11 @@ namespace HBLConsole.Business
IOTDev.GetInstance().CreateLinks();
IOTDev.GetInstance().IOT_Subscribe(IOTDev.BroadcastTopic);//订阅广播主题
IOTDev.actionIOT += actionIOTHandler;//消息数据回调
IOTDev.UNConnectMqtt += new Action<string>((o) =>{ MessageLog.GetInstance.Show(o);});
IOTDev.UNConnectMqtt += new Action<string>((o) => { MessageLog.GetInstance.Show(o); });
if (IOTDev.client.IsConnected) MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接成功.");
else MessageLog.GetInstance.Show($"设备{InternetInfo.DeviceName}阿里云连接失败.不能上报业务信息");
string NameSpace = $"HBLConsole.{GeneralConfig.DeviceType}";
control = (IControl)(Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{GeneralConfig.DeviceType}"))?.GetProperty("Instance").GetValue(null);
//string NameSpace = $"HBLConsole.{GeneralConfig.DeviceType}";
//control = (IControl)(Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{GeneralConfig.DeviceType}"))?.GetProperty("Instance").GetValue(null);
}
#endregion

@@ -38,11 +39,11 @@ namespace HBLConsole.Business
/// 大屏上报Model
/// </summary>
public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel() { SBMC = InternetInfo.DeviceName, SBMS = InternetInfo.DeviceMS };
/// <summary>
/// 当前控制的设备控件
/// </summary>
public IControl control;
//public IControl control;
#endregion

#region 事件
@@ -51,7 +52,7 @@ namespace HBLConsole.Business
/// </summary>
public static void Close()
{
if(IOTDev.client != null)
if (IOTDev.client != null)
IOTDev.GetInstance().Disconnect();
}

@@ -60,7 +61,9 @@ namespace HBLConsole.Business
/// </summary>
public T GetTypeValue<T>(string str)
{
return (T)control.GetT().GetType().GetProperty(str).GetValue(control.GetT(),null);

return (T)SimpleFactory.GetInstance.GVL.GetType().GetProperty(str).GetValue(SimpleFactory.GetInstance.GVL, null);
//return (T)control.GetT().GetType().GetProperty(str).GetValue(control.GetT(),null);
}

/// <summary>
@@ -113,7 +116,7 @@ namespace HBLConsole.Business
}
else
{
iOTDevSXModel.SetKZSX(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "",SXLX = "" } } });
iOTDevSXModel.SetKZSX(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "", SXLX = "" } } });
}
#endregion

@@ -122,7 +125,7 @@ namespace HBLConsole.Business
List<DevSXBase> bases = Tools.JsonToObjectTools<DevSX>(iOTDevSXModel.JBSX)?.data?.ToList().FindAll(par => par.SXStatus == false);
if (bases != null) bases.AddRange(Tools.JsonToObjectTools<DevSX>(iOTDevSXModel.KZSX)?.data?.ToList().FindAll(par => par.SXStatus == false));
List<AlarmModel> alarms = new List<AlarmModel>();
bases?.ForEach(par => alarms.Add(new AlarmModel { DeviceMC = iOTDevSXModel.SBMC,DeviceSJ = DateTime.Now.ToString(),AlarmCD = "一般",DeviceZT = "未处理",DeviceMS = par.SXYCMS }));
bases?.ForEach(par => alarms.Add(new AlarmModel { DeviceMC = iOTDevSXModel.SBMC, DeviceSJ = DateTime.Now.ToString(), AlarmCD = "一般", DeviceZT = "未处理", DeviceMS = par.SXYCMS }));
iOTDevSXModel.SetGJXX(new AlarmMessage { data = alarms });
#endregion

@@ -156,7 +159,7 @@ namespace HBLConsole.Business
IOTDev.GetInstance().IOT_Publish(IOTDev.PubTopic, iOTDevSXModel.Tojson());
}
Thread.Sleep(5000);
}),"设备IOT上报云端");
}), "设备IOT上报云端");
}

/// <summary>
@@ -164,13 +167,13 @@ namespace HBLConsole.Business
/// </summary>
/// <param name="topic"></param>
/// <param name="message"></param>
private void actionIOTHandler(string topic,string message)
private void actionIOTHandler(string topic, string message)
{
if (IOTDev.BroadcastTopic == topic && !string.IsNullOrEmpty(message))//广播主题消息,将广播消息发送到相应客户端
{
IOTCommandModel iOTCommand=Tools.JsonToObjectTools<IOTCommandModel>(message);
if(iOTCommand.deviceName== InternetInfo.DeviceName)
ActionOperate.GetInstance.Send("IotBroadcast",iOTCommand);
IOTCommandModel iOTCommand = Tools.JsonToObjectTools<IOTCommandModel>(message);
if (iOTCommand.deviceName == InternetInfo.DeviceName)
ActionOperate.GetInstance.Send("IotBroadcast", iOTCommand);
}
}
#endregion


+ 47
- 13
HBLConsole.Factory/SimpleFactory.cs Dosyayı Görüntüle

@@ -80,17 +80,18 @@ namespace HBLConsole.Factory
{
string NameSpace = $"HBLConsole.{DeviceType}";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类
Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Control_{DeviceType}");
//control = Activator.CreateInstance(type) as IControl;
control = (IControl)type?.GetProperty("Instance").GetValue(null);
control = Activator.CreateInstance(type) as IControl;
//control = (IControl)type?.GetProperty("Instance").GetValue(null);
//IControl business = (IControl)type?.GetProperty("GetInstance").GetValue(null);
GetBatchingInfo();
GetInterfaceData();
control?.Init();
ActionOperate.GetInstance.Register(new Action<object>((o) => { control?.DataParse(o); }), "DataParse");
ActionOperate.GetInstance.Register(new Action(() => { control?.ConnectOk(); }), $"{GeneralConfig.DeviceType.ToString()}/ConnectOk");
ActionOperate.GetInstance.Register(new Action<object>((o) => { control?.SimOrder(o); }), "SimOrder");
ActionOperate.GetInstance.Register(new Action<object>((o) => { control?.IotBroadcast(o); }), "IotBroadcast");
GetInterfaceData();
ConnectHelper.GetInstance.Init();

}

/// <summary>
@@ -99,24 +100,57 @@ namespace HBLConsole.Factory
private void GetInterfaceData()
{
Type type = control?.GetType();
foreach (var item in type?.GetProperties())

//通过字段查找
var Fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (Fields != null)
{
var interfaces = item.PropertyType.GetInterfaces();
if (interfaces != null)
foreach (var item in Fields)
{
foreach (var inters in interfaces)
var interfaces = item.FieldType.GetInterfaces();
if (interfaces != null)
{
if (inters.Name.Equals("IGvl"))
foreach (var inters in interfaces)
{
GVL = (type?.GetProperty(item.Name).GetValue(control, null)) as IGvl;
}
else if (inters.Name.Equals("IAlarm"))
{
Alarm = (type?.GetProperty(item.Name).GetValue(control, null)) as IAlarm;
if (inters.Name.Equals("IGvl") && GVL == null)
{
GVL = (item.GetValue(control)) as IGvl;
}
else if (inters.Name.Equals("IAlarm") && Alarm == null)
{
Alarm = (item.GetValue(control)) as IAlarm;
}
}
}
}
}

//if (GVL != null && Alarm != null) return;

////通过属性查找
//var prop = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
//if (prop != null)
//{
// foreach (var item in prop)
// {
// var interfaces = item.PropertyType.GetInterfaces();
// if (interfaces != null)
// {
// foreach (var inters in interfaces)
// {
// if (inters.Name.Equals("IGvl"))
// {
// GVL = (type?.GetProperty(item.Name).GetValue(control, null)) as IGvl;
// }
// else if (inters.Name.Equals("IAlarm"))
// {
// Alarm = (type?.GetProperty(item.Name).GetValue(control, null)) as IAlarm;
// }
// }
// }
// }
//}

//return default;
}



+ 1
- 1
HBLConsole.Interface/IControl.cs Dosyayı Görüntüle

@@ -9,7 +9,7 @@ namespace HBLConsole.Interface
public interface IControl
{
void Main();
object GetT();
//object GetT();
void Init();
void ReadData();
void SimOrder<T>(T simOrder);


+ 28
- 27
HBLConsole.MORKD/Control_MORKD.cs Dosyayı Görüntüle

@@ -16,22 +16,23 @@ namespace HBLConsole.MORKD
public class Control_MORKD : IControl
{
#region 单例模式
private static Control_MORKD _instance;
public static Control_MORKD Instance
{
get
{
if (_instance == null)
_instance = new Control_MORKD();
return _instance;
}
}
public Control_MORKD()
{
}
//private static Control_MORKD _instance;
//public static Control_MORKD Instance
//{
// get
// {
// if (_instance == null)
// _instance = new Control_MORKD();
// return _instance;
// }
//}
//public Control_MORKD()
//{
//}
#endregion
public GVL_MORKD mORKD { get; set; } = new GVL_MORKD();
GVL_MORKD mORKD = new GVL_MORKD();
Alarm_MORKD alarm = new Alarm_MORKD();
public void ConnectOk()
{
Main();
@@ -39,10 +40,10 @@ namespace HBLConsole.MORKD
ResetProgram();
}

public object GetT()
{
return mORKD;
}
//public object GetT()
//{
// return mORKD;
//}

public void DataParse<T>(T order)
{
@@ -182,14 +183,14 @@ namespace HBLConsole.MORKD
mORKD.TemperatureReached = bools[10];
}));

var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters);
if (ResLoc != null)
{
if (ResLoc is ushort loc)
{
mORKD.TurntableFeedbackloc = loc;
}
}
//var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters);
//if (ResLoc != null)
//{
// if (ResLoc is ushort loc)
// {
// mORKD.TurntableFeedbackloc = loc;
// }
//}
Thread.Sleep(100);
}), "ReadPLCData");
}


+ 1
- 20
HBLConsole.MORKIC/Control_MORKIC.cs Dosyayı Görüntüle

@@ -29,22 +29,7 @@ namespace HBLConsole.MORKIC
*/
public class Control_MORKIC : IControl
{
#region 单例模式
private static Control_MORKIC _instance;
public static Control_MORKIC Instance
{
get
{
if (_instance == null)
_instance = new Control_MORKIC();
return _instance;
}
}
public Control_MORKIC()
{

}
#endregion
GVL_MORIC mORKD = new GVL_MORIC();
//咖啡机主控程序
private CoffeeMachine coffeeMachine;
@@ -67,10 +52,6 @@ namespace HBLConsole.MORKIC
{

}
public object GetT()
{
return mORKD;
}


ConcurrentQueue<MorkOrderPush> morkOrderPushes = new ConcurrentQueue<MorkOrderPush>();
@@ -290,7 +271,7 @@ namespace HBLConsole.MORKIC
{
if (iOTCommand.CommandValue.ContainsKey("SimOrder"))
{
SimOrder(new SimOrderData { NoodleLoc = 1,BowlLoc = 10 });
SimOrder(new SimOrderData { NoodleLoc = 1, BowlLoc = 10 });
}
}
break;


+ 2
- 23
HBLConsole.MORKS/Control_MORKS.cs Dosyayı Görüntüle

@@ -20,34 +20,13 @@ namespace HBLConsole.MORKS
{
public class Control_MORKS : IControl
{
#region 单例模式
private static Control_MORKS _instance;
public static Control_MORKS Instance
{
get
{
if (_instance == null)
_instance = new Control_MORKS();
return _instance;
}
}
public Control_MORKS()
{

}
#endregion
public GVL_MORKS mORKS { get; set; } = new GVL_MORKS();
GVL_MORKS mORKS = new GVL_MORKS();
public void Init()
{
ActionOperate.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom");
ActionOperate.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand");
}

public object GetT()
{
return mORKS;
}

public void ConnectOk()
{
//WriteRecipeBoms();
@@ -179,7 +158,7 @@ namespace HBLConsole.MORKS
if (iOTCommand.CommandValue.ContainsKey("order"))
{
List<ushort> vs = new List<ushort>();
vs.Add((ushort)(new Random().Next(1,5)));
vs.Add((ushort)(new Random().Next(1, 5)));
vs.Add(ushort.Parse(iOTCommand.CommandValue["order"]));
SimOrder(vs);
}


+ 31
- 20
HBLConsole/ViewModel/ProcessMonitoringViewModel.cs Dosyayı Görüntüle

@@ -17,34 +17,45 @@ namespace HBLConsole.ViewModel
{
public class ProcessMonitoringViewModel : ViewModelBase
{
static Type type;
static IGvl InterfaceGVL;
//static Type type;
//static IGvl InterfaceGVL;
public ProcessMonitoringViewModel()
{
WindowName = "流程监控";
if (type == null)
{
InterfaceGVL = SimpleFactory.GetInstance.GVL;
type = InterfaceGVL?.GetType();
if (ProcessData.GetInstance.Conditions?.Count <= 0)
{
if (InterfaceGVL != null && type != null)
{
GetProcessInfo();
UpdateProcess();
}
}
}
//if (type == null)
//{
// InterfaceGVL = SimpleFactory.GetInstance.GVL;
// type = InterfaceGVL?.GetType();
// if (ProcessData.GetInstance.Conditions?.Count <= 0)
// {
// if (InterfaceGVL != null && type != null)
// {
// GetProcessInfo();
// UpdateProcess();
// }
// }
//}

}

static ProcessMonitoringViewModel()
{
//InterfaceGVL = SimpleFactory.GetInstance.GVL;
//type = InterfaceGVL?.GetType();

GetProcessInfo();
UpdateProcess();


}

/// <summary>
/// 获取流程信息
/// </summary>
private void GetProcessInfo()
private static void GetProcessInfo()
{
//添加流程监控信息
foreach (var item in type.GetProperties())
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties())
{
if (item.CustomAttributes.Count() > 0)
{
@@ -89,11 +100,11 @@ namespace HBLConsole.ViewModel
/// <summary>
/// 更新流程
/// </summary>
private void UpdateProcess()
private static void UpdateProcess()
{
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
foreach (var item in type.GetProperties())
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties())
{
if (item.CustomAttributes.Count() > 0)
{
@@ -113,7 +124,7 @@ namespace HBLConsole.ViewModel
int PropertyIndex = Array.FindIndex(processConditions.ElementAt(index).Conditions.ToArray(), p => p.propertyIllustrate == propertyInfo);
if (PropertyIndex >= 0)
{
var res = type.GetProperty(item.Name)?.GetValue(InterfaceGVL, null);
var res = SimpleFactory.GetInstance.GVL.GetType().GetProperty(item.Name)?.GetValue(SimpleFactory.GetInstance.GVL, null);
if (res != null)
{
if (res is bool blen)


Yükleniyor…
İptal
Kaydet