WebWork.cs
3.8 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
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.IO;
using HalconDotNet;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
using System.Text;
using System.Drawing;
namespace ScanCodeServer
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults = false, UseSynchronizationContext = false)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
internal class WebWork : IWeb
{
public WebWork()
{
}
public Result TakeOldGet(string place)
{
Common.log.Info("takeOld[GET] place=" + place);
return TakeOld(place);
}
public string alive() {
return "1";
}
public string ProcessBitmap(Stream info, string param)
{
BinaryFormatter bf = new BinaryFormatter();
Bitmap bitmap = (Bitmap)bf.Deserialize(info);
HDCodeHelper.Bitmap2HObjectBpp24(bitmap, out HObject ho_Image);
bitmap.Dispose();
return Process(ho_Image, param);
}
public string Process(Stream info, string param)
{
HObject ho_Image = HObject.Deserialize(info);
return Process(ho_Image, param);
}
object o = new object();
string Process(HObject ho_Image, string param)
{
param = param.Replace('-', '+').Replace('_', '/');
var stream = Convert.FromBase64String(param);
MemoryStream mStream = new MemoryStream(stream);
XmlSerializer xf = new XmlSerializer(typeof(RemoteDecodeParam));
RemoteDecodeParam remoteDecodeParam = (RemoteDecodeParam)xf.Deserialize(mStream);
mStream.Close();
string[] codeTypeList = remoteDecodeParam.codeTypeList;
int codeCount = remoteDecodeParam.codeCount;
int timeout = remoteDecodeParam.timeout;
Result res = new Result();
//HObject ho_Image = HObject.Deserialize(info);
List<CodeInfo> cc = new List<CodeInfo>();
List<string> code = new List<string>();
foreach (string codeType in codeTypeList)
{
lock (o) {
Monitor.ScanTimes++;
}
//判断是否是一维码
if (codeType.ToLower().Equals("barcode"))
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, HDCodeHelper.GetCodeParamFilePath(codeType), codeCount, timeout);
}
foreach (CodeInfo c in cc)
{
c.CodeType = codeType;
if (!code.Contains(c.CodeStr))
{
Common.log.Info("识别到:"+c.CodeType+", " + c.CodeStr);
code.Add(c.CodeStr);
res.CodeInfos.Add(c);
}
}
}
MemoryStream respStream = new MemoryStream();
XmlSerializer xff = new XmlSerializer(typeof(List<CodeInfo>));
xff.Serialize(respStream, res.CodeInfos);
Monitor.Test();
return Convert.ToBase64String(respStream.ToArray());
}
private Result TakeOld(string place)
{
Result res = new Result();
return res;
}
}
public struct RemoteDecodeParam
{
public string[] codeTypeList;
public int codeCount;
public int timeout;
}
}