Skip to content

Commit

Permalink
Merge pull request connamara#189 from connamara/ddstream_178
Browse files Browse the repository at this point in the history
  • Loading branch information
gbirchmeier committed May 14, 2013
2 parents 1b1781e + 7cebd96 commit 402bcc3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEXT_VERSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Changes since the last version:
* (minor) issue #48 - IInitiator.Stop() must release resources (jungers42/gbirchmeier)
* (patch) issue #160 - floats without leading zeros (e.g. ".23") now parsed properly (gbirchmeier)
* (patch) issue #187 - make IInitiator implement IDisposable (gbirchmeier)
* (minor) pr #178 - can now load DD from a stream instead of a file (robsonj)

22 changes: 20 additions & 2 deletions QuickFIXn/DataDictionary/DataDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.XPath;

Expand Down Expand Up @@ -42,6 +43,16 @@ public DataDictionary(String path)
Load(path);
}

/// <summary>
/// Initialize a data dictionary from a stream
/// </summary>
/// <param name="stream"></param>
public DataDictionary(Stream stream)
:this()
{
Load(stream);
}

/// <summary>
/// Copy a data dictionary
/// </summary>
Expand Down Expand Up @@ -406,10 +417,17 @@ public bool IsTrailerField(int tag)
return Trailer.IsField(tag);
}

public void Load(String path) {
public void Load(String path)
{
var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
Load(stream);
}

public void Load(Stream stream)
{
XmlDocument doc = new XmlDocument();
RootDoc = doc;
doc.Load(path);
doc.Load(stream);
setVersionInfo(doc);
parseFields(doc);
parseMessages(doc);
Expand Down
13 changes: 13 additions & 0 deletions UnitTests/DataDictionaryTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using QuickFix;

Expand Down Expand Up @@ -31,6 +32,18 @@ public void LoadFieldsTest()
Assert.That(dd.FieldsByTag[QuickFix.Fields.Tags.StatusValue].EnumDict.Count, Is.EqualTo(4));
}

[Test]
public void LoadFieldsFromStreamTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
Stream stream = new FileStream("../../../spec/fix/FIX44.xml", FileMode.Open, FileAccess.Read);
dd.Load(stream);
Assert.That(dd.FieldsByTag[1].Name, Is.EqualTo("Account"));
Assert.That(dd.FieldsByName["Account"].Tag, Is.EqualTo(1));
Assert.That(dd.FieldsByTag[1].EnumDict.Count, Is.EqualTo(0));
Assert.That(dd.FieldsByTag[QuickFix.Fields.Tags.StatusValue].EnumDict.Count, Is.EqualTo(4));
}

[Test]
public void FieldHasValueTest()
{
Expand Down
1 change: 1 addition & 0 deletions web/views/about/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ Contributors
- Ervin Marguc
- Bjorn Andersson
- Christian Jungers
- Jonathan M Robson

0 comments on commit 402bcc3

Please sign in to comment.