ServerConn.cs
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class ServerConn
{
static string inputCounterDataByXRayMachine_URL;
static string DetermineReelStorageLocation_URL;
static ServerConn()
{
inputCounterDataByXRayMachine_URL = ConfigAppSettings.GetValue("inputCounterDataByXRayMachine");
DetermineReelStorageLocation_URL = ConfigAppSettings.GetValue("DetermineReelStorageLocation");
}
public static CountResult inputCounterDataByXRayMachine(string TwoDBarcode, int qty)
{
var wc = new MyWebClient(15000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Encoding = Encoding.UTF8;
var data = new Wiston_Request();
data.userId = "Q14050052";
data.language = 1;
data.requestTime = 0;
data.data.Add("TwoDBarcode", TwoDBarcode);
data.data.Add("Qty", qty);
data.data.Add("Counter", ConfigHelper.Config.Get("upload_Counter"));
string json = JsonHelper.SerializeObject(data);
string result = "";
int retry = 0;
retry:
try
{
result = wc.UploadString(ConfigHelper.Config.Get("inputCounterDataByXRayMachine"), "POST", json);
return JsonHelper.DeserializeJsonToObject<CountResult>(result);
}
catch (Exception e)
{
LogUtil.info($"inputCounterDataByXRayMachine retry:{retry}, {e.ToString()}");
retry++;
if (retry < 3)
goto retry;
return null;
}
finally
{
LogUtil.info($"inputCounterDataByXRayMachine request:{json} response:{result}");
}
}
public static ReelLocation DetermineReelStorageLocation(string TwoDBarcode)
{
var wc = new MyWebClient(15000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Encoding = Encoding.UTF8;
var data = new Wiston_Request();
data.userId = "Q14050052";
data.language = 1;
data.requestTime = 0;
data.data.Add("str2DBarcode", TwoDBarcode);
data.data.Add("labelPrinter", ConfigHelper.Config.Get("upload_labelPrinter"));
string json = JsonHelper.SerializeObject(data);
string result = "";
int retry = 0;
retry:
try
{
result = wc.UploadString(ConfigHelper.Config.Get("DetermineReelStorageLocation"), "POST", json);
return JsonHelper.DeserializeJsonToObject<ReelLocation>(result);
}
catch (Exception e)
{
LogUtil.info($"DetermineReelStorageLocation retry:{retry}, {e.ToString()}");
retry++;
if (retry < 3)
goto retry;
return null;
}
finally
{
LogUtil.info($"DetermineReelStorageLocation request:{json} response:{result}");
}
}
}
class Wiston_Request
{
public string userId = "";
public int language = 0;
public int requestTime = 0;
public Dictionary<string, object> data = new Dictionary<string, object>();
}
public class CountResult
{
public bool result;
public string message;
public string type;
public long responseTime;
public object data;
}
public class ReelLocation {
public string isVacuum;
public string isTower;
public string isVTTower;
public string message;
}
}