ReverseRoute() public method

public ReverseRoute ( Header header ) : void
header Header
return void
示例#1
0
        public void ReverseRoute()
        {
            string str1 = "8=FIX.4.2\x01" + "9=55\x01" + "35=0\x01" + "34=3\x01" + "49=TW\x01" +
                "52=20000426-12:05:06\x01" + "56=ISLD\x01" + "1=acct123\x01" + "10=123\x01";
            Message msg = new Message();
            try
            {
                msg.FromString(str1, true, null, null, _defaultMsgFactory);
            }
            catch (InvalidMessage e)
            {
                Assert.Fail("Unexpected exception (InvalidMessage): " + e.Message);
            }
            Header header = new Header();
            header.SetField(new BeginString("FIX.4.2"));
            header.SetField(new SenderCompID("SENDER"));
            header.SetField(new SenderSubID("SENDERSUB"));
            header.SetField(new SenderLocationID("SENDERLOC"));
            header.SetField(new TargetCompID("TARGET"));
            header.SetField(new TargetSubID("TARGETSUB"));
            header.SetField(new TargetLocationID("TARGETLOC"));

            msg.ReverseRoute(header);
            
            Assert.That(msg.Header.GetString(Tags.BeginString), Is.EqualTo("FIX.4.2"));
            Assert.That(msg.Header.GetString(Tags.TargetCompID), Is.EqualTo("SENDER"));
            Assert.That(msg.Header.GetString(Tags.TargetSubID), Is.EqualTo("SENDERSUB"));
            Assert.That(msg.Header.GetString(Tags.TargetLocationID), Is.EqualTo("SENDERLOC"));
            Assert.That(msg.Header.GetString(Tags.SenderCompID), Is.EqualTo("TARGET"));
            Assert.That(msg.Header.GetString(Tags.SenderSubID), Is.EqualTo("TARGETSUB"));
            Assert.That(msg.Header.GetString(Tags.SenderLocationID), Is.EqualTo("TARGETLOC"));
        }
示例#2
0
        public bool GenerateReject(Message message, FixValues.SessionRejectReason reason, int field)
        {
            string beginString = this.SessionID.BeginString;

            Message reject = msgFactory_.Create(beginString, Fields.MsgType.REJECT);

            reject.ReverseRoute(message.Header);
            InitializeHeader(reject);

            string msgType;

            if (message.Header.IsSetField(Fields.Tags.MsgType))
            {
                msgType = message.Header.GetField(Fields.Tags.MsgType);
            }
            else
            {
                msgType = "";
            }

            int msgSeqNum = 0;

            if (message.Header.IsSetField(Fields.Tags.MsgSeqNum))
            {
                try
                {
                    msgSeqNum = message.Header.GetInt(Fields.Tags.MsgSeqNum);
                    reject.SetField(new Fields.RefSeqNum(msgSeqNum));
                }
                catch (System.Exception)
                { }
            }

            if (beginString.CompareTo(FixValues.BeginString.FIX42) >= 0)
            {
                if (msgType.Length > 0)
                {
                    reject.SetField(new Fields.RefMsgType(msgType));
                }
                if ((FixValues.BeginString.FIX42.Equals(beginString) && reason.Value <= FixValues.SessionRejectReason.INVALID_MSGTYPE.Value) || (beginString.CompareTo(FixValues.BeginString.FIX42) > 0))
                {
                    reject.SetField(new Fields.SessionRejectReason(reason.Value));
                }
            }
            if (!MsgType.LOGON.Equals(msgType) &&
                !MsgType.SEQUENCE_RESET.Equals(msgType) &&
                (msgSeqNum == state_.GetNextTargetMsgSeqNum()))
            {
                state_.IncrNextTargetMsgSeqNum();
            }

            if ((0 != field) || FixValues.SessionRejectReason.INVALID_TAG_NUMBER.Equals(reason))
            {
                if (FixValues.SessionRejectReason.INVALID_MSGTYPE.Equals(reason))
                {
                    if (this.SessionID.BeginString.CompareTo(FixValues.BeginString.FIX43) >= 0)
                    {
                        PopulateRejectReason(reject, reason.Description);
                    }
                    else
                    {
                        PopulateSessionRejectReason(reject, field, reason.Description, false);
                    }
                }
                else
                {
                    PopulateSessionRejectReason(reject, field, reason.Description, true);
                }

                this.Log.OnEvent("Message " + msgSeqNum + " Rejected: " + reason.Description + " (Field=" + field + ")");
            }
            else
            {
                PopulateRejectReason(reject, reason.Description);
                this.Log.OnEvent("Message " + msgSeqNum + " Rejected: " + reason.Value);
            }

            if (!state_.ReceivedLogon)
            {
                throw new QuickFIXException("Tried to send a reject while not logged on");
            }

            return(SendRaw(reject, 0));
        }