6dcd1ef03c
- Update profilo pubblicazione - spostamento conf files
319 lines
11 KiB
C#
319 lines
11 KiB
C#
using System.Windows.Forms;
|
|
using static EgwControlCenter.AccEnum;
|
|
using Microsoft.VisualBasic;
|
|
using EgwControlCenter.Core;
|
|
using System.Diagnostics;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
using System.ComponentModel;
|
|
using EgwControlCenter.Core.Models;
|
|
using Newtonsoft.Json.Linq;
|
|
using Microsoft.VisualBasic.Logging;
|
|
using NLog;
|
|
|
|
namespace EgwControlCenter
|
|
{
|
|
public partial class ControlCenter : Form
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ControlCenter()
|
|
{
|
|
InitializeComponent();
|
|
InitObjects();
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// Modalità di avvio
|
|
/// </summary>
|
|
protected AccEnum.StartMode ModoAvvio = AccEnum.StartMode.STD;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Classe logger
|
|
/// </summary>
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private System.Reflection.AssemblyName CurrAssembly { get; set; } = new System.Reflection.AssemblyName();
|
|
private ReleaseChecker CurrCheck { get; set; } = new ReleaseChecker("", "", "");
|
|
|
|
private bool locCheckOk { get; set; } = false;
|
|
|
|
private bool remCheckOk { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void btnSetup_Click(object sender, EventArgs e)
|
|
{
|
|
string authPwd = Interaction.InputBox("Prego inserire pwd per abilitare lo sblocco", "Verifica Utente", "", 10, 10);
|
|
//verifico passphrase
|
|
if (authPwd == "24068Seriate")
|
|
{
|
|
TargetSetup tgtForm = new TargetSetup();
|
|
tgtForm.Show();
|
|
}
|
|
else
|
|
{
|
|
string message = "La passphrase inserita non è corretta. Impossibile procedere";
|
|
string caption = "Auth Error";
|
|
MessageBoxButtons buttons = MessageBoxButtons.OK;
|
|
DialogResult result;
|
|
result = MessageBox.Show(message, caption, buttons);
|
|
}
|
|
}
|
|
|
|
private void btnUpdate_Click(object sender, EventArgs e)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// effettua un refresh del controllo status...
|
|
locCheckOk = CurrCheck.UpdateLocalStatus(true);
|
|
if (locCheckOk)
|
|
{
|
|
remCheckOk = CurrCheck.CheckRemoteReleases();
|
|
}
|
|
sw.Stop();
|
|
DisplayCheckResult(sw.Elapsed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica stato windows (minimized/normal) e visibilità con tray...
|
|
/// </summary>
|
|
private void CheckFormVisibility()
|
|
{
|
|
// se non può massimizzare imposto COMUNQUE a minimized...
|
|
if (!AccUtils.CRB("windowCanMax"))
|
|
{
|
|
WindowState = FormWindowState.Minimized;
|
|
}
|
|
// SOLO SE se sono in modo STD
|
|
if (ModoAvvio == AccEnum.StartMode.STD)
|
|
{
|
|
// controllo cosa devo mostrare...
|
|
if (WindowState == FormWindowState.Minimized)
|
|
{
|
|
notifyIcon1.Visible = false;
|
|
sendToTray();
|
|
}
|
|
else
|
|
{
|
|
notifyIcon1.Visible = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
notifyIcon1.Visible = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// evento chiusura
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ControlCenter_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
timerCheck.Stop();
|
|
timerCheck.Dispose();
|
|
}
|
|
|
|
private void ControlCenter_Load(object sender, EventArgs e)
|
|
{
|
|
// posiziono in basso a sx...
|
|
Rectangle workArea = Screen.GetWorkingArea(this);
|
|
this.Location = new Point(workArea.Right - Size.Width, workArea.Bottom - Size.Height);
|
|
}
|
|
|
|
/// <summary>
|
|
/// evento resize
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ControlCenter_Resize(object sender, EventArgs e)
|
|
{
|
|
CheckFormVisibility();
|
|
}
|
|
|
|
/// <summary>
|
|
/// evento visualizzazione
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ControlCenter_Shown(object sender, EventArgs e)
|
|
{
|
|
// SOLO SE se sono in modo STD
|
|
if (ModoAvvio == StartMode.STD)
|
|
{
|
|
// avvio minimizzato se richiesto
|
|
if (AccUtils.CRB("startMinimized"))
|
|
{
|
|
// controllo e mando a tray...
|
|
sendToTray();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// crea menù tray x applicazione
|
|
/// </summary>
|
|
private void CreateTrayMenu()
|
|
{
|
|
// Fix testi menù tray...
|
|
trayMenu.Items.Clear();
|
|
// SE permessa massimizzazione...
|
|
trayMenu.Items.Add("Show EgalWare ACC");
|
|
// se è permesso chiudere
|
|
trayMenu.Items.Add("Close EgalWare ACC");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mostra i risultati dell'esito del controllo release
|
|
/// </summary>
|
|
/// <param name="elapsed"></param>
|
|
private void DisplayCheckResult(TimeSpan elapsed)
|
|
{
|
|
var list = new BindingList<VersStatusDTO>(CurrCheck.ListAppStatus);
|
|
dgView.DataSource = list;
|
|
dgView.Columns[0].HeaderCell.Value = "Applicazione";
|
|
dgView.Columns[1].HeaderCell.Value = "Installed";
|
|
dgView.Columns[2].HeaderCell.Value = "Available";
|
|
dgView.Columns[3].HeaderCell.Value = "Note";
|
|
tsLabelOut.Text = $"Last Check: {CurrCheck.LastChecked():yyyy-MM-dd HH:mm:ss}";
|
|
// notifica ballontip se ho aggiornamenti...
|
|
if (CurrCheck.HasUpdate() && WindowState != FormWindowState.Normal)
|
|
{
|
|
notifyIcon1.BalloonTipTitle = "EgalWare's App Control Center";
|
|
notifyIcon1.BalloonTipText = "Update found!";
|
|
notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
|
|
notifyIcon1.BalloonTipClicked += NotifyIcon1_BalloonTipClicked;
|
|
notifyIcon1.ShowBalloonTip(1000);
|
|
}
|
|
}
|
|
|
|
private void InitObjects()
|
|
{
|
|
CurrAssembly = System.Reflection.Assembly.GetExecutingAssembly().GetName();
|
|
Log.Trace($"EgalWare's AppControlCenter Init, v.{CurrAssembly.Version}");
|
|
SetupTrayIcon();
|
|
CreateTrayMenu();
|
|
// recupero info deploy...
|
|
string confDir = AccUtils.confDir;
|
|
string dataDir = Environment.GetEnvironmentVariable("ClickOnce_DataDirectory") ?? AccUtils.dataDir;
|
|
Log.Trace($"Folder Setup | {confDir} | {dataDir}");
|
|
// init obj gestione check...
|
|
CurrCheck = new ReleaseChecker(confDir, dataDir, "ConfPatrol.json");
|
|
tsLabelVers.Text = $"EACC v.{CurrAssembly.Version}";
|
|
tsLabelOut.Text = $"Last Check: {CurrCheck.LastChecked():yyyy-MM-dd HH:mm:ss}";
|
|
timerCheck.Start();
|
|
Log.Trace($"Started timer | {timerCheck.Interval} ms");
|
|
}
|
|
|
|
private void NotifyIcon1_BalloonTipClicked(object? sender, EventArgs e)
|
|
{
|
|
Show();
|
|
WindowState = FormWindowState.Normal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// doppio click su tray icon
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
// SOLO SE PERMESSO mostrare full...
|
|
if (AccUtils.CRB("windowCanMax"))
|
|
{
|
|
Show();
|
|
WindowState = FormWindowState.Normal;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gestisce "andata nel tray" della form
|
|
/// </summary>
|
|
private void sendToTray()
|
|
{
|
|
if (!notifyIcon1.Visible)
|
|
{
|
|
notifyIcon1.BalloonTipTitle = AccUtils.CRS("appName");
|
|
notifyIcon1.BalloonTipText = $"{AccUtils.CRS("appName")} running on tray";
|
|
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
|
|
notifyIcon1.BalloonTipClicked += NotifyIcon1_BalloonTipClicked;
|
|
notifyIcon1.Visible = true;
|
|
notifyIcon1.ShowBalloonTip(100);
|
|
}
|
|
WindowState = FormWindowState.Minimized;
|
|
Hide();
|
|
}
|
|
|
|
private void SetupTrayIcon()
|
|
{
|
|
// fix icon!
|
|
notifyIcon1.Text = $"EgalWare's AppControlCenter | {CurrAssembly.Version}";
|
|
//Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath);
|
|
//notifyIcon1.Icon = Icon.ExtractAssociatedIcon(AccUtils.defIconFilePath);
|
|
}
|
|
|
|
private void timerCheck_Tick(object sender, EventArgs e)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// esegue controllo locale ed eventualmente remoto se scaduto...
|
|
locCheckOk = CurrCheck.UpdateLocalStatus(false);
|
|
if (locCheckOk)
|
|
{
|
|
remCheckOk = CurrCheck.CheckRemoteReleases();
|
|
}
|
|
sw.Stop();
|
|
if (locCheckOk)
|
|
{
|
|
DisplayCheckResult(sw.Elapsed);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// click su menù contestuale in tray
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void trayMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
|
{
|
|
if (e != null && e.ClickedItem != null && !string.IsNullOrEmpty(e.ClickedItem.Text))
|
|
{
|
|
if (e.ClickedItem.Text.StartsWith("Close"))
|
|
{
|
|
#if false
|
|
// stop child adapters...
|
|
closeAllChild();
|
|
#endif
|
|
// chiudo!
|
|
Close();
|
|
}
|
|
else if (e.ClickedItem.Text.StartsWith("Show"))
|
|
{
|
|
if (AccUtils.CRB("windowCanMax"))
|
|
{
|
|
Show();
|
|
WindowState = FormWindowState.Normal;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |