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;
///
/// 内部会使用 serverID,serverID+1
///
///
///
///
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
{
{ ".", 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(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(json);
plcos.SetPlan(pack.objname, pack.propertyNames, (asyncContext, retData) =>
{
ConnContext conn = asyncContext as ConnContext;
long planid = (long)retData;
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(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(json);
plcos.RemovePlan(pack.planid);
}
break;
}
}
}
}