Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DDTool/DDTool/DDTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
50 changes: 50 additions & 0 deletions DDTool/DDTool/Generators/GenCsproj.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace DDTool.Generators;

public static class GenCsproj {
private static string ProjFilePath(string outputDir, string ddName) {
return Path.Join(outputDir, "Messages", ddName, $"QuickFix.{ddName}.csproj");
}

public static bool IsExistingCsproj(string outputDir, string ddName) {
return File.Exists(
ProjFilePath(outputDir, ddName));
}

public static string WriteFile(string outputDir, string ddName, string repoRoot) {
string csprojPath = ProjFilePath(outputDir, ddName);
File.WriteAllText(
csprojPath, Generate(ddName, repoRoot));
return csprojPath;
}

private static string Generate(string name, string repoRoot) {
string qfPath = Path.Join(repoRoot, "QuickFIXn", "QuickFix.csproj");

var lines = new List<string>
{
"<Project Sdk=\"Microsoft.NET.Sdk\">",
" <!--",
" This is a generated file. HOWEVER, the generator won't clobber it if it exists.",
" If you want it regenerated, you must delete it.",
" -->",
"",
" <PropertyGroup>",
" <TargetFramework>net8.0</TargetFramework>",
$" <Description>Custom '{name}' build of QF/n message definitions</Description>",
" <Nullable>enable</Nullable>",
" </PropertyGroup>",
"",
" <ItemGroup>",
$" <ProjectReference Include=\"{qfPath}\" />",
" </ItemGroup>",
"</Project>",
""
};

return string.Join(Environment.NewLine, lines);
}
}
6 changes: 3 additions & 3 deletions DDTool/DDTool/Generators/GenFieldTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public static class GenFieldTags {
/// <summary>
/// Returns path of file that is written
/// </summary>
/// <param name="baseDir"></param>
/// <param name="repoRootDir"></param>
/// <param name="fields"></param>
/// <returns></returns>
public static string WriteFile(string baseDir, List<DDField> fields) {
string fieldTagsPath = Path.Join(baseDir, "QuickFIXn", "Fields", "FieldTags.cs");
public static string WriteFile(string repoRootDir, List<DDField> fields) {
string fieldTagsPath = Path.Join(repoRootDir, "QuickFIXn", "Fields", "FieldTags.cs");
File.WriteAllText(fieldTagsPath, Generate(fields));
return fieldTagsPath;
}
Expand Down
7 changes: 3 additions & 4 deletions DDTool/DDTool/Generators/GenFields.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using DDTool.Structures;

Expand All @@ -14,11 +13,11 @@ public static class GenFields {
/// <summary>
/// Returns path of file that is written
/// </summary>
/// <param name="baseDir"></param>
/// <param name="repoRootDir"></param>
/// <param name="fields"></param>
/// <returns></returns>
public static string WriteFile(string baseDir, List<DDField> fields) {
string fieldsPath = Path.Join(baseDir, "QuickFIXn", "Fields", "Fields.cs");
public static string WriteFile(string repoRootDir, List<DDField> fields) {
string fieldsPath = Path.Join(repoRootDir, "QuickFIXn", "Fields", "Fields.cs");
File.WriteAllText(fieldsPath, Generate(fields));
return fieldsPath;
}
Expand Down
12 changes: 7 additions & 5 deletions DDTool/DDTool/Generators/GenMessageFactories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public static List<string> WriteFiles(string baseDir, List<DataDictionary> dds)
}

private static string WriteFile(string baseDir, DataDictionary dd) {
string filePath = Path.Join(baseDir, "Messages", dd.IdentifierNoDots, "MessageFactory.cs");
string filePath = Path.Join(baseDir, "Messages", dd.Name, "MessageFactory.cs");
Directory.CreateDirectory(
Path.GetDirectoryName(filePath)!);
File.WriteAllText(filePath, Generate(dd));
return filePath;
}
Expand All @@ -30,7 +32,7 @@ private static string Generate(DataDictionary dd) {
"using System.Collections.Generic;",
"using QuickFix.FixValues;",
"",
$"namespace QuickFix.{dd.IdentifierNoDots};",
$"namespace QuickFix.{dd.Name};",
"",
"public class MessageFactory : IMessageFactory",
"{",
Expand All @@ -52,7 +54,7 @@ private static string Generate(DataDictionary dd) {

// TODO: foreach order is technically non-deterministic (though not in practice)
foreach (var msg in dd.Messages.Values) {
var fullname = $"QuickFix.{dd.IdentifierNoDots}.{msg.Name}";
var fullname = $"QuickFix.{dd.Name}.{msg.Name}";
lines.Add(new string(' ', 12) + $"{fullname}.MsgType => new {fullname}(),");
}

Expand All @@ -75,13 +77,13 @@ private static string Generate(DataDictionary dd) {

List<string> xLines = new();

xLines.Add($"if (QuickFix.{dd.IdentifierNoDots}.{msg.Name}.MsgType.Equals(msgType))");
xLines.Add($"if (QuickFix.{dd.Name}.{msg.Name}.MsgType.Equals(msgType))");
xLines.Add("{");
xLines.Add(" switch (correspondingFieldId)");
xLines.Add(" {");

foreach (var group in groups) {
AppendGroupCases(xLines, group, $"QuickFix.{dd.IdentifierNoDots}.{msg.Name}");
AppendGroupCases(xLines, group, $"QuickFix.{dd.Name}.{msg.Name}");
}

xLines.Add(" }");
Expand Down
12 changes: 8 additions & 4 deletions DDTool/DDTool/Generators/GenMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public static List<string> WriteFilesForDD(string baseDir, DataDictionary dd) {

private static string WriteBaseMessageFile(string baseDir, DataDictionary dd) {
var beginString = dd.IdentifierNoDots.Contains("FIX50") ? "FIXT11" : dd.IdentifierNoDots;
string filePath = Path.Join($"{baseDir}", "Messages", dd.IdentifierNoDots, "Message.cs");
string filePath = Path.Join($"{baseDir}", "Messages", dd.Name, "Message.cs");
Directory.CreateDirectory(
Path.GetDirectoryName(filePath)!);

var lines = new List<string>
{
"// This is a generated file. Don't edit it directly!",
"",
$"namespace QuickFix.{dd.IdentifierNoDots};",
$"namespace QuickFix.{dd.Name};",
"",
"public abstract class Message : QuickFix.Message",
"{",
Expand All @@ -51,7 +53,9 @@ private static string WriteBaseMessageFile(string baseDir, DataDictionary dd) {
}

private static string WriteMessageFile(string baseDir, DDMessage msg, DataDictionary dd) {
string filePath = Path.Join($"{baseDir}", "Messages", dd.IdentifierNoDots, $"{msg.Name}.cs");
string filePath = Path.Join($"{baseDir}", "Messages", dd.Name, $"{msg.Name}.cs");
Directory.CreateDirectory(
Path.GetDirectoryName(filePath)!);

var lines = new List<string>
{
Expand All @@ -60,7 +64,7 @@ private static string WriteMessageFile(string baseDir, DDMessage msg, DataDictio
"using System;",
"using QuickFix.Fields;",
"",
$"namespace QuickFix.{dd.IdentifierNoDots};",
$"namespace QuickFix.{dd.Name};",
"",
$"public class {msg.Name} : Message",
"{",
Expand Down
13 changes: 10 additions & 3 deletions DDTool/DDTool/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace DDTool;

public class Options {
public string OutputDir { get; }
public string? RepoRoot { get; }
public bool HasRepoRoot => !string.IsNullOrEmpty(RepoRoot);

public string? OutputDir { get; }
public bool HasOutputDir => !string.IsNullOrEmpty(OutputDir);

public List<string> DDFiles { get; } = new List<string>();
public List<string> DDFiles { get; } = [];

public Options(string[] args) {
var errors = new List<string>();
Expand All @@ -26,6 +28,11 @@ public Options(string[] args) {
}

switch (next) {
case "--reporoot":
RepoRoot = argList.First();
argList.RemoveFirst();
break;

case "--outputdir":
OutputDir = argList.First();
argList.RemoveFirst();
Expand All @@ -35,7 +42,7 @@ public Options(string[] args) {
if (next.StartsWith("-"))
errors.Add($"Unrecognized option: {next}");
else {
// All done with cmd line options now,
// All done with cmd-line options now,
// the rest are files.
DDFiles.Add(next);
foreach (var arg in argList) {
Expand Down
4 changes: 0 additions & 4 deletions DDTool/DDTool/Parsers/DDParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public static DataDictionary ParseFile(string path) {
VersionParser.SetVersionInfo(doc, dd);
FieldParser.ParseFields(doc, dd);
MessageParser.ParseMessages(doc, dd);
/*
ParseHeader(RootDoc);
ParseTrailer(RootDoc)
*/
}

return dd;
Expand Down
14 changes: 7 additions & 7 deletions DDTool/DDTool/Parsers/FieldParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ public static void ParseFields(XmlDocument doc, DataDictionary dd) {
}

private static DDField CreateField(XmlNode node) {
string tagstr = node.Attributes["number"].Value;
string name = node.Attributes["name"].Value;
string fldType = node.Attributes["type"].Value;
string tagstr = node.Attributes!["number"]!.Value;
string name = node.Attributes["name"]!.Value;
string fldType = node.Attributes["type"]!.Value;
int tag = int.Parse(tagstr);
List<EnumValue> enums = new();

if (node.HasChildNodes) {
foreach (XmlNode enumEl in node.SelectNodes(".//value")) {
if (enumEl.Attributes["description"] is null)
foreach (XmlNode enumEl in node.SelectNodes(".//value")!) {
if (enumEl.Attributes!["description"] is null)
throw new Exception($"Node {tagstr}/{name} contains a <value> without a 'description' attribute");
if (enumEl.Attributes["enum"] is null)
throw new Exception($"Node {tagstr}/{name} contains a <value> without a 'enum' attribute");

enums.Add(new EnumValue(
enumEl.Attributes["description"].Value,
enumEl.Attributes["enum"].Value));
enumEl.Attributes["description"]!.Value,
enumEl.Attributes["enum"]!.Value));
}
}

Expand Down
18 changes: 9 additions & 9 deletions DDTool/DDTool/Parsers/MessageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace DDTool.Parsers;

public static class MessageParser {
public static void ParseMessages(XmlDocument doc, DataDictionary dd) {
XmlNodeList nodeList = doc.SelectNodes("//messages/message");
XmlNodeList nodeList = doc.SelectNodes("//messages/message")!;
foreach (XmlNode msgNode in nodeList) {
dd.AddMessage(CreateMessage(msgNode, dd, doc));
}
}

private static DDMessage CreateMessage(XmlNode node, DataDictionary dd, XmlDocument doc) {
var ddMsg = new DDMessage(
node.Attributes["name"].Value,
node.Attributes["msgtype"].Value,
node.Attributes["msgcat"].Value);
node.Attributes!["name"]!.Value,
node.Attributes["msgtype"]!.Value,
node.Attributes["msgcat"]!.Value);

foreach (XmlNode childNode in node.ChildNodes)
ReadChildNode(childNode, ddMsg, dd, doc);
Expand All @@ -26,7 +26,7 @@ private static DDMessage CreateMessage(XmlNode node, DataDictionary dd, XmlDocum
}

private static DDGroup CreateGroup(XmlNode node, DataDictionary dd, XmlDocument doc) {
var groupName = node.Attributes["name"].Value;
var groupName = node.Attributes!["name"]!.Value;
var counterField = dd.LookupField(groupName);

if (node.ChildNodes.Count < 1)
Expand All @@ -44,20 +44,20 @@ private static DDGroup CreateGroup(XmlNode node, DataDictionary dd, XmlDocument

private static void ReadChildNode(
XmlNode childNode, IElementSequence elSeq, DataDictionary dd, XmlDocument doc, bool overrideReq = false) {
bool req = childNode.Attributes["required"]?.Value == "Y" && !overrideReq;
bool req = childNode.Attributes!["required"]?.Value == "Y" && !overrideReq;

switch (childNode.Name.ToLowerInvariant()) {
case "field":
elSeq.AddElement(dd.LookupField(childNode.Attributes["name"].Value), req);
elSeq.AddElement(dd.LookupField(childNode.Attributes["name"]!.Value), req);
break;

case "group":
elSeq.AddElement(CreateGroup(childNode, dd, doc), req);
break;

case "component":
var componentName = childNode.Attributes["name"].Value;
XmlNode compNode = doc.SelectSingleNode($"//components/component[@name='{componentName}']");
var componentName = childNode.Attributes["name"]!.Value;
XmlNode compNode = doc.SelectSingleNode($"//components/component[@name='{componentName}']")!;

if (compNode == null)
throw new ParsingException($"Can't find component: {componentName}");
Expand Down
13 changes: 9 additions & 4 deletions DDTool/DDTool/Parsers/VersionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public static class VersionParser
{
public static void SetVersionInfo(XmlDocument doc, DataDictionary dd)
{
dd.MajorVersion = int.Parse(doc.SelectSingleNode("/fix/@major").Value);
dd.MinorVersion = int.Parse(doc.SelectSingleNode("/fix/@minor").Value);
dd.MajorVersion = int.Parse(doc.SelectSingleNode("/fix/@major")!.Value!);
dd.MinorVersion = int.Parse(doc.SelectSingleNode("/fix/@minor")!.Value!);

XmlNode node = doc.SelectSingleNode("/fix/@type");
if (node != null)
XmlNode? node = doc.SelectSingleNode("/fix/@type");
if (node is not null)
{
if (new[] { "FIX", "FIXT" }.Contains(node.Value) == false)
throw new ParsingException($"Unsupported /fix/type value: '{node.Value}' (expected FIX or FIXT)");
Expand All @@ -29,5 +29,10 @@ public static void SetVersionInfo(XmlDocument doc, DataDictionary dd)
if (dd.ServicePack == 0)
dd.ServicePack = null;
}

XmlNode? customNameNode = doc.SelectSingleNode("/fix/@customname");
if (customNameNode != null && !string.IsNullOrEmpty(customNameNode.Value)) {
dd.CustomName = customNameNode.Value;
}
}
}
Loading