114 lines
3.3 KiB
C#
114 lines
3.3 KiB
C#
using MP.MONO.Core.DTO;
|
|
using NLog;
|
|
using NLua;
|
|
|
|
namespace MP.MONO.DECODER
|
|
{
|
|
public class MPStatusManager
|
|
{
|
|
#region Public Fields
|
|
|
|
public static bool valueChanged = false;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public MPStatusManager()
|
|
{
|
|
// preparo variabile x avvisare script che il modo è da NLua
|
|
state["callMode"] = "NLua";
|
|
|
|
// carico il file
|
|
luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "StatusDecoder.lua");
|
|
state.DoFile(luaPath);
|
|
|
|
Log.Info("MPStatusManager OK");
|
|
Console.WriteLine("MPStatusManager OK");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Funzione chiamata LUA x calcolo dati PLATE (stato macchina e processo)
|
|
/// </summary>
|
|
/// <param name="paramsList"></param>
|
|
/// <param name="MachinePlate"></param>
|
|
/// <returns></returns>
|
|
public MachineDTO processData(Dictionary<string, int> paramsList, MachineDTO MachinePlate)
|
|
{
|
|
bool calcOk = false;
|
|
MachineDTO plateOut = new MachineDTO()
|
|
{
|
|
Manufacturer = MachinePlate.Manufacturer,
|
|
ModeId = MachinePlate.ModeId,
|
|
Model = MachinePlate.Model,
|
|
Name = MachinePlate.Name,
|
|
SerNumber = MachinePlate.SerNumber,
|
|
StatusId = MachinePlate.StatusId
|
|
};
|
|
DateTime adesso = DateTime.Now;
|
|
|
|
state.NewTable("dataList");
|
|
var currTable = state.GetTable("dataList");
|
|
foreach (var item in paramsList)
|
|
{
|
|
currTable[item.Key] = item.Value;
|
|
}
|
|
// ripasso table
|
|
state["dataList"] = currTable;
|
|
state["numRec"] = paramsList.Count;
|
|
|
|
try
|
|
{
|
|
// effettuo calcolo
|
|
state.DoString("doProcess()");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"exception during doProcess{Environment.NewLine}{exc}");
|
|
}
|
|
|
|
// recupero valore calcolato
|
|
bool.TryParse(state.GetString("calcOk"), out calcOk);
|
|
if (calcOk)
|
|
{
|
|
try
|
|
{
|
|
var stringVal = state.GetString("statusId");
|
|
if (!string.IsNullOrEmpty(stringVal))
|
|
{
|
|
plateOut.StatusId = state.GetInteger("statusId");
|
|
}
|
|
stringVal = state.GetString("modeId");
|
|
if (!string.IsNullOrEmpty(stringVal))
|
|
{
|
|
plateOut.ModeId = state.GetInteger("modeId");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"exception during processData{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
else
|
|
{ }
|
|
|
|
return plateOut;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
protected static string luaPath = "";
|
|
|
|
protected static Lua state = new Lua();
|
|
|
|
#endregion Protected Fields
|
|
}
|
|
} |