Files
2024-12-23 15:41:12 +01:00

99 lines
4.0 KiB
C#

// See https://aka.ms/new-console-template for more information
using System.Diagnostics;
using System.Dynamic;
using Newtonsoft.Json;
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine(sep);
Console.WriteLine("Rest Client test application");
Console.WriteLine(sep);
Console.WriteLine();
Console.WriteLine("Call connection");
// setup oggetti
int tOut = 60;
string apiUrl = "http://192.168.80.61:8733/DRIVER_MES/rest/";
rCall = new RestCaller(apiUrl, tOut);
// chiamate!
CallAndLog("checkconnection");
string token = CallAndLog("gettoken/mecmaticames/mecmatica@mes").Replace("\"", "");
string gLamp = CallAndLog($"getsingleladderio/{token}/Y/8E");
string yLamp = CallAndLog($"getsingleladderio/{token}/Y/21");
string rLamp = CallAndLog($"getsingleladderio/{token}/Y/22");
string qtyTot = CallAndLog($"gettotalquantity/{token}");
string qtyReq = CallAndLog($"getneededquantity/{token}");
string qtyWrk = CallAndLog($"getworkedquantity/{token}");
string cTime = CallAndLog($"getcycletime/{token}");
string pName = CallAndLog($"getmainprogram/{token}");
string cAlarm = CallAndLog($"getalarm/{token}");
var sAlarm = JsonConvert.DeserializeObject<WarnInfo>(cAlarm);
cAlarm = JsonConvert.SerializeObject(sAlarm, Formatting.Indented);
string allAlarm = CallAndLog($"getallalarmlog/{token}");
var alarmList = JsonConvert.DeserializeObject<List<AlarmInfo>>(allAlarm);
allAlarm = JsonConvert.SerializeObject(alarmList, Formatting.Indented);
string err = CallAndLog($"getsingleladderio/ABC/Y/22");
// ora scrivo i files dei test x debug successivo
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
var fPath = Directory.GetParent(appPath).FullName;
string basePath = Path.Combine(fPath, "Test");
if (!Directory.Exists(basePath))
{
Directory.CreateDirectory(basePath);
}
File.WriteAllText(Path.Combine(basePath, "token.txt"), token);
File.WriteAllText(Path.Combine(basePath, "gLamp.txt"), gLamp);
File.WriteAllText(Path.Combine(basePath, "yLamp.txt"), yLamp);
File.WriteAllText(Path.Combine(basePath, "rLamp.txt"), rLamp);
File.WriteAllText(Path.Combine(basePath, "qtyTot.txt"), qtyTot);
File.WriteAllText(Path.Combine(basePath, "qtyReq.txt"), qtyReq);
File.WriteAllText(Path.Combine(basePath, "qtyWrk.txt"), qtyWrk);
File.WriteAllText(Path.Combine(basePath, "cTime.txt"), cTime);
File.WriteAllText(Path.Combine(basePath, "pName.txt"), pName);
File.WriteAllText(Path.Combine(basePath, "cAlarm.txt"), cAlarm);
File.WriteAllText(Path.Combine(basePath, "allAlarm.txt"), allAlarm);
}
private static RestCaller rCall { get; set; } = new RestCaller("http://localhost", 60);
private static string sep = "------------------------";
private static Stopwatch sw = new Stopwatch();
private static string CallAndLog(string fullUri)
{
sw.Restart();
Console.WriteLine(sep);
Console.WriteLine($"Calling: {fullUri}");
// chiamo
string answ = rCall.ExecuteCallGet(fullUri);
sw.Stop();
// loggo
Console.WriteLine(answ);
Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}");
Console.WriteLine(sep);
Console.WriteLine();
return answ;
}
}
internal class AlarmInfo
{
public int id { get; set; } = 0;
public string? ErrorMessage { get; set; } = null;
public DateTime date { get; set; } = DateTime.Today.AddYears(-10);
public string message { get; set; } = "";
public string type { get; set; } = "";
}
internal class WarnInfo
{
public bool IsAlarm { get; set; } = false;
public bool IsCaution { get; set; } = false;
public string? ErrorMessage { get; set; } = null;
public string message { get; set; } = "";
}