diff --git a/IOB-MAN/App.config b/IOB-MAN/App.config
index 731f6de6..0b781784 100644
--- a/IOB-MAN/App.config
+++ b/IOB-MAN/App.config
@@ -3,4 +3,7 @@
+
+
+
\ No newline at end of file
diff --git a/IOB-MAN/CForm.Designer.cs b/IOB-MAN/CForm.Designer.cs
deleted file mode 100644
index 9ab0fa44..00000000
--- a/IOB-MAN/CForm.Designer.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-namespace IOB_MAN
-{
- partial class CForm
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.Text = "CForm";
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/IOB-MAN/CForm.cs b/IOB-MAN/CForm.cs
deleted file mode 100644
index 5a6d5447..00000000
--- a/IOB-MAN/CForm.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace IOB_MAN
-{
- public partial class CForm : Form
- {
- public CForm()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/IOB-MAN/IOB-MAN.csproj b/IOB-MAN/IOB-MAN.csproj
index 68105e19..1ea31674 100644
--- a/IOB-MAN/IOB-MAN.csproj
+++ b/IOB-MAN/IOB-MAN.csproj
@@ -33,6 +33,7 @@
+
@@ -45,12 +46,7 @@
-
- Form
-
-
- CForm.cs
-
+
Form
@@ -59,6 +55,7 @@
+
IOBManPanel.cs
diff --git a/IOB-MAN/IOBManPanel.Designer.cs b/IOB-MAN/IOBManPanel.Designer.cs
index c26879b4..df9ab084 100644
--- a/IOB-MAN/IOBManPanel.Designer.cs
+++ b/IOB-MAN/IOBManPanel.Designer.cs
@@ -31,16 +31,21 @@
this.components = new System.ComponentModel.Container();
this.btnOpen = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
- this.childList = new System.Windows.Forms.ListBox();
this.MainTimer = new System.Windows.Forms.Timer(this.components);
+ this.lblNumChild = new System.Windows.Forms.Label();
+ this.dgvManagedItems = new System.Windows.Forms.DataGridView();
+ this.btnCloseAll = new System.Windows.Forms.Button();
+ this.btnRestartAll = new System.Windows.Forms.Button();
+ this.btnUpdateMode = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dgvManagedItems)).BeginInit();
this.SuspendLayout();
//
// btnOpen
//
- this.btnOpen.Location = new System.Drawing.Point(18, 60);
- this.btnOpen.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+ this.btnOpen.Location = new System.Drawing.Point(11, 11);
+ this.btnOpen.Margin = new System.Windows.Forms.Padding(2);
this.btnOpen.Name = "btnOpen";
- this.btnOpen.Size = new System.Drawing.Size(56, 27);
+ this.btnOpen.Size = new System.Drawing.Size(108, 27);
this.btnOpen.TabIndex = 1;
this.btnOpen.Text = "Open";
this.btnOpen.UseVisualStyleBackColor = true;
@@ -48,50 +53,108 @@
//
// btnClose
//
- this.btnClose.Location = new System.Drawing.Point(114, 60);
- this.btnClose.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+ this.btnClose.Location = new System.Drawing.Point(133, 11);
+ this.btnClose.Margin = new System.Windows.Forms.Padding(2);
this.btnClose.Name = "btnClose";
- this.btnClose.Size = new System.Drawing.Size(56, 27);
+ this.btnClose.Size = new System.Drawing.Size(108, 27);
this.btnClose.TabIndex = 70;
- this.btnClose.Text = "Close";
+ this.btnClose.Text = "Close SEL";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
- // childList
- //
- this.childList.FormattingEnabled = true;
- this.childList.Location = new System.Drawing.Point(196, 60);
- this.childList.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
- this.childList.Name = "childList";
- this.childList.Size = new System.Drawing.Size(166, 69);
- this.childList.TabIndex = 71;
- //
// MainTimer
//
+ this.MainTimer.Interval = 500;
this.MainTimer.Tick += new System.EventHandler(this.MainTimer_Tick);
//
+ // lblNumChild
+ //
+ this.lblNumChild.AutoSize = true;
+ this.lblNumChild.Location = new System.Drawing.Point(12, 40);
+ this.lblNumChild.Name = "lblNumChild";
+ this.lblNumChild.Size = new System.Drawing.Size(16, 13);
+ this.lblNumChild.TabIndex = 73;
+ this.lblNumChild.Text = "...";
+ this.lblNumChild.Click += new System.EventHandler(this.lblNumChild_Click);
+ //
+ // dgvManagedItems
+ //
+ this.dgvManagedItems.AllowUserToAddRows = false;
+ this.dgvManagedItems.AllowUserToDeleteRows = false;
+ this.dgvManagedItems.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dgvManagedItems.Location = new System.Drawing.Point(11, 70);
+ this.dgvManagedItems.Name = "dgvManagedItems";
+ this.dgvManagedItems.ReadOnly = true;
+ this.dgvManagedItems.Size = new System.Drawing.Size(647, 246);
+ this.dgvManagedItems.TabIndex = 75;
+ this.dgvManagedItems.SelectionChanged += new System.EventHandler(this.dgvManagedItems_SelectionChanged);
+ //
+ // btnCloseAll
+ //
+ this.btnCloseAll.Location = new System.Drawing.Point(552, 11);
+ this.btnCloseAll.Margin = new System.Windows.Forms.Padding(2);
+ this.btnCloseAll.Name = "btnCloseAll";
+ this.btnCloseAll.Size = new System.Drawing.Size(108, 27);
+ this.btnCloseAll.TabIndex = 77;
+ this.btnCloseAll.Text = "Close ALL";
+ this.btnCloseAll.UseVisualStyleBackColor = true;
+ this.btnCloseAll.Click += new System.EventHandler(this.button1_Click);
+ //
+ // btnRestartAll
+ //
+ this.btnRestartAll.Location = new System.Drawing.Point(429, 11);
+ this.btnRestartAll.Margin = new System.Windows.Forms.Padding(2);
+ this.btnRestartAll.Name = "btnRestartAll";
+ this.btnRestartAll.Size = new System.Drawing.Size(108, 27);
+ this.btnRestartAll.TabIndex = 78;
+ this.btnRestartAll.Text = "Restart ALL";
+ this.btnRestartAll.UseVisualStyleBackColor = true;
+ this.btnRestartAll.Click += new System.EventHandler(this.button2_Click);
+ //
+ // btnUpdateMode
+ //
+ this.btnUpdateMode.Location = new System.Drawing.Point(280, 11);
+ this.btnUpdateMode.Margin = new System.Windows.Forms.Padding(2);
+ this.btnUpdateMode.Name = "btnUpdateMode";
+ this.btnUpdateMode.Size = new System.Drawing.Size(108, 27);
+ this.btnUpdateMode.TabIndex = 79;
+ this.btnUpdateMode.Text = "Update mode";
+ this.btnUpdateMode.UseVisualStyleBackColor = true;
+ //
// IOBManPanel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(745, 596);
- this.Controls.Add(this.childList);
+ this.BackColor = System.Drawing.SystemColors.ControlLight;
+ this.ClientSize = new System.Drawing.Size(670, 409);
+ this.Controls.Add(this.btnUpdateMode);
+ this.Controls.Add(this.btnRestartAll);
+ this.Controls.Add(this.btnCloseAll);
+ this.Controls.Add(this.dgvManagedItems);
+ this.Controls.Add(this.lblNumChild);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnOpen);
this.IsMdiContainer = true;
- this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+ this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "IOBManPanel";
this.Text = "IOB MANAGER";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.IOBManPanel_FormClosing);
+ this.Load += new System.EventHandler(this.IOBManPanel_Load_1);
+ ((System.ComponentModel.ISupportInitialize)(this.dgvManagedItems)).EndInit();
this.ResumeLayout(false);
+ this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnOpen;
private System.Windows.Forms.Button btnClose;
- private System.Windows.Forms.ListBox childList;
private System.Windows.Forms.Timer MainTimer;
- }
+ private System.Windows.Forms.Label lblNumChild;
+ private System.Windows.Forms.DataGridView dgvManagedItems;
+ private System.Windows.Forms.Button btnCloseAll;
+ private System.Windows.Forms.Button btnRestartAll;
+ private System.Windows.Forms.Button btnUpdateMode;
+ }
}
diff --git a/IOB-MAN/IOBManPanel.cs b/IOB-MAN/IOBManPanel.cs
index 110fcfea..86960c16 100644
--- a/IOB-MAN/IOBManPanel.cs
+++ b/IOB-MAN/IOBManPanel.cs
@@ -9,9 +9,13 @@ namespace IOB_MAN
public partial class IOBManPanel : Form
{
///
- /// Elenco dei processi
+ /// Elenco IOB gestite
///
- protected Dictionary childFormList;
+ public List IobManList = new List();
+ ///
+ /// Binding source degli elementi gestiti..
+ ///
+ private BindingSource ElencoIOB = new BindingSource();
public IOBManPanel()
{
@@ -21,10 +25,40 @@ namespace IOB_MAN
private void myInit()
{
- childFormList = new Dictionary();
+ // gestione eventi binding source
+ ElencoIOB.AddingNew += ElencoIOB_AddingNew;
+ ElencoIOB.ListChanged += ElencoIOB_ListChanged;
+ // colelgo tab a binding
+ dgvManagedItems.DataSource = ElencoIOB;
+ MainTimer.Interval = utils.CRI("checkPeriod");
+ string IobList = utils.CRS("IobList");
+ if (!string.IsNullOrEmpty(IobList))
+ {
+ var elenco = IobList.Split(',');
+ foreach (var item in elenco)
+ {
+ IobManList.Add(item);
+ }
+ }
MainTimer.Start();
}
+ 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()
+ {
+ // aggiorno labels
+ lblNumChild.Text = $"Avviati {ElencoIOB.Count} processi child";
+ //dgvManagedItems.bind
+ }
///
/// apro eseguibile dump
///
@@ -33,8 +67,10 @@ namespace IOB_MAN
private void btnOpen_Click(object sender, EventArgs e)
{
apriChild();
+ updateStatus();
}
+
private void apriChild()
{
string path = Application.StartupPath;
@@ -57,9 +93,8 @@ namespace IOB_MAN
newIob.startTime = adesso;
newIob.pID = p.Id;
newIob.isRunning = true;
- childFormList.Add(newIob.CodIOB, newIob);
- // aggiorno elenco...
- childList.Items.Add(p.Id);
+ // aggiungo a datasource
+ ElencoIOB.Add(newIob);
}
///
@@ -70,41 +105,51 @@ namespace IOB_MAN
private void btnClose_Click(object sender, EventArgs e)
{
chiudiChild();
+ updateStatus();
}
private void chiudiChild()
{
- // recupero elenco processi (se almeno 1)
- if (childFormList.Count > 0)
+ int pid = -1;
+ // SOLO SE selezionato in dgv...
+ if (dgvManagedItems.SelectedRows.Count > 0)
{
- KeyValuePair kvp = childFormList.First();
- int pid = kvp.Value.pID;
- // provo a vedere SE ci sia il processo e di conseguenza lo chiudo...
- try
+
+ foreach (DataGridViewRow riga in dgvManagedItems.SelectedRows)
{
- Process p = Process.GetProcessById(pid);
- // cerco e chiudo quelli che mi interessano...
- p.CloseMainWindow();
+ // 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..
+ }
+ // rimuovo da datasource
+ ElencoIOB.RemoveAt(riga.Index);
+ }
}
- catch
- {
- // errore era già chiuso..
- }
- childList.Items.Remove(pid);
- childFormList.Remove(kvp.Key);
}
-#if false
- // Get the current process.
- Process currentProcess = Process.GetCurrentProcess();
-
- // Get all processes running on the local computer.
- Process[] localAll = Process.GetProcesses();
-
- // Get all instances of Notepad running on the local computer.
- // This will return an empty array if notepad isn't running.
- Process[] localByName = Process.GetProcessesByName("notepad");
-#endif
}
+ ///
+ /// Cerca nell'elenco il processo corrente
+ ///
+ ///
+ ///
+ ///
+ public Process myGetProcByID(Process[] processlist, int id)
+ {
+ return processlist.FirstOrDefault(pr => pr.Id == id);
+ }
+
///
/// Effettua tutte le verifiche periodiche...
///
@@ -122,14 +167,18 @@ namespace IOB_MAN
{
int pid = 0;
List proc2rem = new List();
+ List item2rem = new List();
bool needRem = false;
- foreach (var kvp in childFormList)
+
+ // leggo 1 sola volta TUTTO elenco processi...
+ Process[] processList = Process.GetProcesses();
+
+ foreach (iobAdapt item in ElencoIOB.List)
{
// verifico se esista il processo...
- int.TryParse(kvp.Key, out pid);
try
{
- Process p = Process.GetProcessById(pid);
+ Process p = myGetProcByID(processList, item.pID);
needRem = p.HasExited;
}
catch
@@ -138,15 +187,18 @@ namespace IOB_MAN
}
if (needRem)
{
- proc2rem.Add(pid);
+ proc2rem.Add(item.pID);
+ item2rem.Add(item);
}
}
+
// ora procdedo alla cancellazione...
- foreach (var item in proc2rem)
+ foreach (var item in item2rem)
{
- childList.Items.Remove(item);
- childFormList.Remove(item.ToString());
+ ElencoIOB.Remove(item);
}
+ // aggiorno datagrid!
+ dgvManagedItems.Invalidate();
}
private void showUpdate()
@@ -161,44 +213,66 @@ namespace IOB_MAN
private void closeAllChild()
{
- int pid = 0;
- // ultimo controllo e chiusura...
- foreach (var kvp in childFormList)
+ List item2rem = new List();
+
+ foreach (iobAdapt item in ElencoIOB.List)
{
- // verifico se esista il processo...
- int.TryParse(kvp.Key, out pid);
- try
- {
- Process p = Process.GetProcessById(pid);
- p.CloseMainWindow();
- //childList.Items.Remove(pid);
- //childFormList.Remove(pid.ToString());
- }
- catch
- { }
+ item2rem.Add(item);
+ }
+
+
+ foreach (var item in item2rem)
+ {
+ Process p = Process.GetProcessById(item.pID);
+ p.CloseMainWindow();
+ ElencoIOB.Remove(item);
+ }
+
+ }
+
+ private void dgvManagedItems_SelectionChanged(object sender, EventArgs e)
+ {
+ checkButtons();
+ }
+ ///
+ /// verifica buttons attivi data selezione su gridview...
+ ///
+ private void checkButtons()
+ {
+ bool selected = (dgvManagedItems.SelectedRows.Count > 0);
+ btnClose.Enabled = selected;
+ }
+
+ private void IOBManPanel_Load(object sender, EventArgs e)
+ {
+
+ }
+
+ private void button1_Click(object sender, EventArgs e)
+ {
+ closeAllChild();
+ }
+
+ private void button2_Click(object sender, EventArgs e)
+ {
+ // chiude tutto
+ closeAllChild();
+ // FAKE!!! x ora ne apre 10...
+ for (int i = 0; i < 10; i++)
+ {
+ apriChild();
}
}
+ private void lblNumChild_Click(object sender, EventArgs e)
+ {
+
+ }
+
+ private void IOBManPanel_Load_1(object sender, EventArgs e)
+ {
+
+ }
}
-
- public class iobAdapt
- {
- ///
- /// Codice univoco macchina
- ///
- public string CodIOB { get; set; }
- ///
- /// Identificativo univoco processo
- ///
- public int pID { get; set; }
- ///
- /// DataOra avvio dell'IOB
- ///
- public DateTime startTime { get; set; }
- ///
- /// Verifica se il processo sia in RUN
- ///
- public bool isRunning { get; set; }
- }
}
diff --git a/IOB-MAN/iobAdapt.cs b/IOB-MAN/iobAdapt.cs
new file mode 100644
index 00000000..94df4ed5
--- /dev/null
+++ b/IOB-MAN/iobAdapt.cs
@@ -0,0 +1,36 @@
+using System;
+
+namespace IOB_MAN
+{
+ public class iobAdapt
+ {
+ ///
+ /// Codice univoco macchina
+ ///
+ public string CodIOB { get; set; }
+ ///
+ /// Identificativo univoco processo
+ ///
+ public int pID { get; set; }
+ ///
+ /// DataOra avvio dell'IOB
+ ///
+ public DateTime startTime { get; set; }
+ ///
+ /// Calcola uptime processo...
+ ///
+ public string uptime
+ {
+ get
+ {
+ TimeSpan uptime = DateTime.Now.Subtract(startTime);
+ return utils.FormatTimeSpan(uptime);
+ }
+ }
+ ///
+ /// Verifica se il processo sia in RUN
+ ///
+ public bool isRunning { get; set; }
+ }
+
+}
diff --git a/IOB-MAN/utils.cs b/IOB-MAN/utils.cs
new file mode 100644
index 00000000..81a8af52
--- /dev/null
+++ b/IOB-MAN/utils.cs
@@ -0,0 +1,110 @@
+
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+
+namespace IOB_MAN
+{
+ public class utils
+ {
+ ///
+ /// Helper formattazione durata human readable
+ ///
+ ///
+ ///
+ public static string FormatTimeSpan(TimeSpan timeSpan)
+ {
+ Func, string> tupleFormatter = t => $"{t.Item1} {t.Item2}{(t.Item1 == 1 ? string.Empty : "s")}";
+ var components = new List>
+ {
+ Tuple.Create((int) timeSpan.TotalDays, "gg"),
+ Tuple.Create(timeSpan.Hours, "ore"),
+ Tuple.Create(timeSpan.Minutes, "min"),
+ Tuple.Create(timeSpan.Seconds, "sec"),
+ };
+
+ components.RemoveAll(i => i.Item1 == 0);
+
+ string extra = "";
+
+ if (components.Count > 1)
+ {
+ var finalComponent = components[components.Count - 1];
+ components.RemoveAt(components.Count - 1);
+ extra = $" and {tupleFormatter(finalComponent)}";
+ }
+
+ return $"{string.Join(", ", components.Select(tupleFormatter))}{extra}";
+ }
+
+ #region utils lettura app.config
+
+ ///
+ /// legge conf in formato char
+ ///
+ ///
+ ///
+ public static char CRC(string key)
+ {
+ char answ = '-';
+ try
+ {
+ answ = ConfigurationManager.AppSettings[key].ToCharArray()[0];
+ }
+ catch
+ { }
+ return answ;
+ }
+ ///
+ /// legge conf in formato stringa
+ ///
+ ///
+ ///
+ public static string CRS(string key)
+ {
+ string answ = "";
+ try
+ {
+ answ = ConfigurationManager.AppSettings[key].ToString();
+ }
+ catch
+ { }
+ return answ;
+ }
+ ///
+ /// legge conf in formato INT
+ ///
+ ///
+ ///
+ public static Int32 CRI(string key)
+ {
+ int answ = 0;
+ try
+ {
+ answ = Convert.ToInt32(CRS(key));
+ }
+ catch
+ { }
+ return answ;
+ }
+ ///
+ /// legge conf in formato BOOLean
+ ///
+ ///
+ ///
+ public static bool CRB(string key)
+ {
+ bool answ = false;
+ try
+ {
+ answ = Convert.ToBoolean(CRS(key));
+ }
+ catch
+ { }
+ return answ;
+ }
+
+ #endregion
+ }
+}