Ok componente editing config!
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user