PLCProxySystem_OBJProxy.cs 3.47 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
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
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;
46 47 48 49
                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);
50
                        plcos.SetPlan(pack.objname, pack.propertyNames, (asyncContext, retData) =>
51
                        {
52 53
                            ConnContext conn = asyncContext as ConnContext;
                            long planid = (long)retData;
54 55 56 57 58 59 60
                            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;
潘栩锋's avatar
潘栩锋 committed
61 62 63 64 65 66 67
                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;
68 69 70 71 72 73 74
                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;
潘栩锋's avatar
潘栩锋 committed
75 76 77 78
            }
        }
    }
}