Skip to content

Commit

Permalink
Merge pull request #68 from mpostol/CLP
Browse files Browse the repository at this point in the history
main synchronization to release 2.1.1-Bravo
  • Loading branch information
mpostol committed Mar 31, 2022
2 parents d7f3af6 + 63e0f12 commit 8e09204
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 64 deletions.
45 changes: 45 additions & 0 deletions ModelCompilerUI.UnitTest/CommandLineSyntaxUnitTest.cs
Original file line number Diff line number Diff line change
@@ -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<string> commandLine = new List<string>()
{
"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<string>());
Assert.IsNotNull(args);
ParserResult<object> result = Parser.Default.ParseArguments<CompilerOptions, DotNetStackOptions>(commandLine);
CompilerOptions compilerOptions = null;
IEnumerable<Error> error = null;
result.WithParsed<CompilerOptions>(options => compilerOptions = options).WithNotParsed(errors => error = errors);
Assert.IsNotNull(compilerOptions);
Assert.IsNull(error);
//TODO CLI Syntax #67
}
}
}
4 changes: 4 additions & 0 deletions ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
<Reference Include="BouncyCastle.Crypto, Version=1.9.0.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="CommandLine, Version=2.8.0.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -90,6 +93,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ModelCompilerAPIInternalUnitTest.cs" />
<Compile Include="IntegrationUnitTest.cs" />
<Compile Include="CommandLineSyntaxUnitTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
20 changes: 10 additions & 10 deletions ModelCompilerUI.UnitTest/app.config
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Formats.Asn1" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
<assemblyIdentity name="System.Formats.Asn1" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.9.0.0" newVersion="1.9.0.0"/>
<assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.9.0.0" newVersion="1.9.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>
1 change: 1 addition & 0 deletions ModelCompilerUI.UnitTest/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineParser" version="2.8.0" targetFramework="net48" />
<package id="MSTest.TestAdapter" version="2.2.8" targetFramework="net472" />
<package id="MSTest.TestFramework" version="2.2.8" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
Expand Down
20 changes: 10 additions & 10 deletions ModelCompilerUI/App.config
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Formats.Asn1" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
<assemblyIdentity name="System.Formats.Asn1" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.9.0.0" newVersion="1.9.0.0"/>
<assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.9.0.0" newVersion="1.9.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
111 changes: 111 additions & 0 deletions ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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<string> 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";
23 changes: 22 additions & 1 deletion ModelCompilerUI/HelpFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,38 @@ Opc.Ua.ModelCompiler.exe -d2 <filepath> -c[g] <filepath> -o2 <directorypath>
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";
56 changes: 28 additions & 28 deletions ModelCompilerUI/ModelCompilerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Loading

0 comments on commit 8e09204

Please sign in to comment.