public FromString ( string msgstr, bool validate, DataDictionary sessionDD, DataDictionary appDD ) : void | ||
msgstr | string | |
validate | bool | |
sessionDD | DataDictionary | |
appDD | DataDictionary | |
return | void |
public void FromString(string msgstr, bool validate, DataDictionary.DataDictionary sessionDD, DataDictionary.DataDictionary appDD)
{
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);
}
}
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);
}
}
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)))
{
pos = SetGroup(f, msgstr, pos, this, msgMap.GetGroupSpec(f.Tag), sessionDD, appDD);
}
}
}
if (validate)
{
Validate();
}
}
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)); }