PasswordServiceClient.cs 2.53 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.Client
{
15
    public class PasswordServiceClient: FObjServiceClient, IPasswordService
潘栩锋's avatar
潘栩锋 committed
16 17
    {

18 19 20
        public PasswordServiceClient(UInt32 serviceId) : base(serviceId) { }

        public PasswordServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
潘栩锋's avatar
潘栩锋 committed
21 22 23 24
        #region IPasswordService 成员
        /// <summary>
        /// 密码列表。 储存在 服务器
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
25 26 27 28 29
        [PropertyChanged.DoNotCheckEquality]
        public List<PasswordCell> PWs { get; set; } = new List<PasswordCell>();

        [PropertyChanged.DoNotCheckEquality]
        public List<UiLvCell> UiLvs { get; set; } = new List<UiLvCell>();
潘栩锋's avatar
潘栩锋 committed
30 31
        public void Apply()
        {
潘栩锋's avatar
潘栩锋 committed
32 33 34 35 36 37 38
            PASSWORD_OBJ_INTERFACE.Pack_Params p = new PASSWORD_OBJ_INTERFACE.Pack_Params()
            {
                PWs = PWs,
                UiLvs = UiLvs
            };

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
潘栩锋's avatar
潘栩锋 committed
39 40 41 42

            CurrObjSys.SetValueEx(
               mConn, mServerID, ID, 
               PASSWORD_OBJ_INTERFACE.SET_PWLIST,
潘栩锋's avatar
潘栩锋 committed
43
               Misc.Converter.StringToBytes(json)
潘栩锋's avatar
潘栩锋 committed
44 45 46 47 48 49 50 51
               );    
        }

        #endregion


        public override void ConnectNotify(IFConn from)
        {
52
            base.ConnectNotify(from);
潘栩锋's avatar
潘栩锋 committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
            if (from.IsConnected)
            {
                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD);
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    PASSWORD_OBJ_INTERFACE.GET_PWLIST);
            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            PushInfo(from, srcid, memid, infodata);
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            switch (infoid)
            {
                case PASSWORD_OBJ_INTERFACE.PUSH_PWLIST:
                    {
潘栩锋's avatar
潘栩锋 committed
72 73 74 75 76
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject< PASSWORD_OBJ_INTERFACE.Pack_Params>(json);
                        PWs = p.PWs;
                        UiLvs = p.UiLvs;
潘栩锋's avatar
潘栩锋 committed
77 78 79 80 81
                    } break;
            }
        }
    }
}