WarningSystem_OBJProxy.cs 7.93 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.Server;

namespace FLY.Thick.Base.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_CURR = 3;
        #endregion
        WarningSystem mWarningSystem;
        int reasonlist_newcnt = 0;
        public WarningSystem_OBJProxy(int objsys_idx, WarningSystem warningSystem)
            : base(objsys_idx)
        {
            ID = WARNING_OBJ_INTERFACE.ID;
            mWarningSystem = warningSystem;
            mWarningSystem.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mWarningSystem_PropertyChanged);
            mWarningSystem.ReasonList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ReasonList_CollectionChanged);
        }

        void ReasonList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 
            {
                reasonlist_newcnt++;

                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        //reasonlist_newcnt
                        WARNING_OBJ_INTERFACE.Pack_ReasonList p = new WARNING_OBJ_INTERFACE.Pack_ReasonList();
                        if (reasonlist_newcnt > mWarningSystem.ReasonList.Count())
                            reasonlist_newcnt = mWarningSystem.ReasonList.Count();

                        p.list = new FlyData_WarningHistory[reasonlist_newcnt];
                        for (int i = 0; i < p.list.Count(); i++)
                        { 
                            int index = mWarningSystem.ReasonList.Count() - reasonlist_newcnt;
                            p.list[i] = mWarningSystem.ReasonList[index];
                        }
                        reasonlist_newcnt = 0;

                       
                        CurrObjSys.PushObjInfoEx(
                            this, WARNING_OBJ_INTERFACE.PUSH_REASONLIST,
                            p.ToBytes());
                    }), this, MARKNO_PUSH_REASONLIST);
            }
        }

        void mWarningSystem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "OutIdxOfWarning") ||
                (e.PropertyName == "Duration") ||
                (e.PropertyName == "Enable") ||
                (e.PropertyName == "EnSave") ||
                (e.PropertyName == "WhiteList") ||
                (e.PropertyName == "BlackList")
                )
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, WARNING_OBJ_INTERFACE.GET_PARAMS, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, WARNING_OBJ_INTERFACE.PUSH_PARAMS,
                            buf);
                    }), this, MARKNO_PUSH_PARAMS);
            }
            else if ((e.PropertyName == "ErrTime") ||
                (e.PropertyName == "ErrType") ||
                (e.PropertyName == "ErrCode") ||
                (e.PropertyName == "ErrDescription")) 
            {
                FObjBase.PollModule.Current.Poll_JustOnce(
                    new PollModule.PollHandler(delegate()
                    {
                        byte[] buf;
                        GetValue(null, 0, WARNING_OBJ_INTERFACE.GET_CURR, out buf);
                        CurrObjSys.PushObjInfoEx(
                            this, WARNING_OBJ_INTERFACE.PUSH_CURR,
                            buf);
                    }), this, MARKNO_PUSH_CURR);
            }

        }
        public override void CallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] infodata)
        {
            switch (funcid)
            {
                case WARNING_OBJ_INTERFACE.CALL_RESET:
                    mWarningSystem.Reset();
                    break;
                case WARNING_OBJ_INTERFACE.CALL_ADD:
                    {
                        FlyData_WarningHistory p = new FlyData_WarningHistory();
                        int cnt;
                        if (p.TryParse(infodata, 0, out cnt)) 
                        {
                            mWarningSystem.Add(p.ErrType, p.ErrCode, p.Description, p.State);
                        }
                    }break;
                case WARNING_OBJ_INTERFACE.CALL_QUIET:
                    mWarningSystem.Quiet();
                    break;
            }
        }
        public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
        {
            switch (memid)
            {
                case WARNING_OBJ_INTERFACE.GET_PARAMS:
                    {
                        WARNING_OBJ_INTERFACE.Pack_Params p = new WARNING_OBJ_INTERFACE.Pack_Params()
                        {
                            outIdxOfWarning =  mWarningSystem.OutIdxOfWarning,
                            duration =  mWarningSystem.Duration,
                            enable = mWarningSystem.Enable,
                            enSave = mWarningSystem.EnSave,
                            whitelist = mWarningSystem.WhiteList.ToArray(),
                            blacklist = mWarningSystem.BlackList.ToArray()
                        };

                        infodata = p.ToBytes();
                    } break;
                case WARNING_OBJ_INTERFACE.GET_REASONLIST:
                    {
                        WARNING_OBJ_INTERFACE.Pack_ReasonList p = new WARNING_OBJ_INTERFACE.Pack_ReasonList()
                        {
                            list = mWarningSystem.ReasonList.ToArray()
                        };
                        infodata = p.ToBytes();
                    } break;
                case WARNING_OBJ_INTERFACE.GET_CURR:
                    {
                        FlyData_WarningHistory p = new FlyData_WarningHistory(){
                            ErrType = mWarningSystem.ErrType,
                            ErrCode = mWarningSystem.ErrCode,
                            Time = mWarningSystem.ErrTime,
                            Description = mWarningSystem.ErrDescription
                        };
                        infodata = p.ToBytes();
                    }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:
                    {
                        WARNING_OBJ_INTERFACE.Pack_Params p = new WARNING_OBJ_INTERFACE.Pack_Params();
                        if (!p.TryParse(infodata))
                            return;
                        mWarningSystem.Enable = p.enable;
                        mWarningSystem.EnSave = p.enSave;
                        mWarningSystem.OutIdxOfWarning = p.outIdxOfWarning;
                        mWarningSystem.Duration = p.duration;
                        mWarningSystem.WhiteList.Clear();
                        for(int i=0;i<p.whitelist.Count();i++)
                            mWarningSystem.WhiteList.Add(p.whitelist[i]);

                        mWarningSystem.BlackList.Clear();
                        for(int i=0;i<p.blacklist.Count();i++)
                            mWarningSystem.BlackList.Add(p.blacklist[i]);
                        mWarningSystem.Apply();
                        return;
                    } break;
            }
        }
    }

}