FixService.cs 2.6 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Net;

using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.Client
{
    public class FixService : FObj, IFixService
    {
        IFConn mConn;
        UInt32 mServerID;

潘栩锋's avatar
潘栩锋 committed
20 21

        public FixService(UInt32 id)
潘栩锋's avatar
潘栩锋 committed
22
        {
潘栩锋's avatar
潘栩锋 committed
23
            mServerID = id;
潘栩锋's avatar
潘栩锋 committed
24 25 26 27 28 29 30
        }
        #region IFlyAD接口

        /// <summary>
        /// 注册timegrid 事件
        /// </summary>
        /// <param name="handler"></param>
潘栩锋's avatar
潘栩锋 committed
31
        public void RegistTimeGridEvent(FixEventHandler handler)
潘栩锋's avatar
潘栩锋 committed
32
        {
潘栩锋's avatar
潘栩锋 committed
33
            FixEvent += handler;
潘栩锋's avatar
潘栩锋 committed
34 35 36 37 38 39 40 41 42
            CurrObjSys.SenseConfigEx(
                mConn, mServerID, ID,
                Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID),
                SENSE_CONFIG.ADD);
        }
        /// <summary>
        /// 关闭注册timegrid 事件
        /// </summary>
        /// <param name="handler"></param>
潘栩锋's avatar
潘栩锋 committed
43
        public void UnRegistTimeGridEvent(FixEventHandler handler)
潘栩锋's avatar
潘栩锋 committed
44
        {
潘栩锋's avatar
潘栩锋 committed
45 46
            FixEvent -= handler;
            if (FixEvent == null)
潘栩锋's avatar
潘栩锋 committed
47 48 49 50 51 52 53 54
            {
                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID,
                    Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID),
                    SENSE_CONFIG.REMOVE);
            }
        }

潘栩锋's avatar
潘栩锋 committed
55
        event FixEventHandler FixEvent;
潘栩锋's avatar
潘栩锋 committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

        #endregion


        public override void Dispose()
        {
            CurrObjSys.ObjRemove(
                this, mConn);
        }
        public override void ConnectNotify(IFConn from)
        {
            mConn = from;
            if (from.IsConnected)
            {
                //设置推送

潘栩锋's avatar
潘栩锋 committed
72
                if (FixEvent != null)
潘栩锋's avatar
潘栩锋 committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
                {
                    UInt32 sense_mask = Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID);

                    CurrObjSys.SenseConfigEx(
                        mConn, mServerID, ID,
                        sense_mask,
                        SENSE_CONFIG.ADD);
                }
            }
        }

        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            switch (infoid)
            {
                case FIX_OBJ_INTERFACE.PUSH_TIMEGRID:
                    {
潘栩锋's avatar
潘栩锋 committed
90 91 92 93
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FixEventArgs>(json);

                        FixEvent?.Invoke(this, p);
潘栩锋's avatar
潘栩锋 committed
94 95 96 97 98 99 100
                    } break;
            }

        }

    }
}