Ok componente editing config!

This commit is contained in:
Samuele Locatelli
2024-09-21 10:26:46 +02:00
parent 365a3653b4
commit e3421fb657
15 changed files with 528 additions and 123 deletions
+3 -2
View File
@@ -42,15 +42,16 @@
blazorWebView1.TabIndex = 0;
blazorWebView1.Text = "blazorWebView1";
//
// Form1
// BlazorForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(blazorWebView1);
Icon = (Icon)resources.GetObject("$this.Icon");
Name = "Form1";
Name = "BlazorForm";
Text = "EgalWare's AppControlCenter";
Load += BlazorForm_Load;
ResumeLayout(false);
}
+23 -3
View File
@@ -1,4 +1,5 @@
using EgwControlCenter.App.Components.Pages;
using EgwControlCenter.Core;
using Microsoft.AspNetCore.Components.WebView.WindowsForms;
using Microsoft.Extensions.DependencyInjection;
@@ -6,21 +7,40 @@ namespace EgwControlCenter.App
{
public partial class BlazorForm : Form
{
#region Public Constructors
public BlazorForm()
{
InitializeComponent();
InitBlazorView();
}
#endregion Public Constructors
#region Private Methods
private void BlazorForm_Load(object sender, EventArgs e)
{
SetPosition();
}
private void InitBlazorView()
{
var services = new ServiceCollection();
services.AddWindowsFormsBlazorWebView();
//services.AddSingleton<WeatherForecastService>();
services.AddSingleton<AppControlService>();
blazorWebView1.HostPage = "wwwroot\\index.html";
blazorWebView1.Services = services.BuildServiceProvider();
blazorWebView1.RootComponents.Add<MainBlazor>("#app");
//blazorWebView1.RootComponents.Add<IndexBlazor>("#app");
}
private void SetPosition()
{
// posiziono in basso a sx...
Rectangle workArea = Screen.GetWorkingArea(this);
this.Location = new Point(workArea.Right - Size.Width, workArea.Bottom - Size.Height);
}
#endregion Private Methods
}
}
}
@@ -1,3 +1,4 @@
using EgwControlCenter.Core;
using Microsoft.AspNetCore.Components;
namespace EgwControlCenter.App.Components.Compo
@@ -14,6 +15,7 @@ namespace EgwControlCenter.App.Components.Compo
aTimer.Stop();
aTimer.Dispose();
}
ACService.EA_ConfigUpdated -= ACService_EA_ConfigUpdated;
}
#endregion Public Methods
@@ -24,23 +26,12 @@ namespace EgwControlCenter.App.Components.Compo
#endregion Protected Fields
[Inject]
protected AppControlService ACService { get; set; } = null!;
#region Protected Methods
private System.Reflection.AssemblyName? CurrAssembly { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName();
private Version AppVers
{
get
{
Version answ = new Version(0, 0, 0, 0);
if (CurrAssembly != null && CurrAssembly.Version != null)
{
answ = CurrAssembly.Version;
}
return answ;
}
}
protected void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
{
adesso = DateTime.Now;
@@ -54,9 +45,20 @@ namespace EgwControlCenter.App.Components.Compo
protected override void OnInitialized()
{
//var rawVers = typeof(Program).Assembly.GetName().Version;
//version = rawVers != null ? rawVers : new Version("0.0.0.0");
StartTimer();
ACService.EA_ConfigUpdated += ACService_EA_ConfigUpdated;
}
private void ACService_EA_ConfigUpdated()
{
//fermo il timer e lo riavvio...
StartTimer();
}
protected int RefreshPeriod
{
get => ACService.RefreshPeriod;
set => ACService.RefreshPeriod = value;
}
protected void StartTimer()
@@ -67,7 +69,8 @@ namespace EgwControlCenter.App.Components.Compo
aTimer.Dispose();
}
//int tOutPeriod = 300000;
int tOutPeriod = 1000;
//int tOutPeriod = 1000;
int tOutPeriod = RefreshPeriod < 1000 ? RefreshPeriod * 1000 : RefreshPeriod;
aTimer = new System.Timers.Timer(tOutPeriod);
aTimer.Elapsed += ElapsedTimer;
aTimer.Enabled = true;
@@ -81,5 +84,24 @@ namespace EgwControlCenter.App.Components.Compo
private System.Timers.Timer aTimer = null!;
#endregion Private Fields
#region Private Properties
private Version AppVers
{
get
{
Version answ = new Version(0, 0, 0, 0);
if (CurrAssembly != null && CurrAssembly.Version != null)
{
answ = CurrAssembly.Version;
}
return answ;
}
}
private System.Reflection.AssemblyName? CurrAssembly { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName();
#endregion Private Properties
}
}
@@ -0,0 +1,103 @@
@using EgwControlCenter.Core
@using EgwControlCenter.Core.Models
@inject AppControlService ACService
@if (PwdOk)
{
<div class="row">
<div class="col-2">
<button class="btn btn-warning btn-lg w-100 shadow" @onclick="DoCancel">Cancel</button>
</div>
<div class="col-4">
<div class="form-floating">
<input type="number" class="form-control fs-5 text-end" @bind="@RefreshPeriod">
<label>Refresh Period <small>(1..3600 sec)</small></label>
</div>
</div>
<div class="col-4">
<div class="form-floating">
<input type="number" class="form-control fs-4 text-end" @bind="@VetoCheck">
<label>Veto Check <small>(1..14'400 minutes)</small></label>
</div>
</div>
<div class="col-2">
<button class="btn btn-success btn-lg w-100 shadow" @onclick="DoSave">Save</button>
</div>
<div class="col-12 my-2">
<table class="table table-striped table-sm text-start shadow border">
<thead>
<tr class="bg-dark bg-gradient text-light">
<th class="text-center" style="width: 2rem;">
<button class="btn btn-primary btn-sm" @onclick="DoCancel"><i class="fa-solid fa-rotate"></i></button>
</th>
<th>Tipo</th>
<th>Path</th>
<th class="text-end" style="width: 3rem;">Enabled</th>
</tr>
</thead>
<tbody>
@foreach (var item in ListRecords)
{
<tr>
<td class="text-center">@item.Idx</td>
<td>@item.ApplicationType</td>
<td>
<input type="text" class="form-control form-control-sm" @bind="@item.BasePath" />
</td>
<td class="text-end">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" @bind="@item.IsEnabled">
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
else
{
<div class="input-group flex-nowrap">
<span class="input-group-text" id="addon-wrapping">Verify Auth Password</span>
<input type="password" class="form-control" @bind="@SetupPwd">
</div>
}
@code {
protected int RefreshPeriod
{
get => ACService.RefreshPeriod;
set => ACService.RefreshPeriod = value;
}
protected void DoCancel()
{
ACService.DoReloadConfig();
}
protected void DoSave()
{
ACService.DoSaveConfig();
}
private string SetupPwd { get; set; } = "";
private int VetoCheck
{
get => ACService.VetoCheck;
set => ACService.VetoCheck = value;
}
private bool PwdOk
{
get => !string.IsNullOrEmpty(SetupPwd) && SetupPwd == EgwControlCenter.Core.Const.EditPwd;
}
private List<ControlTarget> ListRecords
{
get => ACService.TargetList;
set => ACService.TargetList = value;
}
}
@@ -3,7 +3,6 @@
@page "/Index"
@page "/Nav01"
@inject NavigationManager NavMan
<div class="card shadow">
<div class="card-header">
@@ -12,25 +11,32 @@
<h1>App Control Center</h1>
</div>
<div class="p-0">
<button class="btn btn-info w-100" @onclick="GoTo01"><i class="fa-solid fa-screwdriver-wrench"></i></button>
<button class="btn @SetupBtnClass w-100" @onclick="ToggleSetup"><i class="fa-solid fa-screwdriver-wrench"></i></button>
</div>
</div>
</div>
<div class="card-body">
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<br />
<div class="row my-2">
<div class="col">
<button class="btn btn-info w-100" @onclick="GoTo01">Nav 01</button>
@if (ReqSetup)
{
<TargetSetup></TargetSetup>
}
else
{
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<br />
<div class="row my-2">
<div class="col">
<button class="btn btn-info w-100" @onclick="GoTo01">Nav 01</button>
</div>
<div class="col">
<button class="btn btn-info w-100" @onclick="GoTo02">Nav 02</button>
</div>
<div class="col">
<button class="btn btn-info w-100" @onclick="GoTo03">Nav 03</button>
</div>
</div>
<div class="col">
<button class="btn btn-info w-100" @onclick="GoTo02">Nav 02</button>
</div>
<div class="col">
<button class="btn btn-info w-100" @onclick="GoTo03">Nav 03</button>
</div>
</div>
}
</div>
<div class="card-footer">
@if (CurrAssembly != null)
@@ -40,25 +46,3 @@
</div>
</div>
@code {
private int currentCount = 0;
private System.Reflection.AssemblyName? CurrAssembly { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName();
private void IncrementCount()
{
currentCount++;
}
private void GoTo01()
{
NavMan.NavigateTo("Nav01");
}
private void GoTo02()
{
NavMan.NavigateTo("Nav02");
}
private void GoTo03()
{
NavMan.NavigateTo("Nav03");
}
}
@@ -0,0 +1,68 @@
using EgwControlCenter.Core;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace EgwControlCenter.App.Components.Pages
{
public partial class Index
{
#region Protected Properties
[Inject]
protected NavigationManager NavMan { get; set; } = null!;
#endregion Protected Properties
#region Private Fields
private int currentCount = 0;
#endregion Private Fields
#region Private Properties
private System.Reflection.AssemblyName? CurrAssembly { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName();
#endregion Private Properties
#region Private Methods
private void GoTo01()
{
NavMan.NavigateTo("Nav01");
}
private void GoTo02()
{
NavMan.NavigateTo("Nav02");
}
private void GoTo03()
{
NavMan.NavigateTo("Nav03");
}
private void IncrementCount()
{
currentCount++;
}
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
private bool ReqSetup { get; set; } = false;
private string SetupBtnClass
{
get => ReqSetup ? "btn-info" : "btn-primary";
}
protected void ToggleSetup()
{
ReqSetup = !ReqSetup;
}
#endregion Private Methods
}
}
+24
View File
@@ -0,0 +1,24 @@
{
"RefreshIntSec": 60,
"VetoCheckMinutes": 600,
"TargetList": [
{
"Idx": 1,
"ApplicationType": "Machine",
"BasePath": "C:\\EgtData\\Machines",
"IsEnabled": true
},
{
"Idx": 2,
"ApplicationType": "Machine",
"BasePath": "C:\\TechnoEssetre7\\EgalTech\\EgtCAM5\\Machines",
"IsEnabled": true
},
{
"Idx": 3,
"ApplicationType": "Machine",
"BasePath": "C:\\Testing\\Machine",
"IsEnabled": true
}
]
}
@@ -22,4 +22,9 @@
<ItemGroup>
<ProjectReference Include="..\EgwControlCenter.Core\EgwControlCenter.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="ConfPatrol.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
+1 -19
View File
@@ -1,22 +1,4 @@
@*
<div class="card shadow m-1">
<div class="card-header">
<h1>Counter</h1>
</div>
<div class="card-body">
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
</div>
<div class="card-footer">
@if (CurrAssembly != null)
{
<small>@CurrAssembly.Name | @CurrAssembly.Version</small>
}
</div>
</div> *@
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
-5
View File
@@ -1,8 +1,3 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using NLog;
using System.Diagnostics;
namespace EgwControlCenter.App
{
public partial class MainBlazor
+153
View File
@@ -0,0 +1,153 @@
using EgwControlCenter.Core.Models;
using Newtonsoft.Json;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace EgwControlCenter.Core
{
public class AppControlService
{
#region Public Constructors
public AppControlService()
{
Assembly assembly = Assembly.GetExecutingAssembly();
string startDir = Path.GetDirectoryName(assembly.Location)!;
ConfDir = startDir;
DataDir = Environment.GetEnvironmentVariable("ClickOnce_DataDirectory") ?? startDir;
CurrCheck = new ReleaseChecker(ConfDir, DataDir);
Log.Trace($"Folder Setup | {ConfDir} | {DataDir}");
}
#endregion Public Constructors
#region Public Events
public event Action EA_ConfigUpdated = null!;
#endregion Public Events
#region Public Properties
public int RefreshPeriod
{
get => CurrCheck.CurrPatrolCont.RefreshIntSec;
set
{
if (CurrCheck.CurrPatrolCont.RefreshIntSec != value)
{
// verifico ammissibilità
CurrCheck.CurrPatrolCont.RefreshIntSec = value < 1 ? 1 : value > 3600 ? 3600 : value;
ReportConfigUpd();
}
}
}
public int VetoCheck
{
get => CurrCheck.CurrPatrolCont.VetoCheckMinutes;
set
{
if (CurrCheck.CurrPatrolCont.VetoCheckMinutes != value)
{
// verifico ammissibilità
CurrCheck.CurrPatrolCont.VetoCheckMinutes = value < 1 ? 1 : value > 14400 ? 14400 : value;
ReportConfigUpd();
}
}
}
public List<ControlTarget> TargetList
{
get => CurrCheck.CurrPatrolCont.TargetList;
set
{
if (CurrCheck.CurrPatrolCont.TargetList != value)
{
CurrCheck.CurrPatrolCont.TargetList = value;
ReportConfigUpd();
}
}
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Effettua rilettura configurazione e setup controlli...
/// </summary>
/// <returns></returns>
public void DoReloadConfig()
{
try
{
CurrCheck = new ReleaseChecker(ConfDir, DataDir);
Log.Trace($"Riletta config Setup | {ConfDir} | {DataDir}");
}
catch (Exception exc)
{
Log.Equals($"Eccezione in DoReloadConfig{Environment.NewLine}{exc}");
}
ReportConfigUpd();
}
/// <summary>
/// Effettua salvataggio configurazione
/// </summary>
/// <returns></returns>
public void DoSaveConfig()
{
try
{
var rawData = JsonConvert.SerializeObject(CurrCheck.CurrPatrolCont, Formatting.Indented);
if (rawData != null && rawData.Length > 2)
{
File.WriteAllText(CurrCheck.ConfPath, rawData);
Log.Trace($"Effettuato salvataggio Config Setup! | {ConfDir} | {DataDir}");
}
}
catch (Exception exc)
{
Log.Equals($"Eccezione in DoSaveConfig{Environment.NewLine}{exc}");
}
ReportConfigUpd();
}
#endregion Public Methods
#region Private Fields
/// <summary>
/// Classe logger
/// </summary>
private static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Private Properties
private string ConfDir { get; set; } = "";
private ReleaseChecker CurrCheck { get; set; } = null!;
private string DataDir { get; set; } = "";
#endregion Private Properties
#region Private Methods
private void ReportConfigUpd()
{
if (EA_ConfigUpdated != null)
{
EA_ConfigUpdated?.Invoke();
}
}
#endregion Private Methods
}
}
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwControlCenter.Core
{
public class Const
{
public static string EditPwd = "24068Seriate";
}
}
+67 -38
View File
@@ -16,41 +16,39 @@ namespace EgwControlCenter.Core
{
#region Public Constructors
/// <summary>
/// Init classe ReleaseChecker
/// </summary>
/// <param name="appDir"></param>
/// <param name="dataDir"></param>
/// <param name="confName"></param>
public ReleaseChecker(string appDir, string dataDir, string confName)
{
AppDir = appDir;
DataDir = dataDir;
ConfName = confName;
// imposto veto controlli secondo config verifico path...
if (string.IsNullOrEmpty(AppDir))
{
AppDir = AppDomain.CurrentDomain.BaseDirectory;
}
if (File.Exists(ConfPath))
{
var rawData = File.ReadAllText(ConfPath);
if (!string.IsNullOrEmpty(rawData))
{
CurrPatrolCont = JsonConvert.DeserializeObject<PatrolSettings>(rawData) ?? new PatrolSettings();
// imposto il veto dalla conf...
AutoRefreshVeto = TimeSpan.FromMinutes(CurrPatrolCont.VetoCheckMinutes);
}
}
// cerco se presente file status precedente e lo ricarico...
if (File.Exists(StatusPath))
{
var rawData = File.ReadAllText(StatusPath);
if (!string.IsNullOrEmpty(rawData))
{
ListStatus = JsonConvert.DeserializeObject<List<TargetStatus>>(rawData) ?? new List<TargetStatus>();
}
}
InitObj(appDir, dataDir, confName);
}
/// <summary>
/// Init classe ReleaseChecker
/// </summary>
/// <param name="appDir"></param>
/// <param name="dataDir"></param>
public ReleaseChecker(string appDir, string dataDir)
{
InitObj(appDir, dataDir, CPName);
}
#endregion Public Constructors
#region Public Properties
/// <summary>
/// Path file di conf check
/// </summary>
public string ConfPath
{
get => Path.Combine(AppDir, ConfName);
}
/// <summary>
/// Configurazione degli oggetti da monitorare
/// </summary>
@@ -260,25 +258,19 @@ namespace EgwControlCenter.Core
private TimeSpan AutoRefreshVeto { get; set; } = TimeSpan.FromSeconds(30);
private string ConfName { get; set; } = "";
/// <summary>
/// Path file di conf check
/// </summary>
private string ConfPath
{
get => Path.Combine(AppDir, ConfName);
}
private string CPName { get; set; } = "ConfPatrol.json";
private string DataDir { get; set; } = "";
private string StatusName { get; set; } = "LastStatus.json";
private string LSName { get; set; } = "LastStatus.json";
/// <summary>
/// Path file salvataggio status
/// </summary>
private string StatusPath
{
get => Path.Combine(DataDir, StatusName);
//get => Path.Combine(ApplicationDeployment.CurrentDeployment.DataDirectory, StatusName);
get => Path.Combine(DataDir, LSName);
//get => Path.Combine(ApplicationDeployment.CurrentDeployment.DataDirectory, LSName);
}
#endregion Private Properties
@@ -339,6 +331,43 @@ namespace EgwControlCenter.Core
return answ;
}
/// <summary>
/// init privato oggetti
/// </summary>
/// <param name="appDir"></param>
/// <param name="dataDir"></param>
/// <param name="confName"></param>
private void InitObj(string appDir, string dataDir, string confName)
{
AppDir = appDir;
DataDir = dataDir;
ConfName = confName;
// imposto veto controlli secondo config verifico path...
if (string.IsNullOrEmpty(AppDir))
{
AppDir = AppDomain.CurrentDomain.BaseDirectory;
}
if (File.Exists(ConfPath))
{
var rawData = File.ReadAllText(ConfPath);
if (!string.IsNullOrEmpty(rawData))
{
CurrPatrolCont = JsonConvert.DeserializeObject<PatrolSettings>(rawData) ?? new PatrolSettings();
// imposto il veto dalla conf...
AutoRefreshVeto = TimeSpan.FromMinutes(CurrPatrolCont.VetoCheckMinutes);
}
}
// cerco se presente file status precedente e lo ricarico...
if (File.Exists(StatusPath))
{
var rawData = File.ReadAllText(StatusPath);
if (!string.IsNullOrEmpty(rawData))
{
ListStatus = JsonConvert.DeserializeObject<List<TargetStatus>>(rawData) ?? new List<TargetStatus>();
}
}
}
/// <summary>
/// Recupera oggetto releaseDTO da file indicato
/// </summary>
+1 -1
View File
@@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EgwControlCenter", "EgwCont
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EgwControlCenter.Core", "EgwControlCenter.Core\EgwControlCenter.Core.csproj", "{D30ACE10-49B2-4EA8-B16F-C2E8788EBA2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EgwControlCenter.App", "EgwControlCenter.App\EgwControlCenter.App.csproj", "{1D86ABFB-F09B-4E71-9185-0E727D630816}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EgwControlCenter.App", "EgwControlCenter.App\EgwControlCenter.App.csproj", "{1D86ABFB-F09B-4E71-9185-0E727D630816}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+6
View File
@@ -15,6 +15,7 @@
<ItemGroup>
<Compile Include="..\EgwControlCenter.App\Components\Compo\CmpFooter.razor.cs" Link="CmpFooter.razor.cs" />
<Compile Include="..\EgwControlCenter.App\Components\Pages\Index.razor.cs" Link="Index.razor.cs" />
<Compile Include="..\EgwControlCenter.App\MainBlazor.razor.cs" Link="MainBlazor.razor.cs" />
</ItemGroup>
@@ -24,6 +25,11 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.0" />
<PackageReference Include="Microsoft.JSInterop" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EgwControlCenter.Core\EgwControlCenter.Core.csproj" />
</ItemGroup>