From 3f63fab6885e3d81063d8f1b70120caff4091514 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 21 Dec 2019 09:36:05 +0100 Subject: [PATCH 1/7] tolto subform non impiegata --- IOB-MAN/CForm.Designer.cs | 38 -------------------------------------- IOB-MAN/CForm.cs | 20 -------------------- IOB-MAN/IOB-MAN.csproj | 8 +------- 3 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 IOB-MAN/CForm.Designer.cs delete mode 100644 IOB-MAN/CForm.cs 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..664958c9 100644 --- a/IOB-MAN/IOB-MAN.csproj +++ b/IOB-MAN/IOB-MAN.csproj @@ -1,4 +1,4 @@ - + @@ -45,12 +45,6 @@ - - Form - - - CForm.cs - Form From 84e00a7a4b330bd389f03b4fbb6c5edf163684f9 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 21 Dec 2019 09:37:25 +0100 Subject: [PATCH 2/7] Fix procedura chiusura --- IOB-MAN/IOBManPanel.Designer.cs | 27 ++++++++++++----- IOB-MAN/IOBManPanel.cs | 51 +++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/IOB-MAN/IOBManPanel.Designer.cs b/IOB-MAN/IOBManPanel.Designer.cs index c26879b4..6bf5abd1 100644 --- a/IOB-MAN/IOBManPanel.Designer.cs +++ b/IOB-MAN/IOBManPanel.Designer.cs @@ -33,12 +33,13 @@ 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.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.Margin = new System.Windows.Forms.Padding(2); this.btnOpen.Name = "btnOpen"; this.btnOpen.Size = new System.Drawing.Size(56, 27); this.btnOpen.TabIndex = 1; @@ -49,7 +50,7 @@ // btnClose // this.btnClose.Location = new System.Drawing.Point(114, 60); - this.btnClose.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnClose.Margin = new System.Windows.Forms.Padding(2); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(56, 27); this.btnClose.TabIndex = 70; @@ -60,30 +61,41 @@ // 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.Location = new System.Drawing.Point(223, 60); + this.childList.Margin = new System.Windows.Forms.Padding(2); this.childList.Name = "childList"; - this.childList.Size = new System.Drawing.Size(166, 69); + this.childList.Size = new System.Drawing.Size(166, 264); this.childList.TabIndex = 71; // // MainTimer // this.MainTimer.Tick += new System.EventHandler(this.MainTimer_Tick); // + // lblNumChild + // + this.lblNumChild.AutoSize = true; + this.lblNumChild.Location = new System.Drawing.Point(18, 119); + this.lblNumChild.Name = "lblNumChild"; + this.lblNumChild.Size = new System.Drawing.Size(16, 13); + this.lblNumChild.TabIndex = 73; + this.lblNumChild.Text = "..."; + // // 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.lblNumChild); this.Controls.Add(this.childList); 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.ResumeLayout(false); + this.PerformLayout(); } @@ -92,6 +104,7 @@ private System.Windows.Forms.Button btnClose; private System.Windows.Forms.ListBox childList; private System.Windows.Forms.Timer MainTimer; - } + private System.Windows.Forms.Label lblNumChild; + } } diff --git a/IOB-MAN/IOBManPanel.cs b/IOB-MAN/IOBManPanel.cs index 110fcfea..c742f6e0 100644 --- a/IOB-MAN/IOBManPanel.cs +++ b/IOB-MAN/IOBManPanel.cs @@ -12,6 +12,10 @@ namespace IOB_MAN /// Elenco dei processi /// protected Dictionary childFormList; + /// + /// Lista di IOB gestiti + /// + public List ElencoIOB = new List(); public IOBManPanel() { @@ -25,6 +29,11 @@ namespace IOB_MAN MainTimer.Start(); } + private void updateStatus() + { + // aggiorno labels + lblNumChild.Text = $"Avviati {childFormList.Count} / {childList.Items.Count} processi child"; + } /// /// apro eseguibile dump /// @@ -33,8 +42,10 @@ namespace IOB_MAN private void btnOpen_Click(object sender, EventArgs e) { apriChild(); + updateStatus(); } + private void apriChild() { string path = Application.StartupPath; @@ -70,15 +81,51 @@ namespace IOB_MAN private void btnClose_Click(object sender, EventArgs e) { chiudiChild(); + updateStatus(); } private void chiudiChild() { + int pid = -1; + string currSelection = ""; // recupero elenco processi (se almeno 1) if (childFormList.Count > 0) { KeyValuePair kvp = childFormList.First(); - int pid = kvp.Value.pID; + // se ce ne fosse uno selezionato uso quello... + try + { + currSelection = childList.SelectedItem.ToString(); + if (currSelection != null) + { + pid = childFormList[currSelection].pID; + } + else + { + pid = kvp.Value.pID; + } + } + catch + { + pid = kvp.Value.pID; + } + + } + else + { + try + { + currSelection = childList.SelectedItem.ToString(); + if (currSelection != null) + { + pid = childFormList[currSelection].pID; + } + } + catch + { } + } + if (pid >= 0) + { // provo a vedere SE ci sia il processo e di conseguenza lo chiudo... try { @@ -91,7 +138,7 @@ namespace IOB_MAN // errore era già chiuso.. } childList.Items.Remove(pid); - childFormList.Remove(kvp.Key); + childFormList.Remove(currSelection); } #if false // Get the current process. From 2afe1ead7b099d0633e355a1445368d42e802f7a Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 21 Dec 2019 09:52:02 +0100 Subject: [PATCH 3/7] bozza gestione elencoIOB --- IOB-MAN/IOBManPanel.Designer.cs | 16 ++++++++++++++++ IOB-MAN/IOBManPanel.cs | 25 +++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/IOB-MAN/IOBManPanel.Designer.cs b/IOB-MAN/IOBManPanel.Designer.cs index 6bf5abd1..46ccc97b 100644 --- a/IOB-MAN/IOBManPanel.Designer.cs +++ b/IOB-MAN/IOBManPanel.Designer.cs @@ -34,6 +34,8 @@ 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(); + ((System.ComponentModel.ISupportInitialize)(this.dgvManagedItems)).BeginInit(); this.SuspendLayout(); // // btnOpen @@ -80,11 +82,23 @@ this.lblNumChild.TabIndex = 73; this.lblNumChild.Text = "..."; // + // dgvManagedItems + // + this.dgvManagedItems.AllowUserToAddRows = false; + this.dgvManagedItems.AllowUserToDeleteRows = false; + this.dgvManagedItems.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvManagedItems.Location = new System.Drawing.Point(420, 60); + this.dgvManagedItems.Name = "dgvManagedItems"; + this.dgvManagedItems.ReadOnly = true; + this.dgvManagedItems.Size = new System.Drawing.Size(240, 150); + this.dgvManagedItems.TabIndex = 75; + // // 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.dgvManagedItems); this.Controls.Add(this.lblNumChild); this.Controls.Add(this.childList); this.Controls.Add(this.btnClose); @@ -94,6 +108,7 @@ this.Name = "IOBManPanel"; this.Text = "IOB MANAGER"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.IOBManPanel_FormClosing); + ((System.ComponentModel.ISupportInitialize)(this.dgvManagedItems)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -105,6 +120,7 @@ private System.Windows.Forms.ListBox childList; private System.Windows.Forms.Timer MainTimer; private System.Windows.Forms.Label lblNumChild; + private System.Windows.Forms.DataGridView dgvManagedItems; } } diff --git a/IOB-MAN/IOBManPanel.cs b/IOB-MAN/IOBManPanel.cs index c742f6e0..ba6d6fe8 100644 --- a/IOB-MAN/IOBManPanel.cs +++ b/IOB-MAN/IOBManPanel.cs @@ -13,9 +13,9 @@ namespace IOB_MAN /// protected Dictionary childFormList; /// - /// Lista di IOB gestiti + /// Binding source degli elementi gestiti.. /// - public List ElencoIOB = new List(); + private BindingSource ElencoIOB = new BindingSource(); public IOBManPanel() { @@ -26,13 +26,29 @@ 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.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 {childFormList.Count} / {childList.Items.Count} processi child"; + //dgvManagedItems.bind } /// /// apro eseguibile dump @@ -71,6 +87,8 @@ namespace IOB_MAN childFormList.Add(newIob.CodIOB, newIob); // aggiorno elenco... childList.Items.Add(p.Id); + // aggiungo a datasource + ElencoIOB.Add(newIob); } /// @@ -137,6 +155,9 @@ namespace IOB_MAN { // errore era già chiuso.. } + // rimuovo da datasource + ElencoIOB.Remove(childFormList[currSelection]); + // rimuovo altri childList.Items.Remove(pid); childFormList.Remove(currSelection); } From 271ed4390da7b722112024a44b4f3dd619ce170e Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 21 Dec 2019 10:19:45 +0100 Subject: [PATCH 4/7] OK management (preliminare...) --- IOB-MAN/IOB-MAN.csproj | 3 +- IOB-MAN/IOBManPanel.Designer.cs | 12 ++--- IOB-MAN/IOBManPanel.cs | 77 +++++++++++++++++++++++---------- IOB-MAN/iobAdapt.cs | 28 ++++++++++++ 4 files changed, 92 insertions(+), 28 deletions(-) create mode 100644 IOB-MAN/iobAdapt.cs diff --git a/IOB-MAN/IOB-MAN.csproj b/IOB-MAN/IOB-MAN.csproj index 664958c9..5d79b056 100644 --- a/IOB-MAN/IOB-MAN.csproj +++ b/IOB-MAN/IOB-MAN.csproj @@ -1,4 +1,4 @@ - + @@ -45,6 +45,7 @@ + Form diff --git a/IOB-MAN/IOBManPanel.Designer.cs b/IOB-MAN/IOBManPanel.Designer.cs index 46ccc97b..5fe47b10 100644 --- a/IOB-MAN/IOBManPanel.Designer.cs +++ b/IOB-MAN/IOBManPanel.Designer.cs @@ -63,10 +63,10 @@ // childList // this.childList.FormattingEnabled = true; - this.childList.Location = new System.Drawing.Point(223, 60); + this.childList.Location = new System.Drawing.Point(21, 160); this.childList.Margin = new System.Windows.Forms.Padding(2); this.childList.Name = "childList"; - this.childList.Size = new System.Drawing.Size(166, 264); + this.childList.Size = new System.Drawing.Size(166, 160); this.childList.TabIndex = 71; // // MainTimer @@ -87,17 +87,19 @@ this.dgvManagedItems.AllowUserToAddRows = false; this.dgvManagedItems.AllowUserToDeleteRows = false; this.dgvManagedItems.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvManagedItems.Location = new System.Drawing.Point(420, 60); + this.dgvManagedItems.Location = new System.Drawing.Point(192, 60); this.dgvManagedItems.Name = "dgvManagedItems"; this.dgvManagedItems.ReadOnly = true; - this.dgvManagedItems.Size = new System.Drawing.Size(240, 150); + this.dgvManagedItems.Size = new System.Drawing.Size(468, 260); this.dgvManagedItems.TabIndex = 75; + this.dgvManagedItems.SelectionChanged += new System.EventHandler(this.dgvManagedItems_SelectionChanged); // // 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.BackColor = System.Drawing.SystemColors.ControlLight; + this.ClientSize = new System.Drawing.Size(670, 409); this.Controls.Add(this.dgvManagedItems); this.Controls.Add(this.lblNumChild); this.Controls.Add(this.childList); diff --git a/IOB-MAN/IOBManPanel.cs b/IOB-MAN/IOBManPanel.cs index ba6d6fe8..426164d3 100644 --- a/IOB-MAN/IOBManPanel.cs +++ b/IOB-MAN/IOBManPanel.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Windows.Forms; namespace IOB_MAN @@ -47,7 +46,7 @@ namespace IOB_MAN private void updateStatus() { // aggiorno labels - lblNumChild.Text = $"Avviati {childFormList.Count} / {childList.Items.Count} processi child"; + lblNumChild.Text = $"Avviati {childFormList.Count} / {childList.Items.Count} / {ElencoIOB.Count} processi child"; //dgvManagedItems.bind } /// @@ -106,6 +105,39 @@ namespace IOB_MAN { int pid = -1; string currSelection = ""; + // 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.. + } + // rimuovo da datasource + ElencoIOB.RemoveAt(riga.Index); + // rimuovo altri + childList.Items.Remove(pid); + childFormList.Remove(currSelection); + } + } + } + + +#if false // recupero elenco processi (se almeno 1) if (childFormList.Count > 0) { @@ -161,6 +193,10 @@ namespace IOB_MAN childList.Items.Remove(pid); childFormList.Remove(currSelection); } + +#endif + + #if false // Get the current process. Process currentProcess = Process.GetCurrentProcess(); @@ -247,26 +283,23 @@ namespace IOB_MAN } } + 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) + { + + } } - - 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..86ffe969 --- /dev/null +++ b/IOB-MAN/iobAdapt.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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; } + /// + /// Verifica se il processo sia in RUN + /// + public bool isRunning { get; set; } + } +} From 20db8feb6ece6fc4dcd1d8eea6ff9046f6ba0abf Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 21 Dec 2019 10:39:48 +0100 Subject: [PATCH 5/7] Completato fix check processi + chiusura in blocco --- IOB-MAN/IOBManPanel.cs | 57 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/IOB-MAN/IOBManPanel.cs b/IOB-MAN/IOBManPanel.cs index 426164d3..7226eac0 100644 --- a/IOB-MAN/IOBManPanel.cs +++ b/IOB-MAN/IOBManPanel.cs @@ -7,10 +7,6 @@ namespace IOB_MAN { public partial class IOBManPanel : Form { - /// - /// Elenco dei processi - /// - protected Dictionary childFormList; /// /// Binding source degli elementi gestiti.. /// @@ -24,7 +20,6 @@ namespace IOB_MAN private void myInit() { - childFormList = new Dictionary(); // gestione eventi binding source ElencoIOB.AddingNew += ElencoIOB_AddingNew; ElencoIOB.ListChanged += ElencoIOB_ListChanged; @@ -46,7 +41,7 @@ namespace IOB_MAN private void updateStatus() { // aggiorno labels - lblNumChild.Text = $"Avviati {childFormList.Count} / {childList.Items.Count} / {ElencoIOB.Count} processi child"; + lblNumChild.Text = $"Avviati {childList.Items.Count} / {ElencoIOB.Count} processi child"; //dgvManagedItems.bind } /// @@ -83,7 +78,6 @@ 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 @@ -131,7 +125,6 @@ namespace IOB_MAN ElencoIOB.RemoveAt(riga.Index); // rimuovo altri childList.Items.Remove(pid); - childFormList.Remove(currSelection); } } } @@ -226,14 +219,15 @@ namespace IOB_MAN { int pid = 0; List proc2rem = new List(); + List item2rem = new List(); bool needRem = false; - foreach (var kvp in childFormList) + + 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 = Process.GetProcessById(item.pID); needRem = p.HasExited; } catch @@ -242,14 +236,22 @@ namespace IOB_MAN } if (needRem) { - proc2rem.Add(pid); + proc2rem.Add(item.pID); + item2rem.Add(item); + //item.isRunning = false; } } + + + foreach (var item in item2rem) + { + ElencoIOB.Remove(item); + } + // ora procdedo alla cancellazione... foreach (var item in proc2rem) { childList.Items.Remove(item); - childFormList.Remove(item.ToString()); } } @@ -265,22 +267,21 @@ namespace IOB_MAN private void closeAllChild() { - int pid = 0; - // ultimo controllo e chiusura... - foreach (var kvp in childFormList) - { - // 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 - { } + List item2rem = new List(); + + foreach (iobAdapt item in ElencoIOB.List) + { + 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) From d55b863bf6cbb4d579100f3ba87d5e44673d5207 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 21 Dec 2019 10:46:44 +0100 Subject: [PATCH 6/7] OK comportamento generale... --- IOB-MAN/IOBManPanel.Designer.cs | 71 +++++++++++++++++++++++---------- IOB-MAN/IOBManPanel.cs | 41 +++++++++++++------ 2 files changed, 79 insertions(+), 33 deletions(-) diff --git a/IOB-MAN/IOBManPanel.Designer.cs b/IOB-MAN/IOBManPanel.Designer.cs index 5fe47b10..4d7fd6cf 100644 --- a/IOB-MAN/IOBManPanel.Designer.cs +++ b/IOB-MAN/IOBManPanel.Designer.cs @@ -31,19 +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.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; @@ -51,24 +53,15 @@ // // btnClose // - this.btnClose.Location = new System.Drawing.Point(114, 60); + 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(21, 160); - this.childList.Margin = new System.Windows.Forms.Padding(2); - this.childList.Name = "childList"; - this.childList.Size = new System.Drawing.Size(166, 160); - this.childList.TabIndex = 71; - // // MainTimer // this.MainTimer.Tick += new System.EventHandler(this.MainTimer_Tick); @@ -76,33 +69,68 @@ // lblNumChild // this.lblNumChild.AutoSize = true; - this.lblNumChild.Location = new System.Drawing.Point(18, 119); + 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(192, 60); + this.dgvManagedItems.Location = new System.Drawing.Point(11, 70); this.dgvManagedItems.Name = "dgvManagedItems"; this.dgvManagedItems.ReadOnly = true; - this.dgvManagedItems.Size = new System.Drawing.Size(468, 260); + 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.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.childList); this.Controls.Add(this.btnClose); this.Controls.Add(this.btnOpen); this.IsMdiContainer = true; @@ -110,6 +138,7 @@ 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(); @@ -119,10 +148,12 @@ #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 7226eac0..be6ec6d1 100644 --- a/IOB-MAN/IOBManPanel.cs +++ b/IOB-MAN/IOBManPanel.cs @@ -41,7 +41,7 @@ namespace IOB_MAN private void updateStatus() { // aggiorno labels - lblNumChild.Text = $"Avviati {childList.Items.Count} / {ElencoIOB.Count} processi child"; + lblNumChild.Text = $"Avviati {ElencoIOB.Count} processi child"; //dgvManagedItems.bind } /// @@ -78,8 +78,6 @@ namespace IOB_MAN newIob.startTime = adesso; newIob.pID = p.Id; newIob.isRunning = true; - // aggiorno elenco... - childList.Items.Add(p.Id); // aggiungo a datasource ElencoIOB.Add(newIob); } @@ -98,7 +96,6 @@ namespace IOB_MAN private void chiudiChild() { int pid = -1; - string currSelection = ""; // SOLO SE selezionato in dgv... if (dgvManagedItems.SelectedRows.Count > 0) { @@ -123,8 +120,6 @@ namespace IOB_MAN } // rimuovo da datasource ElencoIOB.RemoveAt(riga.Index); - // rimuovo altri - childList.Items.Remove(pid); } } } @@ -242,17 +237,11 @@ namespace IOB_MAN } } - + // ora procdedo alla cancellazione... foreach (var item in item2rem) { ElencoIOB.Remove(item); } - - // ora procdedo alla cancellazione... - foreach (var item in proc2rem) - { - childList.Items.Remove(item); - } } private void showUpdate() @@ -301,6 +290,32 @@ namespace IOB_MAN { } + + 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) + { + + } } } From 59034631234328bcc14c0aeea0f78f46c4e22647 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 21 Dec 2019 11:17:36 +0100 Subject: [PATCH 7/7] NOTEVOLE speedup check processi!!!! --- IOB-MAN/App.config | 3 + IOB-MAN/IOB-MAN.csproj | 2 + IOB-MAN/IOBManPanel.Designer.cs | 1 + IOB-MAN/IOBManPanel.cs | 111 ++++++++++---------------------- IOB-MAN/iobAdapt.cs | 16 +++-- IOB-MAN/utils.cs | 110 +++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 81 deletions(-) create mode 100644 IOB-MAN/utils.cs 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/IOB-MAN.csproj b/IOB-MAN/IOB-MAN.csproj index 5d79b056..1ea31674 100644 --- a/IOB-MAN/IOB-MAN.csproj +++ b/IOB-MAN/IOB-MAN.csproj @@ -33,6 +33,7 @@ + @@ -54,6 +55,7 @@ + IOBManPanel.cs diff --git a/IOB-MAN/IOBManPanel.Designer.cs b/IOB-MAN/IOBManPanel.Designer.cs index 4d7fd6cf..df9ab084 100644 --- a/IOB-MAN/IOBManPanel.Designer.cs +++ b/IOB-MAN/IOBManPanel.Designer.cs @@ -64,6 +64,7 @@ // // MainTimer // + this.MainTimer.Interval = 500; this.MainTimer.Tick += new System.EventHandler(this.MainTimer_Tick); // // lblNumChild diff --git a/IOB-MAN/IOBManPanel.cs b/IOB-MAN/IOBManPanel.cs index be6ec6d1..86960c16 100644 --- a/IOB-MAN/IOBManPanel.cs +++ b/IOB-MAN/IOBManPanel.cs @@ -1,12 +1,17 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Windows.Forms; namespace IOB_MAN { public partial class IOBManPanel : Form { + /// + /// Elenco IOB gestite + /// + public List IobManList = new List(); /// /// Binding source degli elementi gestiti.. /// @@ -25,6 +30,16 @@ namespace IOB_MAN 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(); } @@ -123,80 +138,18 @@ namespace IOB_MAN } } } - - -#if false - // recupero elenco processi (se almeno 1) - if (childFormList.Count > 0) - { - KeyValuePair kvp = childFormList.First(); - // se ce ne fosse uno selezionato uso quello... - try - { - currSelection = childList.SelectedItem.ToString(); - if (currSelection != null) - { - pid = childFormList[currSelection].pID; - } - else - { - pid = kvp.Value.pID; - } - } - catch - { - pid = kvp.Value.pID; - } - - } - else - { - try - { - currSelection = childList.SelectedItem.ToString(); - if (currSelection != null) - { - pid = childFormList[currSelection].pID; - } - } - catch - { } - } - 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.Remove(childFormList[currSelection]); - // rimuovo altri - childList.Items.Remove(pid); - childFormList.Remove(currSelection); - } - -#endif - - -#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... /// @@ -217,12 +170,15 @@ namespace IOB_MAN List item2rem = new List(); bool needRem = false; + // leggo 1 sola volta TUTTO elenco processi... + Process[] processList = Process.GetProcesses(); + foreach (iobAdapt item in ElencoIOB.List) { // verifico se esista il processo... try { - Process p = Process.GetProcessById(item.pID); + Process p = myGetProcByID(processList, item.pID); needRem = p.HasExited; } catch @@ -233,7 +189,6 @@ namespace IOB_MAN { proc2rem.Add(item.pID); item2rem.Add(item); - //item.isRunning = false; } } @@ -242,6 +197,8 @@ namespace IOB_MAN { ElencoIOB.Remove(item); } + // aggiorno datagrid! + dgvManagedItems.Invalidate(); } private void showUpdate() @@ -259,8 +216,8 @@ namespace IOB_MAN List item2rem = new List(); foreach (iobAdapt item in ElencoIOB.List) - { - item2rem.Add(item); + { + item2rem.Add(item); } diff --git a/IOB-MAN/iobAdapt.cs b/IOB-MAN/iobAdapt.cs index 86ffe969..94df4ed5 100644 --- a/IOB-MAN/iobAdapt.cs +++ b/IOB-MAN/iobAdapt.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace IOB_MAN { @@ -21,8 +17,20 @@ namespace IOB_MAN /// 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 + } +}