Skip to content

Commit

Permalink
cleanup/nullable-ize Message/ classes (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbirchmeier committed Jan 24, 2024
1 parent 585fcdf commit 2389b93
Show file tree
Hide file tree
Showing 22 changed files with 563 additions and 709 deletions.
4 changes: 2 additions & 2 deletions AcceptanceTest/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Setup()

ILogFactory? logFactory = settings.Get().Has("Verbose") && settings.Get().GetBool("Verbose")
? new FileLogFactory(settings)
: null;
: new NullLogFactory();

_acceptor = new ThreadedSocketAcceptor(testApp, storeFactory, settings, logFactory);

Expand All @@ -43,4 +43,4 @@ protected void RunTest(string definitionPath)
using StreamReader sr = new(definitionPath);
runner.Run(sr);
}
}
}
4 changes: 1 addition & 3 deletions Examples/FixToJson/Examples.FixToJson.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>FixToJson</RootNamespace>
<AssemblyName>FixToJson</AssemblyName>
<Nullable>enable</Nullable>
<Copyright>Copyright © Connamara Systems, LLC 2022</Copyright>
<Company>Connamara Systems, LLC</Company>
<Platforms>AnyCPU;x64</Platforms>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
52 changes: 27 additions & 25 deletions Examples/FixToJson/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Text;
using System.IO;

namespace TradeClient
namespace Examples.FixToJson
{
class Program
internal static class Program
{
static void FixToJson(string fname, bool humanReadableValues, QuickFix.DataDictionary.DataDictionary sessionDataDictionary, QuickFix.DataDictionary.DataDictionary appDataDictionary)
static void FixToJson(
string fname,
bool humanReadableValues,
QuickFix.DataDictionary.DataDictionary? sessionDataDictionary,
QuickFix.DataDictionary.DataDictionary? appDataDictionary)
{
try
{
Expand All @@ -15,20 +18,19 @@ static void FixToJson(string fname, bool humanReadableValues, QuickFix.DataDicti
{
QuickFix.IMessageFactory msgFactory = new QuickFix.DefaultMessageFactory();
QuickFix.Message msg = new QuickFix.Message();
string line = null;
string comma = "";
while ((line = streamReader.ReadLine()) != null)
while (streamReader.ReadLine() is { } line)
{
line = line.Trim();
msg.FromString(line, false, sessionDataDictionary, appDataDictionary, msgFactory);
Console.WriteLine(comma + msg.ToJSON(humanReadableValues));
Console.WriteLine(comma + msg.ToJSON(humanReadableValues: humanReadableValues));
comma = ",";
}
}
Console.WriteLine("]\n}");

}
catch (System.Exception e)
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Expand All @@ -40,27 +42,27 @@ static void Main(string[] args)
{
if (args.Length < 1 || args.Length > 4)
{
System.Console.WriteLine("USAGE");
System.Console.WriteLine("");
System.Console.WriteLine(" FixToJson.exe FILE [HUMAN_READABLE_VALUES] [DATA_DICTIONARY]");
System.Console.WriteLine("");
System.Console.WriteLine("EXAMPLES");
System.Console.WriteLine("");
System.Console.WriteLine(" FixToJson.exe messages.log true ../../spec/fix/FIX50SP2.xml");
System.Console.WriteLine(" FixToJson.exe messages.log true ../../spec/fix/FIX44.xml");
System.Console.WriteLine(" FixToJson.exe messages.log false ../../spec/fix/FIX42.xml");
System.Console.WriteLine("");
System.Console.WriteLine("NOTE");
System.Console.WriteLine("");
System.Console.WriteLine(" Per the FIX JSON Encoding Specification, tags are converted to human-readable form, but values are not.");
System.Console.WriteLine(" Set the HUMAN_READABLE_VALUES argument to TRUE to override the standard behavior.");
System.Environment.Exit(2);
Console.WriteLine("USAGE");
Console.WriteLine("");
Console.WriteLine(" FixToJson.exe FILE [HUMAN_READABLE_VALUES] [DATA_DICTIONARY]");
Console.WriteLine("");
Console.WriteLine("EXAMPLES");
Console.WriteLine("");
Console.WriteLine(" FixToJson.exe messages.log true ../../spec/fix/FIX50SP2.xml");
Console.WriteLine(" FixToJson.exe messages.log true ../../spec/fix/FIX44.xml");
Console.WriteLine(" FixToJson.exe messages.log false ../../spec/fix/FIX42.xml");
Console.WriteLine("");
Console.WriteLine("NOTE");
Console.WriteLine("");
Console.WriteLine(" Per the FIX JSON Encoding Specification, tags are converted to human-readable form, but values are not.");
Console.WriteLine(" Set the HUMAN_READABLE_VALUES argument to TRUE to override the standard behavior.");
Environment.Exit(2);
}

string fname = args[0];
bool humanReadableValues = false;
QuickFix.DataDictionary.DataDictionary sessionDataDictionary = null;
QuickFix.DataDictionary.DataDictionary appDataDictionary = null;
QuickFix.DataDictionary.DataDictionary? sessionDataDictionary = null;
QuickFix.DataDictionary.DataDictionary? appDataDictionary = null;

if (args.Length > 1)
{
Expand Down
1 change: 0 additions & 1 deletion Examples/JsonToFix/Examples.JsonToFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Copyright>Copyright © Connamara Systems, LLC 2022</Copyright>
<Company>Connamara Systems, LLC</Company>
Expand Down
41 changes: 20 additions & 21 deletions Examples/JsonToFix/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Text;
using System.Text.Json;
using System.IO;
using System.Text.Json;
using QuickFix;

namespace TradeClient
namespace Examples.JsonToFix
{
class Program
internal static class Program
{
static void JsonMsgToFix(string json, QuickFix.DataDictionary.DataDictionary sessionDataDictionary, QuickFix.DataDictionary.DataDictionary appDataDictionary, QuickFix.IMessageFactory msgFactory)
{
Expand Down Expand Up @@ -36,7 +35,7 @@ static void JsonToFix(string fname, QuickFix.DataDictionary.DataDictionary sessi
}
}
}
catch (System.Exception e)
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Expand All @@ -48,22 +47,22 @@ static void Main(string[] args)
{
if (args.Length < 1 || args.Length > 2)
{
System.Console.WriteLine("USAGE");
System.Console.WriteLine("");
System.Console.WriteLine(" FixToJson.exe FILE DATA_DICTIONARY");
System.Console.WriteLine("");
System.Console.WriteLine(" The FILE may contain either a single message in FIX JSON Encoding, or an array of messages in a root-level \"messages\" element.");
System.Console.WriteLine("");
System.Console.WriteLine("EXAMPLES");
System.Console.WriteLine("");
System.Console.WriteLine(" JsonToFix.exe messages.json ../../spec/fix/FIX50SP2.xml");
System.Console.WriteLine(" JsonToFix.exe messages.json ../../spec/fix/FIX44.xml");
System.Console.WriteLine(" JsonToFix.exe messages.json ../../spec/fix/FIX42.xml");
System.Console.WriteLine("");
System.Console.WriteLine("NOTE");
System.Console.WriteLine("");
System.Console.WriteLine(" Per the FIX JSON Encoding Specification, tags are converted to human-readable form, but values are not.");
System.Environment.Exit(2);
Console.WriteLine("USAGE");
Console.WriteLine("");
Console.WriteLine(" FixToJson.exe FILE DATA_DICTIONARY");
Console.WriteLine("");
Console.WriteLine(" The FILE may contain either a single message in FIX JSON Encoding, or an array of messages in a root-level \"messages\" element.");
Console.WriteLine("");
Console.WriteLine("EXAMPLES");
Console.WriteLine("");
Console.WriteLine(" JsonToFix.exe messages.json ../../spec/fix/FIX50SP2.xml");
Console.WriteLine(" JsonToFix.exe messages.json ../../spec/fix/FIX44.xml");
Console.WriteLine(" JsonToFix.exe messages.json ../../spec/fix/FIX42.xml");
Console.WriteLine("");
Console.WriteLine("NOTE");
Console.WriteLine("");
Console.WriteLine(" Per the FIX JSON Encoding Specification, tags are converted to human-readable form, but values are not.");
Environment.Exit(2);
}

string fname = args[0];
Expand Down
3 changes: 1 addition & 2 deletions QuickFIXn/DataDictionary/DataDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public static void Validate(Message message, DataDictionary sessionDataDict, Dat

if (((null != sessionDataDict) && sessionDataDict.CheckFieldsOutOfOrder) || ((null != appDataDict) && appDataDict.CheckFieldsOutOfOrder))
{
int field;
if (!message.HasValidStructure(out field))
if (!message.HasValidStructure(out var field))
throw new TagOutOfOrder(field);
}

Expand Down
5 changes: 3 additions & 2 deletions QuickFIXn/Fields/IField.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace QuickFix.Fields
#nullable enable
namespace QuickFix.Fields
{
/// <summary>
/// Interface for all field classes
Expand Down Expand Up @@ -29,4 +30,4 @@ public abstract class IField
/// </summary>
public abstract int getTotal();
}
}
}
Loading

0 comments on commit 2389b93

Please sign in to comment.