예제 #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>
        public void FromString(string msgstr, bool validate,
            DataDictionary.DataDictionary sessionDD, DataDictionary.DataDictionary appDD, IMessageFactory msgFactory)
        {
            Clear();

            string msgType = "";
            bool expectingHeader = true;
            bool expectingBody = true;
            int count = 0;
            int pos = 0;
            DataDictionary.IFieldMapSpec msgMap = null;

            if (FixMessageDescriptorEnabled)
            {
                _descriptor = new FixMessageDescriptor();

                if (appDD != null)
                    _descriptor.FixVersion = appDD.Version;

            }
            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 (FixMessageDescriptorEnabled)
                            {
                                QuickFix.DataDictionary.DDMap map = null;

                                if (appDD != null && appDD.Messages.TryGetValue(f.Obj, out map))
                                {
                                    _descriptor.MessageType = map.MessageName;

                                }
                            }
                        }
                    }

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

                    if ((null != sessionDD) && sessionDD.Header.IsGroup(f.Tag))
                    {
                        if (FixMessageDescriptorEnabled)
                        {
                            _currentGroupField = new GroupFixFieldInfo();

                            _currentGroupField.Tag = f.Tag;

                            DataDictionary.DDField field = null;

                            if (sessionDD != null && sessionDD.FieldsByTag.TryGetValue(f.Tag, out field))
                            {
                                _currentGroupField.Name = field.Name;
                            }

                            _currentGroupField.Value = f.getValue();

                            _currentGroupField.EnumValue = GetEnumValueFromField(f, field);

                            _descriptor.Fields.Add(_currentGroupField);
                        }

                        pos = SetGroup(f, msgstr, pos, this.Header, sessionDD.Header.GetGroupSpec(f.Tag), sessionDD, appDD, msgFactory);

                    }
                    else
                    {
                        if (FixMessageDescriptorEnabled)
                        {
                            AddFixFieldInfo(f, sessionDD);

                        }
                    }
                }
                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))
                    {
                        if (FixMessageDescriptorEnabled)
                        {

                            _currentGroupField = new GroupFixFieldInfo();

                            _currentGroupField.Tag = f.Tag;

                            DataDictionary.DDField field = null;

                            if (sessionDD.FieldsByTag.TryGetValue(f.Tag, out field))
                            {
                                _currentGroupField.Name = field.Name;
                            }

                            _currentGroupField.Value = f.getValue();

                            _currentGroupField.EnumValue = GetEnumValueFromField(f, field);

                            _descriptor.Fields.Add(_currentGroupField);

                        }

                        pos = SetGroup(f, msgstr, pos, this.Trailer, sessionDD.Trailer.GetGroup(f.Tag), sessionDD, appDD, msgFactory);

                    }
                    else
                    {
                        if (FixMessageDescriptorEnabled)
                        {
                            AddFixFieldInfo(f, sessionDD);
                        }
                    }
                }
                else
                {
                    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)))
                    {
                        if (FixMessageDescriptorEnabled)
                        {
                            _currentGroupField = new GroupFixFieldInfo();

                            _currentGroupField.Tag = f.Tag;

                            DataDictionary.DDField field = null;

                            if (sessionDD != null && sessionDD.FieldsByTag.TryGetValue(f.Tag, out field))
                            {
                                _currentGroupField.Name = field.Name;
                            }

                            _currentGroupField.Value = f.getValue();

                            _currentGroupField.EnumValue = GetEnumValueFromField(f, field);

                            _descriptor.Fields.Add(_currentGroupField);

                        }
                        pos = SetGroup(f, msgstr, pos, this, msgMap.GetGroupSpec(f.Tag), sessionDD, appDD, msgFactory);

                    }
                    else
                    {
                        if (FixMessageDescriptorEnabled)
                        {
                            AddFixFieldInfo(f, appDD);

                        }

                    }
                }
            }

            if (validate)
            {
                Validate();
            }
        }
예제 #2
0
        /// <summary>
        /// Constructs a group and stores it in this Message object
        /// </summary>
        /// <param name="grpNoFld"></param>
        /// <param name="msgstr"></param>
        /// <param name="pos"></param>
        /// <param name="fieldMap"></param>
        /// <param name="dd"></param>
        /// <param name="sessionDataDictionary"></param>
        /// <param name="appDD"></param>
        /// <param name="msgFactory">if this is null, then this method will use the generic Group class constructor</param>
        /// <returns></returns>
        protected int SetGroup(StringField grpNoFld, string msgstr, int pos, FieldMap fieldMap, DataDictionary.IGroupSpec dd, DataDictionary.DataDictionary sessionDataDictionary, DataDictionary.DataDictionary appDD, IMessageFactory msgFactory)
        {
            int delim = dd.Delim;
            int grpPos = pos;
            Group grp = null;

            while (pos < msgstr.Length)
            {
                grpPos = pos;
                StringField f = ExtractField(msgstr, ref pos, sessionDataDictionary, appDD);
                if (f.Tag == delim)
                {
                    if (grp != null)
                    {
                        fieldMap.AddGroup(grp, false);
                    }

                    if (msgFactory != null)
                        grp = msgFactory.Create(Message.ExtractBeginString(msgstr), Message.GetMsgType(msgstr), grpNoFld.Tag);

                    //If above failed, just use a generic Group.
                    if (grp == null)
                        grp = new Group(grpNoFld.Tag, delim);
                }
                else if (!dd.IsField(f.Tag))
                {
                    if (grp != null)
                    {
                        fieldMap.AddGroup(grp, false);
                    }
                    return grpPos;
                }

                grp.SetField(f);

                if (dd.IsGroup(f.Tag))
                {

                    if (FixMessageDescriptorEnabled)
                    {
                        var oldCurrField = _currentGroupField;

                        _currentGroupField = new GroupFixFieldInfo();

                        _currentGroupField.Tag = f.Tag;

                        DataDictionary.DDField field = null;

                        if (appDD != null && appDD.FieldsByTag.TryGetValue(f.Tag, out field))
                        {
                            _currentGroupField.Name = field.Name;
                        }
                        else if (sessionDataDictionary != null && sessionDataDictionary.FieldsByTag.TryGetValue(f.Tag, out field))
                        {
                            _currentGroupField.Name = field.Name;
                        }
                        _currentGroupField.Value = f.getValue();

                        _currentGroupField.EnumValue = GetEnumValueFromField(f, field);

                        oldCurrField.Fields.Add(_currentGroupField);
                    }

                    pos = SetGroup(f, msgstr, pos, grp, dd.GetGroupSpec(f.Tag), sessionDataDictionary, appDD, msgFactory);

                }
                else
                {
                    if (FixMessageDescriptorEnabled)
                    {
                        FixFieldInfo fi = new FixFieldInfo();

                        fi.Tag = f.Tag;

                        DataDictionary.DDField field = null;

                        if (appDD != null && appDD.FieldsByTag.TryGetValue(f.Tag, out field))
                        {
                            _currentGroupField.Name = field.Name;
                        }
                        else if (sessionDataDictionary != null && sessionDataDictionary.FieldsByTag.TryGetValue(f.Tag, out field))
                        {
                            _currentGroupField.Name = field.Name;
                        }

                        fi.Value = f.getValue();

                        fi.EnumValue = GetEnumValueFromField(f, field);

                        _currentGroupField.Fields.Add(fi);

                    }

                }
            }

            return grpPos;
        }
예제 #3
0
        public override void Clear()
        {
            _descriptor = null;

            _currentGroupField = null;

            field_ = 0;
            this.Header.Clear();
            base.Clear();
            this.Trailer.Clear();
        }