From 6f3b4ef5cba264174cb59da033e6646dc4aad02a Mon Sep 17 00:00:00 2001 From: MPostol Date: Fri, 15 Apr 2022 16:09:31 +0200 Subject: [PATCH 1/2] Improve logging infrastructure #71 - Updated some packages - Redesigned login infrastructure for ModelCompilerUI - ready for removing dependency on Forms. --- ModelCompiler Solution.sln | 5 +- .../ModelCompilerUI.UnitTest.csproj | 12 +- ModelCompilerUI.UnitTest/app.config | 4 + ModelCompilerUI.UnitTest/packages.config | 4 +- ModelCompilerUI/App.config | 77 ++++++++---- .../Diagnostic/AssemblyTraceSource.cs | 63 ++++++++++ .../Diagnostic/IBuildErrorsHandling.cs | 26 ++++ ModelCompilerUI/EntryPoint.cs | 115 ++++++++++-------- ModelCompilerUI/ModelCompilerUI.csproj | 17 ++- ModelCompilerUI/ToForms/GUIHandling.cs | 1 + ModelCompilerUI/packages.config | 4 +- .../ModelCompilerUnitTest.csproj | 20 +-- ModelCompilerUnitTest/app.config | 4 + ModelCompilerUnitTest/packages.config | 6 +- 14 files changed, 253 insertions(+), 105 deletions(-) create mode 100644 ModelCompilerUI/Diagnostic/AssemblyTraceSource.cs create mode 100644 ModelCompilerUI/Diagnostic/IBuildErrorsHandling.cs diff --git a/ModelCompiler Solution.sln b/ModelCompiler Solution.sln index e381de70..0ed37da3 100644 --- a/ModelCompiler Solution.sln +++ b/ModelCompiler Solution.sln @@ -1,12 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.1622 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32228.430 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{01D50556-A863-4999-9A5E-13488F9ABFDF}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore .gitmodules = .gitmodules + Bin\Debug\asp.log = Bin\Debug\asp.log BuildEngineeringUnits.bat = BuildEngineeringUnits.bat BuildStandardTypes.bat = BuildStandardTypes.bat PublishModel.bat = PublishModel.bat diff --git a/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj b/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj index dd559537..4c5282f7 100644 --- a/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj +++ b/ModelCompilerUI.UnitTest/ModelCompilerUI.UnitTest.csproj @@ -1,6 +1,6 @@  - + Debug @@ -58,10 +58,10 @@ ..\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll - ..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.2.2.9\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.2.2.9\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -139,8 +139,8 @@ 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.UnitTest/app.config b/ModelCompilerUI.UnitTest/app.config index ce209d4f..47558568 100644 --- a/ModelCompilerUI.UnitTest/app.config +++ b/ModelCompilerUI.UnitTest/app.config @@ -18,6 +18,10 @@ + + + + diff --git a/ModelCompilerUI.UnitTest/packages.config b/ModelCompilerUI.UnitTest/packages.config index bf1a775d..cae5c8c0 100644 --- a/ModelCompilerUI.UnitTest/packages.config +++ b/ModelCompilerUI.UnitTest/packages.config @@ -1,8 +1,8 @@  - - + + diff --git a/ModelCompilerUI/App.config b/ModelCompilerUI/App.config index 4041f028..66f0521f 100644 --- a/ModelCompilerUI/App.config +++ b/ModelCompilerUI/App.config @@ -1,26 +1,55 @@  - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ModelCompilerUI/Diagnostic/AssemblyTraceSource.cs b/ModelCompilerUI/Diagnostic/AssemblyTraceSource.cs new file mode 100644 index 00000000..01ba892d --- /dev/null +++ b/ModelCompilerUI/Diagnostic/AssemblyTraceSource.cs @@ -0,0 +1,63 @@ +//__________________________________________________________________________________________________ +// +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. +// +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ + +using System; +using UAOOI.Common.Infrastructure.Diagnostic; +using UAOOI.SemanticData.BuildingErrorsHandling; + +namespace OOI.ModelCompilerUI.Diagnostic +{ + /// + /// Class AssemblyTraceSource. Implements the + /// + /// + internal class AssemblyTraceSource : IBuildErrorsHandling + { + #region constructors + + /// + /// Returns singleton of the . + /// + internal static IBuildErrorsHandling Log => buildErrorsHandling.Value; + + /// + /// Initializes a new instance of the class using a provided implementation of the . + /// + /// The provided implementation of the . + private AssemblyTraceSource(ITraceSource traceSource) + { + this.traceSource = traceSource; + } + + #endregion constructors + + #region IBuildErrorsHandling + + /// + /// Writes the trace message . + /// + /// A numeric identifier for the event. + /// The trace message. + public void WriteTraceMessage(TraceMessage traceMessage, int id = 1560515041) + { + traceSource.TraceData(traceMessage.TraceLevel, id, traceMessage.ToString()); + if (traceMessage.BuildError.Focus != Focus.Diagnostic) + Errors++; + } + + public int Errors { get; private set; } = 0; + + #endregion IBuildErrorsHandling + + #region private + + private ITraceSource traceSource = null; + private static Lazy buildErrorsHandling = new Lazy(() => new AssemblyTraceSource(new TraceSourceBase("ModelCompilerUI"))); + + #endregion private + } +} \ No newline at end of file diff --git a/ModelCompilerUI/Diagnostic/IBuildErrorsHandling.cs b/ModelCompilerUI/Diagnostic/IBuildErrorsHandling.cs new file mode 100644 index 00000000..395a0857 --- /dev/null +++ b/ModelCompilerUI/Diagnostic/IBuildErrorsHandling.cs @@ -0,0 +1,26 @@ +//__________________________________________________________________________________________________ +// +// 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 UAOOI.SemanticData.BuildingErrorsHandling; + +namespace OOI.ModelCompilerUI.Diagnostic +{ + internal interface IBuildErrorsHandling + { + /// + /// Traces the event using . + /// + /// The message to be send to trace. + void WriteTraceMessage(TraceMessage traceMessage, int id = 1560515041); + + /// + /// Gets the number of traced errors. + /// + /// The errors. + int Errors { get; } + } +} \ No newline at end of file diff --git a/ModelCompilerUI/EntryPoint.cs b/ModelCompilerUI/EntryPoint.cs index 4437f7f2..05937392 100644 --- a/ModelCompilerUI/EntryPoint.cs +++ b/ModelCompilerUI/EntryPoint.cs @@ -1,96 +1,103 @@ //__________________________________________________________________________________________________ // -// Copyright (C) 2021, Mariusz Postol LODZ POLAND. +// 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 OOI.ModelCompilerUI.ToForms; using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text; -using System.Windows.Forms; +using UAOOI.SemanticData.BuildingErrorsHandling; +using static OOI.ModelCompilerUI.Diagnostic.AssemblyTraceSource; namespace OOI.ModelCompilerUI { internal class EntryPoint { + private const string Copyright = "Copyright(c) 2022 Mariusz Postol"; + [STAThread] private static void Main(string[] args) { AssemblyName myAssembly = Assembly.GetExecutingAssembly().GetName(); string AssemblyHeader = $"Starting UA-Compiler Version {myAssembly.Version}"; - Console.WriteLine($"{1637887218} - {AssemblyHeader}"); + TraceMessage message = TraceMessage.BuildErrorTraceMessage(BuildError.DiagnosticInformation, AssemblyHeader); + Log.WriteTraceMessage(message, 716624168); + Log.WriteTraceMessage(TraceMessage.DiagnosticTraceMessage(Copyright), 716624169); string commandLine = Environment.CommandLine; - bool noGui = commandLine.Contains(consoleOutputCommandLineArgument); - if (!noGui) - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - } + //bool noGui = commandLine.Contains(consoleOutputCommandLineArgument); + //if (!noGui) + //{ + // Application.EnableVisualStyles(); + // Application.SetCompatibleTextRenderingDefault(false); + //} //IList args = Environment.GetCommandLineArgs(); int exitCode = 0; - if (MeasurementUnits.ProcessCommandLine(args)) - exitCode = 0; - else - exitCode = Main(noGui, commandLine, new GUIHandling()); + //if (MeasurementUnits.ProcessCommandLine(args)) + // exitCode = 0; + //else + exitCode = Main(commandLine); Environment.Exit(exitCode); } /// /// The main entry point for the application. /// - private static int Main(bool noGui, string commandLine, IGUIHandling guiHandling) + private static int Main(string commandLine) { try { //ServiceMessageContext context = ServiceMessageContext.GlobalContext; - if (!ProcessCommandLine(commandLine, noGui, guiHandling)) - { - StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("OOI.ModelCompilerUI.HelpFile.txt")); - if (noGui) - Console.Error.WriteLine(reader.ReadToEnd()); - else - guiHandling.Show(reader.ReadToEnd(), "ModelCompiler"); - reader.Close(); - return 2; - } + ProcessCommandLine(commandLine); + //if (!ProcessCommandLine(commandLine)) + //{ + // StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("OOI.ModelCompilerUI.HelpFile.txt")); + // if (noGui) + // Console.Error.WriteLine(reader.ReadToEnd()); + // else + // guiHandling.Show(reader.ReadToEnd(), "ModelCompiler"); + // reader.Close(); + // return 2; + //} } catch (Exception e) { - if (noGui) - { - Console.Error.WriteLine(e.Message); - Console.Error.WriteLine(e.StackTrace); - return 3; - } - else - guiHandling.ShowDialog(e); + Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, e.Message), 823547120); + Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, $"Stack Trace: {Environment.NewLine}{e.StackTrace}"), 823547121); + //if (noGui) + //{ + // Console.Error.WriteLine(e.Message); + // Console.Error.WriteLine(e.StackTrace); + // return 3; + //} + //else + // guiHandling.ShowDialog(e); } return 0; } - private const string consoleOutputCommandLineArgument = "-console"; + //private const string consoleOutputCommandLineArgument = "-console"; /// /// Processes the command line arguments. /// - private static bool ProcessCommandLine(string commandLine, bool noGui, IGUIHandling guiHandling) + private static void ProcessCommandLine(string commandLine) { - if (commandLine.IndexOf("-?") != -1) - { - StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("OOI.ModelCompilerUI.HelpFile.txt")); - guiHandling.Show(reader.ReadToEnd(), "ModelCompiler"); - reader.Close(); - return true; - } + //if (commandLine.IndexOf("-?") != -1) + //{ + // StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("OOI.ModelCompilerUI.HelpFile.txt")); + // guiHandling.Show(reader.ReadToEnd(), "ModelCompiler"); + // reader.Close(); + // return true; + //} List tokens = GetTokens(commandLine); // launch gui if no arguments provided. - if (tokens.Count == 1) - return false; + //if (tokens.Count == 1) + // return false; try { ModelCompilerAPIInternal mc = new ModelCompilerAPIInternal(); @@ -99,16 +106,18 @@ private static bool ProcessCommandLine(string commandLine, bool noGui, IGUIHandl } catch (Exception e) { - if (!noGui) - { - Console.Error.WriteLine(e.Message); - Console.Error.WriteLine(e.StackTrace); - Environment.Exit(4); - } - else - guiHandling.ShowDialog(e); + Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, e.Message), 823547120); + Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, $"Stack Trace: {Environment.NewLine}{e.StackTrace}"), 823547121); + // if (!noGui) + // { + // Console.Error.WriteLine(e.Message); + // Console.Error.WriteLine(e.StackTrace); + // Environment.Exit(4); + // } + // else + // guiHandling.ShowDialog(e); } - return true; + //return true; } /// diff --git a/ModelCompilerUI/ModelCompilerUI.csproj b/ModelCompilerUI/ModelCompilerUI.csproj index 93e36cdf..fadd85ff 100644 --- a/ModelCompilerUI/ModelCompilerUI.csproj +++ b/ModelCompilerUI/ModelCompilerUI.csproj @@ -56,8 +56,8 @@ ..\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\Microsoft.Extensions.Logging.Abstractions.6.0.1\lib\net461\Microsoft.Extensions.Logging.Abstractions.dll ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -107,9 +107,18 @@ + + ..\packages\UAOOI.Common.Infrastructure.6.4.7\lib\netstandard2.0\UAOOI.Common.Infrastructure.dll + + + ..\packages\UAOOI.SemanticData.BuildingErrorsHandling.5.1.0\lib\netstandard2.0\UAOOI.SemanticData.BuildingErrorsHandling.dll + + + + Form @@ -148,11 +157,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/ToForms/GUIHandling.cs b/ModelCompilerUI/ToForms/GUIHandling.cs index 8559b4e6..4b440e36 100644 --- a/ModelCompilerUI/ToForms/GUIHandling.cs +++ b/ModelCompilerUI/ToForms/GUIHandling.cs @@ -10,6 +10,7 @@ namespace OOI.ModelCompilerUI.ToForms { + [Obsolete()] internal class GUIHandling : IGUIHandling { public void Show(string message) diff --git a/ModelCompilerUI/packages.config b/ModelCompilerUI/packages.config index 272ac94b..7bcf40e4 100755 --- a/ModelCompilerUI/packages.config +++ b/ModelCompilerUI/packages.config @@ -1,7 +1,7 @@  - + @@ -14,4 +14,6 @@ + + \ No newline at end of file diff --git a/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj b/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj index 5669fef6..5a10e0ad 100644 --- a/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj +++ b/ModelCompilerUnitTest/ModelCompilerUnitTest.csproj @@ -1,6 +1,6 @@  - + Debug @@ -49,14 +49,14 @@ ..\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\Microsoft.Extensions.Logging.Abstractions.6.0.1\lib\net461\Microsoft.Extensions.Logging.Abstractions.dll - ..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.2.2.9\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.2.2.9\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -120,10 +120,10 @@ 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/ModelCompilerUnitTest/app.config b/ModelCompilerUnitTest/app.config index 4097c346..2d8afc16 100644 --- a/ModelCompilerUnitTest/app.config +++ b/ModelCompilerUnitTest/app.config @@ -14,6 +14,10 @@ + + + + diff --git a/ModelCompilerUnitTest/packages.config b/ModelCompilerUnitTest/packages.config index d2dd4b14..a9a806a1 100644 --- a/ModelCompilerUnitTest/packages.config +++ b/ModelCompilerUnitTest/packages.config @@ -1,8 +1,8 @@  - - - + + + From 2291312ca26f1efbd75efe962b167f97be7eeac2 Mon Sep 17 00:00:00 2001 From: MPostol Date: Fri, 15 Apr 2022 17:37:57 +0200 Subject: [PATCH 2/2] Improve logging infrastructure #71 - Removed dependency on System.Forms --- ModelCompilerUI/App.config | 2 +- .../CommandLineSyntax/CompilerOptions.cs | 4 +- ModelCompilerUI/EntryPoint.cs | 91 +--------- ModelCompilerUI/ExceptionDlg.Designer.cs | 130 -------------- ModelCompilerUI/ExceptionDlg.cs | 105 ----------- ModelCompilerUI/ExceptionDlg.resx | 120 ------------- ModelCompilerUI/ModelCompilerUI.csproj | 16 -- ModelCompilerUI/ToForms/GUIHandling.cs | 37 ---- ModelCompilerUI/ToForms/IGUIHandling.cs | 166 ------------------ ModelCompilerUI/ToForms/ToFormsConverters.cs | 143 --------------- 10 files changed, 7 insertions(+), 807 deletions(-) delete mode 100644 ModelCompilerUI/ExceptionDlg.Designer.cs delete mode 100644 ModelCompilerUI/ExceptionDlg.cs delete mode 100644 ModelCompilerUI/ExceptionDlg.resx delete mode 100644 ModelCompilerUI/ToForms/GUIHandling.cs delete mode 100644 ModelCompilerUI/ToForms/IGUIHandling.cs delete mode 100644 ModelCompilerUI/ToForms/ToFormsConverters.cs diff --git a/ModelCompilerUI/App.config b/ModelCompilerUI/App.config index 66f0521f..274777be 100644 --- a/ModelCompilerUI/App.config +++ b/ModelCompilerUI/App.config @@ -12,7 +12,7 @@ - + diff --git a/ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs b/ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs index 915885ea..ba5f1161 100644 --- a/ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs +++ b/ModelCompilerUI/CommandLineSyntax/CompilerOptions.cs @@ -57,7 +57,7 @@ internal class CompilerOptions 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 excludeHeelp = "Comma separated 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."; @@ -101,8 +101,6 @@ 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"; diff --git a/ModelCompilerUI/EntryPoint.cs b/ModelCompilerUI/EntryPoint.cs index 05937392..aa1f851b 100644 --- a/ModelCompilerUI/EntryPoint.cs +++ b/ModelCompilerUI/EntryPoint.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Reflection; using System.Text; using UAOOI.SemanticData.BuildingErrorsHandling; @@ -17,8 +16,6 @@ namespace OOI.ModelCompilerUI { internal class EntryPoint { - private const string Copyright = "Copyright(c) 2022 Mariusz Postol"; - [STAThread] private static void Main(string[] args) { @@ -27,20 +24,8 @@ private static void Main(string[] args) TraceMessage message = TraceMessage.BuildErrorTraceMessage(BuildError.DiagnosticInformation, AssemblyHeader); Log.WriteTraceMessage(message, 716624168); Log.WriteTraceMessage(TraceMessage.DiagnosticTraceMessage(Copyright), 716624169); - string commandLine = Environment.CommandLine; - //bool noGui = commandLine.Contains(consoleOutputCommandLineArgument); - //if (!noGui) - //{ - // Application.EnableVisualStyles(); - // Application.SetCompatibleTextRenderingDefault(false); - //} - //IList args = Environment.GetCommandLineArgs(); - int exitCode = 0; - //if (MeasurementUnits.ProcessCommandLine(args)) - // exitCode = 0; - //else - exitCode = Main(commandLine); + int exitCode = Main(commandLine); Environment.Exit(exitCode); } @@ -51,55 +36,7 @@ private static int Main(string commandLine) { try { - //ServiceMessageContext context = ServiceMessageContext.GlobalContext; - ProcessCommandLine(commandLine); - //if (!ProcessCommandLine(commandLine)) - //{ - // StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("OOI.ModelCompilerUI.HelpFile.txt")); - // if (noGui) - // Console.Error.WriteLine(reader.ReadToEnd()); - // else - // guiHandling.Show(reader.ReadToEnd(), "ModelCompiler"); - // reader.Close(); - // return 2; - //} - } - catch (Exception e) - { - Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, e.Message), 823547120); - Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, $"Stack Trace: {Environment.NewLine}{e.StackTrace}"), 823547121); - //if (noGui) - //{ - // Console.Error.WriteLine(e.Message); - // Console.Error.WriteLine(e.StackTrace); - // return 3; - //} - //else - // guiHandling.ShowDialog(e); - } - return 0; - } - - //private const string consoleOutputCommandLineArgument = "-console"; - - /// - /// Processes the command line arguments. - /// - private static void ProcessCommandLine(string commandLine) - { - //if (commandLine.IndexOf("-?") != -1) - //{ - // StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("OOI.ModelCompilerUI.HelpFile.txt")); - // guiHandling.Show(reader.ReadToEnd(), "ModelCompiler"); - // reader.Close(); - // return true; - //} - List tokens = GetTokens(commandLine); - // launch gui if no arguments provided. - //if (tokens.Count == 1) - // return false; - try - { + List tokens = GetTokens(commandLine); ModelCompilerAPIInternal mc = new ModelCompilerAPIInternal(); mc.ProcessCommandLine(tokens); mc.Build(); @@ -108,16 +45,8 @@ private static void ProcessCommandLine(string commandLine) { Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, e.Message), 823547120); Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, $"Stack Trace: {Environment.NewLine}{e.StackTrace}"), 823547121); - // if (!noGui) - // { - // Console.Error.WriteLine(e.Message); - // Console.Error.WriteLine(e.StackTrace); - // Environment.Exit(4); - // } - // else - // guiHandling.ShowDialog(e); } - //return true; + return 0; } /// @@ -126,14 +55,11 @@ private static void ProcessCommandLine(string commandLine) private static List GetTokens(string commandLine) { List tokens = new List(); - bool quotedToken = false; StringBuilder token = new StringBuilder(); - for (int ii = 0; ii < commandLine.Length; ii++) { char ch = commandLine[ii]; - if (quotedToken) { if (ch == '"') @@ -143,11 +69,9 @@ private static List GetTokens(string commandLine) tokens.Add(token.ToString()); token = new StringBuilder(); } - quotedToken = false; continue; } - token.Append(ch); } else @@ -160,7 +84,6 @@ private static List GetTokens(string commandLine) continue; } } - if (char.IsWhiteSpace(ch)) { if (token.Length > 0) @@ -168,20 +91,16 @@ private static List GetTokens(string commandLine) tokens.Add(token.ToString()); token = new StringBuilder(); } - continue; } - token.Append(ch); } } - if (token.Length > 0) - { tokens.Add(token.ToString()); - } - return tokens; } + + private const string Copyright = "Copyright(c) 2022 Mariusz Postol"; } } \ No newline at end of file diff --git a/ModelCompilerUI/ExceptionDlg.Designer.cs b/ModelCompilerUI/ExceptionDlg.Designer.cs deleted file mode 100644 index bd138d70..00000000 --- a/ModelCompilerUI/ExceptionDlg.Designer.cs +++ /dev/null @@ -1,130 +0,0 @@ -/* ======================================================================== - * Copyright (c) 2005-2021 The OPC Foundation, Inc. All rights reserved. - * - * OPC Foundation MIT License 1.00 - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * The complete license agreement can be found here: - * http://opcfoundation.org/License/MIT/1.00/ - * ======================================================================*/ - -namespace OOI.ModelCompilerUI -{ - partial class ExceptionDlg - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.BottomPanel = new System.Windows.Forms.Panel(); - this.MainPN = new System.Windows.Forms.Panel(); - this.ExceptionBrowser = new System.Windows.Forms.WebBrowser(); - this.OkButton = new System.Windows.Forms.Button(); - this.BottomPanel.SuspendLayout(); - this.MainPN.SuspendLayout(); - this.SuspendLayout(); - // - // BottomPanel - // - this.BottomPanel.Controls.Add(this.OkButton); - this.BottomPanel.Dock = System.Windows.Forms.DockStyle.Bottom; - this.BottomPanel.Location = new System.Drawing.Point(0, 433); - this.BottomPanel.Name = "BottomPanel"; - this.BottomPanel.Size = new System.Drawing.Size(770, 37); - this.BottomPanel.TabIndex = 0; - // - // MainPN - // - this.MainPN.Controls.Add(this.ExceptionBrowser); - this.MainPN.Dock = System.Windows.Forms.DockStyle.Fill; - this.MainPN.Location = new System.Drawing.Point(0, 0); - this.MainPN.Name = "MainPN"; - this.MainPN.Padding = new System.Windows.Forms.Padding(3); - this.MainPN.Size = new System.Drawing.Size(770, 433); - this.MainPN.TabIndex = 1; - // - // ExceptionBrowser - // - this.ExceptionBrowser.Dock = System.Windows.Forms.DockStyle.Fill; - this.ExceptionBrowser.Location = new System.Drawing.Point(3, 3); - this.ExceptionBrowser.MinimumSize = new System.Drawing.Size(20, 20); - this.ExceptionBrowser.Name = "ExceptionBrowser"; - this.ExceptionBrowser.Size = new System.Drawing.Size(764, 427); - this.ExceptionBrowser.TabIndex = 0; - // - // OkButton - // - this.OkButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); - this.OkButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.OkButton.Location = new System.Drawing.Point(348, 8); - this.OkButton.Name = "OkButton"; - this.OkButton.Size = new System.Drawing.Size(75, 23); - this.OkButton.TabIndex = 0; - this.OkButton.Text = "OK"; - this.OkButton.UseVisualStyleBackColor = true; - this.OkButton.Click += new System.EventHandler(this.OkButton_Click); - // - // ExceptionDlg - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(770, 470); - this.Controls.Add(this.MainPN); - this.Controls.Add(this.BottomPanel); - this.Name = "ExceptionDlg"; - this.Text = "Exception"; - this.BottomPanel.ResumeLayout(false); - this.MainPN.ResumeLayout(false); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Panel BottomPanel; - private System.Windows.Forms.Button OkButton; - private System.Windows.Forms.Panel MainPN; - private System.Windows.Forms.WebBrowser ExceptionBrowser; - } -} diff --git a/ModelCompilerUI/ExceptionDlg.cs b/ModelCompilerUI/ExceptionDlg.cs deleted file mode 100644 index b92b069c..00000000 --- a/ModelCompilerUI/ExceptionDlg.cs +++ /dev/null @@ -1,105 +0,0 @@ -/* ======================================================================== - * Copyright (c) 2005-2021 The OPC Foundation, Inc. All rights reserved. - * - * OPC Foundation MIT License 1.00 - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * The complete license agreement can be found here: - * http://opcfoundation.org/License/MIT/1.00/ - * ======================================================================*/ - -using System; -using System.Text; -using System.Windows.Forms; - -namespace OOI.ModelCompilerUI -{ - public partial class ExceptionDlg : Form - { - public ExceptionDlg() - { - InitializeComponent(); - } - - public ExceptionDlg(Exception e) - { - InitializeComponent(); - - StringBuilder buffer = new StringBuilder(); - - buffer.Append(""); - buffer.Append(""); - - var ae = e as AggregateException; - - if (ae != null) - { - string message = e.Message; - message = message.Replace("<", "<"); - message = message.Replace(">", ">"); - message = message.Replace("\r\n", "
"); - - buffer.AppendFormat("{0}
", message); - buffer.AppendFormat("{0}

", e.StackTrace); - - for (int ii = 0; ii < ae.InnerExceptions.Count; ii++) - { - e = ae.InnerExceptions[ii]; - - message = e.Message; - message = message.Replace("<", "<"); - message = message.Replace(">", ">"); - message = message.Replace("\r\n", "
"); - - buffer.AppendFormat("{0}
", message); - buffer.AppendFormat("{0}

", e.StackTrace); - } - } - else - { - while (e != null) - { - string message = e.Message; - message = message.Replace("<", "<"); - message = message.Replace(">", ">"); - message = message.Replace("\r\n", "
"); - - buffer.AppendFormat("{0}
", message); - buffer.AppendFormat("{0}

", e.StackTrace); - - e = e.InnerException; - } - } - - buffer.Append(""); - buffer.Append(""); - - ExceptionBrowser.DocumentText = buffer.ToString(); - } - - private void OkButton_Click(object sender, EventArgs e) - { - Close(); - } - } -} - diff --git a/ModelCompilerUI/ExceptionDlg.resx b/ModelCompilerUI/ExceptionDlg.resx deleted file mode 100644 index 08f1b248..00000000 --- a/ModelCompilerUI/ExceptionDlg.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/ModelCompilerUI/ModelCompilerUI.csproj b/ModelCompilerUI/ModelCompilerUI.csproj index fadd85ff..cafc6768 100644 --- a/ModelCompilerUI/ModelCompilerUI.csproj +++ b/ModelCompilerUI/ModelCompilerUI.csproj @@ -100,7 +100,6 @@ ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll - @@ -117,15 +116,8 @@ - - - Form - - - ExceptionDlg.cs - @@ -133,20 +125,12 @@ - - - - - - ExceptionDlg.cs - - diff --git a/ModelCompilerUI/ToForms/GUIHandling.cs b/ModelCompilerUI/ToForms/GUIHandling.cs deleted file mode 100644 index 4b440e36..00000000 --- a/ModelCompilerUI/ToForms/GUIHandling.cs +++ /dev/null @@ -1,37 +0,0 @@ -//__________________________________________________________________________________________________ -// -// Copyright (C) 2021, Mariusz Postol LODZ POLAND. -// -// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions -//__________________________________________________________________________________________________ - -using System; -using System.Windows.Forms; - -namespace OOI.ModelCompilerUI.ToForms -{ - [Obsolete()] - internal class GUIHandling : IGUIHandling - { - public void Show(string message) - { - MessageBox.Show(message); - } - - public void Show(string message, string caption) - { - MessageBox.Show(message, caption); - } - - public DialogResultCompiler Show(string text, string caption, MessageBoxButtonsCompiler buttons, MessageBoxIconCompiler icon) - { - return MessageBox.Show(text, caption, buttons.Convert(), icon.Convert()).Convert(); - } - - public void ShowDialog(Exception e) - { - ExceptionDlg dialog = new ExceptionDlg(e); - dialog.ShowDialog(); - } - } -} \ No newline at end of file diff --git a/ModelCompilerUI/ToForms/IGUIHandling.cs b/ModelCompilerUI/ToForms/IGUIHandling.cs deleted file mode 100644 index 6aea0045..00000000 --- a/ModelCompilerUI/ToForms/IGUIHandling.cs +++ /dev/null @@ -1,166 +0,0 @@ -//__________________________________________________________________________________________________ -// -// Copyright (C) 2021, Mariusz Postol LODZ POLAND. -// -// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions -//__________________________________________________________________________________________________ - -using System; - -namespace OOI.ModelCompilerUI.ToForms -{ - internal interface IGUIHandling - { - void Show(string message); - void Show(string message, string caption); - - DialogResultCompiler Show(string text, string caption, MessageBoxButtonsCompiler buttons, MessageBoxIconCompiler icon); - - void ShowDialog(Exception e); - } - - // - // Summary: - // Specifies constants defining which information to display. - public enum MessageBoxIconCompiler - { - // - // Summary: - // The message box contain no symbols. - None, - - // - // Summary: - // The message box contains a symbol consisting of a white X in a circle with a - // red background. - Hand, - - // - // Summary: - // The message box contains a symbol consisting of white X in a circle with a red - // background. - Stop, - - // - // Summary: - // The message box contains a symbol consisting of white X in a circle with a red - // background. - Error, - - // - // Summary: - // The message box contains a symbol consisting of a question mark in a circle. - // The question-mark message icon is no longer recommended because it does not clearly - // represent a specific type of message and because the phrasing of a message as - // a question could apply to any message type. In addition, users can confuse the - // message symbol question mark with Help information. Therefore, do not use this - // question mark message symbol in your message boxes. The system continues to support - // its inclusion only for backward compatibility. - Question, - - // - // Summary: - // The message box contains a symbol consisting of an exclamation point in a triangle - // with a yellow background. - Exclamation, - - // - // Summary: - // The message box contains a symbol consisting of an exclamation point in a triangle - // with a yellow background. - Warning, - - // - // Summary: - // The message box contains a symbol consisting of a lowercase letter i in a circle. - Asterisk, - - // - // Summary: - // The message box contains a symbol consisting of a lowercase letter i in a circle. - Information - } - - // - // Summary: - // Specifies constants defining which buttons to display on a System.Windows.Forms.MessageBox. - public enum MessageBoxButtonsCompiler - { - // - // Summary: - // The message box contains an OK button. - OK = 0, - - // - // Summary: - // The message box contains OK and Cancel buttons. - OKCancel = 1, - - // - // Summary: - // The message box contains Abort, Retry, and Ignore buttons. - AbortRetryIgnore = 2, - - // - // Summary: - // The message box contains Yes, No, and Cancel buttons. - YesNoCancel = 3, - - // - // Summary: - // The message box contains Yes and No buttons. - YesNo = 4, - - // - // Summary: - // The message box contains Retry and Cancel buttons. - RetryCancel = 5 - } - - // - // Summary: - // Specifies identifiers to indicate the return value of a dialog box. - public enum DialogResultCompiler - { - // - // Summary: - // Nothing is returned from the dialog box. This means that the modal dialog continues - // running. - None = 0, - - // - // Summary: - // The dialog box return value is OK (usually sent from a button labeled OK). - OK = 1, - - // - // Summary: - // The dialog box return value is Cancel (usually sent from a button labeled Cancel). - Cancel = 2, - - // - // Summary: - // The dialog box return value is Abort (usually sent from a button labeled Abort). - Abort = 3, - - // - // Summary: - // The dialog box return value is Retry (usually sent from a button labeled Retry). - Retry = 4, - - // - // Summary: - // The dialog box return value is Ignore (usually sent from a button labeled Ignore). - Ignore = 5, - - // - // Summary: - // The dialog box return value is Yes (usually sent from a button labeled Yes). - Yes = 6, - - // - // Summary: - // The dialog box return value is No (usually sent from a button labeled No). - No = 7 - } -} \ No newline at end of file diff --git a/ModelCompilerUI/ToForms/ToFormsConverters.cs b/ModelCompilerUI/ToForms/ToFormsConverters.cs deleted file mode 100644 index d6c46f51..00000000 --- a/ModelCompilerUI/ToForms/ToFormsConverters.cs +++ /dev/null @@ -1,143 +0,0 @@ -//__________________________________________________________________________________________________ -// -// Copyright (C) 2021, Mariusz Postol LODZ POLAND. -// -// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions -//__________________________________________________________________________________________________ - -using System.Windows.Forms; - -namespace OOI.ModelCompilerUI.ToForms -{ - internal static class ToFormsConverters - { - internal static DialogResult Convert(this DialogResultCompiler result) - { - switch (result) - { - case DialogResultCompiler.None: - return DialogResult.None; - - case DialogResultCompiler.OK: - return DialogResult.OK; - - case DialogResultCompiler.Cancel: - return DialogResult.Cancel; - - case DialogResultCompiler.Abort: - return DialogResult.Abort; - - case DialogResultCompiler.Retry: - return DialogResult.Retry; - - case DialogResultCompiler.Ignore: - return DialogResult.Ignore; - - case DialogResultCompiler.Yes: - return DialogResult.Yes; - - case DialogResultCompiler.No: - return DialogResult.No; - - default: - return DialogResult.Yes; - } - } - - internal static DialogResultCompiler Convert(this DialogResult result) - { - switch (result) - { - case DialogResult.None: - return DialogResultCompiler.None; - - case DialogResult.OK: - return DialogResultCompiler.OK; - - case DialogResult.Cancel: - return DialogResultCompiler.Cancel; - - case DialogResult.Abort: - return DialogResultCompiler.Abort; - - case DialogResult.Retry: - return DialogResultCompiler.Retry; - - case DialogResult.Ignore: - return DialogResultCompiler.Ignore; - - case DialogResult.Yes: - return DialogResultCompiler.Yes; - - case DialogResult.No: - return DialogResultCompiler.No; - - default: - return DialogResultCompiler.Yes; - } - } - - internal static MessageBoxButtons Convert(this MessageBoxButtonsCompiler value) - { - switch (value) - { - case MessageBoxButtonsCompiler.OK: - return MessageBoxButtons.OK; - - case MessageBoxButtonsCompiler.OKCancel: - return MessageBoxButtons.OKCancel; - - case MessageBoxButtonsCompiler.AbortRetryIgnore: - return MessageBoxButtons.AbortRetryIgnore; - - case MessageBoxButtonsCompiler.YesNoCancel: - return MessageBoxButtons.YesNoCancel; - - case MessageBoxButtonsCompiler.YesNo: - return MessageBoxButtons.YesNo; - - case MessageBoxButtonsCompiler.RetryCancel: - return MessageBoxButtons.RetryCancel; - - default: - return MessageBoxButtons.OK; - } - } - - internal static MessageBoxIcon Convert(this MessageBoxIconCompiler value) - { - switch (value) - { - case MessageBoxIconCompiler.None: - return MessageBoxIcon.None; - - case MessageBoxIconCompiler.Hand: - return MessageBoxIcon.Hand; - - case MessageBoxIconCompiler.Stop: - return MessageBoxIcon.Stop; - - case MessageBoxIconCompiler.Error: - return MessageBoxIcon.Error; - - case MessageBoxIconCompiler.Question: - return MessageBoxIcon.Question; - - case MessageBoxIconCompiler.Exclamation: - return MessageBoxIcon.Exclamation; - - case MessageBoxIconCompiler.Warning: - return MessageBoxIcon.Warning; - - case MessageBoxIconCompiler.Asterisk: - return MessageBoxIcon.Asterisk; - - case MessageBoxIconCompiler.Information: - return MessageBoxIcon.Information; - - default: - return MessageBoxIcon.None; - } - } - } -} \ No newline at end of file