WarningSystem_OBJProxy.cs 4.05 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
using FLY.OBJComponents.Common;
using FLY.OBJComponents.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.OBJComponents.Server.OBJProxy
{
    public class WarningSystem_OBJProxy : FObj
    {
        #region 延时推送 MARKNO
        const int MARKNO_PUSH_PARAMS = 1;
        const int MARKNO_PUSH_REASONLIST = 2;
        const int MARKNO_PUSH_NEWESTLIST = 3;
        #endregion
        WarningSystem mWarningSystem;
        Buffer_OBJProxy<FlyData_WarningHistory> mReasonListOBJProxy;
        Buffer_OBJProxy<FlyData_WarningHistory> mNewestListOBJProxy;

        /// <summary>
        /// 使用id,id+1,id+2
        /// </summary>
        /// <param name="objsys_idx"></param>
        /// <param name="id"></param>
        /// <param name="warningSystem"></param>
        public WarningSystem_OBJProxy(int objsys_idx, uint id, WarningSystem warningSystem)
            : base(objsys_idx)
        {
            ID = id;
            mWarningSystem = warningSystem;
            mWarningSystem.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mWarningSystem_PropertyChanged);

            mReasonListOBJProxy = new Buffer_OBJProxy<FlyData_WarningHistory>(objsys_idx, id+1, mWarningSystem.ReasonList);
            mNewestListOBJProxy = new Buffer_OBJProxy<FlyData_WarningHistory>(objsys_idx, id+2, mWarningSystem.NewestList);
        }
        void mWarningSystem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            Dictionary<string, object> p = new Dictionary<string, object>();
            p.Add(e.PropertyName, Misc.PropertiesManager.GetValue(mWarningSystem, e.PropertyName));

            string json = JsonConvert.SerializeObject(p);
            CurrObjSys.PushObjInfoEx(
                this, WARNING_OBJ_INTERFACE.PUSH_PARAMS,
                Misc.Converter.StringToBytes(json)
                );
        }
        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case WARNING_OBJ_INTERFACE.GET_PARAMS:
                    {
                        Dictionary<string, object> p = new Dictionary<string, object>();
                        //IEnumerable<string> propertynames = Misc.PropertiesManager.GetAllPropertyNames(mWarningSystem);
                        string[] propertynames = mWarningSystem.GetPropertys();
                        foreach (string pn in propertynames)
                        {
                            p.Add(pn, Misc.PropertiesManager.GetValue(mWarningSystem, pn));
                        }
                        string json = JsonConvert.SerializeObject(p);
                        infodata = Misc.Converter.StringToBytes(json);
                    }
                    break;
                default:
                    infodata = null;
                    break;
            }
        }
        public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case WARNING_OBJ_INTERFACE.SET_PARAMS:
                    {
                        
                        string json = Misc.Converter.BytesToString(infodata);

                        Dictionary<string, object> datas = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);

                        foreach (KeyValuePair<string, object> kv in datas)
                        {
                            PropertiesManager_JSON.SetValue(this, kv.Key, kv.Value);
                        }

                        return;
                    }
                    break;
            }
        }

        public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
        {
            switch (funcid)
            {
                case WARNING_OBJ_INTERFACE.CALL_RESET:
                    mWarningSystem.Reset();
                    break;
            }
        }
    }
}