BlowingFixProfile_OBJProxy.cs 5.13 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Blowing.Common;
using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
6
using Newtonsoft.Json;
潘栩锋's avatar
潘栩锋 committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Thick.Blowing.Server.OBJProxy
{
    public class BlowingFixProfile_OBJProxy: FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMS = 1;
        #endregion

        IBlowingFixProfileService mProfile;

22
        public BlowingFixProfile_OBJProxy(int objsys_idx,UInt32 id, IBlowingFixProfileService profile)
潘栩锋's avatar
潘栩锋 committed
23 24
            : base(objsys_idx)
        {
25
            ID = id;
潘栩锋's avatar
潘栩锋 committed
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
            mProfile = profile;
            mProfile.Param.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mProfile_PropertyChanged);
        }

        void mProfile_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
                new PollModule.PollHandler(delegate ()
                {
                    byte[] buf;
                    GetValue(null, ID, BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS, out buf);
                    CurrObjSys.PushObjInfoEx(
                        this, BLOWINGFIX_PROFILE_OBJ_INTERFACE.PUSH_PARAMS,
                        buf);
                }), this, MARKNO_PUSH_PARAMS);

        }

        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            infodata = null;
            switch (memid)
            {
                case BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS:
                    {
51 52
                        string json = JsonConvert.SerializeObject(mProfile.Param);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
53 54 55 56 57 58 59 60 61 62 63 64 65
                    }
                    break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS:
                    {
66 67 68 69
                        string json = Misc.Converter.BytesToString(infodata);

                        BlowingFixProfileParam p = JsonConvert.DeserializeObject<BlowingFixProfileParam>(json);
                        Misc.PropertiesManager.CopyTo(p, mProfile.Param);
潘栩锋's avatar
潘栩锋 committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
                        mProfile.Apply();
                    }
                    break;
            }
        }
        public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
        {
            switch (funcid)
            {
                case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_GETLIST:
                    {
                        mProfile.GetList(
                            new AsyncCBHandler(delegate (object AsyncState, object retdata)
                            {
                                ConnContext context = (ConnContext)AsyncState;
85 86
                                string json = JsonConvert.SerializeObject(retdata);
                                
潘栩锋's avatar
潘栩锋 committed
87 88 89 90 91 92
                                CurrObjSys.PushCallFunctionEx(
                                    context.from,
                                    context.srcid,
                                    ID,
                                    context.magic,
                                    BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_GETLIST,
93
                                    Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
94 95 96 97 98
                            }), new ConnContext(from, srcid, magic));
                    }
                    break;
                case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_DEL:
                    {
99 100 101
                        string json = Misc.Converter.BytesToString(infodata);
                        string p = JsonConvert.DeserializeObject<string>(json);
                        mProfile.Del(p);
潘栩锋's avatar
潘栩锋 committed
102 103 104 105
                    }
                    break;
                case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ:
                    {
106 107 108
                        string json = Misc.Converter.BytesToString(infodata);
                        string p = JsonConvert.DeserializeObject<string>(json);

潘栩锋's avatar
潘栩锋 committed
109
                        mProfile.Read(
110
                            p,
潘栩锋's avatar
潘栩锋 committed
111 112 113
                            new AsyncCBHandler(delegate (object AsyncState, object retdata)
                            {
                                ConnContext context = (ConnContext)AsyncState;
114
                                json = JsonConvert.SerializeObject(retdata);
潘栩锋's avatar
潘栩锋 committed
115 116 117 118 119 120 121

                                CurrObjSys.PushCallFunctionEx(
                                    context.from,
                                    context.srcid,
                                    ID,
                                    context.magic,
                                    BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ,
122
                                    Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
123 124 125 126 127 128 129
                            }), new ConnContext(from, srcid, magic));
                    }
                    break;
            }
        }
    }
}