Exemple #1
0
 public void SetClientInfo(string clientID, int clientVer)
 {
     if (this.channel != null)
     {
         FTCAPI.FTAPIChannel_SetClientInfo(this.channel, clientID, clientVer);
     }
 }
Exemple #2
0
 public void SetRSAPrivateKey(string key)
 {
     if (this.channel != null)
     {
         FTCAPI.FTAPIChannel_SetRSAPrivateKey(this.channel, key);
     }
 }
Exemple #3
0
 public void Close()
 {
     if (this.channel != null)
     {
         FTCAPI.FTAPIChannel_Close(this.channel);
     }
 }
Exemple #4
0
 public ulong GetConnectID()
 {
     if (this.channel != null)
     {
         return(FTCAPI.FTAPIChannel_GetConnectID(this.channel));
     }
     return(0);
 }
Exemple #5
0
 public void Close()
 {
     if (this.channel != null)
     {
         //FTCAPI.ReleaseFTAPIChannel(this.channel);
         FTCAPI.FTAPIChannel_Close(this.channel);
     }
 }
Exemple #6
0
        public bool InitConnect(string ip, ushort port, bool isEnableEncrypt)
        {
            if (this.channel != null)
            {
                int ret = FTCAPI.FTAPIChannel_InitConnect(this.channel, ip, port, isEnableEncrypt ? 1 : 0);
                return(ret == 0);
            }

            return(false);
        }
Exemple #7
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            FTCAPI.ReleaseFTAPIChannel(channel);
            channel  = (IntPtr)0;
            disposed = true;
        }
Exemple #8
0
 /// <summary>
 /// 清理底层库,程序退出时调用一次。
 /// </summary>
 public static void UnInit()
 {
     lock (initLock)
     {
         if (!isInited)
         {
             return;
         }
         FTCAPI.FTAPIChannel_UnInit();
         isInited = false;
     }
 }
Exemple #9
0
 /// <summary>
 /// 初始化底层库,程序启动时调用一次。
 /// </summary>
 public static void Init()
 {
     lock (initLock)
     {
         if (isInited)
         {
             return;
         }
         FTCAPI.FTAPIChannel_Init();
         isInited = true;
     }
 }
Exemple #10
0
 protected uint SendProto <TMessage, TBuilder>(uint protoID, GeneratedMessage <TMessage, TBuilder> req)
     where TMessage : Google.ProtocolBuffers.GeneratedMessage <TMessage, TBuilder>
     where TBuilder : Google.ProtocolBuffers.GeneratedBuilder <TMessage, TBuilder>, new()
 {
     if (this.channel != null)
     {
         byte[] data    = req.ToByteArray();
         IntPtr dataPtr = Marshal.AllocHGlobal(data.Length);
         Marshal.Copy(data, 0, dataPtr, data.Length);
         uint serialNo = FTCAPI.FTAPIChannel_SendProto(this.channel, protoID, (byte)0, dataPtr, data.Length);
         Marshal.FreeHGlobal(dataPtr);
         return(serialNo);
     }
     return(0);
 }
Exemple #11
0
        public FTAPI_Conn()
        {
            this.channel = FTCAPI.CreateFTAPIChannel();
            FTCAPI.FTAPIChannel_SetProgrammingLanguage(this.channel, "C#");
            this.initConnectCallback = (IntPtr pChannel, long errCode, string desc) =>
            {
                this.OnInitConnect(errCode, desc);
            };
            this.replyCallback = (IntPtr pChannel, int enReqReplyType, IntPtr protoHeaderPtr, IntPtr protoData, int nDataLen) =>
            {
                ProtoHeader protoHeader = (ProtoHeader)Marshal.PtrToStructure(protoHeaderPtr, typeof(ProtoHeader));
                byte[]      data        = null;
                if (nDataLen > 0 && protoData != IntPtr.Zero)
                {
                    data = new byte[nDataLen];
                    Marshal.Copy(protoData, data, 0, nDataLen);
                }

                this.OnReply((ReqReplyType)enReqReplyType, protoHeader, data);
            };
            this.pushCallback = (IntPtr pChannel, IntPtr protoHeaderPtr, IntPtr protoData, int nDataLen) =>
            {
                ProtoHeader protoHeader = (ProtoHeader)Marshal.PtrToStructure(protoHeaderPtr, typeof(ProtoHeader));
                byte[]      data        = new byte[nDataLen];
                Marshal.Copy(protoData, data, 0, nDataLen);
                this.OnPush(protoHeader, data);
            };
            this.disConnCallback = (IntPtr pChannel, long errCode) =>
            {
                this.OnDisConnect(errCode);
            };

            FTCAPI.FTAPIChannel_SetOnInitConnectCallback(channel, initConnectCallback);
            FTCAPI.FTAPIChannel_SetOnDisconnectCallback(channel, disConnCallback);
            FTCAPI.FTAPIChannel_SetOnReplyCallback(channel, replyCallback);
            FTCAPI.FTAPIChannel_SetOnPushCallback(channel, pushCallback);
        }