CoatingSegmentSearch_OBJProxy.cs 7.58 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 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.Server;
namespace FLY.Thick.Base.Server.OBJProxy
{
    public class CoatingSegmentSearch_OBJProxy : FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMS = 1;
        const int MARKNO_PUSH_PROFILE = 2;
        const int MARKNO_PUSH_LAST = 3;
        #endregion

        CoatingSegmentSearch mCoatingSegmentService;
        FLY.Thick.RemoteHistory.RemoteHistory_OBJProxy mRemoteHistoryOBJProxy;
        public CoatingSegmentSearch_OBJProxy(int objsys_idx, CoatingSegmentSearch coatingSegmentService)
            : base(objsys_idx)
        {
            ID = COATINGSEGMENT_OBJ_INTERFACE.ID;
            mCoatingSegmentService = coatingSegmentService;

            mRemoteHistoryOBJProxy = new FLY.Thick.RemoteHistory.RemoteHistory_OBJProxy(objsys_idx, OBJ_INTERFACE_ID.CS_HISTORY_ID, mCoatingSegmentService.mHistory);


            mCoatingSegmentService.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mCoatingSegmentService_PropertyChanged);
            mCoatingSegmentService.Profile.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Profile_PropertyChanged);
            mCoatingSegmentService.Recent.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Recent_CollectionChanged);
        }

        void Recent_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                CurrObjSys.PushObjInfoEx(
                    this, COATINGSEGMENT_OBJ_INTERFACE.PUSH_LAST,
                    mCoatingSegmentService.Recent.Last().ToBytes());
            }
        }

        void Profile_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
                new PollModule.PollHandler(delegate()
                {
                    byte[] buf;
                    GetValue(null, 0, COATINGSEGMENT_OBJ_INTERFACE.GET_PROFILE, out buf);
                    CurrObjSys.PushObjInfoEx(
                        this, COATINGSEGMENT_OBJ_INTERFACE.PUSH_PROFILE,
                        buf);
                }), this, MARKNO_PUSH_PROFILE);
        }

        void mCoatingSegmentService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (
                (e.PropertyName == "Enable") ||
                (e.PropertyName == "EnSave") ||
                (e.PropertyName == "SaveCnt") ||
                (e.PropertyName == "RecentCnt") ||
                (e.PropertyName == "InIdxOfVSide") ||
                (e.PropertyName == "Mmpr") ||
                (e.PropertyName == "WarningTol_Total") ||
                (e.PropertyName == "WarningTol_Distance")
                )
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, COATINGSEGMENT_OBJ_INTERFACE.GET_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, COATINGSEGMENT_OBJ_INTERFACE.PUSH_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_PARAMS);
            }
            else if(e.PropertyName == "Last")
            {
                byte[] buf;
                GetValue(null, 0, COATINGSEGMENT_OBJ_INTERFACE.GET_LAST, out buf);
                CurrObjSys.PushObjInfoEx(
                    this, COATINGSEGMENT_OBJ_INTERFACE.PUSH_LAST,
                    buf);
            }
                
        }

        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case COATINGSEGMENT_OBJ_INTERFACE.GET_PARAMS:
                    {
                        COATINGSEGMENT_OBJ_INTERFACE.Pack_Params p = new COATINGSEGMENT_OBJ_INTERFACE.Pack_Params()
                        {
                            enable = mCoatingSegmentService.Enable,
                            enSave = mCoatingSegmentService.EnSave,
                            saveCnt = mCoatingSegmentService.SaveCnt,
                            recentCnt = mCoatingSegmentService.RecentCnt,
                            inIdxOfVSide = mCoatingSegmentService.InIdxOfVSide,
                            warningtol_distance = mCoatingSegmentService.WarningTol_Distance,
                            warningtol_total = mCoatingSegmentService.WarningTol_Total
                        };
                        infodata = p.ToBytes();
                    } break;
                case COATINGSEGMENT_OBJ_INTERFACE.GET_PROFILE:
                    {
                        infodata = mCoatingSegmentService.Profile.ToBytes();
                    } break;
                case COATINGSEGMENT_OBJ_INTERFACE.GET_LAST:
                    {
                        if (mCoatingSegmentService.Last != null)
                        {
                            infodata = mCoatingSegmentService.Last.ToBytes();
                        }
                        else 
                        {
                            infodata = null;
                        }
                    }break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case COATINGSEGMENT_OBJ_INTERFACE.SET_PARAMS:
                    {
                        COATINGSEGMENT_OBJ_INTERFACE.Pack_Params p = new COATINGSEGMENT_OBJ_INTERFACE.Pack_Params();
                        if (!p.TryParse(infodata))
                            break;
                        mCoatingSegmentService.Enable = p.enable;
                        mCoatingSegmentService.EnSave = p.enSave;
                        mCoatingSegmentService.SaveCnt = p.saveCnt;
                        mCoatingSegmentService.RecentCnt = p.recentCnt;
                        mCoatingSegmentService.InIdxOfVSide = p.inIdxOfVSide;
                        mCoatingSegmentService.WarningTol_Distance = p.warningtol_distance;
                        mCoatingSegmentService.WarningTol_Total = p.warningtol_total;
                        mCoatingSegmentService.Apply();
                    } break;
                case COATINGSEGMENT_OBJ_INTERFACE.SET_PROFILE:
                    {
                        int count;
                        if (!mCoatingSegmentService.Profile.TryParse(infodata, 0, out count))
                            break;
                        mCoatingSegmentService.ProfileApply();
                    } break;
            }
        }
        public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
        {
            switch (funcid)
            {
                case COATINGSEGMENT_OBJ_INTERFACE.CALL_GETRECENT:
                    {
                        COATINGSEGMENT_OBJ_INTERFACE.Pack_Recent p = new COATINGSEGMENT_OBJ_INTERFACE.Pack_Recent();
                        p.data = mCoatingSegmentService.Recent.ToArray();

                        this.CurrObjSys.PushCallFunctionEx(from, srcid, ID, magic, funcid, p.ToBytes());
                    }
                    break;
            }
        }
    }
}