Commit b38ed426 LN

1

1 个父辈 34fc623e
......@@ -99,7 +99,7 @@ namespace OnlineStore.AssemblyLine
tabControl1.Controls.Add(lineTabPage);
}
private void FrmMain_Load(object sender, EventArgs e)
{
{
FrmBase.GetVersion(true);
if (!LineManager.Init())
{
......
......@@ -57,7 +57,6 @@
<Compile Include="util\AcSerialBean.cs" />
<Compile Include="util\ConfigAppSettings.cs" />
<Compile Include="util\FormUtil.cs" />
<Compile Include="util\HttpHelper.cs" />
<Compile Include="util\JsonHelper.cs" />
<Compile Include="util\LogUtil.cs" />
<Compile Include="util\MyWebClient.cs">
......
......@@ -22,57 +22,6 @@ namespace OnlineStore.Common
{
return Post(url, paramData, Encoding.UTF8);
}
public static Operation Post(string url, Operation operation, bool simulate)
{
try
{
if (simulate)
{//模拟服务器返回
operation.status = 200;
operation.data.Clear();
operation.data.Add("posId", "A001");
string pos = "D100-111#D102-222#D104-333";
operation.data.Add("pos", pos);
if (operation.op == 1 || operation.op == 2)
{//入库或出库
string json = JsonHelper.SerializeObject(operation);
LogUtil.error(LOGGER, "模拟HTTP服务器返回出库入库信息:" + json);
return operation;
}
}
else
{
string json = "";
try
{
json = JsonHelper.SerializeObject(operation);
}
catch (Exception ex)
{
LOGGER.Error("JsonHelper.SerializeObject(operation) 出错【operation.op=" + operation.op + "】" + ex);
}
string result = Post(url, json);
if (!string.IsNullOrEmpty(result))
{
try
{
return JsonHelper.DeserializeJsonToObject<Operation>(result);
}
catch (Exception ex)
{
LOGGER.Error("JsonHelper.DeserializeJsonToObject 出错【result=" + result + "】" + ex);
}
}
}
}
catch (Exception ex)
{
LOGGER.Error("Post 出错【operation.op=" + operation.op + "】:" + ex);
}
return null;
}
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open);
public static string Post(string url, string paramData, Encoding encoding)
{
......
......@@ -63,36 +63,4 @@ namespace OnlineStore.Common
return t;
}
}
///// <summary>
///// 与服务器通信用对象
///// </summary>
//public class Operation
//{
// private string _cid = "";
// public string cid
// {
// get { return _cid; }
// set { _cid = value; }
// }
// public int seq { get; set; }
// public int op { get; set; }
// public int status { get; set; }
// private string _error = "";
// public string error
// {
// get { return _error; }
// set { _error = value; }
// }
// private Dictionary<string, string> _data = new Dictionary<string,string>();
// public Dictionary<string, string> data {
// get { return _data; }
// set { _data = value; }
// }
//}
}
using System;
using log4net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Text;
namespace OnlineStore.Common
......@@ -42,4 +46,81 @@ namespace OnlineStore.Common
return result;
}
}
public class HttpHelper
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static string Post(string url, string paramData)
{
return Post(url, paramData, Encoding.UTF8);
}
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open);
public static string Post(string url, string paramData, Encoding encoding)
{
if (isLog == 1)
{
LOGGER.Info("给服务器发送数据【" + paramData + "】 ");
}
if (paramData != "null" && paramData != null)
{
// LogUtil.debug(LOGGER, "HTTP POST to " + url + " \n\t >> " + paramData);
}
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
try
{
var wc = new MyWebClient(5000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
//LogUtil.info(result);
}
catch (Exception e)
{
LogUtil.error("POST ERROR:" + e.StackTrace, 1001);
}
if (!result.Contains("null") && result.Length != 0)
{
//LogUtil.debug(LOGGER,"receive << " + result);
}
if (isLog == 1)
{
LOGGER.Info("收到服务器数据【" + result + "】");
}
return result;
}
public static string Get(string url)
{
return Get(url, Encoding.UTF8);
}
public static string Get(string url, Encoding encoding)
{
try
{
LogUtil.info(LOGGER, "HTTP GET FROM: " + url);
var wc = new WebClient { Encoding = encoding };
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
{
var result = sr.ReadToEnd();
LogUtil.info(LOGGER, "receive << " + result);
return result;
}
}
catch (Exception e)
{
LogUtil.error("HTTP GET ERROR:" + e.Message, 1002);
}
return "";
}
}
}
......@@ -146,8 +146,8 @@ namespace OnlineStore.DeviceLibrary
{
robotIndex = 2;
}
SServerManager.GetTraySize(Name, robotIndex, LastCodeList, out LastWidth);
LogInfo(hengyiName + "出口有料,二维码[" + lastCode + "] 获取料盘尺寸【" + LastWidth + "】");
string result = SServerManager.GetTraySize(Name, robotIndex, LastCodeList, out LastWidth);
LogInfo(hengyiName + "出口有料,二维码[" + lastCode + "] 获取料盘尺寸【" + LastWidth + "】【" + result + "】");
}
// MoveInfo.EndMove();
}
......
......@@ -177,7 +177,7 @@ namespace OnlineStore.DeviceLibrary
{
return msg = deviceName + " 【" + robotIndex + "】 条码【 " + codeStr + "】没有收到服务器反馈";
}
else if ((!string.IsNullOrEmpty(serverResult.msg)) || serverResult.code.Equals(0).Equals(false))
else if ( serverResult.code.Equals(0).Equals(false))
{
// code: 0为正常,其他为异常,
// msg:消息,
......@@ -220,19 +220,23 @@ namespace OnlineStore.DeviceLibrary
ServerData serverResult = JsonHelper.DeserializeJsonToObject<ServerData>(resultStr);
if (serverResult == null)
{
return msg = deviceName + "UpdateTrayLoc【 " + barcode + "】【" + status + "】【" + locInfo + "】没有收到服务器反馈";
msg = deviceName + "UpdateTrayLoc【 " + barcode + "】【" + status + "】【" + locInfo + "】没有收到服务器反馈";
}
else if ((!string.IsNullOrEmpty(serverResult.msg)) || serverResult.code.Equals(0).Equals(false))
else if (serverResult.code.Equals(0).Equals(false))
{
// code: 0为正常,其他为异常, msg: 消息, data: 为空
return msg = deviceName + " UpdateTrayLoc【 " + barcode + "】【" + status + "】【" + locInfo + "】 :" + "[" + serverResult.code + "]" + serverResult.msg;
msg = deviceName + " UpdateTrayLoc【 " + barcode + "】【" + status + "】【" + locInfo + "】 :" + "[" + serverResult.code + "]" + serverResult.msg;
}
if (!msg.Equals(""))
{
LogUtil.error(msg);
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return "";
return msg;
}
......@@ -256,7 +260,7 @@ namespace OnlineStore.DeviceLibrary
{
return msg = deviceName + "PutShelfFinished【 " + barcode + "】【" + rfid + "】【" + rfidPosId + "】没有收到服务器反馈";
}
else if ((!string.IsNullOrEmpty(serverResult.msg)) || serverResult.code.Equals(0).Equals(false))
else if (serverResult.code.Equals(0).Equals(false))
{
return msg = deviceName + " PutShelfFinished【 " + barcode + "】【" + rfid + "】【" + rfidPosId + "】 :" + serverResult.msg;
}
......@@ -270,7 +274,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error(deviceName + " " + ex.ToString());
}
return "";
}
}
}
public class LocStatus
{
......@@ -289,8 +293,9 @@ namespace OnlineStore.DeviceLibrary
}
public class ServerData
{
//返回: {"code": 0, "msg":"ok", "data":{"rfid":"xxx","smallEmpty":0,"bigEmpty":0, "packageEmpty":0,"cutPackageTask":0,"packageTask":10,"cutTask":10, "smallTask":5, "bigTask":5}
public int code { get; set; }
//{"code":0,"msg":"ok","data":"7"}
//返回: {"code": 0, "msg":"ok", "data":{"rfid":"xxx","smallEmpty":0,"bigEmpty":0, "packageEmpty":0,"cutPackageTask":0,"packageTask":10,"cutTask":10, "smallTask":5, "bigTask":5}
public int code { get; set; }
public string msg { get; set; }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!