Curve_OBJProxy.cs 3.37 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.IService;

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

        ICurveService mCurveService;



潘栩锋's avatar
潘栩锋 committed
21
        public Curve_OBJProxy(int objsys_idx, UInt32 id, ICurveService CurveService) :base(objsys_idx)
潘栩锋's avatar
潘栩锋 committed
22
        {
潘栩锋's avatar
潘栩锋 committed
23
            ID = id;
潘栩锋's avatar
潘栩锋 committed
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
            mCurveService = CurveService;
            mCurveService.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mCurveService_PropertyChanged);

        }

        void mCurveService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
                new PollModule.PollHandler(delegate()
                {
                    byte[] buf;
                    GetValue(null, 0, CURVE_OBJ_INTERFACE.GET_CURVELIST, out buf);
                    CurrObjSys.PushObjInfoEx(
                        this, CURVE_OBJ_INTERFACE.PUSH_CURVELIST,
                        buf);
                }), this, MARKNO_PUSH_CURVELIST);
        }

        void Curves_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
                new PollModule.PollHandler(delegate()
                {
                    byte[] buf;
                    GetValue(null, 0, CURVE_OBJ_INTERFACE.GET_CURVELIST, out buf);
                    CurrObjSys.PushObjInfoEx(
                        this, CURVE_OBJ_INTERFACE.PUSH_CURVELIST,
                        buf);
                }), this, MARKNO_PUSH_CURVELIST);
        }



        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case CURVE_OBJ_INTERFACE.GET_CURVELIST:
                    {
潘栩锋's avatar
潘栩锋 committed
63
                        var p = new CURVE_OBJ_INTERFACE.Pack_CurveList()
潘栩锋's avatar
潘栩锋 committed
64 65 66
                        {
                            correctway = mCurveService.CorrectWay,
                            flag = mCurveService.Flag,
潘栩锋's avatar
潘栩锋 committed
67
                            list = mCurveService.Curves
潘栩锋's avatar
潘栩锋 committed
68
                        };
潘栩锋's avatar
潘栩锋 committed
69 70
                        string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
71 72 73 74 75 76 77 78 79 80 81 82
                    } break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case CURVE_OBJ_INTERFACE.SET_CURVELIST:
                    {
潘栩锋's avatar
潘栩锋 committed
83 84 85 86 87 88 89 90 91
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<CURVE_OBJ_INTERFACE.Pack_CurveList>(json);
                        
                        mCurveService.CorrectWay = p.correctway;
                        mCurveService.Flag = p.flag;
                        mCurveService.Curves = p.list;
                        mCurveService.Apply();
                        
潘栩锋's avatar
潘栩锋 committed
92 93 94 95 96 97
                    } break;
            }
        }

    }
}