From b351d5f521091a77cc0e7e1487b0c703f6fc89d4 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 4 Sep 2024 09:36:18 +0200 Subject: [PATCH] IobConf: - update NLog - update nuget --- IobConf.Core/IobConf.Core.csproj | 6 +- IobConf.UI/Components/IniConverter.razor | 73 +++++++++------- IobConf.UI/Components/IniConverter.razor.cs | 97 +++++++++++++-------- IobConf.UI/IobConf.UI.csproj | 4 + IobConf.UI/NLog.config | 39 --------- IobConf.UI/Pages/Converter.razor.cs | 5 -- IobConf.UI/Program.cs | 8 ++ IobConf.UI/appsettings.json | 45 +++++++++- 8 files changed, 159 insertions(+), 118 deletions(-) delete mode 100644 IobConf.UI/NLog.config diff --git a/IobConf.Core/IobConf.Core.csproj b/IobConf.Core/IobConf.Core.csproj index d36839cf..1aee7485 100644 --- a/IobConf.Core/IobConf.Core.csproj +++ b/IobConf.Core/IobConf.Core.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/IobConf.UI/Components/IniConverter.razor b/IobConf.UI/Components/IniConverter.razor index 8396668f..b83224bc 100644 --- a/IobConf.UI/Components/IniConverter.razor +++ b/IobConf.UI/Components/IniConverter.razor @@ -11,48 +11,57 @@
-
-
-
-
-

INI

+ @if (!fileOk) + { +
+ No file found +
+ } + else + { +
+
+
+
+

INI

+
+
+
-
+
+

@confINI

-
-

@confINI

-
-
-
-
-
-
-

JSON

+
+
+
+
+

JSON

+
+
+ +
-
- +
+

@confJson

-
-

@confJson

-
-
-
-
-
-
-

YAML

+
+
+
+
+

YAML

+
+
+ +
-
- +
+

@confYaml

-
-

@confYaml

-
-
+ }
\ No newline at end of file diff --git a/IobConf.UI/Components/IniConverter.razor.cs b/IobConf.UI/Components/IniConverter.razor.cs index a9b777f1..5949b386 100644 --- a/IobConf.UI/Components/IniConverter.razor.cs +++ b/IobConf.UI/Components/IniConverter.razor.cs @@ -7,15 +7,23 @@ namespace IobConf.UI.Components { #region Public Methods - public async Task LoadINI() + public void LoadINI() { checkOutDir(); - await Task.Delay(1); - rawFileContent = File.ReadAllText(iniPath); - confINI=getMarkup(rawFileContent); - CurrentConf = IobConfTree.LoadFromINI(iniPath); - updateConf(); + if (File.Exists(iniPath)) + { + fileOk = true; + rawFileContent = File.ReadAllText(iniPath); + confINI = getMarkup(rawFileContent); + CurrentConf = IobConfTree.LoadFromINI(iniPath); + updateConf(); + } + else + { + fileOk = false; + } } + public async Task SaveJson() { checkOutDir(); @@ -32,13 +40,33 @@ namespace IobConf.UI.Components CurrentConf.SaveYaml(fileName); } - private void updateConf() + #endregion Public Methods + + #region Protected Properties + + protected MarkupString confINI { get; set; } + protected MarkupString confJson { get; set; } + protected MarkupString confYaml { get; set; } + protected IobConfTree CurrentConf { get; set; } = new IobConfTree(); + protected bool fileOk { get; set; } = false; + + protected string iniPath { - // aggiorno conf JSON/YAML - confJson = getMarkup(CurrentConf.GetJson()); - confYaml = getMarkup(CurrentConf.GetYaml()); + get => _iniPath; + set + { + if (!iniPath.Equals(value)) + { + _iniPath = value; + LoadINI(); + } + } } + #endregion Protected Properties + + #region Protected Methods + /// /// Converte la stringa in formato markup valido /// @@ -49,40 +77,26 @@ namespace IobConf.UI.Components return new MarkupString(rawData.Replace("\n", "
").Replace(" ", "  ")); } - protected string iniPath = @"C:\temp\DATA\CONF\SIMUL_01.ini"; - - #endregion Public Methods - - #region Protected Fields - - protected string baseDir = @"c:\temp\IobConf"; - - protected string CodIOB = "NewIOB_00"; - - #endregion Protected Fields - - #region Protected Properties - - protected MarkupString confINI { get; set; } - protected MarkupString confJson { get; set; } - - protected MarkupString confYaml { get; set; } - - protected string rawFileContent = ""; - - protected IobConfTree CurrentConf { get; set; } = new IobConfTree(); - - #endregion Protected Properties - - #region Protected Methods - protected override async Task OnInitializedAsync() { - await LoadINI(); + LoadINI(); + await Task.Delay(1); } #endregion Protected Methods + #region Private Fields + + private string _iniPath = @"C:\temp\DATA\CONF\SIMUL_01.ini"; + + private string baseDir = @"c:\temp\IobConf"; + + private string CodIOB = "NewIOB_00"; + + private string rawFileContent = ""; + + #endregion Private Fields + #region Private Methods private void checkOutDir() @@ -93,6 +107,13 @@ namespace IobConf.UI.Components } } + private void updateConf() + { + // aggiorno conf JSON/YAML + confJson = getMarkup(CurrentConf.GetJson()); + confYaml = getMarkup(CurrentConf.GetYaml()); + } + #endregion Private Methods } } \ No newline at end of file diff --git a/IobConf.UI/IobConf.UI.csproj b/IobConf.UI/IobConf.UI.csproj index e62007f2..398ab854 100644 --- a/IobConf.UI/IobConf.UI.csproj +++ b/IobConf.UI/IobConf.UI.csproj @@ -12,6 +12,10 @@ <_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS04.pubxml" /> + + + + diff --git a/IobConf.UI/NLog.config b/IobConf.UI/NLog.config deleted file mode 100644 index 154a5706..00000000 --- a/IobConf.UI/NLog.config +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - diff --git a/IobConf.UI/Pages/Converter.razor.cs b/IobConf.UI/Pages/Converter.razor.cs index 5da535d4..6c82ddc9 100644 --- a/IobConf.UI/Pages/Converter.razor.cs +++ b/IobConf.UI/Pages/Converter.razor.cs @@ -19,10 +19,5 @@ namespace IobConf.UI.Pages { public partial class Converter { - private int currentCount = 0; - private void IncrementCount() - { - currentCount++; - } } } \ No newline at end of file diff --git a/IobConf.UI/Program.cs b/IobConf.UI/Program.cs index 3b6381ad..b9ce99ac 100644 --- a/IobConf.UI/Program.cs +++ b/IobConf.UI/Program.cs @@ -1,9 +1,16 @@ using IobConf.UI.Data; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; +using NLog; +using NLog.Web; var builder = WebApplication.CreateBuilder(args); +var logger = LogManager.Setup() + .LoadConfigurationFromAppSettings() + .GetCurrentClassLogger(); +logger.Info("Program.cs: startup"); + // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); @@ -28,4 +35,5 @@ app.UseRouting(); app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); +logger.Info("Run App"); app.Run(); diff --git a/IobConf.UI/appsettings.json b/IobConf.UI/appsettings.json index 10f68b8c..566ce6d4 100644 --- a/IobConf.UI/appsettings.json +++ b/IobConf.UI/appsettings.json @@ -5,5 +5,48 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "NLog": { + "variables": { + "baseFileDir": "${basedir}/logs/", + "layout": "${longdate} | ${uppercase:${level}} | ${logger:shortName=false} | ${message}" + }, + // "internalLogLevel": "Info", + // "internalLogFile": "c:\\temp\\internal-nlog.txt", + "extensions": [ + { "assembly": "NLog.Extensions.Logging" }, + { "assembly": "NLog.Web.AspNetCore" } + ], + "throwConfigExceptions": true, + "targets": { + "async": true, + "logfile": { + "type": "File", + "fileName": "${basedir}/logs/${shortdate}.log", + "archiveEvery": "Day", + "archiveFileName": "${basedir}/logs/old/${shortdate}_{#}.log", + "archiveNumbering": "DateAndSequence", + "archiveAboveSize": "1024000", + "archiveDateFormat": "HH", + "maxArchiveFiles": "60", + "maxArchiveDays": "30" + }, + "logconsole": { + "type": "ColoredConsole", + "layout": "${longdate} | ${uppercase:${level}} | ${logger:shortName=true} | ${message}" + } + }, + "rules": [ + { + "logger": "*", + "minLevel": "Trace", + "writeTo": "logconsole" + }, + { + "logger": "*", + "minLevel": "Info", + "writeTo": "logfile" + } + ] + } }