Aggiornato ISCCUpdater.
Aggiunto supporto alla deploy dei branch.
This commit is contained in:
@@ -27,6 +27,15 @@
|
||||
Text="{Binding PvmConfig.Url}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Orientation="Vertical">
|
||||
<Label Content="Branch da pubblicare" />
|
||||
<TextBox
|
||||
HorizontalAlignment="Stretch"
|
||||
Watermark="Branch da pubblicare"
|
||||
Text="{Binding PvmConfig.BranchToDeploy}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Orientation="Vertical">
|
||||
<Label Content="Personalizzazione azienda" />
|
||||
|
||||
@@ -27,6 +27,15 @@
|
||||
Text="{Binding TomcatConfig.BaseFolder}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Orientation="Vertical">
|
||||
<Label Content="Branch da pubblicare" />
|
||||
<TextBox
|
||||
HorizontalAlignment="Stretch"
|
||||
Watermark="Branch da pubblicare"
|
||||
Text="{Binding TomcatConfig.BranchToDeploy}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Orientation="Vertical">
|
||||
<Label Content="Host" />
|
||||
|
||||
@@ -53,15 +53,25 @@ public class EmsApiUpdaterCommandService(
|
||||
try
|
||||
{
|
||||
NextStep("Download ems-api.war");
|
||||
string? emsApiTempPath = null;
|
||||
IDictionary<string, string> emsApiTempPath = new Dictionary<string, string>();
|
||||
IList<string>? wmsFileList = null;
|
||||
|
||||
//#if !DEBUG
|
||||
if (Configuration.Any(x => x is { Enabled: true, RemoteAgentEnabled: false }))
|
||||
{
|
||||
//Se c'è almeno un update locale da fare (almeno uno che non sia remote update)
|
||||
emsApiTempPath = await downloadHelperService.DownloadEmsApi();
|
||||
|
||||
var branchNames = Configuration.Where(x => x is { Enabled: true, RemoteAgentEnabled: false })
|
||||
.Cast<TomcatConfigModel>()
|
||||
.Select(x => x.BranchToDeploy)
|
||||
.ToList();
|
||||
|
||||
foreach (var branchName in branchNames)
|
||||
{
|
||||
DetailStep($"Scarico compilazione branch \"{branchName}\"");
|
||||
var emsApiPath = await downloadHelperService.DownloadEmsApi(branchName);
|
||||
emsApiTempPath.Add(branchName, emsApiPath);
|
||||
}
|
||||
|
||||
var wmsConfigModels = settingsService.WmsConfigs.Where(x => x.Enabled)
|
||||
.ToList();
|
||||
@@ -111,7 +121,7 @@ public class EmsApiUpdaterCommandService(
|
||||
continue;
|
||||
}
|
||||
|
||||
#if !DEBUG
|
||||
//#if !DEBUG
|
||||
DetailStep($"Configuro {tomcatConfig.ServiceName}");
|
||||
|
||||
var tomcatServiceHelper = Ioc.Default.GetRequiredService<ISystemServiceHelper>();
|
||||
@@ -137,7 +147,7 @@ public class EmsApiUpdaterCommandService(
|
||||
await UtilityFile.Delete(tomcatConfig.GetEmsApiWarFilePath());
|
||||
|
||||
DetailStep("Copio il nuovo ems-api.war");
|
||||
await UtilityFile.Copy(emsApiTempPath, tomcatConfig.GetEmsApiWarFilePath());
|
||||
await UtilityFile.Copy(emsApiTempPath[tomcatConfig.BranchToDeploy!], tomcatConfig.GetEmsApiWarFilePath());
|
||||
|
||||
DetailStep("Avvio il servizio");
|
||||
await tomcatServiceHelper.Start();
|
||||
@@ -168,7 +178,7 @@ public class EmsApiUpdaterCommandService(
|
||||
}
|
||||
|
||||
await ExecutePostUpdateCommands(tomcatConfig);
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -181,7 +191,10 @@ public class EmsApiUpdaterCommandService(
|
||||
|
||||
#if !DEBUG
|
||||
NextStep("Cancello i file temporanei");
|
||||
await UtilityFile.Delete(emsApiTempPath);
|
||||
foreach (var emsApi in emsApiTempPath)
|
||||
{
|
||||
await UtilityFile.Delete(emsApi.Value);
|
||||
}
|
||||
foreach (var wmsFile in wmsFileList)
|
||||
{
|
||||
await UtilityFile.Delete(wmsFile);
|
||||
|
||||
@@ -53,14 +53,24 @@ public class PvmUpdaterCommandService : BaseUpdaterCommandService, IUpdaterComma
|
||||
_downloadHelperService.OnProgressUpdate = s => LogAction?.Invoke("\tProgress: " + s + "%");
|
||||
try
|
||||
{
|
||||
string? pvmBaseZip = null;
|
||||
IDictionary<string, string> pvmBaseZips = new Dictionary<string, string>();
|
||||
|
||||
if (Configuration.Any(x => x is { Enabled: true, RemoteAgentEnabled: false }))
|
||||
if (Configuration.Any(x => x is { Enabled: true, RemoteAgentEnabled: false }))
|
||||
{
|
||||
//Se c'è almeno un update locale da fare (almeno uno che non sia remote update)
|
||||
NextStep($"Download base folder _base.zip");
|
||||
pvmBaseZip = await _downloadHelperService.DownloadPVMBase();
|
||||
}
|
||||
var branchNames = Configuration.Where(x => x is { Enabled: true, RemoteAgentEnabled: false })
|
||||
.Cast<PvmConfigModel>()
|
||||
.Select(x => x.BranchToDeploy)
|
||||
.ToList();
|
||||
|
||||
foreach (var branchName in branchNames)
|
||||
{
|
||||
DetailStep($"Scarico compilazione branch \"{branchName}\"");
|
||||
var pvmBasePath = await _downloadHelperService.DownloadPVMBase(branchName);
|
||||
pvmBaseZips.Add(branchName, pvmBasePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < _settingsService.PVMConfig.Count; i++)
|
||||
@@ -85,8 +95,10 @@ public class PvmUpdaterCommandService : BaseUpdaterCommandService, IUpdaterComma
|
||||
return;
|
||||
}
|
||||
|
||||
NextStep($"Download {pvmConfig.Azienda}.zip");
|
||||
string pvmZip = await _downloadHelperService.DownloadPVM(pvmConfig.Azienda);
|
||||
string pvmBaseZip = pvmBaseZips[pvmConfig.BranchToDeploy];
|
||||
|
||||
NextStep($"Download {pvmConfig.Azienda}.zip");
|
||||
string pvmZip = await _downloadHelperService.DownloadPVM(pvmConfig.BranchToDeploy, pvmConfig.Azienda);
|
||||
|
||||
|
||||
string pvmWorkspacePath = UtilityDir.GetTempPath(true);
|
||||
@@ -139,9 +151,12 @@ public class PvmUpdaterCommandService : BaseUpdaterCommandService, IUpdaterComma
|
||||
|
||||
|
||||
NextStep($"Cancello file temporanei");
|
||||
await UtilityFile.Delete(pvmBaseZip);
|
||||
foreach (var pvmZip in pvmBaseZips)
|
||||
{
|
||||
await UtilityFile.Delete(pvmZip.Value);
|
||||
}
|
||||
|
||||
Completed();
|
||||
Completed();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -235,7 +250,7 @@ public class PvmUpdaterCommandService : BaseUpdaterCommandService, IUpdaterComma
|
||||
" in " +
|
||||
tmpOldFolder);
|
||||
await UtilityDir.Delete(tmpOldFolder);
|
||||
await UtilityDir.MoveContent(pvmConfig.Folder.Folder, tmpOldFolder);
|
||||
await UtilityDir.MoveContent(pvmConfig.Folder.Folder, tmpOldFolder, [tmpOldFolder, tempPvmRemoteFolder]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ public class CommonConsts
|
||||
public const string AZURE_CDN_WINGEST_FOLDER = AZURE_CDN + "wingest-{0}/{1}?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_TEXTILES_FOLDER = AZURE_CDN + "textiles-{0}/{1}?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_DMS2_FOLDER = AZURE_CDN + "dms-{0}/{1}?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_EMS_API_URL = AZURE_CDN + "ems-api/ems-api.war?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_PVM_URL = AZURE_CDN + "pvm/{0}.zip?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_EMS_API_URL = AZURE_CDN + "ems-api/{0}/ems-api.war?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_PVM_URL = AZURE_CDN + "pvm/{0}/{1}.zip?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_MES_URL = AZURE_CDN + "mes/{0}.zip?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_WMS_APK_URL = AZURE_CDN + "wms/android-release{0}.apk?" + AZURE_TOKEN;
|
||||
public const string AZURE_CDN_WMS_VERSION_URL = AZURE_CDN + "wms/version{0}.txt?" + AZURE_TOKEN;
|
||||
|
||||
@@ -49,11 +49,11 @@ public class DownloadHelperService : IDownloadHelperService
|
||||
public Action<int> OnProgressUpdate { get; set; }
|
||||
public Action<string> OnLog { get; set; }
|
||||
|
||||
public async Task<string> DownloadEmsApi()
|
||||
public async Task<string> DownloadEmsApi(string branchName)
|
||||
{
|
||||
string destPath = UtilityDir.GetTempPath() + bindingsPackageToName[Packages.EMS_API_WAR];
|
||||
string destPath = Path.Combine(UtilityDir.GetTempPath(), branchName.Replace('/', Path.DirectorySeparatorChar), bindingsPackageToName[Packages.EMS_API_WAR]);
|
||||
|
||||
await UtilityDownload.DownloadFile(CommonConsts.Repo.AZURE_CDN_EMS_API_URL,
|
||||
await UtilityDownload.DownloadFile(string.Format(CommonConsts.Repo.AZURE_CDN_EMS_API_URL, branchName),
|
||||
destPath,
|
||||
CommonConsts.Config.DOWNLOAD_PROGRESS_STEP_SIZE,
|
||||
OnProgressUpdate,
|
||||
@@ -485,11 +485,11 @@ public class DownloadHelperService : IDownloadHelperService
|
||||
|
||||
|
||||
|
||||
public async Task<string> DownloadPVMBase()
|
||||
public async Task<string> DownloadPVMBase(string branchName)
|
||||
{
|
||||
string destPath = Path.Combine(UtilityDir.GetTempPath(), "_base.zip");
|
||||
string destPath = Path.Combine(UtilityDir.GetTempPath(), branchName, "_base.zip");
|
||||
|
||||
await UtilityDownload.DownloadFile(string.Format(CommonConsts.Repo.AZURE_CDN_PVM_URL, "_base"),
|
||||
await UtilityDownload.DownloadFile(string.Format(CommonConsts.Repo.AZURE_CDN_PVM_URL, branchName, "_base"),
|
||||
destPath,
|
||||
CommonConsts.Config.DOWNLOAD_PROGRESS_STEP_SIZE,
|
||||
OnProgressUpdate,
|
||||
@@ -499,11 +499,11 @@ public class DownloadHelperService : IDownloadHelperService
|
||||
return destPath;
|
||||
}
|
||||
|
||||
public async Task<string> DownloadPVM(string azienda)
|
||||
public async Task<string> DownloadPVM(string branchName, string azienda)
|
||||
{
|
||||
string destPath = Path.Combine(UtilityDir.GetTempPath(), azienda + ".zip");
|
||||
string destPath = Path.Combine(UtilityDir.GetTempPath(), branchName, azienda + ".zip");
|
||||
|
||||
await UtilityDownload.DownloadFile(string.Format(CommonConsts.Repo.AZURE_CDN_PVM_URL, azienda),
|
||||
await UtilityDownload.DownloadFile(string.Format(CommonConsts.Repo.AZURE_CDN_PVM_URL, branchName, azienda),
|
||||
destPath,
|
||||
CommonConsts.Config.DOWNLOAD_PROGRESS_STEP_SIZE,
|
||||
OnProgressUpdate,
|
||||
|
||||
@@ -9,7 +9,7 @@ public interface IDownloadHelperService
|
||||
Action<int> OnProgressUpdate { get; set; }
|
||||
Action<string> OnLog { get; set; }
|
||||
|
||||
Task<string> DownloadEmsApi();
|
||||
Task<string> DownloadEmsApi(string branchName);
|
||||
Task<string> DownloadWmsApk(string personalizzazioneAzienda, string? fileSuffix, bool betaVersion = false);
|
||||
Task<string> DownloadWmsVersion(string personalizzazioneAzienda, string? fileSuffix, bool betaVersion = false);
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface IDownloadHelperService
|
||||
Task<string> DownloadTextilesAziende(PowerbuilderRuntimeVersionEnum version);
|
||||
Task<string> DownloadTextilesRuntime(PowerbuilderRuntimeVersionEnum version);
|
||||
|
||||
Task<string> DownloadPVMBase();
|
||||
Task<string> DownloadPVM(string azienda);
|
||||
Task<string> DownloadPVMBase(string branchName);
|
||||
Task<string> DownloadPVM(string branchName, string azienda);
|
||||
Task<string> DownloadMES(string azienda);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ public class PvmConfigModel : BaseConfigModel, IBaseConfigModel
|
||||
public FolderConfigModel? Folder { get; set; }
|
||||
public string Azienda { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string? BranchToDeploy { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,11 +16,6 @@ class SettingsModel
|
||||
public IList<PvmConfigModel>? PVMList { get; set; }
|
||||
public IList<MesConfigModel>? MESList { get; set; }
|
||||
|
||||
[Obsolete]
|
||||
public PvmConfigModel? PVM { get; set; }
|
||||
[Obsolete]
|
||||
public MesConfigModel? MES { get; set; }
|
||||
|
||||
public MailConfigModel? MailConfig { get; set; }
|
||||
|
||||
}
|
||||
@@ -16,10 +16,12 @@ public class TomcatConfigModel : BaseConfigModel, IBaseConfigModel
|
||||
public string? Host { get; set; }
|
||||
public string ServiceName { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
public override IList<PostExecutionCommandModel> PostUpdateCommands { get; set; } = new List<PostExecutionCommandModel>();
|
||||
public string? BranchToDeploy { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
public override IList<PostExecutionCommandModel> PostUpdateCommands { get; set; } = new List<PostExecutionCommandModel>();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,11 +43,10 @@ public class SettingsService : ISettingsService
|
||||
_settingsModel.NomeAzienda ??= "Nome azienda";
|
||||
_settingsModel.TomcatList ??= new List<TomcatConfigModel> { GenerateDefaultTomcatConfig() };
|
||||
_settingsModel.WMSList ??= new List<WmsConfigModel> { GenerateDefaultWmsConfig() };
|
||||
_settingsModel.PVMList ??= new List<PvmConfigModel> { GenerateDefaultPvmConfig() };
|
||||
_settingsModel.Dms2ConfigList ??= new List<Dms2ConfigModel> { GenerateDefaultDms2Config() };
|
||||
_settingsModel.Wingest190List ??= new List<WingestConfigModel> { GenerateDefaultWingest190Config() };
|
||||
_settingsModel.Textiles190List ??= new List<TextilesConfigModel> { GenerateDefaultTextiles190Config() };
|
||||
_settingsModel.PVM ??= GenerateDefaultPvmConfig();
|
||||
_settingsModel.MES ??= GenerateDefaultMesConfig();
|
||||
_settingsModel.MailConfig ??= GenerateDefaultMailConfig();
|
||||
|
||||
foreach (var tomcatConfigModel in _settingsModel.TomcatList)
|
||||
@@ -58,13 +57,11 @@ public class SettingsService : ISettingsService
|
||||
}
|
||||
}
|
||||
|
||||
_settingsModel.PVMList ??= _settingsModel.PVM != null ? new List<PvmConfigModel> { _settingsModel.PVM } : new List<PvmConfigModel>();
|
||||
_settingsModel.MESList ??= _settingsModel.MES != null ? new List<MesConfigModel> { _settingsModel.MES } : new List<MesConfigModel>();
|
||||
_settingsModel.TomcatList[0].BranchToDeploy ??= "master";
|
||||
_settingsModel.PVMList[0].BranchToDeploy ??= "master";
|
||||
|
||||
_settingsModel.PVM = null;
|
||||
_settingsModel.MES = null;
|
||||
|
||||
File.WriteAllText(_settingsFilename, JsonConvert.SerializeObject(_settingsModel, Formatting.Indented));
|
||||
File.WriteAllText(_settingsFilename, JsonConvert.SerializeObject(_settingsModel, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,10 +130,11 @@ public class SettingsService : ISettingsService
|
||||
return new TomcatConfigModel
|
||||
{
|
||||
RemoteAgentPort = 10251,
|
||||
BaseFolder = Path.Combine(programFiles != null ? programFiles : programFilesX86, "Tomcat7"),
|
||||
BaseFolder = Path.Combine(programFiles != null ? programFiles : programFilesX86, "Tomcat9"),
|
||||
Host = "http://localhost:8080/",
|
||||
ServiceName = "Tomcat7"
|
||||
};
|
||||
ServiceName = "Tomcat9",
|
||||
BranchToDeploy = "master"
|
||||
};
|
||||
}
|
||||
|
||||
private WmsConfigModel GenerateDefaultWmsConfig()
|
||||
@@ -200,8 +198,9 @@ public class SettingsService : ISettingsService
|
||||
Folder = new FolderConfigModel()
|
||||
{
|
||||
Folder = null
|
||||
}
|
||||
};
|
||||
},
|
||||
BranchToDeploy = "master"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -107,22 +107,25 @@ public class UtilityDir
|
||||
});
|
||||
}
|
||||
|
||||
public static Task MoveContent(string sourcePath, string destPath)
|
||||
public static Task MoveContent(string sourcePath, string destPath, string[]? pathsToExclude = null)
|
||||
{
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
if (!Directory.Exists(destPath))
|
||||
Directory.CreateDirectory(destPath);
|
||||
|
||||
string[] files = Directory.GetFiles(sourcePath);
|
||||
foreach (string file in files)
|
||||
var files = Directory.GetFiles(sourcePath)
|
||||
.Except(pathsToExclude ?? [])
|
||||
.ToArray();
|
||||
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
string name = Path.GetFileName(file);
|
||||
string dest = Path.Combine(destPath, name);
|
||||
var name = Path.GetFileName(file);
|
||||
var dest = Path.Combine(destPath, name);
|
||||
try
|
||||
{
|
||||
await UtilityFile.Move(file, dest);
|
||||
//System.IO.File.Move(file, dest);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -130,32 +133,17 @@ public class UtilityDir
|
||||
}
|
||||
}
|
||||
|
||||
string[] folders = Directory.GetDirectories(sourcePath);
|
||||
foreach (string folder in folders)
|
||||
var folders = Directory.GetDirectories(sourcePath)
|
||||
.Except(pathsToExclude ?? [])
|
||||
.ToArray();
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
string name = Path.GetFileName(folder);
|
||||
string dest = Path.Combine(destPath, name);
|
||||
await MoveContent(folder, dest);
|
||||
var name = Path.GetFileName(folder);
|
||||
var dest = Path.Combine(destPath, name);
|
||||
await MoveContent(folder, dest, pathsToExclude);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//string args = $" \"{sourcePath}\" \"{destPath}\" /D /Y /E";
|
||||
|
||||
//ProcessStartInfo p = new ProcessStartInfo("xcopy", args);
|
||||
//p.WindowStyle = ProcessWindowStyle.Hidden; //hide mode
|
||||
//Process.Start(p);
|
||||
|
||||
|
||||
/*
|
||||
string tempPath = GetTempPath() + Guid.NewGuid() + "\\";
|
||||
|
||||
Directory.Move(sourcePath, tempPath);
|
||||
|
||||
Delete(destPath);
|
||||
|
||||
|
||||
Directory.Move(tempPath, destPath);
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Integry_Server_Control_Center_Updater.Core.Model;
|
||||
|
||||
[JsonSerializable(typeof(LatestAppVersion))]
|
||||
public class LatestAppVersion
|
||||
{
|
||||
[JsonPropertyName("downloadLink")]
|
||||
public string DownloadLink { get; set; }
|
||||
|
||||
[JsonPropertyName("versionNumber")]
|
||||
public string VersionNumber { get; set; }
|
||||
|
||||
[JsonPropertyName("versionCode")]
|
||||
public int VersionCode { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Integry_Server_Control_Center_Updater.Core.Model;
|
||||
|
||||
namespace Integry_Server_Control_Center_Updater.Core.REST;
|
||||
|
||||
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true, WriteIndented = true)]
|
||||
[JsonSerializable(typeof(LatestAppVersion))]
|
||||
public partial class AppJsonSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
@@ -1,34 +1,77 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Integry_Server_Control_Center_Updater.Core.REST;
|
||||
|
||||
public class RestConsumer
|
||||
{
|
||||
public T Get<T>(string url, IDictionary<string, object> queryParams)
|
||||
{
|
||||
T response;
|
||||
queryParams ??= new Dictionary<string, object>();
|
||||
|
||||
string queryParamString = string.Join("&",
|
||||
queryParams.Select(kvp =>
|
||||
string.Format("{0}={1}", kvp.Key, kvp.Value)));
|
||||
private readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions()
|
||||
{
|
||||
TypeInfoResolver = AppJsonSerializerContext.Default,
|
||||
};
|
||||
|
||||
url += "?" + queryParamString;
|
||||
public async Task<T> GetAsync<T>(string url, IDictionary<string, object>? queryParams = null)
|
||||
{
|
||||
// Validazione URL
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
throw new ArgumentException("URL non può essere vuoto.", nameof(url));
|
||||
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
using (var stream = client.OpenRead(url))
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
string content = reader.ReadLine();
|
||||
response = JsonConvert.DeserializeObject<T>(content);
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
// Aggiungi parametri alla query string
|
||||
var uriBuilder = new UriBuilder(url);
|
||||
var queryParameters = new List<string>();
|
||||
|
||||
if (queryParams != null)
|
||||
{
|
||||
foreach (var kvp in queryParams)
|
||||
{
|
||||
queryParameters.Add($"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value.ToString())}");
|
||||
}
|
||||
}
|
||||
|
||||
uriBuilder.Query = string.Join("&", queryParameters);
|
||||
|
||||
// Configura HttpClient (usa un singleton o factory in produzione)
|
||||
using var httpClient = new HttpClient();
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, uriBuilder.Uri);
|
||||
|
||||
try
|
||||
{
|
||||
// Invia la richiesta
|
||||
var response = await httpClient.SendAsync(request).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode(); // Lancia eccezione per errori HTTP
|
||||
|
||||
// Leggi il contenuto completo
|
||||
var content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||
|
||||
// Deserializza con il contesto (assicurati che sia configurato correttamente)
|
||||
var result = JsonSerializer.Deserialize<T>(content, _serializerOptions);
|
||||
|
||||
return result ?? throw new JsonException("Deserializzazione fallita: il risultato è null.");
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
// Gestisci errori HTTP
|
||||
await Console.Error.WriteLineAsync($"Errore HTTP: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
// Gestisci errori di deserializzazione
|
||||
await Console.Error.WriteLineAsync($"Errore JSON: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Altri errori imprevisti
|
||||
await Console.Error.WriteLineAsync($"Errore generico: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<RootNamespace>Integry_Server_Control_Center_Updater</RootNamespace>
|
||||
<AssemblyVersion>1.0.0.3</AssemblyVersion>
|
||||
<FileVersion>1.0.0.3</FileVersion>
|
||||
<AssemblyVersion>1.0.0.4</AssemblyVersion>
|
||||
<FileVersion>1.0.0.4</FileVersion>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<PublishAot>true</PublishAot>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController" Version="9.0.2" />
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -6,6 +6,7 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Integry_Server_Control_Center_Updater.Core.Helper;
|
||||
using Integry_Server_Control_Center_Updater.Core.Logger;
|
||||
using Integry_Server_Control_Center_Updater.Core.Model;
|
||||
using Integry_Server_Control_Center_Updater.Core.REST;
|
||||
using Integry_Server_Control_Center_Updater.Core.Utility;
|
||||
|
||||
@@ -26,19 +27,22 @@ class Program
|
||||
IsccProcess
|
||||
};
|
||||
|
||||
private static readonly ILoggerService LoggerService = new FileLoggerService("logs");
|
||||
private static ILoggerService LoggerService;
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
var exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Process.GetCurrentProcess().MainModule.FileName);
|
||||
var version = typeof(Program).Assembly.GetName().Version?.ToString();
|
||||
var currentDirectory = AppContext.BaseDirectory;
|
||||
|
||||
LoggerService.LogDebug(
|
||||
$"Running version v{FileVersionInfo.GetVersionInfo(exePath).FileVersion}");
|
||||
var logsPath = Path.Combine(currentDirectory, "logs");
|
||||
LoggerService = new FileLoggerService(logsPath);
|
||||
|
||||
var updaterLogsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
|
||||
LoggerService.LogDebug(
|
||||
$"Running version v{version}");
|
||||
|
||||
if (!Directory.Exists(updaterLogsPath)) Directory.CreateDirectory(updaterLogsPath);
|
||||
UtilityFile.RemoveFileOlderThan(updaterLogsPath, 30);
|
||||
|
||||
if (!Directory.Exists(logsPath)) Directory.CreateDirectory(logsPath);
|
||||
UtilityFile.RemoveFileOlderThan(logsPath, 30);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -57,7 +61,7 @@ class Program
|
||||
systemServiceHelper.Init(ServiceName);
|
||||
|
||||
|
||||
string parentDir = new FileInfo(AppDomain.CurrentDomain.BaseDirectory).Directory!.Parent!.ToString();
|
||||
string parentDir = Directory.GetParent(currentDirectory)!.FullName;
|
||||
|
||||
var tempPath = UtilityDir.GetTempPath(true);
|
||||
var isccZipPath = await DownloadUpdates(tempPath);
|
||||
@@ -101,11 +105,11 @@ class Program
|
||||
{
|
||||
RestConsumer restConsumer = new();
|
||||
|
||||
dynamic response = restConsumer.Get<dynamic>(DownloadLink, null);
|
||||
var response = await restConsumer.GetAsync<LatestAppVersion>(DownloadLink, null);
|
||||
|
||||
string downloadLink = response.downloadLink;
|
||||
string versionNumber = response.versionNumber;
|
||||
int versionCode = response.versionCode;
|
||||
string downloadLink = response.DownloadLink;
|
||||
string versionNumber = response.VersionNumber;
|
||||
int versionCode = response.VersionCode;
|
||||
|
||||
var destPath = Path.Combine(tempPath, "ISCC.zip");
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"RemoteAgentPort": 10251,
|
||||
"Host": "http://localhost:8080/",
|
||||
"ServiceName": "Tomcat7",
|
||||
"BranchToDeploy": "master",
|
||||
"PostUpdateCommands": []
|
||||
}
|
||||
],
|
||||
@@ -73,6 +74,7 @@
|
||||
},
|
||||
"Azienda": "integry",
|
||||
"Url": "http://localhost/pvm",
|
||||
"BranchToDeploy": "master",
|
||||
"PostUpdateCommands": []
|
||||
}
|
||||
],
|
||||
@@ -90,8 +92,6 @@
|
||||
"PostUpdateCommands": []
|
||||
}
|
||||
],
|
||||
"PVM": null,
|
||||
"MES": null,
|
||||
"MailConfig": {
|
||||
"SmtpServer": "smtps.aruba.it",
|
||||
"SmtpPort": 465,
|
||||
|
||||
Reference in New Issue
Block a user