CallImplementation.cs
7.3 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using DataHandling;
using log4net;
using MemoryRead;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
namespace Plugin
{
public class Plugin
{
private static ILog log = LogManager.GetLogger("SmartScan");
public Dictionary<string, string> CompleteData = new Dictionary<string, string>();
/// <summary>
/// 请求webserver获取替换数据
/// </summary>
/// <param name="pasr">请求的关键字和内容</param>
/// <param name="method">0:http_get;1:http_post;2:soap</param>
/// <returns>返回键值对</returns>
public Dictionary<string, string> RequestServer(Dictionary<string, string> pasr, int method)
{
try
{
log.Info($"WebServer_请求参数:{JsonConvert.SerializeObject(pasr)}");
if (pasr == null || pasr.Count <= 0)
{
log.Info("WebServer_传入参数为空");
return pasr;
}
CompleteData = pasr;
if (!ConfigHelper.Config.Get("WebServer_Isformal", true))
{
pasr = MatchDicData(pasr);
log.Info($"对应关系处理后数据:{JsonConvert.SerializeObject(pasr)}");
}
Dictionary<string, string> dic = new Dictionary<string, string>();
String Url = ConfigHelper.Config.Get("WebServer_Url", "http://10.159.150.10/EIWebService/Service1.asmx");
String MethodName = ConfigHelper.Config.Get("WebServer_MethodName", "VmsizBarkodOlusturUserName");
WebServiceHelper webService = new WebServiceHelper(log);
switch (method)
{
case 0:
dic = webService.QueryGetWebService(Url, MethodName, pasr);
break;
case 1:
dic = webService.QueryPostWebService(Url, MethodName, pasr);
break;
case 2:
dic = webService.QuerySoapWebService(Url, MethodName, pasr);
break;
default:
break;
}
//foreach (var item in dic)
//{
// if (CompleteData.ContainsKey(item.Key))
// {
// CompleteData[item.Key] = item.Value;
// }
//}
//return CompleteData;
if (dic != null || dic.Count != 0)
{
string json = JsonConvert.SerializeObject(dic);
log.Info($"WebServer_返回数据:{json}");
}
else
{
log.Info($"WebServer_返回数据:为空!");
}
return YourMethod(dic);
}
catch (Exception ex)
{
log.Info($"WebServer请求出错:{ex.Message}");
return CompleteData;
}
//string[] shuz = { "Material code", "Tracibilty Serial Number", "Qty", "Supplier Code", "Code for who printed this label", "Qr barcode" };
}
/// <summary>
/// 对应键值对信息
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
public Dictionary<string, string> MatchDicData(Dictionary<string, string> dic)
{
Dictionary<string, string> parameterToContent = new Dictionary<string, string>();
string json = ConfigHelper.Config.Get("WebServer_Match", "{\"malzemeKodu\":\"\",\"firmaKodu\":\"\",\"malzemeAdet\":\"\",\"lot\":\"\",\"firmaUrunKodu\":\"PN\"}");
Dictionary<string, string> matchdata = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
foreach (var item in matchdata)
{
if (dic.ContainsKey(item.Value))
{
parameterToContent.Add(item.Key, dic[item.Value]);
}
}
parameterToContent.Add("barkodAdet", "1");
parameterToContent.Add("printerMacId", "0F0F0F0F0F0F");
parameterToContent.Add("userName", "bekoservice");
parameterToContent.Add("pass", "beko1209tyu");
parameterToContent.Add("basanUserName", "579");
return parameterToContent;
}
/// <summary>
/// 对应返回的键值对数据
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
public Dictionary<string, string> YourMethod(Dictionary<string, string> dic)
{
List<string> strings = new List<string>();
foreach (var item in dic)
{
strings.Add(item.Value);
}
log.Info($"请求完成数据:{string.Join(",", strings)}");
if (strings.Contains("OK"))
{
string[] arr = strings[1].Split('$');
if (ConfigHelper.Config.Get("WebServer_Isformal", true))
{
Dictionary<string, string> keys = new Dictionary<string, string>()
{
{"Material code", arr[1]},
{"Tracibilty Serial Number", arr[2]},
{"Qty", arr[3]},
{"Supplier Code", arr[4]},
{"Code for who printed this label", "579579"},
{"Qr barcode", strings[1]}
};
return keys;
}
else
{
try
{
Dictionary<string, int> valuePairs = new Dictionary<string, int>()
{
{"Material code", 0},
{"Tracibilty Serial Number", 1},
{"Qty", 2},
{"Supplier Code", 3},
{"Code for who printed this label", 4},
{"Qr barcode", 5}
};
foreach (var item in valuePairs)
{
if (CompleteData.ContainsKey(item.Key))
{
if (valuePairs.Count > 4)
{
CompleteData[item.Key] = arr[item.Value];
}
}
}
if (CompleteData.ContainsKey("Code for who printed this label"))
{
CompleteData["Code for who printed this label"] = "579579";
}
if (CompleteData.ContainsKey("Qr barcode"))
{
CompleteData["Qr barcode"] = strings[1];
}
log.Info($"请求对应完成数据:{string.Join(",", CompleteData.Values)}");
}
catch (Exception ex)
{
log.Error($"处理返回数据报错:{ex.Message}");
}
}
}
return CompleteData;
}
}
}