WarningServiceClient.cs 4.47 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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
{
16
    public class WarningServiceClient : FObjServiceClient, IWarningService
潘栩锋's avatar
潘栩锋 committed
17 18 19 20 21
    {

        #region IWarningService
        
        public bool Enable { get; set; }
22
        public bool IsRinging { get; protected set; }
潘栩锋's avatar
潘栩锋 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
        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; } }

        #endregion
38
        public WarningServiceClient(UInt32 serviceId) : base(serviceId) 
潘栩锋's avatar
潘栩锋 committed
39 40 41 42 43 44 45 46
        {
            Init(serviceId);
        }
        public WarningServiceClient(UInt32 serviceId, string connName) : this(serviceId) 
        {
            FObjServiceClientManager.Instance.Connect_to_Another_OBJSys(connName, this);
        }
        void Init(UInt32 serviceId) 
潘栩锋's avatar
潘栩锋 committed
47 48 49
        {
            this.PropertyChanged += WarningService_PropertyChanged;

潘栩锋's avatar
潘栩锋 committed
50
            reasonlist = new BufferServiceClient<FlyData_WarningHistory>(serviceId + 1);
潘栩锋's avatar
潘栩锋 committed
51

潘栩锋's avatar
潘栩锋 committed
52
            newestlist = new BufferServiceClient<FlyData_WarningHistory>(serviceId + 2);
潘栩锋's avatar
潘栩锋 committed
53
        }
54
        public override UInt32[] GetIDs()
潘栩锋's avatar
潘栩锋 committed
55 56 57 58 59 60 61 62
        {
            return new UInt32[] { ID,
                reasonlist.ID,
                newestlist.ID
            };
        }
        private void WarningService_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
潘栩锋's avatar
潘栩锋 committed
63 64 65 66
            Dictionary<string, object> p = new Dictionary<string, object>
            {
                { e.PropertyName, Misc.PropertiesManager.GetValue(this, e.PropertyName) }
            };
潘栩锋's avatar
潘栩锋 committed
67 68 69 70 71 72 73 74 75 76 77 78

            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);
        }
79 80 81 82 83
        public void Silence()
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                WARNING_OBJ_INTERFACE.CALL_SILENCE, null);
        }
潘栩锋's avatar
潘栩锋 committed
84 85 86 87 88 89 90
        public override void Dispose()
        {
            CurrObjSys.ObjRemove(
                this, mConn);
        }
        public override void ConnectNotify(IFConn from)
        {
91
            base.ConnectNotify(from);
潘栩锋's avatar
潘栩锋 committed
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
            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;
            }
        }
    }
}