WarningServiceClient.cs 4.25 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

using FObjBase;
using FLY.OBJComponents.Common;
using FLY.OBJComponents.IService;
using FLY.OBJComponents.OBJ_INTERFACE;
using Newtonsoft.Json;

namespace FLY.OBJComponents.Client
{
    public class WarningServiceClient : FObj, IWarningService
    {
        IFConn mConn;
        UInt32 mServerID;

        #region IWarningService
        
        public bool Enable { get; set; }
24
        public bool IsRinging { get; protected set; }
潘栩锋'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
        private BufferServiceClient<FlyData_WarningHistory> reasonlist;

        /// <summary>
        /// 当前正在报警的!!!!!!
        /// </summary>
        public IBuffer<FlyData_WarningHistory> ReasonList { get { return reasonlist; } }

        private BufferServiceClient<FlyData_WarningHistory> newestlist;

        /// <summary>
        /// 最近报警列表
        /// </summary>
        public IBuffer<FlyData_WarningHistory> NewestList { get { return newestlist; } }

        public event PropertyChangedEventHandler PropertyChanged;
        #endregion
        public WarningServiceClient(UInt32 serverid)
        {
            mServerID = serverid;
            this.PropertyChanged += WarningService_PropertyChanged;

            reasonlist = new BufferServiceClient<FlyData_WarningHistory>(serverid+1);

            newestlist = new BufferServiceClient<FlyData_WarningHistory>(serverid+2);
        }
        public UInt32[] GetIDs()
        {
            return new UInt32[] { ID,
                reasonlist.ID,
                newestlist.ID
            };
        }
        private void WarningService_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Dictionary<string, object> p = new Dictionary<string, object>();
            p.Add(e.PropertyName, Misc.PropertiesManager.GetValue(this, e.PropertyName));

            string json = JsonConvert.SerializeObject(p);
            CurrObjSys.PushObjInfoEx(
                this, WARNING_OBJ_INTERFACE.PUSH_PARAMS,
                Misc.Converter.StringToBytes(json)
                );
        }
        public void Reset()
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                WARNING_OBJ_INTERFACE.CALL_RESET, null);
        }
73 74 75 76 77
        public void Silence()
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                WARNING_OBJ_INTERFACE.CALL_SILENCE, null);
        }
潘栩锋's avatar
潘栩锋 committed
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
        public override void Dispose()
        {
            CurrObjSys.ObjRemove(
                this, mConn);
        }
        public override void ConnectNotify(IFConn from)
        {
            mConn = from;
            if (from.IsConnected)
            {
                //获取所有数据,设置推送
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    WARNING_OBJ_INTERFACE.GET_PARAMS);

                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID,
                    0xffffffff,
                    SENSE_CONFIG.ADD);
            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case WARNING_OBJ_INTERFACE.GET_PARAMS:
                    {
                        string json = Misc.Converter.BytesToString(infodata);

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

                        this.PropertyChanged -= WarningService_PropertyChanged;
                        foreach (KeyValuePair<string, object> kv in datas)
                        {
                            PropertiesManager_JSON.SetValue(this, kv.Key, kv.Value);
                        }
                        this.PropertyChanged += WarningService_PropertyChanged;
                    }
                    break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            switch (infoid)
            {
                case WARNING_OBJ_INTERFACE.GET_PARAMS:
                    PushGetValue(from, srcid, infoid, infodata);
                    break;
            }
        }
    }
}