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
using FLY.OBJComponents.IService;
using FLY.OBJComponents.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLY.OBJComponents.Server.OBJProxy
{
public class PLCProxySystem_OBJProxy : FObj
{
IPLCProxySystemService plcos;
SyncProp_OBJProxy syncProp_OBJProxy;
/// <summary>
/// 内部会使用 serverID,serverID+1
/// </summary>
/// <param name="objsys_idx"></param>
/// <param name="serverID"></param>
/// <param name="plcos"></param>
public PLCProxySystem_OBJProxy(int objsys_idx, UInt32 serverID, IPLCProxySystemService plcos) : base(objsys_idx)
{
ID = serverID;
this.plcos = plcos;
syncProp_OBJProxy = new SyncProp_OBJProxy(
objsys_idx, serverID + 1,
new Dictionary<string, System.ComponentModel.INotifyPropertyChanged>
{
{ ".", plcos }
});
}
public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
{
switch (funcid)
{
case PLCOS_OBJ_INTERFACE.CALL_SET_PLAN:
{
string json = Misc.Converter.BytesToString(infodata);
PLCOS_OBJ_INTERFACE.Pack_SetPlanRequest pack = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlanRequest>(json);
plcos.SetPlan(pack.objname, pack.propertyNames, pack.planid);
}
break;
case PLCOS_OBJ_INTERFACE.CALL_SET_PLAN2:
{
string json = Misc.Converter.BytesToString(infodata);
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request pack = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request>(json);
plcos.SetPlan(pack.objname, pack.propertyNames, (planid, context) =>
{
ConnContext conn = context as ConnContext;
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse p = new PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse() { planid = planid };
string s = JsonConvert.SerializeObject(p);
CurrObjSys.PushCallFunctionEx(conn.from, srcid, ID, magic, funcid, Misc.Converter.StringToBytes(s));
}, new ConnContext(from, srcid, magic));
}
break;
case PLCOS_OBJ_INTERFACE.CALL_FEED_PLAN:
{
string json = Misc.Converter.BytesToString(infodata);
PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest pack = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest>(json);
plcos.FeedPlan(pack.planid);
}
break;
case PLCOS_OBJ_INTERFACE.CALL_REMOVE_PLAN:
{
string json = Misc.Converter.BytesToString(infodata);
PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest pack = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest>(json);
plcos.RemovePlan(pack.planid);
}
break;
}
}
}
}