BlowingFixProfileService.cs 4.92 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
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Blowing.Common;
using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Thick.Blowing.Client
{
    public class BlowingFixProfileService : FObj, IBlowingFixProfileService
    {
        IFConn mConn;
        UInt32 mServerID;

        public BlowingFixProfileService()
        {
            mServerID = FLY.Thick.Blowing.OBJ_INTERFACE.OBJ_INTERFACE_ID.BFPROFILE_ID;
        }
        public BlowingFixProfileService(UInt32 id)
        {
            mServerID = id;
        }

        #region IProfileService  接口
        BlowingFixProfileParam param = new BlowingFixProfileParam();
        public BlowingFixProfileParam Param
        {
            get
            {
                return param;
            }
        }


        /// <summary>
        /// 应用 &amp; 保存
        /// </summary>
        public void Apply()
        {
            CurrObjSys.SetValueEx(mConn, mServerID, ID,
                BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS,
                Param.ToBytes());
        }



        /// <summary>
        /// 获取产品列表, 返回类型为 List&lt;string&gt;
        /// </summary>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        public void GetList(AsyncCBHandler AsyncDelegate, object AsyncState)
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_GETLIST,
                null,
                AsyncDelegate, AsyncState);
        }

        /// <summary>
        /// 删除指定产品
        /// </summary>
        /// <param name="productname"></param>
        public void Del(string productname)
        {
            Pack_String p = new Pack_String();
            p.data = productname;
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_DEL, p.ToBytes());
        }

        /// <summary>
        /// 读取指定产品,返回类型为 ProfileParam
        /// </summary>
        /// <param name="productname"></param>
        /// <param name="AsyncDelegate"></param>
        /// <param name="AsyncState"></param>
        public void Read(string productname, AsyncCBHandler AsyncDelegate, object AsyncState)
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ,
                new Pack_String() { data = productname }.ToBytes(),
                AsyncDelegate, AsyncState);
        }
        #endregion



        public override void Dispose()
        {
            CurrObjSys.ObjRemove(
                this, mConn);
        }
        public override void ConnectNotify(IFConn from)
        {
            mConn = from;
            if (from.IsConnected)
            {
                //获取所有数据,设置推送
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    BLOWINGFIX_PROFILE_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 BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS:
                    {
                        BlowingFixProfileParam p = new BlowingFixProfileParam();

                        if (!p.TryParse(infodata))
                            return;
                        Param.TryParse(infodata);

                    }
                    break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {

            PushGetValue(from, srcid, infoid, infodata);


        }
        public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
        {
            switch (funcid)
            {
                case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_GETLIST:
                    {
                        Pack_StringList p = new Pack_StringList();
                        if (!p.TryParse(retdata))
                            return;
                        ((AsyncCBHandler)AsyncDelegate)(AsyncState, p.list);
                    }
                    break;
                case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ:
                    {
                        BlowingFixProfileParam p = new BlowingFixProfileParam();
                        if (!p.TryParse(retdata))
                            return;
                        ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
                    }
                    break;
            }
        }
    }
}