WebCallWork.cs
4.2 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
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.IO;
using Model;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing;
using System.Collections.Generic;
using BLL;
namespace SmartScan
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
internal class WebCallWork : IWeb
{
public WebCallWork()
{
}
public void CloseApp()
{
LogNet.log.Info("WebService CloseApp 接口被调用");
Common.frmMain.Invoke(new Action(() => { Common.frmMain.Close(); }));
}
public WebResultCamera WorkWithCamera()
{
LogNet.log.Info("WebService WorkWithCamera 接口被调用");
WebCodeAll[] msg = null;
Common.frmMain.Invoke(new Action(() => { msg = Common.frmMain.WebTouchWork(); }));
return new WebResultCamera() { Data = msg };
}
public WebResultCode WorkWithCode(Stream json)
{
LogNet.log.Info($"WebService WorkWithCode 接口被调用");
StreamReader sr = new(json);
string input = sr.ReadToEnd();
System.Web.Script.Serialization.JavaScriptSerializer serializer = new();
object[] obj = (object[])serializer.DeserializeObject(input);
string[] str = new string[obj.Length];
for (int i = 0; i < str.Length; i++)
str[i] = obj[i].ToString();
WebCodeText[] msg = null;
Common.frmMain.Invoke(new Action(() => { msg = Common.frmMain.WebTouchWork(str); }));
return new WebResultCode() { Data = msg };
}
public string alive()
{
return "1";
}
public WebResultCode ProcessBitmap(Stream info, string param)
{
BinaryFormatter bf = new BinaryFormatter();
Bitmap bitmap = (Bitmap)bf.Deserialize(info);
try
{
List<CameraVisionLib.Model.BarcodeInfo> workCodeInfo = new();
Dictionary<string, string> workCodeKeyword;// = new(StringComparer.OrdinalIgnoreCase);
bool[] originalCodeIsUsed = null;
workCodeInfo = Camera.GetBarCode(bitmap);
if (workCodeInfo.Count == 0)
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败" };
BLLCommon.mateEdit.CurrntBitmap = bitmap;
bool rtn = BLLCommon.mateEdit.MatchingTemplate(workCodeInfo, BLLCommon.config.DefaultMaterialName, false, out string mateName, out workCodeKeyword, out originalCodeIsUsed);
LogNet.log.Info("Work SetKey hasMatch:" + rtn);
WebResultCode webResultCode = null;
if (!BLLCommon.extension.SetKey(null, workCodeKeyword, rtn, out string errmsg))
{
webResultCode = new WebResultCode() { ErrorCode = -2, Msg = errmsg };
}
if (webResultCode != null || !rtn)
return webResultCode;
LogNet.log.Info("Work scan is done");
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
#region 判断是否需要请求http替换数据
if (BLL.Config.isReplaceData)
{
Dictionary<string, string> keyValues = new Dictionary<string, string>();
workCodeKeyword= BLLCommon.extension.ReplaceData(workCodeKeyword);
}
#endregion
foreach (var wc in workCodeKeyword)
{
result.Add(new KeyValuePair<string, string>(wc.Key, wc.Value));
}
return new WebResultCode() { workCodeKeyword = result, workCodeInfo = workCodeInfo };
}
catch (Exception ex)
{
LogNet.log.Error("ProcessBitmap", ex);
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败:" + ex };
}
}
}
}