Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
RC30-AutoInOutStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit bdb4f1c3
由
LN
编写于
2021-01-06 15:12:25 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
给服务器发送消息增加锁验证
1 个父辈
e34d6510
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
74 行增加
和
68 行删除
source/Common/util/HttpHelper.cs
source/Common/util/JsonHelper.cs
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean.cs
source/DeviceLibrary/acSingleStore/AutomaticBaiting_Partial.cs
source/Common/util/HttpHelper.cs
查看文件 @
bdb4f1c
...
@@ -12,64 +12,49 @@ using System.Security.Cryptography;
...
@@ -12,64 +12,49 @@ using System.Security.Cryptography;
using
System.Security.Cryptography.X509Certificates
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Reflection
;
using
System.Reflection
;
using
log4net
;
using
log4net
;
using
System.Threading
;
namespace
OnlineStore.Common
namespace
OnlineStore.Common
{
{
public
class
HttpHelper
public
class
HttpHelper
{
{
public
static
int
isLog
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
Server_Log_Open
);
public
static
int
isLog
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
Server_Log_Open
);
private
static
object
lockObj
=
""
;
public
static
Operation
PostOP
(
string
url
,
Operation
operation
,
bool
simulate
)
public
static
Operation
PostOP
(
string
url
,
Operation
operation
,
int
lockTime
=
0
)
{
{
try
if
(
Monitor
.
TryEnter
(
lockObj
,
lockTime
))
{
{
if
(
simulate
)
try
{
//模拟服务器返回
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
(
"模拟HTTP服务器返回出库入库信息:"
+
json
);
return
operation
;
}
}
else
{
{
string
json
=
""
;
string
json
=
JsonHelper
.
SerializeObject
(
operation
);
try
{
json
=
JsonHelper
.
SerializeObject
(
operation
);
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"PostOP JsonHelper.SerializeObject(operation) 出错【operation.op="
+
operation
.
op
+
"】"
+
ex
);
}
string
result
=
PostJson
(
url
,
json
,
Encoding
.
UTF8
);
string
result
=
PostJson
(
url
,
json
,
Encoding
.
UTF8
);
if
(
operation
.
op
>
0
)
if
(
operation
.
op
>
0
)
{
{
LogUtil
.
info
(
"send 【"
+
url
+
"】【"
+
json
+
"】 "
+
",receive 【 "
+
result
+
"】"
);
LogUtil
.
info
(
"send 【"
+
url
+
"】【"
+
json
+
"】 "
+
",receive 【 "
+
result
+
"】"
);
}
}
if
(!
string
.
IsNullOrEmpty
(
result
))
if
(!
string
.
IsNullOrEmpty
(
result
))
{
{
try
Operation
resultOP
=
JsonHelper
.
DeserializeJsonToObject
<
Operation
>(
result
);
{
if
(
resultOP
!=
null
&&
(!
operation
.
seq
.
Equals
(
resultOP
.
seq
)))
return
JsonHelper
.
DeserializeJsonToObject
<
Operation
>(
result
);
}
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
"
PostOP JsonHelper.DeserializeJsonToObject 出错【result="
+
result
+
"】"
+
ex
);
LogUtil
.
error
(
"
seq error : send 【"
+
json
+
"】 "
+
",receive 【 "
+
result
+
"】"
);
}
}
return
resultOP
;
}
}
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"PostOP error【operation.op="
+
operation
.
op
+
"】:"
+
ex
);
}
finally
{
Monitor
.
Exit
(
lockObj
);
}
}
}
catch
(
Exception
ex
)
else
if
(
lockTime
>
10
)
{
{
LogUtil
.
error
(
"PostOP 出错【operation.op="
+
operation
.
op
+
"】:"
+
ex
);
string
json
=
JsonHelper
.
SerializeObject
(
operation
);
LogUtil
.
error
(
" PostOP "
+
lockTime
+
" send "
+
json
+
" TryEnter fail "
);
}
}
return
null
;
return
null
;
}
}
...
...
source/Common/util/JsonHelper.cs
查看文件 @
bdb4f1c
using
System.Collections.Generic
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
...
@@ -9,24 +10,34 @@ namespace OnlineStore.Common
...
@@ -9,24 +10,34 @@ namespace OnlineStore.Common
/// </summary>
/// </summary>
public
class
JsonHelper
public
class
JsonHelper
{
{
/// <summary>
/// <summary>
/// 将对象序列化为JSON格式
/// 将对象序列化为JSON格式
/// </summary>
/// </summary>
/// <param name="o">对象</param>
/// <param name="o">对象</param>
/// <returns>json字符串</returns>
/// <returns>json字符串</returns>
public
static
string
SerializeObject
(
object
o
)
public
static
string
SerializeObject
(
object
o
)
{
try
{
{
string
json
=
JsonConvert
.
SerializeObject
(
o
);
string
json
=
JsonConvert
.
SerializeObject
(
o
);
return
json
;
return
json
;
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"JsonHelper.SerializeObject error【"
+
o
.
ToString
()
+
"】"
+
ex
);
}
return
""
;
}
/// <summary>
/// <summary>
/// 解析JSON字符串生成对象实体
/// 解析JSON字符串生成对象实体
/// </summary>
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
/// <returns>对象实体</returns>
/// <returns>对象实体</returns>
public
static
T
DeserializeJsonToObject
<
T
>(
string
json
)
where
T
:
class
public
static
T
DeserializeJsonToObject
<
T
>(
string
json
)
where
T
:
class
{
try
{
{
JsonSerializer
serializer
=
new
JsonSerializer
();
JsonSerializer
serializer
=
new
JsonSerializer
();
StringReader
sr
=
new
StringReader
(
json
);
StringReader
sr
=
new
StringReader
(
json
);
...
@@ -34,6 +45,12 @@ namespace OnlineStore.Common
...
@@ -34,6 +45,12 @@ namespace OnlineStore.Common
T
t
=
o
as
T
;
T
t
=
o
as
T
;
return
t
;
return
t
;
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
" JsonHelper.DeserializeJsonToObject error【"
+
json
+
"】"
+
ex
);
}
return
null
;
}
/// <summary>
/// <summary>
/// 解析JSON数组生成对象实体集合
/// 解析JSON数组生成对象实体集合
...
...
source/DeviceLibrary/acSingleStore/AC_SA_BoxBean.cs
查看文件 @
bdb4f1c
...
@@ -963,7 +963,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -963,7 +963,7 @@ namespace OnlineStore.DeviceLibrary
{
{
if
(
IsChongfu
)
if
(
IsChongfu
)
{
{
LogUtil
.
info
(
"
【"
+
info
+
"】 处理完成,耗时:"
+
stopwatch
.
Elapsed
.
ToString
()
);
LogUtil
.
info
(
"
ShowTimeLog【"
+
info
+
"】 :"
+
stopwatch
.
Elapsed
.
ToString
()+
" ms"
);
}
}
}
}
private
void
LedProcess
()
private
void
LedProcess
()
...
@@ -1867,7 +1867,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1867,7 +1867,7 @@ namespace OnlineStore.DeviceLibrary
Operation
lineOperation
=
getLineBoxStatus
();
Operation
lineOperation
=
getLineBoxStatus
();
string
server
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
http_server
);
string
server
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
http_server
);
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
lineOperation
,
false
);
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
lineOperation
);
//发送状态信息到服务器
//发送状态信息到服务器
if
(
resultOperation
==
null
)
if
(
resultOperation
==
null
)
{
{
...
@@ -1879,7 +1879,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1879,7 +1879,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan
span
=
DateTime
.
Now
-
time
;
TimeSpan
span
=
DateTime
.
Now
-
time
;
if
(
span
.
TotalMilliseconds
>
500
)
if
(
span
.
TotalMilliseconds
>
500
)
{
{
LogUtil
.
info
(
StoreName
+
"SendLineStatus
共处理了【"
+
span
.
TotalMilliseconds
+
"】毫秒
"
);
LogUtil
.
info
(
StoreName
+
"SendLineStatus
【"
+
span
.
TotalMilliseconds
+
"】ms
"
);
}
}
}
}
...
@@ -1902,12 +1902,11 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1902,12 +1902,11 @@ namespace OnlineStore.DeviceLibrary
}
}
else
if
(
resultOperation
.
op
.
Equals
(
1
))
else
if
(
resultOperation
.
op
.
Equals
(
1
))
{
{
string
json
=
JsonHelper
.
SerializeObject
(
resultOperation
);
//ReviceInStoreProcess("", resultOperation);
//ReviceInStoreProcess("", resultOperation);
LogUtil
.
error
(
"发送定时消息时,服务器返回Op=1 【"
+
json
+
"】"
);
}
}
//else if (resultOperation.op.Equals(5))
//{
// ProcessHumidityCMD(resultOperation);
//}
else
if
(
resultOperation
.
data
!=
null
)
else
if
(
resultOperation
.
data
!=
null
)
{
{
string
result
=
""
;
string
result
=
""
;
...
...
source/DeviceLibrary/acSingleStore/AutomaticBaiting_Partial.cs
查看文件 @
bdb4f1c
...
@@ -495,7 +495,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -495,7 +495,7 @@ namespace OnlineStore.DeviceLibrary
//message = CodeManager.ReplaceCode(message);
//message = CodeManager.ReplaceCode(message);
if
(
message
.
Equals
(
""
)
||
string
.
IsNullOrEmpty
(
message
))
if
(
message
.
Equals
(
""
)
||
string
.
IsNullOrEmpty
(
message
))
{
{
CodeMsg
=
ResourceControl
.
GetString
(
ResourceControl
.
NoCodeMsg
,
"没有收到二维码信息,请重新放入料盘"
);
CodeMsg
=
ResourceControl
.
GetString
(
ResourceControl
.
NoCodeMsg
,
"没有收到二维码信息,请重新放入料盘"
);
LogUtil
.
info
(
LogName
+
"没有收到二维码信息,请重新放入料盘"
);
LogUtil
.
info
(
LogName
+
"没有收到二维码信息,请重新放入料盘"
);
return
null
;
return
null
;
}
}
...
@@ -528,11 +528,11 @@ namespace OnlineStore.DeviceLibrary
...
@@ -528,11 +528,11 @@ namespace OnlineStore.DeviceLibrary
LogUtil
.
debug
(
"添加自动入库库位号:"
+
autoposId
);
LogUtil
.
debug
(
"添加自动入库库位号:"
+
autoposId
);
}
}
string
server
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
http_server
);
string
server
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
http_server
);
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
operation
,
false
);
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
operation
,
2000
);
if
(
resultOperation
==
null
)
if
(
resultOperation
==
null
)
{
{
LogUtil
.
info
(
LogName
+
"二维码【"
+
message
+
"】没有收到服务器反馈
!
"
);
LogUtil
.
info
(
LogName
+
"二维码【"
+
message
+
"】没有收到服务器反馈"
);
return
null
;
return
null
;
}
}
else
if
(!
string
.
IsNullOrEmpty
(
resultOperation
.
msg
))
else
if
(!
string
.
IsNullOrEmpty
(
resultOperation
.
msg
))
...
@@ -543,7 +543,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -543,7 +543,7 @@ namespace OnlineStore.DeviceLibrary
Dictionary
<
string
,
string
>
data
=
resultOperation
.
data
;
Dictionary
<
string
,
string
>
data
=
resultOperation
.
data
;
if
(
data
!=
null
&&
data
.
ContainsKey
(
ParamDefine
.
posId
)
&&
data
.
ContainsKey
(
ParamDefine
.
plateH
)
&&
data
.
ContainsKey
(
ParamDefine
.
plateW
))
if
(
data
!=
null
&&
data
.
ContainsKey
(
ParamDefine
.
posId
)
&&
data
.
ContainsKey
(
ParamDefine
.
plateH
)
&&
data
.
ContainsKey
(
ParamDefine
.
plateW
))
{
{
string
posId
=
data
[
ParamDefine
.
posId
];
string
posId
=
data
[
ParamDefine
.
posId
];
try
try
{
{
...
@@ -554,8 +554,8 @@ namespace OnlineStore.DeviceLibrary
...
@@ -554,8 +554,8 @@ namespace OnlineStore.DeviceLibrary
//bool isSingleOut = singleOut.ToLower().Equals("true");
//bool isSingleOut = singleOut.ToLower().Equals("true");
string
[]
posArray
=
posId
.
Split
(
'#'
);
string
[]
posArray
=
posId
.
Split
(
'#'
);
if
(!(
posArray
.
Length
==
2
))
if
(!(
posArray
.
Length
==
2
))
{
{
SetWarnMsgAndLog
(
ResourceControl
.
InStoreError
,
message
,
posId
);
SetWarnMsgAndLog
(
ResourceControl
.
InStoreError
,
message
,
posId
);
return
null
;
return
null
;
}
}
...
@@ -563,8 +563,8 @@ namespace OnlineStore.DeviceLibrary
...
@@ -563,8 +563,8 @@ namespace OnlineStore.DeviceLibrary
//根据发送的posId获取位置列表
//根据发送的posId获取位置列表
AutoStorePosition
position
=
CSVPositionReader
<
AutoStorePosition
>.
GetPositon
(
posId
);
AutoStorePosition
position
=
CSVPositionReader
<
AutoStorePosition
>.
GetPositon
(
posId
);
if
(
position
==
null
)
if
(
position
==
null
)
{
{
SetWarnMsgAndLog
(
ResourceControl
.
InStoreNoPosition
,
message
,
posId
);
SetWarnMsgAndLog
(
ResourceControl
.
InStoreNoPosition
,
message
,
posId
);
return
null
;
return
null
;
}
}
...
@@ -577,7 +577,12 @@ namespace OnlineStore.DeviceLibrary
...
@@ -577,7 +577,12 @@ namespace OnlineStore.DeviceLibrary
{
{
LogUtil
.
error
(
LogName
+
"解析服务发送的入库【"
+
posId
+
"】出错"
+
ex
.
StackTrace
);
LogUtil
.
error
(
LogName
+
"解析服务发送的入库【"
+
posId
+
"】出错"
+
ex
.
StackTrace
);
}
}
}
return
null
;
}
else
{
LogUtil
.
error
(
LogName
+
"二维码【"
+
message
+
"】获取入库库位失败 "
);
}
return
null
;
}
}
public
static
Dictionary
<
string
,
string
>
GetBtnStatus
()
public
static
Dictionary
<
string
,
string
>
GetBtnStatus
()
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论