From 1cf33caac300a27ac4481f5bad54ecb74f8dc3c1 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 20 Feb 2021 12:37:17 +0100 Subject: [PATCH] ok eliminazione files vecchi + test connesisone camera auto da helper --- Thermo.Cam.Setup/MainForm.Designer.cs | 68 ++++++++++++++++----------- Thermo.Cam.Setup/MainForm.cs | 11 +++-- Thermo.Cam.Utils/TCContr.cs | 36 ++++++++++++++ 3 files changed, 83 insertions(+), 32 deletions(-) diff --git a/Thermo.Cam.Setup/MainForm.Designer.cs b/Thermo.Cam.Setup/MainForm.Designer.cs index bd550e73..3daad559 100644 --- a/Thermo.Cam.Setup/MainForm.Designer.cs +++ b/Thermo.Cam.Setup/MainForm.Designer.cs @@ -67,7 +67,6 @@ this.chkLive = new System.Windows.Forms.CheckBox(); this.btnSave = new System.Windows.Forms.Button(); this.labelTitle = new System.Windows.Forms.Label(); - this.lblReadTemp = new System.Windows.Forms.Label(); this.lblPoint = new System.Windows.Forms.Label(); this.pBoxB = new System.Windows.Forms.PictureBox(); this.lblImgA = new System.Windows.Forms.Label(); @@ -78,6 +77,8 @@ this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.txtMaxDays = new System.Windows.Forms.TextBox(); + this.btnDeleteOlder = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pBoxA)).BeginInit(); @@ -179,6 +180,8 @@ this.panelCmd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.panelCmd.BackColor = System.Drawing.SystemColors.ControlDark; + this.panelCmd.Controls.Add(this.btnDeleteOlder); + this.panelCmd.Controls.Add(this.txtMaxDays); this.panelCmd.Controls.Add(this.chkSaveAll); this.panelCmd.Controls.Add(this.btnLoad); this.panelCmd.Controls.Add(this.groupBox3); @@ -242,11 +245,11 @@ // lblMaxTemp // this.lblMaxTemp.AutoSize = true; - this.lblMaxTemp.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lblMaxTemp.Location = new System.Drawing.Point(89, 42); - this.lblMaxTemp.MinimumSize = new System.Drawing.Size(80, 0); + this.lblMaxTemp.ForeColor = System.Drawing.SystemColors.ButtonHighlight; + this.lblMaxTemp.Location = new System.Drawing.Point(78, 91); + this.lblMaxTemp.MinimumSize = new System.Drawing.Size(40, 0); this.lblMaxTemp.Name = "lblMaxTemp"; - this.lblMaxTemp.Size = new System.Drawing.Size(80, 13); + this.lblMaxTemp.Size = new System.Drawing.Size(40, 13); this.lblMaxTemp.TabIndex = 17; this.lblMaxTemp.Text = "? °C"; this.lblMaxTemp.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -254,13 +257,14 @@ // lblMinTemp // this.lblMinTemp.AutoSize = true; - this.lblMinTemp.ForeColor = System.Drawing.SystemColors.ControlText; - this.lblMinTemp.Location = new System.Drawing.Point(7, 42); - this.lblMinTemp.MinimumSize = new System.Drawing.Size(80, 0); + this.lblMinTemp.ForeColor = System.Drawing.SystemColors.ButtonHighlight; + this.lblMinTemp.Location = new System.Drawing.Point(78, 64); + this.lblMinTemp.MinimumSize = new System.Drawing.Size(40, 0); this.lblMinTemp.Name = "lblMinTemp"; - this.lblMinTemp.Size = new System.Drawing.Size(80, 13); + this.lblMinTemp.Size = new System.Drawing.Size(40, 13); this.lblMinTemp.TabIndex = 16; this.lblMinTemp.Text = "? °C"; + this.lblMinTemp.TextAlign = System.Drawing.ContentAlignment.TopRight; // // label6 // @@ -273,9 +277,9 @@ // // txtMaxScale // - this.txtMaxScale.Location = new System.Drawing.Point(92, 88); + this.txtMaxScale.Location = new System.Drawing.Point(120, 88); this.txtMaxScale.Name = "txtMaxScale"; - this.txtMaxScale.Size = new System.Drawing.Size(77, 20); + this.txtMaxScale.Size = new System.Drawing.Size(49, 20); this.txtMaxScale.TabIndex = 12; this.txtMaxScale.Text = "60"; this.txtMaxScale.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; @@ -292,9 +296,9 @@ // // txtMinScale // - this.txtMinScale.Location = new System.Drawing.Point(92, 61); + this.txtMinScale.Location = new System.Drawing.Point(120, 61); this.txtMinScale.Name = "txtMinScale"; - this.txtMinScale.Size = new System.Drawing.Size(77, 20); + this.txtMinScale.Size = new System.Drawing.Size(49, 20); this.txtMinScale.TabIndex = 10; this.txtMinScale.Text = "0"; this.txtMinScale.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; @@ -470,17 +474,6 @@ this.labelTitle.TabIndex = 0; this.labelTitle.Text = "ThermoCam SETUP"; // - // lblReadTemp - // - this.lblReadTemp.AutoSize = true; - this.lblReadTemp.Location = new System.Drawing.Point(1185, 364); - this.lblReadTemp.MinimumSize = new System.Drawing.Size(80, 0); - this.lblReadTemp.Name = "lblReadTemp"; - this.lblReadTemp.Size = new System.Drawing.Size(80, 13); - this.lblReadTemp.TabIndex = 8; - this.lblReadTemp.Text = "? °C"; - this.lblReadTemp.TextAlign = System.Drawing.ContentAlignment.TopRight; - // // lblPoint // this.lblPoint.AutoSize = true; @@ -544,9 +537,9 @@ this.columnHeader2, this.columnHeader3}); this.lstView.HideSelection = false; - this.lstView.Location = new System.Drawing.Point(954, 380); + this.lstView.Location = new System.Drawing.Point(954, 334); this.lstView.Name = "lstView"; - this.lstView.Size = new System.Drawing.Size(311, 277); + this.lstView.Size = new System.Drawing.Size(320, 323); this.lstView.TabIndex = 13; this.lstView.UseCompatibleStateImageBehavior = false; this.lstView.View = System.Windows.Forms.View.Details; @@ -567,6 +560,25 @@ this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.columnHeader3.Width = 150; // + // txtMaxDays + // + this.txtMaxDays.Location = new System.Drawing.Point(128, 403); + this.txtMaxDays.Name = "txtMaxDays"; + this.txtMaxDays.Size = new System.Drawing.Size(49, 20); + this.txtMaxDays.TabIndex = 14; + this.txtMaxDays.Text = "1"; + this.txtMaxDays.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // btnDeleteOlder + // + this.btnDeleteOlder.Location = new System.Drawing.Point(6, 401); + this.btnDeleteOlder.Name = "btnDeleteOlder"; + this.btnDeleteOlder.Size = new System.Drawing.Size(94, 23); + this.btnDeleteOlder.TabIndex = 15; + this.btnDeleteOlder.Text = "Delete > days"; + this.btnDeleteOlder.UseVisualStyleBackColor = true; + this.btnDeleteOlder.Click += new System.EventHandler(this.btnDeleteOlder_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -579,7 +591,6 @@ this.Controls.Add(this.pBoxB); this.Controls.Add(this.pBoxA); this.Controls.Add(this.lblPoint); - this.Controls.Add(this.lblReadTemp); this.Controls.Add(this.panelCmd); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.menuStrip1); @@ -635,7 +646,6 @@ private System.Windows.Forms.TextBox txtAB; private System.Windows.Forms.CheckBox chkPointSetup; private System.Windows.Forms.CheckBox chkReadTemp; - private System.Windows.Forms.Label lblReadTemp; private System.Windows.Forms.PictureBox pBoxB; private System.Windows.Forms.Label lblImgA; private System.Windows.Forms.Label lblImgB; @@ -659,6 +669,8 @@ private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; private System.Windows.Forms.ColumnHeader columnHeader3; + private System.Windows.Forms.Button btnDeleteOlder; + private System.Windows.Forms.TextBox txtMaxDays; } } diff --git a/Thermo.Cam.Setup/MainForm.cs b/Thermo.Cam.Setup/MainForm.cs index a2b4ea2f..a1692b25 100644 --- a/Thermo.Cam.Setup/MainForm.cs +++ b/Thermo.Cam.Setup/MainForm.cs @@ -189,6 +189,13 @@ namespace Thermo.Cam.Setup #region Private Methods + private void btnDeleteOlder_Click(object sender, EventArgs e) + { + int maxDays = 90; + int.TryParse(txtMaxDays.Text, out maxDays); + TCamCtrl.cleanDataDir(maxDays); + } + private void btnLoad_Click(object sender, EventArgs e) { // "" --> carica ultima scattata (altrimenti nome) @@ -238,10 +245,6 @@ namespace Thermo.Cam.Setup { pointSetup = false; } - if (!readTemp) - { - lblReadTemp.Text = "? °C"; - } } private void chkShowOrig_CheckedChanged(object sender, EventArgs e) diff --git a/Thermo.Cam.Utils/TCContr.cs b/Thermo.Cam.Utils/TCContr.cs index 48947e43..783e26be 100644 --- a/Thermo.Cam.Utils/TCContr.cs +++ b/Thermo.Cam.Utils/TCContr.cs @@ -169,6 +169,31 @@ namespace Thermo.Cam.Utils #region Private Methods + /// + /// Elimina dalla dir selezionata i files + vecchi del num giorni indicati + /// + /// + /// età massima file + private static void cleanSingleDirectory(string currDir, int maxDayOld) + { + if (Directory.Exists(currDir)) + { + var fileList = Directory.GetFiles(currDir); + foreach (var item in fileList) + { + var fInfo = new FileInfo(item); + if (DateTime.Now > fInfo.LastWriteTime.AddDays(maxDayOld)) + { + fInfo.Delete(); + } + else + { + Console.WriteLine($"File ok: {item}"); + } + } + } + } + private void Camera_ConnectionStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e) { if (eh_CameraConnStatusChanged != null) @@ -335,6 +360,17 @@ namespace Thermo.Cam.Utils } } + /// + /// Eliminazione files nelle folder dati quando hannon età > maxDayOld + /// + /// + public void cleanDataDir(int maxDayOld) + { + cleanSingleDirectory(dirDataTemp, maxDayOld); + cleanSingleDirectory(dirImgColor, maxDayOld); + cleanSingleDirectory(dirImgOrigi, maxDayOld); + } + public void ConnectCamera(CameraDeviceInfo cameraDeviceInfo) { DisposeCamera();