當前位置: 首頁>>代碼示例>>C#>>正文


C# Message.FromString方法代碼示例

本文整理匯總了C#中QuickFix.Message.FromString方法的典型用法代碼示例。如果您正苦於以下問題:C# Message.FromString方法的具體用法?C# Message.FromString怎麽用?C# Message.FromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在QuickFix.Message的用法示例。


在下文中一共展示了Message.FromString方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CheckSumTest

        public void CheckSumTest()
        {
            string str1 = "8=FIX.4.2\x01" + "9=45\x01" + "35=0\x01" + "34=3\x01" + "49=TW\x01" +
                "52=20000426-12:05:06\x01" + "56=ISLD\x01";

            int chksum = 0;
            foreach (char c in str1)
                chksum += (int)c;
            chksum %= 256;

            str1 += "10=218\x01";  // checksum field
            Message msg = new Message();
            try
            {
                msg.FromString(str1, true, null, null, _defaultMsgFactory);
            }
            catch (InvalidMessage e)
            {
                Assert.Fail("Unexpected exception (InvalidMessage): " + e.Message);
            }
            Assert.That(msg.CheckSum(), Is.EqualTo(chksum));
        }
開發者ID:RemiGaudin,項目名稱:quickfixn,代碼行數:22,代碼來源:MessageTests.cs

示例2: NextResendRequest

        protected void NextResendRequest(Message resendReq)
        {
            if (!Verify(resendReq, false, false))
                return;
            try
            {
                int msgSeqNum = 0;
                if (!(this.IgnorePossDupResendRequests && resendReq.Header.IsSetField(Tags.PossDupFlag)))
                {
                    int begSeqNo = resendReq.GetInt(Fields.Tags.BeginSeqNo);
                    int endSeqNo = resendReq.GetInt(Fields.Tags.EndSeqNo);
                    this.Log.OnEvent("Got resend request from " + begSeqNo + " to " + endSeqNo);

                    if ((endSeqNo == 999999) || (endSeqNo == 0))
                    {
                        endSeqNo = state_.GetNextSenderMsgSeqNum() - 1;
                    }

                    if (!PersistMessages)
                    {
                        endSeqNo++;
                        int next = state_.GetNextSenderMsgSeqNum();
                        if (endSeqNo > next)
                            endSeqNo = next;
                        GenerateSequenceReset(resendReq, begSeqNo, endSeqNo);
                        return;
                    }

                    List<string> messages = new List<string>();
                    state_.Get(begSeqNo, endSeqNo, messages);
                    int current = begSeqNo;
                    int begin = 0;
                    foreach (string msgStr in messages)
                    {
                        Message msg = new Message();
                        msg.FromString(msgStr, true, this.SessionDataDictionary, this.ApplicationDataDictionary, msgFactory_);
                        msgSeqNum = msg.Header.GetInt(Tags.MsgSeqNum);

                        if ((current != msgSeqNum) && begin == 0)
                        {
                            begin = current;
                        }

                        if (IsAdminMessage(msg) && !(this.ResendSessionLevelRejects && msg.Header.GetString(Tags.MsgType) == MsgType.REJECT))
                        {
                            if (begin == 0)
                            {
                                begin = msgSeqNum;
                            }
                        }
                        else
                        {

                            initializeResendFields(msg);
                            if(!ResendApproved(msg, SessionID)) 
                            {
                                continue;
                            }

                            if (begin != 0)
                            {
                                GenerateSequenceReset(resendReq, begin, msgSeqNum);
                            }
                            Send(msg.ToString());
                            begin = 0;
                        }
                        current = msgSeqNum + 1;
                    }

                    int nextSeqNum = state_.GetNextSenderMsgSeqNum();
                    if (++endSeqNo > nextSeqNum)
                    {
                        endSeqNo = nextSeqNum;
                    }

                    if (begin == 0)
                    {
                        begin = current;
                    }

                    if (endSeqNo > begin)
                    {
                        GenerateSequenceReset(resendReq, begin, endSeqNo);
                    }
                }
                msgSeqNum = resendReq.Header.GetInt(Tags.MsgSeqNum);
                if (!IsTargetTooHigh(msgSeqNum) && !IsTargetTooLow(msgSeqNum))
                {
                    state_.IncrNextTargetMsgSeqNum();
                }

            }
            catch (System.Exception e)
            {
                this.Log.OnEvent("ERROR during resend request " + e.Message);
            }
        }
開發者ID:loning,項目名稱:quickfixn,代碼行數:97,代碼來源:Session.cs

示例3: FromStringTestWithNoDataDictionary

 public void FromStringTestWithNoDataDictionary()
 {
     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);
     }
     StringField f1 = new StringField(8);
     StringField f2 = new StringField(9);
     StringField f3 = new StringField(35);
     StringField f4 = new StringField(34);
     StringField f5 = new StringField(49);
     StringField f6 = new StringField(52);
     StringField f7 = new StringField(56);
     StringField f8 = new StringField(10);
     StringField f9 = new StringField(1);
     msg.Header.GetField(f1);
     msg.Header.GetField(f2);
     msg.Header.GetField(f3);
     msg.Header.GetField(f4);
     msg.Header.GetField(f5);
     msg.Header.GetField(f6);
     msg.Header.GetField(f7);
     msg.GetField(f9);
     msg.Trailer.GetField(f8);
     Assert.That(f1.Obj, Is.EqualTo("FIX.4.2"));
     Assert.That(f2.Obj, Is.EqualTo("55"));
     Assert.That(f3.Obj, Is.EqualTo("0"));
     Assert.That(f4.Obj, Is.EqualTo("3"));
     Assert.That(f5.Obj, Is.EqualTo("TW"));
     Assert.That(f6.Obj, Is.EqualTo("20000426-12:05:06"));
     Assert.That(f7.Obj, Is.EqualTo("ISLD"));
     Assert.That(f8.Obj, Is.EqualTo("123"));
     Assert.That(f9.Obj, Is.EqualTo("acct123"));
 }
開發者ID:RemiGaudin,項目名稱:quickfixn,代碼行數:41,代碼來源:MessageTests.cs

示例4: issue95

        public void issue95()
        {
            // Parser screws up on triple-nested groups.  Contributes to ResendRequest failures.
            string msgStr = String.Join(Message.SOH, new string[]{
                "8=FIX.4.4","9=999","35=R","34=6","49=sendercompid","52=20130225-10:44:59.149","56=targetcompid", //headers
                    "131=quotereqid",
                    "146=1", // NoRelatedSym
                        "55=ABC","65=CD","48=securityid","22=1", // group
                        "711=1", // NoUnderlyings
                            "311=underlyingsymbol","312=WI","309=underlyingsecurityid","305=1",
                "10=999",""
            });

            var dd = new QuickFix.DataDictionary.DataDictionary();
            dd.Load("../../../spec/fix/FIX44.xml");

            Message msg = new Message();
            msg.FromString(msgStr, false, dd, dd, _defaultMsgFactory);

            // make sure no fields were dropped in parsing
            Assert.AreEqual(msgStr.Length, msg.ToString().Length);

            // make sure repeating groups are not rearranged
            // 1 level deep
            StringAssert.Contains(String.Join(Message.SOH, new string[] { "55=ABC", "65=CD", "48=securityid", "22=1" }), msg.ToString());
            // 2 levels deep
            StringAssert.Contains(String.Join(Message.SOH, new string[] { "311=underlyingsymbol", "312=WI", "309=underlyingsecurityid", "305=1" }), msg.ToString());
        }
開發者ID:RemiGaudin,項目名稱:quickfixn,代碼行數:28,代碼來源:MessageTests.cs

示例5: ReverseRoute

        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"));
        }
開發者ID:RemiGaudin,項目名稱:quickfixn,代碼行數:32,代碼來源:MessageTests.cs

示例6: ToXMLTest

        public void ToXMLTest()
        {
            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);
            }

            string xmlDoc = msg.toXML();
            XDocument doc = null;
            try
            {
                doc = XDocument.Parse(xmlDoc);
            }
            catch (Exception e)
            {
                Assert.Fail("Badly formed XML generated: " + e.Message);
            }

            var fields = doc.Descendants("message").Descendants("body")
                .Select(field =>
                    new
                    {
                        number = field.Descendants("field").Attributes("number").Single().Value,
                        value = field.Descendants("field").Single().Value
                    })
                    .ToList();

            foreach (var elem in fields)
            {
                int number = 0;
                if (int.TryParse(elem.number.ToString(), out number) == false)
                {
                    Assert.Fail("should be number " + elem.number.ToString() + " " + elem.value.ToString());
                }
                else
                {
                    string value = msg.GetField(number);
                    Assert.That(value, Is.EqualTo(elem.value));
                }
            }

        }
開發者ID:baffled,項目名稱:quickfixn,代碼行數:49,代碼來源:MessageTests.cs

示例7: TestNewParser

        public void TestNewParser()
        {
            HiPerfTimer timer = new HiPerfTimer();
            string fix = GenRandomFIXString();

            const int times = 50000;
            timer.Start();
            for (int i = 0; i < times; i++)
            {
                Message m = new Message();
                m.FromString(fix);
            }
            timer.Stop();
            Console.WriteLine("Total per second [new parser]: " + ((1 / timer.Duration) * times).ToString());
        }
開發者ID:kennystone,項目名稱:quickfixn,代碼行數:15,代碼來源:PerformanceTests.cs


注:本文中的QuickFix.Message.FromString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。