FixtureService.cs
23.1 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using System;
using System.IO;
using System.Runtime.Serialization;
using Common;
using DeviceLibrary.manager;
namespace DeviceLibrary
{
[ServiceContract(Name = "FixtureServices")]
internal interface IFixtureService
{
[OperationContract]
[WebInvoke(UriTemplate = "call", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result CallByPost(Stream stream);
[OperationContract]
[WebInvoke(UriTemplate = "call?target={target}&type={type}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result CallByGet(string target, int type);
[OperationContract]
[WebInvoke(UriTemplate = "transfer", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result TransferByPost(Stream stream);
[OperationContract]
[WebInvoke(UriTemplate = "transfer?name={name}&target={target}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result TransferByGet(string name, string target);
[OperationContract]
[WebInvoke(UriTemplate = "getType", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
FixInfo GetTypeByPost();
[OperationContract]
[WebInvoke(UriTemplate = "getType", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
FixInfo GetTypeByGet();
[OperationContract]
[WebInvoke(UriTemplate = "mayEnter", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result MayEnterByPost(Stream stream);
[OperationContract]
[WebInvoke(UriTemplate = "mayEnter?allow={allow}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result MayEnterByGet(bool allow);
[OperationContract]
[WebInvoke(UriTemplate = "stopEnter", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result StopEnterByPost(Stream stream);
[OperationContract]
[WebInvoke(UriTemplate = "stopEnter?allow={allow}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result StopEnterByGet(bool allow);
[OperationContract]
[WebInvoke(UriTemplate = "outStore", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result OutStoreByPost(Stream stream);
[OperationContract]
[WebInvoke(UriTemplate = "outStore?has={has}&type={type}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result OutStoreByGet(bool has, int type);
[OperationContract]
[WebInvoke(UriTemplate = "mayLeave", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result MayLeaveByPost(Stream stream);
[OperationContract]
[WebInvoke(UriTemplate = "mayLeave?allow={allow}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result MayLeaveByGet(bool allow);
}
[DataContract]
internal class Result
{
/// <summary>
/// 呼叫成功;false:呼叫失败
/// </summary>
[DataMember]
public bool Succeed { get; set; }
/// <summary>
/// 返回对应接口呼叫的参数信息;
/// </summary>
[DataMember]
public string Data { get; set; }
/// <summary>
/// 呼叫成功,为空。呼叫失败会返回原因
/// </summary>
[DataMember]
public string Msg { get; set; }
}
[DataContract]
internal class FixInfo
{
[DataMember]
public string Succeed { get; set; }
[DataMember]
public string Type { get; set; }
[DataMember]
public string HasLoad { get; set; }
[DataMember]
public string Arrived { get; set; }
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
internal class FixtureWebService : IFixtureService
{
static log4net.ILog Log = log4net.LogManager.GetLogger("FixtureServices");
#region 呼叫
public Result CallByGet(string target, int type)
{
Result res;
MissionInfo missionInfo;
if (SettingString.Warehouse.Equals(target))
{
missionInfo = new MissionInfo(target, (FixType)type, MissionType.Warehouse);
if (!FixMissionManager.Contains(missionInfo))
{
if (AGVManager.agvInfo[0].CurJob is StandyJob || AGVManager.agvInfo[0].CurJob is ChargeJob)
{
if (FixMissionManager.HasNext(MissionType.Line))
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"AGV has Line Misssion,{target} is not allowed to call." };
FixMissionManager.Add(missionInfo);
Log.Error("立库呼叫失败[GET](AGV正在执行任务):" + missionInfo.ToString());
return res;
}
}
else
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"AGV is doing Misssion,{target} is not allowed to call." };
FixMissionManager.Add(missionInfo);
Log.Error("立库呼叫失败[GET](AGV正在执行任务):" + missionInfo.ToString());
return res;
}
}
}
else
{
missionInfo = new MissionInfo(target, (FixType)type, MissionType.Line);
}
if (!NodeManager.HasNode(target))
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"节点名{target}不存在" };
Log.Error("呼叫失败[GET](节点不存在):" + missionInfo.ToString());
}
else
{
if (!FixMissionManager.Contains(missionInfo))
{
FixMissionManager.Add(missionInfo);
res = new Result() { Succeed = true, Data = $"target:{target},type:{type}", Msg = "" };
Log.Info("呼叫成功[GET]:" + missionInfo.ToString());
}
else
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"目的地{target}任务已存在,无法添加重复任务" };
Log.Error("呼叫失败[GET](已存在相同任务):" + missionInfo.ToString());
}
}
return res;
}
public Result CallByPost(Stream stream)
{
Result res;
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
System.Collections.Specialized.NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
string target = nvc["target"];
int type = int.Parse(nvc["type"]);
MissionInfo missionInfo;
if (SettingString.Warehouse.Equals(target))
{
missionInfo = new MissionInfo(target, (FixType)type, MissionType.Warehouse);
if (!FixMissionManager.Contains(missionInfo))
{
if (AGVManager.agvInfo[0].CurJob is StandyJob || AGVManager.agvInfo[0].CurJob is ChargeJob)
{
if (FixMissionManager.HasNext(MissionType.Line))
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"AGV has Line Misssion,{target} is not allowed to call." };
FixMissionManager.Add(missionInfo);
Log.Error("立库呼叫失败[POST](AGV正在执行任务):" + missionInfo.ToString());
return res;
}
}
else
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"AGV is doing Misssion,{target} is not allowed to call." };
FixMissionManager.Add(missionInfo);
Log.Error("立库呼叫失败[POST](AGV正在执行任务):" + missionInfo.ToString());
return res;
}
}
}
else
{
missionInfo = new MissionInfo(target, (FixType)type, MissionType.Line);
}
if (!NodeManager.HasNode(target))
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"节点名{target}不存在" };
Log.Error("呼叫失败[POST](节点不存在):" + missionInfo.ToString());
}
else
{
if (!FixMissionManager.Contains(missionInfo))
{
FixMissionManager.Add(missionInfo);
res = new Result() { Succeed = true, Data = $"target:{target},type:{type}", Msg = "" };
Log.Info("呼叫成功[POST]:" + missionInfo.ToString());
}
else
{
res = new Result() { Succeed = false, Data = $"target:{target},type:{type}", Msg = $"目的地{target}任务已存在,无法添加重复任务" };
Log.Error("呼叫失败[POST](已存在相同任务):" + missionInfo.ToString());
}
}
return res;
}
#endregion
#region 获取治具类型
public FixInfo GetTypeByGet()
{
FixInfo fixInfo;
if (AGVManager.agvInfo[0].CurJob == null)
{
fixInfo = new FixInfo() { Succeed = true.ToString(), HasLoad = AGVManager.agvInfo[0].IsExistShelf.ToString(), Type = ((int)FixType.None).ToString(),Arrived="False"};
Log.Info($"GetTypeByGet : 当前无任务,治具类型为空");
}
else if (AGVManager.agvInfo[0].CurJob.JobParam != null && AGVManager.agvInfo[0].CurJob.JobParam.FixMissionInfo != null)
{
fixInfo = new FixInfo() { Succeed = true.ToString(), HasLoad = AGVManager.agvInfo[0].IsExistShelf.ToString(), Type = ((int)AGVManager.agvInfo[0].CurJob.JobParam.FixMissionInfo.Type).ToString(),Arrived= AGVManager.agvInfo[0].TaskRunState.TaskState.Equals(SettingString.Done)?"True":"False"};
Log.Info($"GetTypeByGet : {AGVManager.agvInfo[0].IsExistShelf},{AGVManager.agvInfo[0].CurJob.JobParam.FixMissionInfo.Type.ToString()}");
}
else
{
fixInfo = new FixInfo() { Succeed = false.ToString(), HasLoad = AGVManager.agvInfo[0].IsExistShelf.ToString(), Type = ((int)FixType.None).ToString(), Arrived = "False" };
Log.Info($"GetTypeByGet : 当前无任务,查询失败");
}
return fixInfo;
}
public FixInfo GetTypeByPost()
{
FixInfo fixInfo;
if (AGVManager.agvInfo[0].CurJob == null)
{
fixInfo = new FixInfo() { Succeed = true.ToString(), HasLoad = AGVManager.agvInfo[0].IsExistShelf.ToString(), Type = ((int)FixType.None).ToString(), Arrived = "False" };
Log.Info($"GetTypeByPost : 当前无任务,治具类型为空");
}
else if (AGVManager.agvInfo[0].CurJob.JobParam != null && AGVManager.agvInfo[0].CurJob.JobParam.FixMissionInfo != null)
{
fixInfo = new FixInfo() { Succeed = true.ToString(), HasLoad = AGVManager.agvInfo[0].IsExistShelf.ToString(), Type = ((int)AGVManager.agvInfo[0].CurJob.JobParam.FixMissionInfo.Type).ToString(), Arrived = AGVManager.agvInfo[0].TaskRunState.TaskState.Equals(SettingString.Done) ? "True" : "False" };
Log.Info($"GetTypeByPost : {AGVManager.agvInfo[0].IsExistShelf},{AGVManager.agvInfo[0].CurJob.JobParam.FixMissionInfo.Type.ToString()}");
}
else
{
fixInfo = new FixInfo() { Succeed = false.ToString(), HasLoad = AGVManager.agvInfo[0].IsExistShelf.ToString(), Type = ((int)FixType.None).ToString(), Arrived = "False" };
Log.Info($"GetTypeByPost : 当前无任务,查询失败");
}
return fixInfo;
}
#endregion
public Result MayEnterByGet(bool allow)
{
WarehouseSigManager.MayEnter = allow;
Log.Info($"Get: 收到MayEnter={allow}信号");
return new Result() { Succeed = true, Data = $"MayEnter={allow}", Msg = "" };
}
public Result MayEnterByPost(Stream stream)
{
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
System.Collections.Specialized.NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
bool allow = bool.Parse(nvc["allow"]);
WarehouseSigManager.MayEnter = allow;
Log.Info($"Post: 收到MayEnter={allow}信号");
return new Result() { Succeed = true, Data = $"MayEnter={allow}", Msg = "" };
}
public Result MayLeaveByGet(bool allow)
{
Result result1;
//if (AGVManager.agvInfo[0].StateID.Equals(eAGVState.Executing))
//{
// result1 = new Result() { Succeed = false, Data = $"MayLeave={allow}", Msg = "AGV正在运行,无法进料" };
// Log.Info($"Get: 收到MayLeave={allow}信号,AGV正在运行,无法进料");
//}
//else
{
WarehouseSigManager.MayLeave = allow;
result1 = new Result() { Succeed = true, Data = $"MayLeave={allow}", Msg = "" };
Log.Info($"Get: 收到MayLeave={allow}信号");
}
return result1;
}
public Result MayLeaveByPost(Stream stream)
{
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
System.Collections.Specialized.NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
bool allow = bool.Parse(nvc["allow"]);
Result result1;
//if (AGVManager.agvInfo[0].StateID.Equals(eAGVState.Executing))
//{
// result1 = new Result() { Succeed = false, Data = $"MayLeave={allow}", Msg = "AGV正在运行,无法进料" };
// Log.Info($"Post: 收到MayLeave={allow}信号,AGV正在运行,无法进料");
//}
//else
{
WarehouseSigManager.MayLeave = allow;
result1 = new Result() { Succeed = true, Data = $"MayLeave={allow}", Msg = "" };
Log.Info($"Post: 收到MayLeave={allow}信号");
}
return result1;
}
public Result OutStoreByGet(bool has, int type)
{
WarehouseSigManager.OutStore.Set(has, (FixType)type);
Log.Info($"Get: 收到出库信息:{has.ToString()} {type}");
return new Result() { Succeed = true, Data = $"OutStore:{has},{type}", Msg = "" };
}
public Result OutStoreByPost(Stream stream)
{
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
System.Collections.Specialized.NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
bool has = bool.Parse(nvc["has"]);
int type = int.Parse(nvc["type"]);
WarehouseSigManager.OutStore.Set(has, (FixType)type);
Log.Info($"Post: 收到出库信息:{has.ToString()} {type}");
return new Result() { Succeed = true, Data = $"OutStore:{has},{type}", Msg = "" };
}
public Result StopEnterByGet(bool allow)
{
WarehouseSigManager.StopEnter = allow;
Log.Info($"Get: 收到StopEnter={allow}信号");
return new Result() { Succeed = true, Data = $"StopEnter={allow}", Msg = "" };
}
public Result StopEnterByPost(Stream stream)
{
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
System.Collections.Specialized.NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
bool allow = bool.Parse(nvc["allow"]);
WarehouseSigManager.StopEnter = allow;
Log.Info($"Post: 收到StopEnter={allow}信号");
return new Result() { Succeed = true, Data = $"StopEnter={allow}", Msg = "" };
}
public Result TransferByGet(string name, string target)
{
Result result1;
if (!NodeManager.HasNode(name))
{
result1 = new Result() { Succeed = false, Data = "", Msg = $"name {name} do not exist" };
Log.Info($"运送接口调用失败[GET]: : 呼叫地不存在, name={name},target={target},curplace={WarehouseSigManager.TargetWithFix.CurPlace}");
}
else if (WarehouseSigManager.TargetWithFix.CurPlace.Equals(name) && NodeManager.HasNode(target))
{
result1 = new Result() { Succeed = true, Data = $"name={name},target={target}", Msg = "" };
WarehouseSigManager.TargetWithFix.Set(name, target);
Log.Info($"运送接口调用成功[GET]: name={name},target={target}");
}
else if (WarehouseSigManager.TargetWithFix.CurPlace.Equals(name) && SettingString.Cancel.Equals(target))
{
result1 = new Result() { Succeed = true, Data = $"name={name},target={target}", Msg = "" };
WarehouseSigManager.TargetWithFix.Set(name, target);
Log.Info($"运送接口调用成功[GET]: name={name},target={target}");
}
else if (!NodeManager.HasNode(target))
{
result1 = new Result() { Succeed = false, Data = "", Msg = $"target={target} do not exist" };
Log.Info($"运送接口调用失败[GET]: : 目的地不存在, name={name},target={target},curplace={WarehouseSigManager.TargetWithFix.CurPlace}");
}
else
{
result1 = new Result() { Succeed = false, Data = "", Msg = $" AGV is in {WarehouseSigManager.TargetWithFix.CurPlace}, line {name} is not allowed to call this interface TransferByGet at this time." };
Log.Info($"运送接口调用失败[GET]: : name={name},target={target},curplace={WarehouseSigManager.TargetWithFix.CurPlace}");
}
return result1;
}
public Result TransferByPost(Stream stream)
{
Result result1;
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
System.Collections.Specialized.NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
string name = nvc["name"];
string target = nvc["target"];
if (!NodeManager.HasNode(name))
{
result1 = new Result() { Succeed = false, Data = "", Msg = $"name {name} do not exist" };
Log.Info($"运送接口调用失败[POST]: : 呼叫地不存在, name={name},target={target},curplace={WarehouseSigManager.TargetWithFix.CurPlace}");
}
else if (WarehouseSigManager.TargetWithFix.CurPlace.Equals(name) && NodeManager.HasNode(target))
{
result1 = new Result() { Succeed = true, Data = $"name={name},target={target}", Msg = "" };
WarehouseSigManager.TargetWithFix.Set(name, target);
Log.Info($"运送接口调用成功[POST]: name={name},target={target}");
}
else if (WarehouseSigManager.TargetWithFix.CurPlace.Equals(name) && SettingString.Cancel.Equals(target))
{
result1 = new Result() { Succeed = true, Data = $"name={name},target={target}", Msg = "" };
WarehouseSigManager.TargetWithFix.Set(name, target);
Log.Info($"运送接口调用成功[GET]: name={name},target={target}");
}
else if (!NodeManager.HasNode(target))
{
result1 = new Result() { Succeed = false, Data = "", Msg = $"target={target} do not exist" };
Log.Info($"运送接口调用失败[POST]: : 目的地不存在, name={name},target={target},curplace={WarehouseSigManager.TargetWithFix.CurPlace}");
}
else
{
result1 = new Result() { Succeed = false, Data = "", Msg = $" AGV is in {WarehouseSigManager.TargetWithFix.CurPlace}, line {name} is not allowed to call this interface TransferByGet at this time." };
Log.Info($"运送接口调用失败[POST]: : name={name},target={target},curplace={WarehouseSigManager.TargetWithFix.CurPlace}");
}
return result1;
}
}
public class WebService
{
private WebServiceHost _serviceHost;
public bool State = false;
public void Open(string url)
{
try
{
FixtureWebService service = new FixtureWebService();
_serviceHost = new WebServiceHost(service, new Uri(url));//service, new Uri(url)
_serviceHost.Open();
State = true;
LogUtil.info("Web服务已开启");
}
catch (Exception ex)
{
State = false;
LogUtil.error("Web服务开启", ex);
}
}
public void Close()
{
try
{
if (_serviceHost != null)//判断服务是否关闭
_serviceHost.Close();//关闭服务
State = false;
LogUtil.info("Web服务已关闭");
}
catch (Exception ex)
{
LogUtil.error("Web服务关闭", ex);
}
}
}
}