Esempio n. 1
0
        /// <summary>
        /// 若是Session類訊息, 將由這個Method處理
        /// </summary>
        /// <param name="protoConn"></param>
        /// <param name="msg"></param>
        /// <returns>true代表己處理, 你不需再處理</returns>
        public bool ProcessSession(ISNetProtoConnectBase protoConn, object msg)
        {
            var secsMsg = msg as CxHsmsMessage;

            if (secsMsg == null)
            {
                throw new ArgumentException("不正確的msg型態");
            }

            switch (secsMsg.header.SType)
            {
            case 1:
                protoConn.WriteMsg(CxHsmsMessage.CtrlMsg_SelectRsp(0));
                return(true);

            case 2:
                return(true);

            case 5:
                protoConn.WriteMsg(CxHsmsMessage.CtrlMsg_LinktestRsp());
                return(true);

            case 6:
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="protoConn">並非所有通訊都是繼續自Stream, 因此請實作IProtoConnectBase</param>
        public void FirstConnect(ISNetProtoConnectBase protoConn)
        {
            var txMsg = CxHsmsMessage.CtrlMsg_SelectReq();

            protoConn.WriteMsg(txMsg);
            txMsg = CxHsmsMessage.CtrlMsg_LinktestReq();
            protoConn.WriteMsg(txMsg);
        }
Esempio n. 3
0
        public void Close()
        {
            this.CfIsRunning = false;
            this.areMsg.Set();//若在等訊號也通知結束等待

            if (this.taskRun != null)
            {
                this.taskRun.Cancel();//取消執行Task
                this.taskRun.Wait(1000);
                this.taskRun.Dispose();
                this.taskRun = null;
            }
            if (this.ProtoConn != null)
            {
                this.ProtoConn.Disconnect();
                this.ProtoConn.Dispose();
                this.ProtoConn = null;
            }
            CtkEventUtil.RemoveEventHandlersOfOwnerByFilter(this, (dlgt) => true);
        }
Esempio n. 4
0
        public virtual int CfInit()
        {
            if (this.Config == null)
            {
                throw new SNetException("沒有設定參數");
            }

            var remoteUri   = new Uri(this.Config.RemoteUri);
            var localUri    = string.IsNullOrEmpty(this.Config.LocalUri) ? null : new Uri(this.Config.LocalUri);
            var localIpAddr = CtkNetUtil.GetSuitableIp(localUri == null ? null : localUri.Host, remoteUri.Host);

            localUri = CtkNetUtil.ToUri(localIpAddr.ToString(), localUri == null ? 0 : localUri.Port);


            switch (this.Config.ProtoConnect)
            {
            case SNetEnumProtoConnect.Tcp:
                this.ProtoConn = new SNetProtoConnTcp(localUri, remoteUri, this.Config.IsActivelyConnect);
                break;

            case SNetEnumProtoConnect.Custom:
                //由使用者自己實作
                break;

            default: throw new ArgumentException("ProtoConn");;
            }

            this.ProtoConn.IntervalTimeOfConnectCheck = this.Config.IntervalTimeOfConnectCheck;
            this.ProtoConn.EhFirstConnect            += (ss, ee) =>
            {
                this.ProtoSession.FirstConnect(this.ProtoConn);

                if (this.Config.IsActivelyTx)
                {
                    var ackDataMsg = this.SignalTran.CreateAckMsg(this.Config.SignalCfgList);
                    if (ackDataMsg != null)
                    {
                        this.ProtoConn.WriteMsg(ackDataMsg);
                    }
                }
                else
                {
                    var reqDataMsg = this.SignalTran.CreateDataReqMsg(this.Config.SignalCfgList);
                    if (reqDataMsg != null)
                    {
                        this.ProtoConn.WriteMsg(reqDataMsg);
                    }
                }
            };
            this.ProtoConn.EhDataReceive += (ss, ee) =>
            {
                var ea = ee as CtkProtocolEventArgs;
                this.ProtoFormat.ReceiveMsg(ea.TrxMessage);
                this.areMsg.Set();

                if (this.ProtoFormat.HasMessage())
                {
                    SignalHandle();
                }
            };



            switch (this.Config.ProtoFormat)
            {
            case SNetEnumProtoFormat.SNetCmd:
                this.ProtoFormat = new SNetProtoFormatSNetCmd();
                break;

            case SNetEnumProtoFormat.Secs:
                this.ProtoFormat = new SNetProtoFormatSecs();
                break;

            case SNetEnumProtoFormat.Custom:
                //由使用者自己實作
                break;

            default: throw new ArgumentException("必須指定ProtoFormat");
            }



            switch (this.Config.ProtoSession)
            {
            case SNetEnumProtoSession.SNetCmd:
                this.ProtoSession = new SNetProtoSessionSNetCmd();
                break;

            case SNetEnumProtoSession.Secs:
                this.ProtoSession = new SNetProtoSessionSecs();
                break;

            case SNetEnumProtoSession.Custom:
                //由使用者自己實作
                break;

            default: throw new ArgumentException("必須指定ProtoFormat");
            }


            switch (this.Config.SignalTran)
            {
            case SNetEnumSignalTrans.SNetCmd:
                this.SignalTran = new SNetSignalTransSNetCmd();
                break;

            case SNetEnumSignalTrans.Secs001:
                this.SignalTran = new SNetSignalTransSecs001();
                break;

            case SNetEnumSignalTrans.Custom:
                //由使用者自己實作
                break;

            default: throw new ArgumentException("必須指定ProtoFormat");
            }



            return(0);
        }
Esempio n. 5
0
 public bool ProcessSession(ISNetProtoConnectBase protoConn, object msg)
 {
     return(false);
 }
Esempio n. 6
0
 public void FirstConnect(ISNetProtoConnectBase protoConn)
 {
 }