集成mes接口,请求-响应-错误处理
This commit is contained in:
@@ -95,6 +95,7 @@ namespace JYControl
|
|||||||
|
|
||||||
_manager.listView1.EndUpdate();
|
_manager.listView1.EndUpdate();
|
||||||
|
|
||||||
|
string fileName = $"{DateTime.Now.ToString("yyyyMMdd")}.txt";
|
||||||
switch (logAddtype)
|
switch (logAddtype)
|
||||||
{
|
{
|
||||||
case LogAddtype.MES:
|
case LogAddtype.MES:
|
||||||
@@ -102,7 +103,9 @@ namespace JYControl
|
|||||||
{
|
{
|
||||||
Directory.CreateDirectory(logMesPath);
|
Directory.CreateDirectory(logMesPath);
|
||||||
}
|
}
|
||||||
using (StreamWriter sw = new StreamWriter(logMesPath+DateTime.Now.ToString("yyyyMMdd") + ".txt", true))
|
|
||||||
|
string logMesFilePath = Path.Combine(logMesPath, fileName);
|
||||||
|
using (StreamWriter sw = new StreamWriter(logMesFilePath, true))
|
||||||
{
|
{
|
||||||
sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog);
|
sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog);
|
||||||
}
|
}
|
||||||
@@ -112,7 +115,9 @@ namespace JYControl
|
|||||||
{
|
{
|
||||||
Directory.CreateDirectory(loglocalPath);
|
Directory.CreateDirectory(loglocalPath);
|
||||||
}
|
}
|
||||||
using (StreamWriter sw = new StreamWriter(loglocalPath+DateTime.Now.ToString("yyyyMMdd") + ".txt", true))
|
|
||||||
|
string loglocalFilePath = Path.Combine(loglocalPath, fileName);
|
||||||
|
using (StreamWriter sw = new StreamWriter(loglocalFilePath, true))
|
||||||
{
|
{
|
||||||
sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog);
|
sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2445,7 +2445,8 @@ namespace JY.Inspection
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogManagerControl.AddLog("结果数据上传MES失败NG" + resMes.OriResponse.Message, LogAddtype.local, Logtype.Error);
|
string errMsg = resMes.OriResponse == null ? resMes.ErrorMessage : resMes.OriResponse.ToString();
|
||||||
|
LogManagerControl.AddLog("结果数据上传MES失败NG," + errMsg, LogAddtype.local, Logtype.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Generated
-1
@@ -2194,7 +2194,6 @@ namespace JY.Inspection
|
|||||||
this.button1.TabIndex = 51;
|
this.button1.TabIndex = 51;
|
||||||
this.button1.Text = "MEStest";
|
this.button1.Text = "MEStest";
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
this.button1.Visible = false;
|
|
||||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||||
//
|
//
|
||||||
// contextMenuStrip1
|
// contextMenuStrip1
|
||||||
|
|||||||
@@ -331,7 +331,7 @@
|
|||||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
||||||
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
||||||
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAE
|
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAE
|
||||||
CgAAAk1TRnQBSQFMAgEBAwEAAZABCAGQAQgBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
CgAAAk1TRnQBSQFMAgEBAwEAAZgBCAGYAQgBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
||||||
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
|
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
|
||||||
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
|
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
|
||||||
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
|
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
|
||||||
|
|||||||
@@ -214,17 +214,17 @@ namespace JY.Inspection.Mes
|
|||||||
|
|
||||||
var sw = new Stopwatch();
|
var sw = new Stopwatch();
|
||||||
sw.Start();
|
sw.Start();
|
||||||
var mesCallResult = MESApiHelper.HttpPostJsonAPI<RespProductResult>(Global.systemConfig.ResultProcessMesUrl, p, Global.systemConfig.MesRequestTime);
|
resp = MESApiHelper.HttpPostJsonAPI<RespProductResult>(Global.systemConfig.ResultProcessMesUrl, p, Global.systemConfig.MesRequestTime);
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
|
|
||||||
if (mesCallResult?.OriResponse?.Success != true)
|
if (resp?.OriResponse != null && resp?.OriResponse.Success != true)
|
||||||
{
|
{
|
||||||
resp.IsSuccess = false;
|
resp.IsSuccess = false;
|
||||||
resp.ErrorType = MesErrorType.BusinessError;
|
resp.ErrorType = MesErrorType.BusinessError;
|
||||||
resp.ErrorMessage = mesCallResult?.OriResponse.Message ?? "MES业务处理失败";
|
resp.ErrorMessage = resp?.OriResponse?.Message ?? "MES业务处理失败, 错误消息为空";
|
||||||
}
|
}
|
||||||
|
|
||||||
new MesLog().LogProductResult(nowTime, p, mesCallResult.OriRespJsonStr, sw.ElapsedMilliseconds);
|
new MesLog().LogProductResult(nowTime, p, resp.OriRespJsonStr, sw.ElapsedMilliseconds);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ namespace JY.MES
|
|||||||
result.OriResponse = mesResp;
|
result.OriResponse = mesResp;
|
||||||
result.OriRespJsonStr = respJsonStr;
|
result.OriRespJsonStr = respJsonStr;
|
||||||
}
|
}
|
||||||
|
catch (TaskCanceledException ex)
|
||||||
|
{
|
||||||
|
result.ErrorType = MesErrorType.NetworkTimeout;
|
||||||
|
result.ErrorMessage = $"MES请求超时: {ex.Message}";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
catch (TimeoutException ex)
|
catch (TimeoutException ex)
|
||||||
{
|
{
|
||||||
result.ErrorType = MesErrorType.NetworkTimeout;
|
result.ErrorType = MesErrorType.NetworkTimeout;
|
||||||
@@ -75,6 +81,12 @@ namespace JY.MES
|
|||||||
result.ErrorMessage = $"MES响应解析失败: {ex.Message}";
|
result.ErrorMessage = $"MES响应解析失败: {ex.Message}";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.ErrorType = MesErrorType.NetworkTimeout;
|
||||||
|
result.ErrorMessage = $"MES请求超时: {ex.Message}";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user