Merge branch 'develop' into IobMan

This commit is contained in:
Samuele E. Locatelli
2019-12-21 11:17:42 +01:00
8 changed files with 384 additions and 159 deletions
+3
View File
@@ -3,4 +3,7 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<add key="checkPeriod" value="500" />
</appSettings>
</configuration>
-38
View File
@@ -1,38 +0,0 @@
namespace IOB_MAN
{
partial class CForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "CForm";
}
#endregion
}
}
-20
View File
@@ -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();
}
}
}
+3 -6
View File
@@ -33,6 +33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -45,12 +46,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CForm.Designer.cs">
<DependentUpon>CForm.cs</DependentUpon>
</Compile>
<Compile Include="iobAdapt.cs" />
<Compile Include="IOBManPanel.cs">
<SubType>Form</SubType>
</Compile>
@@ -59,6 +55,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="utils.cs" />
<EmbeddedResource Include="IOBManPanel.resx">
<DependentUpon>IOBManPanel.cs</DependentUpon>
</EmbeddedResource>
+85 -22
View File
@@ -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;
}
}
+147 -73
View File
@@ -9,9 +9,13 @@ namespace IOB_MAN
public partial class IOBManPanel : Form
{
/// <summary>
/// Elenco dei processi
/// Elenco IOB gestite
/// </summary>
protected Dictionary<string, iobAdapt> childFormList;
public List<string> IobManList = new List<string>();
/// <summary>
/// Binding source degli elementi gestiti..
/// </summary>
private BindingSource ElencoIOB = new BindingSource();
public IOBManPanel()
{
@@ -21,10 +25,40 @@ namespace IOB_MAN
private void myInit()
{
childFormList = new Dictionary<string, iobAdapt>();
// 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
}
/// <summary>
/// apro eseguibile dump
/// </summary>
@@ -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);
}
/// <summary>
@@ -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<string, iobAdapt> 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
}
/// <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...
/// </summary>
@@ -122,14 +167,18 @@ namespace IOB_MAN
{
int pid = 0;
List<int> proc2rem = new List<int>();
List<iobAdapt> item2rem = new List<iobAdapt>();
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<iobAdapt> item2rem = new List<iobAdapt>();
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();
}
/// <summary>
/// verifica buttons attivi data selezione su gridview...
/// </summary>
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
{
/// <summary>
/// Codice univoco macchina
/// </summary>
public string CodIOB { get; set; }
/// <summary>
/// Identificativo univoco processo
/// </summary>
public int pID { get; set; }
/// <summary>
/// DataOra avvio dell'IOB
/// </summary>
public DateTime startTime { get; set; }
/// <summary>
/// Verifica se il processo sia in RUN
/// </summary>
public bool isRunning { get; set; }
}
}
+36
View File
@@ -0,0 +1,36 @@
using System;
namespace IOB_MAN
{
public class iobAdapt
{
/// <summary>
/// Codice univoco macchina
/// </summary>
public string CodIOB { get; set; }
/// <summary>
/// Identificativo univoco processo
/// </summary>
public int pID { get; set; }
/// <summary>
/// DataOra avvio dell'IOB
/// </summary>
public DateTime startTime { get; set; }
/// <summary>
/// Calcola uptime processo...
/// </summary>
public string uptime
{
get
{
TimeSpan uptime = DateTime.Now.Subtract(startTime);
return utils.FormatTimeSpan(uptime);
}
}
/// <summary>
/// Verifica se il processo sia in RUN
/// </summary>
public bool isRunning { get; set; }
}
}
+110
View File
@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
namespace IOB_MAN
{
public class utils
{
/// <summary>
/// Helper formattazione durata human readable
/// </summary>
/// <param name="timeSpan"></param>
/// <returns></returns>
public static string FormatTimeSpan(TimeSpan timeSpan)
{
Func<Tuple<int, string>, string> tupleFormatter = t => $"{t.Item1} {t.Item2}{(t.Item1 == 1 ? string.Empty : "s")}";
var components = new List<Tuple<int, string>>
{
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
/// <summary>
/// legge conf in formato char
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static char CRC(string key)
{
char answ = '-';
try
{
answ = ConfigurationManager.AppSettings[key].ToCharArray()[0];
}
catch
{ }
return answ;
}
/// <summary>
/// legge conf in formato stringa
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string CRS(string key)
{
string answ = "";
try
{
answ = ConfigurationManager.AppSettings[key].ToString();
}
catch
{ }
return answ;
}
/// <summary>
/// legge conf in formato INT
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static Int32 CRI(string key)
{
int answ = 0;
try
{
answ = Convert.ToInt32(CRS(key));
}
catch
{ }
return answ;
}
/// <summary>
/// legge conf in formato BOOLean
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static bool CRB(string key)
{
bool answ = false;
try
{
answ = Convert.ToBoolean(CRS(key));
}
catch
{ }
return answ;
}
#endregion
}
}