Update step di backup/zip per install
This commit is contained in:
@@ -56,6 +56,8 @@ namespace EgwControlCenter.App.Components.Compo
|
||||
protected async void DoUpdate(VersStatusDTO ReqApp)
|
||||
{
|
||||
isUpdating = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Task.Delay(50);
|
||||
// verifico il TIPO di oggetto gestito x la procedura di update...
|
||||
switch (ReqApp.ApplicationType)
|
||||
{
|
||||
@@ -69,37 +71,17 @@ namespace EgwControlCenter.App.Components.Compo
|
||||
break;
|
||||
case CoreEnum.AppType.WinApp:
|
||||
// esegue update delle app Iob-*
|
||||
await DoUpdateIobWin(ReqApp);
|
||||
await ACService.DoUpdateIobWin(ReqApp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
isUpdating = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Task.Delay(50);
|
||||
}
|
||||
|
||||
// metodo update specifico x app IobWin
|
||||
private async Task DoUpdateIobWin(VersStatusDTO reqApp)
|
||||
{
|
||||
// step 0: inserisce i file semaforo di segnalazione update in corso
|
||||
|
||||
// step 1: backup configurazioni
|
||||
|
||||
// step 2: kill processi
|
||||
|
||||
// step 3: backup intera folder
|
||||
|
||||
// step 4: download
|
||||
|
||||
// step 5: unzip
|
||||
|
||||
// step 6: restore conf
|
||||
|
||||
// step 7: rimozione file lock semaforo
|
||||
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
|
||||
protected async Task ForceCheck()
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.1.2412.2411</Version>
|
||||
<Version>1.1.2412.2418</Version>
|
||||
<Configurations>Debug;Release;DEBUG_Local</Configurations>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,8 +4,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ApplicationRevision>2411</ApplicationRevision>
|
||||
<ApplicationVersion>1.1.2412.2411</ApplicationVersion>
|
||||
<ApplicationRevision>2418</ApplicationRevision>
|
||||
<ApplicationVersion>1.1.2412.2418</ApplicationVersion>
|
||||
<BootstrapperEnabled>True</BootstrapperEnabled>
|
||||
<Configuration>Release</Configuration>
|
||||
<CreateWebPageOnPublish>True</CreateWebPageOnPublish>
|
||||
|
||||
@@ -5,6 +5,8 @@ using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
@@ -103,88 +105,6 @@ namespace EgwControlCenter.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Directory di backup x IobWin
|
||||
/// </summary>
|
||||
private string backupDir = @"C:\Steamware\backup";
|
||||
|
||||
/// <summary>
|
||||
/// File segnaposto x lock fasi di update
|
||||
/// </summary>
|
||||
private string updFilePath = @"c:\Steamware\IOB-MAN\update.run";
|
||||
|
||||
/// <summary>
|
||||
/// metodo update specifico x app IobWin
|
||||
/// </summary>
|
||||
/// <param name="reqApp"></param>
|
||||
/// <returns></returns>
|
||||
public async Task DoUpdateIobWin(VersStatusDTO reqApp)
|
||||
{
|
||||
// controllo di avere un file di riferimento...
|
||||
string appDir = Path.GetDirectoryName(reqApp.LocalPath) ?? "";
|
||||
if (!string.IsNullOrEmpty(appDir))
|
||||
{
|
||||
// step 0: inserisce i file semaforo di segnalazione update in corso
|
||||
using (FileStream fs = File.Create(updFilePath))
|
||||
{
|
||||
// File is created and access is released when the using block ends
|
||||
}
|
||||
|
||||
// step 1: backup configurazioni partendo da path applicazione...
|
||||
string srcDir = Path.Combine(appDir, "DATA", "CONF");
|
||||
string destDir = Path.Combine(backupDir, reqApp.CodApp, "DATA", "CONF");
|
||||
// se MAN uso folder "accorciata"
|
||||
if(reqApp.CodApp=="IOB-MAN")
|
||||
{
|
||||
srcDir = Path.Combine(appDir, "CONF");
|
||||
destDir = Path.Combine(backupDir, reqApp.CodApp, "CONF");
|
||||
}
|
||||
CopyDirectory(srcDir, destDir);
|
||||
|
||||
// step 2: kill processi
|
||||
|
||||
// step 3: backup + zip intera folder
|
||||
|
||||
// step 4: download
|
||||
|
||||
// step 5: unzip
|
||||
|
||||
// step 6: restore conf
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
// step 7: rimozione file lock semaforo
|
||||
File.Delete(updFilePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper copia directory + contenuto
|
||||
/// </summary>
|
||||
/// <param name="sourceDir"></param>
|
||||
/// <param name="destDir"></param>
|
||||
protected void CopyDirectory(string sourceDir, string destDir)
|
||||
{
|
||||
// Create the destination directory if it doesn't exist
|
||||
if (!Directory.Exists(destDir))
|
||||
{
|
||||
Directory.CreateDirectory(destDir);
|
||||
}
|
||||
|
||||
// Copy all files
|
||||
foreach (var file in Directory.GetFiles(sourceDir))
|
||||
{
|
||||
string destFile = Path.Combine(destDir, Path.GetFileName(file));
|
||||
File.Copy(file, destFile, true);
|
||||
}
|
||||
|
||||
// Copy all subdirectories
|
||||
foreach (var dir in Directory.GetDirectories(sourceDir))
|
||||
{
|
||||
string destSubDir = Path.Combine(destDir, Path.GetFileName(dir));
|
||||
CopyDirectory(dir, destSubDir);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CloudCallActive
|
||||
{
|
||||
get => cloudCallActive;
|
||||
@@ -309,11 +229,6 @@ namespace EgwControlCenter.Core
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DataOra ultimo controllo effettuato
|
||||
/// </summary>
|
||||
private DateTime lastCheckDone = DateTime.Today.AddMonths(-1);
|
||||
|
||||
/// <summary>
|
||||
/// Effettua un controllo completo (loacele remoto)
|
||||
/// </summary>
|
||||
@@ -385,6 +300,80 @@ namespace EgwControlCenter.Core
|
||||
ReportConfigUpd();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// metodo update specifico x app IobWin
|
||||
/// </summary>
|
||||
/// <param name="reqApp"></param>
|
||||
/// <returns></returns>
|
||||
public async Task DoUpdateIobWin(VersStatusDTO reqApp)
|
||||
{
|
||||
// controllo di avere un file di riferimento...
|
||||
string appDir = Path.GetDirectoryName(reqApp.LocalPath) ?? "";
|
||||
if (!string.IsNullOrEmpty(appDir))
|
||||
{
|
||||
// step 0: inserisce i file semaforo di segnalazione update in corso
|
||||
using (FileStream fs = File.Create(updFilePath))
|
||||
{
|
||||
// File is created and access is released when the using block ends
|
||||
}
|
||||
|
||||
// step 1: backup configurazioni partendo da path applicazione...
|
||||
string srcDir = Path.Combine(appDir, "DATA", "CONF");
|
||||
string destDir = Path.Combine(backupDir, "Conf", reqApp.CodApp, "DATA", "CONF");
|
||||
// se MAN uso folder "accorciata"
|
||||
if (reqApp.CodApp == "IOB-MAN")
|
||||
{
|
||||
srcDir = Path.Combine(appDir, "CONF");
|
||||
destDir = Path.Combine(backupDir, "Conf", reqApp.CodApp, "CONF");
|
||||
}
|
||||
CopyDirectory(srcDir, destDir);
|
||||
|
||||
// step 2: kill processi
|
||||
ForceKillByName(reqApp.CodApp);
|
||||
|
||||
// step 3: backup + zip intera folder applicativo
|
||||
string tempZip = Path.Combine(tempDir, "FULL", reqApp.CodApp);
|
||||
if (Directory.Exists(tempZip))
|
||||
{
|
||||
Directory.Delete(tempZip, true);
|
||||
}
|
||||
Directory.CreateDirectory(tempZip);
|
||||
CopyDirectory(appDir, tempZip);
|
||||
|
||||
string zipPath = Path.Combine(backupDir, "Archive", reqApp.CodApp, $"{DateTime.Now:yyyyMMdd}_{DateTime.Now:HHmmss}.zip");
|
||||
if (File.Exists(zipPath))
|
||||
{
|
||||
File.Delete(zipPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
string zipDir = Path.GetDirectoryName(zipPath) ?? "";
|
||||
if (!string.IsNullOrEmpty(zipDir))
|
||||
{
|
||||
if (!Directory.Exists(zipDir))
|
||||
{
|
||||
Directory.CreateDirectory(zipDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
await Task.Run(() =>
|
||||
{
|
||||
ZipFile.CreateFromDirectory(tempZip, zipPath);
|
||||
});
|
||||
|
||||
// step 4: download
|
||||
|
||||
// step 5: unzip + overwrite
|
||||
|
||||
//// step 6: restore conf
|
||||
//CopyDirectory(destDir, srcDir);
|
||||
|
||||
}
|
||||
// step 7: rimozione file lock semaforo
|
||||
File.Delete(updFilePath);
|
||||
await Task.Delay(10);
|
||||
}
|
||||
|
||||
public void ResetConf()
|
||||
{
|
||||
bool fatto = CurrCheck.ResetConf();
|
||||
@@ -421,6 +410,38 @@ namespace EgwControlCenter.Core
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Helper copia directory + contenuto
|
||||
/// </summary>
|
||||
/// <param name="sourceDir"></param>
|
||||
/// <param name="destDir"></param>
|
||||
protected void CopyDirectory(string sourceDir, string destDir)
|
||||
{
|
||||
// Create the destination directory if it doesn't exist
|
||||
if (!Directory.Exists(destDir))
|
||||
{
|
||||
Directory.CreateDirectory(destDir);
|
||||
}
|
||||
|
||||
// Copy all files
|
||||
foreach (var file in Directory.GetFiles(sourceDir))
|
||||
{
|
||||
string destFile = Path.Combine(destDir, Path.GetFileName(file));
|
||||
File.Copy(file, destFile, true);
|
||||
}
|
||||
|
||||
// Copy all subdirectories
|
||||
foreach (var dir in Directory.GetDirectories(sourceDir))
|
||||
{
|
||||
string destSubDir = Path.Combine(destDir, Path.GetFileName(dir));
|
||||
CopyDirectory(dir, destSubDir);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
@@ -428,6 +449,21 @@ namespace EgwControlCenter.Core
|
||||
/// </summary>
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// Directory di backup x IobWin
|
||||
/// </summary>
|
||||
private string backupDir = @"C:\Steamware\backup";
|
||||
|
||||
/// <summary>
|
||||
/// Directory temp di appoggio
|
||||
/// </summary>
|
||||
private string tempDir = @"C:\Steamware\temp";
|
||||
|
||||
/// <summary>
|
||||
/// DataOra ultimo controllo effettuato
|
||||
/// </summary>
|
||||
private DateTime lastCheckDone = DateTime.Today.AddMonths(-1);
|
||||
|
||||
/// <summary>
|
||||
/// Valore massimo ammesso refresh sec
|
||||
/// </summary>
|
||||
@@ -438,6 +474,11 @@ namespace EgwControlCenter.Core
|
||||
/// </summary>
|
||||
private int refPMin = 1;
|
||||
|
||||
/// <summary>
|
||||
/// File segnaposto x lock fasi di update
|
||||
/// </summary>
|
||||
private string updFilePath = @"c:\Steamware\IOB-MAN\update.run";
|
||||
|
||||
/// <summary>
|
||||
/// Valore massimo ammesso veto minuti
|
||||
/// </summary>
|
||||
@@ -448,19 +489,71 @@ namespace EgwControlCenter.Core
|
||||
/// </summary>
|
||||
private int vetoPMin = 30;
|
||||
|
||||
/// <summary>
|
||||
/// Ms di attesa x uscita processo (std)
|
||||
/// </summary>
|
||||
private int waitForExitMsec = 250;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private bool cloudCallActive { get; set; } = false;
|
||||
|
||||
private string ConfDir { get; set; } = "";
|
||||
|
||||
private ReleaseChecker CurrCheck { get; set; } = null!;
|
||||
|
||||
private string DataDir { get; set; } = "";
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Effettua un force kill dato nome processo
|
||||
/// </summary>
|
||||
/// <param name="nomeProc"></param>
|
||||
private void ForceKillByName(string nomeProc)
|
||||
{
|
||||
Process[] stillRunningProc = Process.GetProcessesByName(nomeProc);
|
||||
if (stillRunningProc != null)
|
||||
{
|
||||
if (stillRunningProc.Length > 0)
|
||||
{
|
||||
foreach (var item in stillRunningProc)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process p = Process.GetProcessById(item.Id);
|
||||
{
|
||||
if (!p.HasExited)
|
||||
{
|
||||
p.Kill();
|
||||
p.WaitForExit(waitForExitMsec);
|
||||
}
|
||||
if (!p.HasExited)
|
||||
{
|
||||
Log.Error($"Process not Killed, 2nd try p.kill()");
|
||||
p.Kill();
|
||||
p.WaitForExit(waitForExitMsec * 2);
|
||||
}
|
||||
if (!p.HasExited)
|
||||
{
|
||||
Log.Error($"Process not Killed, 3th try p.kill()");
|
||||
p.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in fase di kill processo da nome {exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportConfigUpd()
|
||||
{
|
||||
if (EA_ConfigUpdated != null)
|
||||
|
||||
Reference in New Issue
Block a user