GetSample_OBJProxy.cs 10.5 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.ComponentModel;
using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
namespace FLY.Thick.Base.Server.OBJProxy
{
    public class GetSample_OBJProxy : FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMS = 1;
        const int MARKNO_PUSH_STATE = 2;
        #endregion

        IGetSampleService mGetSampleService;

潘栩锋's avatar
潘栩锋 committed
22
        public GetSample_OBJProxy(int objsys_idx, UInt32 id, IGetSampleService getSampleService) :base(objsys_idx)
潘栩锋's avatar
潘栩锋 committed
23
        {
潘栩锋's avatar
潘栩锋 committed
24
            ID = id;
潘栩锋's avatar
潘栩锋 committed
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
            mGetSampleService = getSampleService;


            mGetSampleService.PropertyChanged += new PropertyChangedEventHandler(mGetSampleService_PropertyChanged);
            for(int i=0;i<mGetSampleService.Samples.Length;i++)
            {
                mGetSampleService.Samples[i].PropertyChanged += new PropertyChangedEventHandler(mSampleCell_PropertyChanged);
            }
            for (int i = 0; i < mGetSampleService.Features.Length; i++)
            {
                mGetSampleService.Features[i].PropertyChanged += new PropertyChangedEventHandler(mSampleFeature_PropertyChanged);
            }
        }
        void push_params() 
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
                new PollModule.PollHandler(delegate()
                {
                    byte[] buf;
                    GetValue(null, 0, GETSAMPLE_OBJ_INTERFACE.GET_PARAMS, out buf);
                    CurrObjSys.PushObjInfoEx(
                        this, GETSAMPLE_OBJ_INTERFACE.PUSH_PARAMS,
                        buf);
                }), this, MARKNO_PUSH_PARAMS);
        }
        void push_state()
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
                new PollModule.PollHandler(delegate()
                {
                    byte[] buf;
                    GetValue(null, 0, GETSAMPLE_OBJ_INTERFACE.GET_STATE, out buf);
                    CurrObjSys.PushObjInfoEx(
                        this, GETSAMPLE_OBJ_INTERFACE.PUSH_STATE,
                        buf);
                }), this, MARKNO_PUSH_STATE);
        }
        void mSampleFeature_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "Enable") ||
                (e.PropertyName == "StartPos") ||
                (e.PropertyName == "EndPos"))
            {
                push_params();
            }
            else if ((e.PropertyName == "MaxRelevancy") ||
                (e.PropertyName == "MaxOffset") ||
                (e.PropertyName == "ScanData"))
            {
                push_state();
            }
        }
        void mSampleCell_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "Enable") ||
                (e.PropertyName == "JustForCheck") ||
                (e.PropertyName == "OrgAD") ||
                (e.PropertyName == "Position")) 
            {
                push_params();
            }
            else if ((e.PropertyName == "AD") ||
                (e.PropertyName == "SampleValue"))
            {
                push_state();
            }
        }

        void mGetSampleService_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "Enable") ||
                (e.PropertyName == "Interval") ||
                (e.PropertyName == "Velocity") ||
                (e.PropertyName == "Range") ||
                (e.PropertyName == "Window") ||
100 101 102
                (e.PropertyName == "IsCheckByPercent") ||
                (e.PropertyName == "ErrPercent") ||
                (e.PropertyName == "ErrValue") ||
潘栩锋's avatar
潘栩锋 committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
                (e.PropertyName == "Search"))
            {
                push_params();
            }
            else if (e.PropertyName == "PosOfGrid") 
            {
                push_state();
            }
        }

        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            infodata = null;
            switch (memid)
            {
                case GETSAMPLE_OBJ_INTERFACE.GET_PARAMS:
                    {
                        GETSAMPLE_OBJ_INTERFACE.Pack_Params p = new GETSAMPLE_OBJ_INTERFACE.Pack_Params()
                        {
                            enable = mGetSampleService.Enable,
                            range = mGetSampleService.Range,
                            velocity = mGetSampleService.Velocity,
                            window = mGetSampleService.Window,
126 127 128
                            IsCheckByPercent = mGetSampleService.IsCheckByPercent,
                            ErrPercent = mGetSampleService.ErrPercent,
                            ErrValue = mGetSampleService.ErrValue,
潘栩锋's avatar
潘栩锋 committed
129 130 131 132 133 134 135 136 137 138 139
                            search = mGetSampleService.Search
                        };

                        p.samples = (from sample in mGetSampleService.Samples
                                     select
                                         new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleCell()
                                         {
                                             enable = sample.Enable,
                                             justForCheck = sample.JustForCheck,
                                             orgad = sample.OrgAD,
                                             position = sample.Position
潘栩锋's avatar
潘栩锋 committed
140
                                         });
潘栩锋's avatar
潘栩锋 committed
141 142

                        p.features = (from feature in mGetSampleService.Features
143
                                      select
潘栩锋's avatar
潘栩锋 committed
144
                                          new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleFeature()
145
                                          {
潘栩锋's avatar
潘栩锋 committed
146 147 148 149 150
                                              enable = feature.Enable,
                                              startpos = feature.StartPos,
                                              endpos = feature.EndPos
                                          });
                       
151 152
                        string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
潘栩锋's avatar
潘栩锋 committed
153 154 155 156 157
                    } break;
                case GETSAMPLE_OBJ_INTERFACE.GET_STATE:
                    {
                        GETSAMPLE_OBJ_INTERFACE.Pack_State p = new GETSAMPLE_OBJ_INTERFACE.Pack_State()
                        {
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                           posOfGrid = mGetSampleService.PosOfGrid,
                            samples = from sample in mGetSampleService.Samples
                                    select
                                        new GETSAMPLE_OBJ_INTERFACE.Pack_State_SampleCell()
                                        {
                                            ad = sample.AD,
                                            value = sample.SampleValue
                                        },
                            features = from feature in mGetSampleService.Features
                                        select
                                            new GETSAMPLE_OBJ_INTERFACE.Pack_State_SampleFeature()
                                            {
                                                maxRelevancy = feature.MaxRelevancy,
                                                maxOffset = feature.MaxOffset,
                                                scanData = feature.ScanData
                                            }
潘栩锋's avatar
潘栩锋 committed
174
                        };
175 176 177 178
                        string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
                    }
                    break;
潘栩锋's avatar
潘栩锋 committed
179 180 181 182 183 184 185 186 187 188 189
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case GETSAMPLE_OBJ_INTERFACE.SET_PARAMS:
                    {
190 191 192 193 194 195 196
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<GETSAMPLE_OBJ_INTERFACE.Pack_Params>(json);

                        mGetSampleService.Enable = p.enable;
                        mGetSampleService.Range = p.range;
                        mGetSampleService.Velocity = p.velocity;
                        mGetSampleService.Window = p.window;
潘栩锋's avatar
潘栩锋 committed
197 198 199
                        mGetSampleService.IsCheckByPercent = p.IsCheckByPercent;
                        mGetSampleService.ErrPercent = p.ErrPercent;
                        mGetSampleService.ErrValue = p.ErrValue;
200
                        mGetSampleService.Search = p.search;
潘栩锋's avatar
潘栩锋 committed
201
                        
202 203 204 205 206 207 208 209 210
                        for(int i=0;i<mGetSampleService.Samples.Count() && i<p.samples.Count();i++)
                        {
                            var sample_src = p.samples.ElementAt(i);
                            var sample_desp = mGetSampleService.Samples[i];

                            sample_desp.Enable = sample_src.enable;
                            sample_desp.JustForCheck = sample_src.justForCheck;
                            sample_desp.OrgAD = sample_src.orgad;
                            sample_desp.Position = sample_src.position;
潘栩锋's avatar
潘栩锋 committed
211
                        }
212 213 214 215 216 217 218 219 220 221 222 223
                        for (int i = 0; i < mGetSampleService.Features.Count() && i < p.features.Count(); i++)
                        {
                            var feature_src = p.features.ElementAt(i);
                            var feature_desp = mGetSampleService.Features[i];


                            feature_desp.Enable = feature_src.enable;
                            feature_desp.StartPos = feature_src.startpos;
                            feature_desp.EndPos = feature_src.endpos;
                        }
                        mGetSampleService.Apply();
                        
潘栩锋's avatar
潘栩锋 committed
224 225 226
                    } break;
            }
        }
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

        public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
        {
            switch (funcid) {
                case GETSAMPLE_OBJ_INTERFACE.CALL_GET_TEMPDATAS:
                    {
                        mGetSampleService.GetTempFilterDatas((context,retdata) =>
                        {
                            string json = Newtonsoft.Json.JsonConvert.SerializeObject(retdata);
                            
                            CurrObjSys.PushCallFunctionEx(from, srcid, ID, magic, funcid, Misc.Converter.StringToBytes(json));
                        }, null);
                    }break;
            }
        }
潘栩锋's avatar
潘栩锋 committed
242 243
    }
}