diff --git a/ModelCompilerUI.UnitTest/CommandLineSyntaxUnitTest.cs b/ModelCompilerUI.UnitTest/CommandLineSyntaxUnitTest.cs new file mode 100644 index 00000000..2f4280f7 --- /dev/null +++ b/ModelCompilerUI.UnitTest/CommandLineSyntaxUnitTest.cs @@ -0,0 +1,45 @@ +//__________________________________________________________________________________________________ +// +// Copyright (C) 2022, Mariusz Postol LODZ POLAND. +// +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ + +using CommandLine; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OOI.ModelCompilerUI.CommandLineSyntax; +using System.Collections.Generic; +using System.Linq; + +namespace OOI.ModelCompilerUI +{ + [TestClass] + public class CommandLineSyntaxUnitTest + { + [TestMethod] + public void TestMethod1() + { + List commandLine = new List() + { + "exeName", + "compile", + "--d2", @".\Opc.Ua.ModelCompiler\Design.v104\StandardTypes.xml", @".\Opc.Ua.ModelCompiler\Design.v104\UA Core Services.xml", + "--version", "v104", +// "-d2", @".\Opc.Ua.ModelCompiler\Design.v104\UA Core Services.xml", + "-c", @".\Opc.Ua.ModelCompiler\CSVs\StandardTypes.csv", + "--o2", @".\Bin\nodesets\master\Schema\", +// "-stack", @".\Bin\nodesets\master\DotNet\", +// "-ansic", @".\Bin\nodesets\master\AnsiC\" + }; + string args = string.Join(",", commandLine.ToArray()); + Assert.IsNotNull(args); + ParserResult result = Parser.Default.ParseArguments(commandLine); + CompilerOptions compilerOptions = null; + IEnumerable error = null; + result.WithParsed(options => compilerOptions = options).WithNotParsed(errors => error = errors); + Assert.IsNotNull(compilerOptions); + Assert.IsNull(error); + //TODO CLI Syntax #67 + } + } +} \ No newline at end of file diff --git a/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj b/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj index 9d360b08..dd559537 100644 --- a/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj +++ b/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj @@ -54,6 +54,9 @@ ..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll + + ..\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll + ..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll @@ -90,6 +93,7 @@ + diff --git a/ModelCompilerUI.UnitTest/app.config b/ModelCompilerUI.UnitTest/app.config index 50b158d0..ce209d4f 100644 --- a/ModelCompilerUI.UnitTest/app.config +++ b/ModelCompilerUI.UnitTest/app.config @@ -1,23 +1,23 @@ - + - - + + - - + + - - + + - - + + - + diff --git a/ModelCompilerUI.UnitTest/packages.config b/ModelCompilerUI.UnitTest/packages.config index 8cb54d1a..bf1a775d 100644 --- a/ModelCompilerUI.UnitTest/packages.config +++ b/ModelCompilerUI.UnitTest/packages.config @@ -1,5 +1,6 @@  + diff --git a/ModelCompilerUI/App.config b/ModelCompilerUI/App.config index ea714f02..4041f028 100644 --- a/ModelCompilerUI/App.config +++ b/ModelCompilerUI/App.config @@ -1,25 +1,25 @@ - + - + - - + + - - + + - - + + - - + + diff --git a/ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs b/ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs new file mode 100644 index 00000000..915885ea --- /dev/null +++ b/ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs @@ -0,0 +1,111 @@ +//__________________________________________________________________________________________________ +// +// Copyright (C) 2022, Mariusz Postol LODZ POLAND. +// +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ + +using CommandLine; +using System.Collections.Generic; + +namespace OOI.ModelCompilerUI.CommandLineSyntax +{ + [Verb("compile", true, HelpText = "Generates classes that implement a UA information model")] + internal class CompilerOptions + { + [Option('d', "d2", HelpText = d2Help, MetaValue = "ModelDesign", Required = true)] + public IList DesignFiles { get; set; } + + [Option('c', "CSVfile", SetName = "csv", HelpText = cHelp, MetaValue = "CSVfile", Required = false)] + public string IdentifierFile { get; set; } + + [Option('g', "cg", SetName = "csv", HelpText = cgHelp, MetaValue = "CSVfileGenrate", Required = false)] + public bool CreateIdentifierFile { get; set; } + + [Option('o', "o2", HelpText = oHelp, MetaValue = "output", Required = false)] + public string OutputPath { get; set; } + + [Option('i', "id", HelpText = idHelp, Required = false, Default = (uint)0)] + public uint StartId { get; set; } + + [Option('e', "exclude", HelpText = excludeHeelp, Required = false)] + public IList Exclusions { get; set; } + + [Option('v', "version", HelpText = versionHelp, Required = false, Default = "v104")] + public string Version { get; set; } + + [Option('s', "useAllowSubtypes", HelpText = useAllowSubtypesHelp, Required = false)] + public bool UseAllowSubtypes { get; set; } + + [Option('m', "mv", HelpText = mvHelp, Required = false)] + public string ModelVersion { get; set; } + + [Option('m', "mv", HelpText = pdHelp, Required = false)] + public string ModelPublicationDate { get; set; } + + public string InputPath; + public string FilePattern; + public LicenseType LicenseType; + public bool Silent; + public string Annex1Path; + public string Annex2Path; + + private const string d2Help = + "The path to the ModelDesign files which contain the UA information model. The new version of the code generator is used (option -stack forces to use -d2 switch)"; + + private const string cHelp = "The path to the CSV file which contains the unique identifiers for the types defined in the UA information model."; + private const string cgHelp = "Creates the identifier file if it does not exist (used instead of the -c option)."; + private const string oHelp = "The output directory for the generated files."; + private const string idHelp = "The first identifier to use when assigning new ids to nodes."; + private const string excludeHeelp = "Comma seperated list of ReleaseStatus values to exclude from output."; + private const string versionHelp = "Selects the source for the input files. v103 | v104 | v105 are supported."; + private const string useAllowSubtypesHelp = " When subtypes are allowed for a field, C# code with the class name from the model is created instead of ExtensionObject. No effect when subtypes are not allowed."; + private const string mvHelp = "The version of the model to produce."; + private const string pdHelp = "The publication date of the model to produce."; + } + + [Verb("DotNetStack", false, HelpText = "Generates code for the core model (not used for vendor defined models)")] + public class DotNetStackOptions + { + [Option('n', "stack", HelpText = stackHelp, Group = "StackType", Required = true)] + public string DotNetStackPath { get; set; } + + [Option('a', "ansic", HelpText = ansicHelp, Group = "StackType", Required = true)] + public string AnsiCStackPath { get; set; } + + private const string ansicHelp = "Generates the ANSI C stack code for the core model (not used for vendor defined models). The path to use when generating ANSI C stack code."; + private const string stackHelp = "Generates the .NET stack code for the core model (not used for vendor defined models). The path to use when generating .NET stack code."; + } + + [Verb("units", false, HelpText = "Generates the OPC UA Engineering Units CSV from the official UNECE table of units.")] + public class UnitsOptions + { + [Option("annex1", HelpText = annex1Help, Required = false)] + public string Annex1Path { get; set; } + + [Option("annex2", HelpText = annex2Help, Required = false)] + public string Annex2Path { get; set; } + + [Option("output", HelpText = outputHelp, Required = false)] + public string OutputPath { get; set; } + + private const string annex1Help = "The path to the UNECE Annex 1 CSV file."; + private const string annex2Help = "The path to the UNECE Annex 2/3 CSV file."; + private const string outputHelp = "The units output directory."; + } + + public class UpdateHeadersOptions + { + } +} + +//Opc.Ua.ModelCompiler.exe - d2 < filepath > -c[g] < filepath > -o2 < directorypath > + +//-console The output goes to the standard error output (console) instead of error window + +// OptionsNames: +// +//InputPath = "input"; +//FilePattern = "pattern"; +//LicenseType = "license"; +//Silent = "silent"; \ No newline at end of file diff --git a/ModelCompilerUI/HelpFile.txt b/ModelCompilerUI/HelpFile.txt index ee1927bc..b36d8526 100644 --- a/ModelCompilerUI/HelpFile.txt +++ b/ModelCompilerUI/HelpFile.txt @@ -3,17 +3,38 @@ Opc.Ua.ModelCompiler.exe -d2 -c[g] -o2 Generates classes that implement a UA information model. -? Prints this help text + -d2 The path to the XML file which contains the UA information model. New version of code generator is used (option -stack forces to use -d2 switch) +-d2 The path to the ModelDesign file which contains the UA information model., MultipleValue -c The path to the CSV file which contains the unique identifiers for the types defined in the UA information model. +-c The path to the CSV file which contains the unique identifiers for the types defined in the UA information model., SingleValue -cg Creates the identifier file if it does not exist (used instead of the -c option). --o No longer supported. +-cg Creates the identifier file if it does not exist (used instead of the -c option)., SingleValue -o2 The output directory for a multiple file output. +-o2 The output directory for the generated files.", SingleValue -id The start identifier +-id The first identifier to use when assigning new ids to nodes.", SingleValue -ansic Generates the ANSI C stack code for the core model (not used for vendor defined models). +-ansic The path to use when generating ANSI C stack code., SingleValue -stack Generates the .NET stack code for the core model (not used for vendor defined models). +-stack The path to use when generating .NET stack code., SingleValue -useXmlInitializers No longer supported. -console The output goes to the standard error output (console) instead of error window -exclude Excludes types based on thier ReleaseStatus and/or Category. A simple string compare is used to test. +-exclude Comma seperated list of ReleaseStatus values to exclude from output., SingleValue -version Selects the source for the input files. v103 | v104 | v105 are supported. +-version Selects the source for the input files. v103 | v104 | v105 are supported.", SingleValue -useAllowSubtypes When subtypes are allowed for a field, C# code with the class name from the model is created instead of ExtensionObject. No effect when subtypes are not allowed. +-useAllowSubtypes When subtypes are allowed for a field, C# code with the class name from the model is created instead of ExtensionObject. No effect when subtypes are not allowed.", NoValue +-mv The version of the model to produce., SingleValue +-pd The publication date of the model to produce., SingleValue + +-o No longer supported. +InputPath = "input"; +FilePattern = "pattern"; +LicenseType = "license"; +Silent = "silent"; +Annex1Path = "annex1"; +Annex2Path = "annex2"; +UnitsOutputPath = "output"; diff --git a/ModelCompilerUI/ModelCompilerAPI.cs b/ModelCompilerUI/ModelCompilerAPI.cs index 9210443f..c91f9caf 100644 --- a/ModelCompilerUI/ModelCompilerAPI.cs +++ b/ModelCompilerUI/ModelCompilerAPI.cs @@ -11,34 +11,34 @@ namespace OOI.ModelCompilerUI { - public abstract class ModelCompilerAPI - { - protected internal string stackRootDir = null; - protected internal string ansicRootDir = null; - protected internal string OutputDir = null; + public abstract class ModelCompilerAPI + { + protected internal string stackRootDir = null; + protected internal string ansicRootDir = null; + protected internal string OutputDir = null; - protected virtual void Execute(IModelGeneratorGenerate generateParameters, IModelGeneratorValidate validateParameters) - { - ModelGenerator2 Generator = new ModelGenerator2(); - //Build model - Generator.ValidateAndUpdateIds(validateParameters); - if (!string.IsNullOrEmpty(OutputDir)) - Generator.Generate(generateParameters, OutputDir); - //.NET stack generator - if (!string.IsNullOrEmpty(stackRootDir)) - { - if (!Directory.Exists(stackRootDir)) - throw new ArgumentException($"The directory does not exist: {stackRootDir}"); - StackGenerator.GenerateDotNet(validateParameters, stackRootDir.Trim(), generateParameters.ExcludeCategories); - } - //Build ANSI C stack - if (!string.IsNullOrEmpty(ansicRootDir)) - { - if (!Directory.Exists(ansicRootDir)) - throw new ArgumentException($"The directory does not exist: {ansicRootDir}"); - StackGenerator.GenerateAnsiC(validateParameters, ansicRootDir, generateParameters.ExcludeCategories); - Generator.GenerateIdentifiersAndNamesForAnsiC(ansicRootDir, generateParameters.ExcludeCategories); - } - } + protected virtual void Execute(IModelGeneratorGenerate generateParameters, IModelGeneratorValidate validateParameters) + { + ModelGenerator2 Generator = new ModelGenerator2(); + //Build model + Generator.ValidateAndUpdateIds(validateParameters); + if (!string.IsNullOrEmpty(OutputDir)) + Generator.Generate(generateParameters, OutputDir); + //.NET stack generator + if (!string.IsNullOrEmpty(stackRootDir)) + { + if (!Directory.Exists(stackRootDir)) + throw new ArgumentException($"The directory does not exist: {stackRootDir}"); + StackGenerator.GenerateDotNet(validateParameters, stackRootDir.Trim(), generateParameters.ExcludeCategories); + } + //Build ANSI C stack + if (!string.IsNullOrEmpty(ansicRootDir)) + { + if (!Directory.Exists(ansicRootDir)) + throw new ArgumentException($"The directory does not exist: {ansicRootDir}"); + StackGenerator.GenerateAnsiC(validateParameters, ansicRootDir, generateParameters.ExcludeCategories); + Generator.GenerateIdentifiersAndNamesForAnsiC(ansicRootDir, generateParameters.ExcludeCategories); + } } + } } \ No newline at end of file diff --git a/ModelCompilerUI/ModelCompilerUI.csproj b/ModelCompilerUI/ModelCompilerUI.csproj index 35f5a693..c438fa18 100644 --- a/ModelCompilerUI/ModelCompilerUI.csproj +++ b/ModelCompilerUI/ModelCompilerUI.csproj @@ -13,6 +13,8 @@ true true + + AnyCPU @@ -50,14 +52,20 @@ ..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll + + ..\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll + + + ..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\lib\net461\Microsoft.Extensions.Logging.Abstractions.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\OPCFoundation.NetStandard.Opc.Ua.Core.1.4.367.95\lib\net462\Opc.Ua.Core.dll + + ..\packages\OPCFoundation.NetStandard.Opc.Ua.Core.1.4.368.33\lib\net462\Opc.Ua.Core.dll - - ..\packages\OPCFoundation.NetStandard.Opc.Ua.Security.Certificates.1.4.367.95\lib\net462\Opc.Ua.Security.Certificates.dll + + ..\packages\OPCFoundation.NetStandard.Opc.Ua.Security.Certificates.1.4.368.33\lib\net462\Opc.Ua.Security.Certificates.dll @@ -100,6 +108,7 @@ + Form @@ -138,4 +147,11 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/ModelCompilerUI/packages.config b/ModelCompilerUI/packages.config index 9e277110..272ac94b 100755 --- a/ModelCompilerUI/packages.config +++ b/ModelCompilerUI/packages.config @@ -1,8 +1,10 @@  + + - - + + diff --git a/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj b/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj index 61ec31bc..5669fef6 100644 --- a/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj +++ b/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj @@ -49,6 +49,9 @@ ..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll + + ..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\lib\net461\Microsoft.Extensions.Logging.Abstractions.dll + ..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll @@ -58,11 +61,11 @@ ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\OPCFoundation.NetStandard.Opc.Ua.Core.1.4.367.95\lib\net462\Opc.Ua.Core.dll + + ..\packages\OPCFoundation.NetStandard.Opc.Ua.Core.1.4.368.33\lib\net462\Opc.Ua.Core.dll - - ..\packages\OPCFoundation.NetStandard.Opc.Ua.Security.Certificates.1.4.367.95\lib\net462\Opc.Ua.Security.Certificates.dll + + ..\packages\OPCFoundation.NetStandard.Opc.Ua.Security.Certificates.1.4.368.33\lib\net462\Opc.Ua.Security.Certificates.dll @@ -119,6 +122,8 @@ + + \ No newline at end of file diff --git a/ModelCompilerUnitTest/packages.config b/ModelCompilerUnitTest/packages.config index d0d56908..d2dd4b14 100644 --- a/ModelCompilerUnitTest/packages.config +++ b/ModelCompilerUnitTest/packages.config @@ -1,10 +1,11 @@  + - - + + diff --git a/Opc.Ua.ModelCompiler/ModelCompiler.csproj b/Opc.Ua.ModelCompiler/ModelCompiler.csproj index d970948f..e5d387f3 100644 --- a/Opc.Ua.ModelCompiler/ModelCompiler.csproj +++ b/Opc.Ua.ModelCompiler/ModelCompiler.csproj @@ -342,8 +342,8 @@ - - + + diff --git a/Tests/DemoModel/DemoModel.csproj b/Tests/DemoModel/DemoModel.csproj index 909e71b8..cc80990a 100644 --- a/Tests/DemoModel/DemoModel.csproj +++ b/Tests/DemoModel/DemoModel.csproj @@ -32,7 +32,7 @@ - +