コード例 #1
0
        /// <summary>
        /// Creates a Message from a FIX string
        /// </summary>
        /// <param name="msgstr"></param>
        /// <param name="validate"></param>
        /// <param name="sessionDD"></param>
        /// <param name="appDD"></param>
        /// <param name="msgFactory">If null, any groups will be constructed as generic Group objects</param>
        /// <param name="ignoreBody">(default false) if true, ignores all non-header non-trailer fields.
        ///   Intended for callers that only need rejection-related information from the header.
        ///   </param>
        public void FromString(string msgstr, bool validate,
                               DataDictionary.DataDictionary sessionDD, DataDictionary.DataDictionary appDD, IMessageFactory msgFactory,
                               bool ignoreBody)
        {
            Clear();

            string msgType         = "";
            bool   expectingHeader = true;
            bool   expectingBody   = true;
            int    count           = 0;
            int    pos             = 0;

            DataDictionary.IFieldMapSpec msgMap = null;

            while (pos < msgstr.Length)
            {
                StringField f = ExtractField(msgstr, ref pos, sessionDD, appDD);

                if (validate && (count < 3) && (Header.HEADER_FIELD_ORDER[count++] != f.Tag))
                {
                    throw new InvalidMessage("Header fields out of order");
                }

                if (IsHeaderField(f.Tag, sessionDD))
                {
                    if (!expectingHeader)
                    {
                        if (0 == field_)
                        {
                            field_ = f.Tag;
                        }
                        validStructure_ = false;
                    }

                    if (Tags.MsgType.Equals(f.Tag))
                    {
                        msgType = string.Copy(f.Obj);
                        if (appDD != null)
                        {
                            msgMap = appDD.GetMapForMessage(msgType);
                        }
                    }

                    if (!this.Header.SetField(f, false))
                    {
                        this.Header.RepeatedTags.Add(f);
                    }

                    if ((null != sessionDD) && sessionDD.Header.IsGroup(f.Tag))
                    {
                        pos = SetGroup(f, msgstr, pos, this.Header, sessionDD.Header.GetGroupSpec(f.Tag), sessionDD, appDD, msgFactory);
                    }
                }
                else if (IsTrailerField(f.Tag, sessionDD))
                {
                    expectingHeader = false;
                    expectingBody   = false;
                    if (!this.Trailer.SetField(f, false))
                    {
                        this.Trailer.RepeatedTags.Add(f);
                    }

                    if ((null != sessionDD) && sessionDD.Trailer.IsGroup(f.Tag))
                    {
                        pos = SetGroup(f, msgstr, pos, this.Trailer, sessionDD.Trailer.GetGroup(f.Tag), sessionDD, appDD, msgFactory);
                    }
                }
                else if (ignoreBody == false)
                {
                    if (!expectingBody)
                    {
                        if (0 == field_)
                        {
                            field_ = f.Tag;
                        }
                        validStructure_ = false;
                    }

                    expectingHeader = false;
                    if (!SetField(f, false))
                    {
                        this.RepeatedTags.Add(f);
                    }


                    if ((null != msgMap) && (msgMap.IsGroup(f.Tag)))
                    {
                        pos = SetGroup(f, msgstr, pos, this, msgMap.GetGroupSpec(f.Tag), sessionDD, appDD, msgFactory);
                    }
                }
            }

            if (validate)
            {
                Validate();
            }
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: IressSmartHub/quickfixn
        /// <summary>
        /// Creates a Message from a FIX string
        /// </summary>
        /// <param name="msgstr"></param>
        /// <param name="validate"></param>
        /// <param name="sessionDD"></param>
        /// <param name="appDD"></param>
        /// <param name="msgFactory">If null, any groups will be constructed as generic Group objects</param>
        /// <param name="ignoreBody">(default false) if true, ignores all non-header non-trailer fields.
        ///   Intended for callers that only need rejection-related information from the header.
        ///   </param>
        public void FromString(string msgstr, bool validate,
                               DataDictionary.DataDictionary sessionDD, DataDictionary.DataDictionary appDD, IMessageFactory msgFactory,
                               bool ignoreBody)
        {
            Clear();

            string msgType         = "";
            bool   expectingHeader = true;
            bool   expectingBody   = true;
            int    count           = 0;
            int    pos             = 0;

            DataDictionary.IFieldMapSpec msgMap = null;

            while (pos < msgstr.Length)
            {
                StringField f = ExtractField(msgstr, ref pos, sessionDD, appDD);

                if (validate && (count < 3) && (Header.HEADER_FIELD_ORDER[count++] != f.Tag))
                {
                    throw new InvalidMessage("Header fields out of order");
                }

                if (IsHeaderField(f.Tag, sessionDD))
                {
                    if (!expectingHeader)
                    {
                        if (0 == field_)
                        {
                            field_ = f.Tag;
                        }
                        validStructure_ = false;
                    }

                    if (Tags.MsgType.Equals(f.Tag))
                    {
                        msgType = string.Copy(f.Obj);
                        if (appDD != null)
                        {
                            msgMap = appDD.GetMapForMessage(msgType);
                        }
                    }

                    if (!this.Header.SetField(f, false))
                    {
                        this.Header.RepeatedTags.Add(f);
                    }

                    if ((null != sessionDD) && sessionDD.Header.IsGroup(f.Tag))
                    {
                        pos = SetGroup(f, msgstr, pos, this.Header, sessionDD.Header.GetGroupSpec(f.Tag), sessionDD, appDD, msgFactory);
                    }
                }
                else if (IsTrailerField(f.Tag, sessionDD))
                {
                    expectingHeader = false;
                    expectingBody   = false;
                    if (!this.Trailer.SetField(f, false))
                    {
                        this.Trailer.RepeatedTags.Add(f);
                    }

                    if ((null != sessionDD) && sessionDD.Trailer.IsGroup(f.Tag))
                    {
                        pos = SetGroup(f, msgstr, pos, this.Trailer, sessionDD.Trailer.GetGroup(f.Tag), sessionDD, appDD, msgFactory);
                    }
                }
                else if (ignoreBody == false)
                {
                    if (!expectingBody)
                    {
                        if (0 == field_)
                        {
                            field_ = f.Tag;
                        }
                        validStructure_ = false;
                    }

                    expectingHeader = false;
                    if (!SetField(f, false))
                    {
                        this.RepeatedTags.Add(f);
                    }


                    if ((null != msgMap) && (msgMap.IsGroup(f.Tag)))
                    {
                        pos = SetGroup(f, msgstr, pos, this, msgMap.GetGroupSpec(f.Tag), sessionDD, appDD, msgFactory);
                    }
                }
                // Aidan Chisholm  IRESS 23/10/2017
                // Bypassing body validation so need to keep fields in original order due to FieldMap re-ordering combined with unknown tags/repeating-groups
                else if (ignoreBody == true)
                {
                    if (!expectingBody)
                    {
                        if (0 == field_)
                        {
                            field_ = f.Tag;
                        }
                        validStructure_ = false;
                    }

                    expectingHeader = false;
                    SetUnorderedField(f);
                    //Console.WriteLine("{0} - {1}", f.Tag.ToString(), f.ToString());
                }
            }

            if (validate)
            {
                Validate();
            }
        }