1025 lines
27 KiB
C#
1025 lines
27 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace IOB_MAN
|
|
{
|
|
|
|
|
|
|
|
public partial class IOBManPanel : Form
|
|
{
|
|
#region area gestione hide/maximize finestre
|
|
|
|
private const int SW_SHOWNORMAL = 1;
|
|
private const int SW_SHOWMINIMIZED = 2;
|
|
private const int SW_SHOWMAXIMIZED = 3;
|
|
[DllImport("user32.dll")]
|
|
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Token x cancellazione thread
|
|
/// </summary>
|
|
private CancellationTokenSource _cts;
|
|
/// <summary>
|
|
/// Context x sync thread
|
|
/// </summary>
|
|
private readonly SynchronizationContext synchronizationContext;
|
|
|
|
/// <summary>
|
|
/// Totale processi avviati
|
|
/// </summary>
|
|
protected int numProcAvviati;
|
|
/// <summary>
|
|
/// Totale processi running
|
|
/// </summary>
|
|
protected int numProcRunning;
|
|
/// <summary>
|
|
/// Counter del timer di forceCheck
|
|
/// </summary>
|
|
protected int forceCheckPeriod = 5000;
|
|
/// <summary>
|
|
/// Counter del timer di base
|
|
/// </summary>
|
|
protected int checkPeriod = 1000;
|
|
/// <summary>
|
|
/// Counter del timer UI
|
|
/// </summary>
|
|
protected int uiPeriod = 200;
|
|
/// <summary>
|
|
/// Elenco ARGS (uno per child da avviare)
|
|
/// </summary>
|
|
public List<string> ArgsList = new List<string>();
|
|
/// <summary>
|
|
/// Binding source degli elementi gestiti..
|
|
/// </summary>
|
|
private BindingSource ElencoIOB = new BindingSource();
|
|
/// <summary>
|
|
/// Path dell'exe da chiamare
|
|
/// </summary>
|
|
protected string TargetExe = "";
|
|
/// <summary>
|
|
/// Name dell'exe da chiamare
|
|
/// </summary>
|
|
protected string TargetName = "";
|
|
/// <summary>
|
|
/// Contatore autockeck nativo
|
|
/// </summary>
|
|
protected int tOutAutocheck = 100;
|
|
/// <summary>
|
|
/// semaforo check...
|
|
/// </summary>
|
|
protected bool checkRunning = false;
|
|
/// <summary>
|
|
/// Oggetto locker x evitare problemi timer
|
|
/// </summary>
|
|
private static object _locker = new object();
|
|
/// <summary>
|
|
/// Init classe
|
|
/// </summary>
|
|
public IOBManPanel()
|
|
{
|
|
InitializeComponent();
|
|
synchronizationContext = SynchronizationContext.Current;
|
|
preInit();
|
|
loadConfig();
|
|
initTimers();
|
|
initControls();
|
|
updateStatus();
|
|
}
|
|
|
|
private void initControls()
|
|
{
|
|
// gestione eventi binding source
|
|
ElencoIOB.AddingNew += ElencoIOB_AddingNew;
|
|
ElencoIOB.ListChanged += ElencoIOB_ListChanged;
|
|
// collego tab a binding
|
|
dgvManagedItems.DataSource = ElencoIOB;
|
|
utils.lgInfo("Timer started");
|
|
if (utils.CRB("autoStartProc"))
|
|
{
|
|
apriChild();
|
|
utils.lgInfo("Start processi effettuato");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inizializzazione timers
|
|
/// </summary>
|
|
private void initTimers()
|
|
{
|
|
MainTimer.Interval = checkPeriod;
|
|
MainTimer.Start();
|
|
UI_Timer.Interval = uiPeriod;
|
|
UI_Timer.Start();
|
|
forceCheckTimer.Interval = forceCheckPeriod;
|
|
forceCheckTimer.Start();
|
|
}
|
|
|
|
private void preInit()
|
|
{
|
|
utils.lgInfo("Starting App");
|
|
lblApp.Text = $"{ConfigurationManager.AppSettings.Get("appName")}";
|
|
lblVers.Text = string.Format(" v.{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
|
|
// init prog bar
|
|
tsProgBar.Maximum = 100;
|
|
tsProgBar.Step = 4;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Caricamento configurazione
|
|
/// </summary>
|
|
private void loadConfig()
|
|
{
|
|
ArgsList.Clear();
|
|
checkPeriod = utils.CRI("checkPeriod");
|
|
uiPeriod = utils.CRI("uiPeriod");
|
|
forceCheckPeriod = utils.CRI("forceCheckPeriod");
|
|
TargetExe = utils.CRS("targetExe");
|
|
TargetName = utils.CRS("appNameExt");
|
|
if (string.IsNullOrEmpty(TargetExe))
|
|
{
|
|
TargetExe = string.Format(@"{0}\Resources\Test.bat", Application.StartupPath);
|
|
}
|
|
utils.lgInfo($"Target exe: {TargetExe}");
|
|
// caricamento configurazione argomenti di avvio processi
|
|
loadArgList();
|
|
}
|
|
|
|
private void loadArgList()
|
|
{
|
|
// in primis cerco SE ESISTA il file json di configuraizone parametri avvio
|
|
string fileName = utils.CRS("ArgsConfFile");
|
|
string jsonFileName = $"{Application.StartupPath}{fileName}";
|
|
// verifico se esista il file richeisto
|
|
if (File.Exists(jsonFileName))
|
|
{
|
|
// leggo il file json
|
|
StreamReader reader = new StreamReader(jsonFileName);
|
|
string jsonData = reader.ReadToEnd();
|
|
if (!string.IsNullOrEmpty(jsonData))
|
|
{
|
|
ArgsList = JsonConvert.DeserializeObject<List<string>>(jsonData);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// se non lo trovassi --> uso la chaive in web.config e GENERO un nuovo file x prox avvio...
|
|
string ArgsString = utils.CRS("ArgsList");
|
|
utils.lgInfo($"Args found: {ArgsString}");
|
|
if (string.IsNullOrEmpty(ArgsString))
|
|
{
|
|
var rand = new Random();
|
|
// ne creo rand (5-15) di default...
|
|
for (int i = 0; i < rand.Next(5, 10); i++)
|
|
{
|
|
ArgsList.Add($"127.0.0.{i + 1}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var elenco = ArgsString.Split(',');
|
|
foreach (var item in elenco)
|
|
{
|
|
ArgsList.Add(item);
|
|
}
|
|
}
|
|
// serializzo e salvo file!
|
|
string jsonData = JsonConvert.SerializeObject(ArgsList);
|
|
File.WriteAllText(jsonFileName, jsonData);
|
|
}
|
|
|
|
}
|
|
|
|
private void ElencoIOB_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
|
|
{
|
|
//updateStatus();
|
|
}
|
|
|
|
private void ElencoIOB_AddingNew(object sender, System.ComponentModel.AddingNewEventArgs e)
|
|
{
|
|
updateStatus();
|
|
}
|
|
|
|
private void updateStatus()
|
|
{
|
|
synchronizationContext.Post(new SendOrPostCallback(o =>
|
|
{
|
|
// aggiorno labels
|
|
tsslNumProc.Text = $"Configurati {ArgsList.Count} processi | Avviati: {numProcAvviati} | Attivi: {numProcRunning}";
|
|
bool hlRestart = false;
|
|
// colore da num proc...
|
|
if (numProcRunning == ArgsList.Count)
|
|
{
|
|
tsslNumProc.ForeColor = Color.Green;
|
|
}
|
|
else if (numProcAvviati < ArgsList.Count)
|
|
{
|
|
tsslNumProc.ForeColor = Color.DarkRed;
|
|
hlRestart = true;
|
|
}
|
|
else
|
|
{
|
|
tsslNumProc.ForeColor = Color.OrangeRed;
|
|
hlRestart = true;
|
|
}
|
|
// fix autorestart...
|
|
if (hlRestart)
|
|
{
|
|
chkAutoRestart.ForeColor = System.Drawing.Color.Red;
|
|
chkAutoRestart.Text = "Auto Restart!!!";
|
|
txtTOutAutoCheck.Visible = true;
|
|
btnMoreTOut.Visible = true;
|
|
// se NON checked aggiorno contatore...
|
|
if (!chkAutoRestart.Checked)
|
|
{
|
|
tOutAutocheck--;
|
|
txtTOutAutoCheck.Text = (tOutAutocheck / (1000 / (utils.CRI("checkPeriod")))).ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
chkAutoRestart.ForeColor = DefaultForeColor;
|
|
chkAutoRestart.Text = "Auto Restart";
|
|
txtTOutAutoCheck.Visible = false;
|
|
btnMoreTOut.Visible = false;
|
|
}
|
|
}), "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Apro un child x ogni args specificato
|
|
/// </summary>
|
|
private void apriChild()
|
|
{
|
|
// preventivamente CHIUDO TUTTO
|
|
closeAllChild(true);
|
|
Thread.Sleep(250);
|
|
// avvio i child
|
|
foreach (var item in ArgsList)
|
|
{
|
|
startChildProc(item);
|
|
}
|
|
numProcAvviati = ArgsList.Count;
|
|
numProcRunning = numProcAvviati;
|
|
}
|
|
/// <summary>
|
|
/// Avvio di un child process da parametro ARG
|
|
/// </summary>
|
|
/// <param name="procArg"></param>
|
|
private void startChildProc(string procArg)
|
|
{
|
|
ProcessStartInfo psi = null;
|
|
// da testare x aprire chiudere risorsa...
|
|
psi = new ProcessStartInfo
|
|
{
|
|
FileName = TargetExe,
|
|
Arguments = $"{utils.CRS("BaseArg")}{procArg}",
|
|
WindowStyle = ProcessWindowStyle.Minimized
|
|
};
|
|
|
|
//childProc.StartInfo = psi;
|
|
Process p = Process.Start(psi);
|
|
|
|
// accodo nuovo IOB...
|
|
iobAdapt newIob = new iobAdapt();
|
|
DateTime adesso = DateTime.Now;
|
|
newIob.redisMan = new RedisIobCache("", procArg);
|
|
newIob.CodIOB = procArg;
|
|
newIob.startTime = adesso;
|
|
newIob.pID = p.Id;
|
|
newIob.isRunning = true;
|
|
// aggiungo a datasource
|
|
ElencoIOB.Add(newIob);
|
|
|
|
utils.lgInfo($"Avviato child process per {procArg} | pid: {p.Id}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Apro un child x fare udpate con parametro che impedisca avvio IOB
|
|
/// </summary>
|
|
private void apriOneUpdate()
|
|
{
|
|
ProcessStartInfo psi = null;
|
|
|
|
// da testare x aprire chiudere risorsa...
|
|
psi = new ProcessStartInfo
|
|
{
|
|
FileName = TargetExe,
|
|
Arguments = "MODE=UPD IOB=NONE",
|
|
WindowStyle = ProcessWindowStyle.Normal
|
|
};
|
|
|
|
// avvio processo con using...
|
|
using (Process p = Process.Start(psi))
|
|
{
|
|
p.WaitForExit();
|
|
// ora chiudo current... SE configurato
|
|
if (utils.CRB("closeOnChildUpdate"))
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Chiudo primo processo child (se ce ne sono)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
chiudiChildSel();
|
|
}
|
|
|
|
private void chiudiChildSel()
|
|
{
|
|
int pid = -1;
|
|
// SOLO SE selezionato in dgv...
|
|
if (dgvManagedItems.SelectedRows.Count > 0)
|
|
{
|
|
|
|
foreach (DataGridViewRow riga in dgvManagedItems.SelectedRows)
|
|
{
|
|
// chiudo!
|
|
int.TryParse(riga.Cells["pID"].Value.ToString(), out pid);
|
|
|
|
if (pid >= 0)
|
|
{
|
|
// provo a vedere SE ci sia il processo e di conseguenza lo chiudo...
|
|
try
|
|
{
|
|
Process p = Process.GetProcessById(pid);
|
|
// cerco e chiudo quelli che mi interessano...
|
|
p.CloseMainWindow();
|
|
}
|
|
catch
|
|
{
|
|
// errore era già chiuso..
|
|
}
|
|
// indico NON running su datasource
|
|
((iobAdapt)ElencoIOB[riga.Index]).isRunning = false;
|
|
}
|
|
}
|
|
}
|
|
updateStatus();
|
|
}
|
|
/// <summary>
|
|
/// Cerca nell'elenco il processo corrente
|
|
/// </summary>
|
|
/// <param name="processlist"></param>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public Process myGetProcByID(Process[] processlist, int id)
|
|
{
|
|
return processlist.FirstOrDefault(pr => pr.Id == id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua tutte le verifiche periodiche a timer...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MainTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
MainTimer.Stop();
|
|
if (!checkRunning)
|
|
{
|
|
//checkProcessStatusAsync();
|
|
try
|
|
{
|
|
Task result = checkProcessStatusAsync();
|
|
result.Wait();
|
|
}
|
|
catch (Exception exc)
|
|
{ }
|
|
}
|
|
MainTimer.Start();
|
|
}
|
|
|
|
private void forceCheckTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
if (!checkRunning)
|
|
{
|
|
//checkProcessStatusAsync();
|
|
try
|
|
{
|
|
Task result = checkProcessStatusAsync();
|
|
result.Wait();
|
|
}
|
|
catch (Exception exc)
|
|
{ }
|
|
}
|
|
checkWatchdog();
|
|
// riavvio i timer x sicurezza...
|
|
UI_Timer.Stop();
|
|
UI_Timer.Start();
|
|
MainTimer.Stop();
|
|
MainTimer.Start();
|
|
}
|
|
private void UI_Timer_Tick(object sender, EventArgs e)
|
|
{
|
|
UI_Timer.Stop();
|
|
Task result = updateProgBarAsync();
|
|
result.Wait();
|
|
UI_Timer.Start();
|
|
}
|
|
/// <summary>
|
|
/// Controllo periodico dei processi DA RIATTIVARE
|
|
/// </summary>
|
|
private void checkWatchdog()
|
|
{
|
|
processAutoRestart();
|
|
// aggiorno datagrid!
|
|
dgvManagedItems.Invalidate();
|
|
}
|
|
/// <summary>
|
|
/// Effettua processing autorestart
|
|
/// </summary>
|
|
private void processAutoRestart()
|
|
{
|
|
// verifico se ci siano processi (da ARGS LIST) NON running --> li riavvio!
|
|
List<iobAdapt> proc2restart = new List<iobAdapt>();
|
|
foreach (iobAdapt item in ElencoIOB.List)
|
|
{
|
|
if (!item.isRunning)
|
|
{
|
|
// segno da eliminare e riavviare
|
|
proc2restart.Add(item);
|
|
}
|
|
}
|
|
|
|
// SE abilitato autorestart...
|
|
if (chkAutoRestart.Checked)
|
|
{
|
|
// se ho da riavviare... elimino!
|
|
foreach (var item in proc2restart)
|
|
{
|
|
ElencoIOB.Remove(item);
|
|
utils.lgInfo($"Chiusura processo non running | IOB: {item.CodIOB} | pid: {item.pID}");
|
|
}
|
|
// li faccio ripartire!
|
|
foreach (var item in proc2restart)
|
|
{
|
|
startChildProc(item.CodIOB);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// se autorestart scaduto e NON checked --> lo imposto
|
|
if (tOutAutocheck < 0)
|
|
{
|
|
// lo riattivo
|
|
chkAutoRestart.Checked = true;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Controllo periodico dei processi attivi
|
|
/// </summary>
|
|
private async Task checkProcessStatusAsync()
|
|
{
|
|
var hasLock = false;
|
|
try
|
|
{
|
|
Monitor.TryEnter(_locker, ref hasLock);
|
|
if (!hasLock)
|
|
{
|
|
return;
|
|
}
|
|
if (!checkRunning)
|
|
{
|
|
// reset variabili appoggio
|
|
checkRunning = true;
|
|
// eseguo task!
|
|
await Task.Run(() => checkRunningchild()).ConfigureAwait(false);
|
|
updateStatus();
|
|
checkRunning = false;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (hasLock)
|
|
{
|
|
Monitor.Exit(_locker);
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task updateProgBarAsync()
|
|
{
|
|
await Task.Run(() => performBarAdvance()).ConfigureAwait(false);
|
|
}
|
|
|
|
private void performBarAdvance()
|
|
{
|
|
synchronizationContext.Post(new SendOrPostCallback(o =>
|
|
{
|
|
tsProgBar.PerformStep();
|
|
if (tsProgBar.Value >= tsProgBar.Maximum)
|
|
{
|
|
tsProgBar.Value = 0;
|
|
}
|
|
tsProgBar.Invalidate();
|
|
}), "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se i proc child siano ancora in RUN
|
|
/// </summary>
|
|
private void checkRunningchild()
|
|
{
|
|
List<iobAdapt> item2rem = new List<iobAdapt>();
|
|
IList<iobAdapt> allItems = (IList<iobAdapt>)ElencoIOB.List;
|
|
bool needRem = false;
|
|
|
|
numProcRunning = numProcAvviati;
|
|
|
|
// 2020.02.01 passato chiamata specifica x leggere in 1 sola volta TUTTO elenco processi (x nome)...
|
|
Process[] processList = Process.GetProcessesByName(TargetName);
|
|
|
|
// ciclo
|
|
Parallel.ForEach(allItems, item =>
|
|
{
|
|
needRem = checkIstance(item, item2rem, processList);
|
|
}
|
|
);
|
|
// aggiorno datagrid!
|
|
dgvManagedItems.Invalidate();
|
|
}
|
|
|
|
private bool checkIstance(iobAdapt item, List<iobAdapt> item2rem, Process[] processList)
|
|
{
|
|
bool needRem;
|
|
// verifico se esista il processo...
|
|
try
|
|
{
|
|
if (processList.Length > 0)
|
|
{
|
|
Process p = myGetProcByID(processList, item.pID);
|
|
needRem = p.HasExited;
|
|
}
|
|
else
|
|
{
|
|
needRem = true;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
needRem = true;
|
|
}
|
|
if (needRem)
|
|
{
|
|
if (!item2rem.Contains(item))
|
|
{
|
|
item2rem.Add(item);
|
|
}
|
|
item.isRunning = false;
|
|
numProcRunning--;
|
|
}
|
|
else
|
|
{
|
|
item.isRunning = true;
|
|
}
|
|
|
|
return needRem;
|
|
}
|
|
|
|
private void IOBManPanel_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
closeAllChild(true);
|
|
Thread.Sleep(500);
|
|
closeAllChild(true);
|
|
closeTimers();
|
|
}
|
|
|
|
private void closeTimers()
|
|
{
|
|
MainTimer.Dispose();
|
|
forceCheckTimer.Dispose();
|
|
UI_Timer.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiude tutti i child
|
|
/// </summary>
|
|
/// <param name="doReset">resetta elenco</param>
|
|
private void closeAllChild(bool doReset)
|
|
{
|
|
List<iobAdapt> item2rem = new List<iobAdapt>();
|
|
|
|
foreach (iobAdapt item in ElencoIOB.List)
|
|
{
|
|
item2rem.Add(item);
|
|
}
|
|
// processod a elenco noto
|
|
foreach (var item in item2rem)
|
|
{
|
|
if (item.isRunning)
|
|
{
|
|
try
|
|
{
|
|
Process p = Process.GetProcessById(item.pID);
|
|
p.CloseMainWindow();
|
|
// indico NON running su datasource
|
|
if (doReset)
|
|
{
|
|
ElencoIOB.Remove(item);
|
|
}
|
|
else
|
|
{
|
|
item.isRunning = false;
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
}
|
|
// per sicurezza CERCO i processi x nome...
|
|
string nomeProc = Path.GetFileName(TargetExe).Replace(".exe", "");
|
|
var stillRunningProc = Process.GetProcessesByName(nomeProc);
|
|
if (stillRunningProc != null)
|
|
{
|
|
foreach (var item in stillRunningProc)
|
|
{
|
|
try
|
|
{
|
|
Process p = Process.GetProcessById(item.Id);
|
|
p.CloseMainWindow();
|
|
p.WaitForExit(250);
|
|
if (!p.HasExited)
|
|
{
|
|
utils.lgError($"Process not exited, now calling p.Close()");
|
|
p.Close();
|
|
}
|
|
p.WaitForExit(250);
|
|
if (!p.HasExited)
|
|
{
|
|
utils.lgError($"Process not exited, now calling p.Kill()");
|
|
p.Kill();
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
}
|
|
if (doReset)
|
|
{
|
|
// resetto elenco!
|
|
ElencoIOB.Clear();
|
|
numProcAvviati = 0;
|
|
}
|
|
numProcRunning = 0;
|
|
// update!
|
|
updateStatus();
|
|
}
|
|
|
|
private void dgvManagedItems_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
checkButtons();
|
|
}
|
|
/// <summary>
|
|
/// verifica buttons attivi data selezione su gridview...
|
|
/// </summary>
|
|
private void checkButtons()
|
|
{
|
|
bool selected = (dgvManagedItems.SelectedRows.Count > 0);
|
|
btnClose.Enabled = selected;
|
|
}
|
|
|
|
private void dgvManagedItems_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
// seleziono riga...
|
|
int pid = -1;
|
|
if (e.RowIndex >= 0)
|
|
{
|
|
//dgvManagedItems.CurrentCell = dgvManagedItems.Rows[e.RowIndex].Cells[0];
|
|
|
|
dgvManagedItems.Rows[e.RowIndex].Selected = true;
|
|
using (var riga = dgvManagedItems.Rows[e.RowIndex])
|
|
{
|
|
int.TryParse(riga.Cells["pID"].Value.ToString(), out pid);
|
|
if (pid >= 0)
|
|
{
|
|
// provo a vedere SE ci sia il processo e di conseguenza lo chiudo...
|
|
try
|
|
{
|
|
Process p = Process.GetProcessById(pid);
|
|
// cerco e chiudo quelli che mi interessano...
|
|
var windowsHandle = p.MainWindowHandle;
|
|
ShowWindowAsync(windowsHandle, SW_SHOWNORMAL);
|
|
}
|
|
catch
|
|
{
|
|
// errore era già chiuso..
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnMinimizeAll_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (iobAdapt item in ElencoIOB.List)
|
|
{
|
|
if (item.isRunning)
|
|
{
|
|
try
|
|
{
|
|
Process p = Process.GetProcessById(item.pID);
|
|
// cerco e chiudo quelli che mi interessano...
|
|
var windowsHandle = p.MainWindowHandle;
|
|
ShowWindowAsync(windowsHandle, SW_SHOWMINIMIZED);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
// errore era già chiuso..
|
|
utils.lgError($"Errore in HIDE windows:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnMaximixeAll_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (iobAdapt item in ElencoIOB.List)
|
|
{
|
|
if (item.isRunning)
|
|
{
|
|
try
|
|
{
|
|
Process p = Process.GetProcessById(item.pID);
|
|
// cerco e chiudo quelli che mi interessano...
|
|
var windowsHandle = p.MainWindowHandle;
|
|
ShowWindowAsync(windowsHandle, SW_SHOWNORMAL);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
// errore era già chiuso..
|
|
utils.lgError($"Errore in SHOW windows:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiama apertura + update status...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void openALLToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Chiama Restart (close/start) + update status...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void restartALLToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// chiude tutto
|
|
closeAllChild(false);
|
|
apriChild();
|
|
updateStatus();
|
|
}
|
|
|
|
private void loadConfToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// per iscurezza chiudo tutto
|
|
closeAllChild(true);
|
|
Thread.Sleep(1000);
|
|
// lettura conf file...
|
|
loadConfig();
|
|
// apertura
|
|
apriChild();
|
|
updateStatus();
|
|
}
|
|
|
|
private void updateModeToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// chiude tutte
|
|
closeAllChild(true);
|
|
Thread.Sleep(1000);
|
|
updateStatus();
|
|
// apre solo 1 con conf "fake" x condurre update...
|
|
apriOneUpdate();
|
|
}
|
|
|
|
private void btnCloseAll_Click(object sender, EventArgs e)
|
|
{
|
|
// chiude tutto
|
|
closeAllChild(false);
|
|
//apriChild();
|
|
updateStatus();
|
|
}
|
|
|
|
private void btnRestartAll_Click(object sender, EventArgs e)
|
|
{
|
|
// chiude tutto
|
|
closeAllChild(true);
|
|
apriChild();
|
|
updateStatus();
|
|
}
|
|
|
|
|
|
private void btnOpenAll_Click(object sender, EventArgs e)
|
|
{
|
|
// per iscurezza chiudo tutto
|
|
closeAllChild(true);
|
|
Thread.Sleep(1000);
|
|
// lettura conf file...
|
|
loadConfig();
|
|
// apertura
|
|
apriChild();
|
|
updateStatus();
|
|
}
|
|
/// <summary>
|
|
/// Ramo applicazione (x update)
|
|
/// </summary>
|
|
protected string branchName = "master";
|
|
/// <summary>
|
|
/// URL stringa di UPDATE...
|
|
/// </summary>
|
|
protected string updateUrl
|
|
{
|
|
get
|
|
{
|
|
return string.Format("http://seriate.steamware.net:8083/SWS/MAPO/IOB-MAN/{0}/manifest.xml", branchName);
|
|
}
|
|
}
|
|
|
|
private void AutoUpdater_ApplicationExitEvent()
|
|
{
|
|
utils.lgInfo("Chiusura IOB-WIN");
|
|
Thread.Sleep(100);
|
|
// chiudo tutto
|
|
closeAllChild(true);
|
|
Thread.Sleep(1000);
|
|
utils.lgInfo("Chiusura Applicazione");
|
|
// attendo 1 sec...
|
|
Thread.Sleep(1000);
|
|
// ESCO!
|
|
Application.Exit();
|
|
}
|
|
private void updateIOBWINToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// chiude tutte
|
|
closeAllChild(true);
|
|
Thread.Sleep(1000);
|
|
updateStatus();
|
|
// apre solo 1 con conf "fake" x condurre update...
|
|
apriOneUpdate();
|
|
}
|
|
|
|
private void chkAutoRestart_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
// se tolgo autorestart --> imposto NUOVA scadenza x forzare check
|
|
tOutAutocheck = 60 * utils.CRI("autoRestartTimeoutMin") * (1000 / (utils.CRI("checkPeriod")));
|
|
// fa subito controllo riavvio...
|
|
processAutoRestart();
|
|
}
|
|
|
|
private void btnMoreTOut_Click(object sender, EventArgs e)
|
|
{
|
|
tOutAutocheck += 60 * utils.CRI("autoRestartTimeoutMin") * (1000 / (utils.CRI("checkPeriod")));
|
|
}
|
|
|
|
private void txtTOutAutoCheck_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void forceCloseALLToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// per iscurezza chiudo tutto
|
|
closeAllChild(true);
|
|
Thread.Sleep(1000);
|
|
updateStatus();
|
|
}
|
|
|
|
private void reloadConfRestartToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// per iscurezza chiudo tutto
|
|
closeAllChild(true);
|
|
Thread.Sleep(1000);
|
|
updateStatus();
|
|
// rileggo conf
|
|
loadConfig();
|
|
Thread.Sleep(500);
|
|
// riapro
|
|
apriChild();
|
|
}
|
|
|
|
private void dgvManagedItems_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
if (this.dgvManagedItems.Columns[e.ColumnIndex].Name == "iobOnline")
|
|
{
|
|
if (e.Value != null)
|
|
{
|
|
bool isOk = false;
|
|
bool.TryParse(e.Value.ToString(), out isOk);
|
|
if (!isOk)
|
|
{
|
|
e.CellStyle.BackColor = Color.Red;
|
|
}
|
|
else
|
|
{
|
|
e.CellStyle.BackColor = Color.White;
|
|
}
|
|
}
|
|
}
|
|
else if (this.dgvManagedItems.Columns[e.ColumnIndex].Name == "queueElLen")
|
|
{
|
|
if (e.Value != null)
|
|
{
|
|
int coda = 0;
|
|
int.TryParse(e.Value.ToString(), out coda);
|
|
if (coda > 0)
|
|
{
|
|
e.CellStyle.ForeColor = Color.Red;
|
|
}
|
|
else
|
|
{
|
|
e.CellStyle.ForeColor = Color.Green;
|
|
}
|
|
}
|
|
}
|
|
else if (this.dgvManagedItems.Columns[e.ColumnIndex].Name == "queueFlLen")
|
|
{
|
|
if (e.Value != null)
|
|
{
|
|
int coda = 0;
|
|
int.TryParse(e.Value.ToString(), out coda);
|
|
if (coda > 0)
|
|
{
|
|
e.CellStyle.ForeColor = Color.Red;
|
|
}
|
|
else
|
|
{
|
|
e.CellStyle.ForeColor = Color.Green;
|
|
}
|
|
}
|
|
}
|
|
else if (this.dgvManagedItems.Columns[e.ColumnIndex].Name == "isRunning")
|
|
{
|
|
if (e.Value != null)
|
|
{
|
|
bool isOk = false;
|
|
bool.TryParse(e.Value.ToString(), out isOk);
|
|
if (!isOk)
|
|
{
|
|
e.CellStyle.ForeColor = Color.Red;
|
|
DataGridViewCellStyle currstyle = dgvManagedItems[0, e.RowIndex].Style;
|
|
currstyle.ForeColor = Color.Red;
|
|
dgvManagedItems[1, e.RowIndex].Style = currstyle;
|
|
dgvManagedItems[2, e.RowIndex].Style = currstyle;
|
|
dgvManagedItems[3, e.RowIndex].Style = currstyle;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnStartSel_Click(object sender, EventArgs e)
|
|
{
|
|
// riapro child (SOLO SE non era già aperto...)
|
|
apriChildSel();
|
|
}
|
|
|
|
|
|
private void apriChildSel()
|
|
{
|
|
int pid = -1;
|
|
// SOLO SE selezionato in dgv...
|
|
if (dgvManagedItems.SelectedRows.Count > 0)
|
|
{
|
|
// ciclo su row selezionate
|
|
foreach (DataGridViewRow riga in dgvManagedItems.SelectedRows)
|
|
{
|
|
// verifico che sia già chiuso...
|
|
if (((iobAdapt)ElencoIOB[riga.Index]).isRunning == false)
|
|
{
|
|
startChildProc(((iobAdapt)ElencoIOB[riga.Index]).CodIOB);
|
|
// rimuovo vecchia riga...
|
|
ElencoIOB.RemoveAt(riga.Index);
|
|
}
|
|
}
|
|
}
|
|
updateStatus();
|
|
}
|
|
|
|
}
|
|
|
|
}
|