Ok singolo download

This commit is contained in:
Samuele Locatelli
2021-09-20 19:21:42 +02:00
parent 5cdb0e077d
commit 4f4cd7bf2f
19 changed files with 520 additions and 21 deletions
@@ -96,7 +96,6 @@ namespace MP.AppAuth.Controllers
dbResult = dbCtx
.DbSetUpdMan
//.Where(x => !string.IsNullOrEmpty(x.AppName))
.ToList();
return dbResult;
+1 -1
View File
@@ -16,7 +16,7 @@ namespace MP.AppAuth.Models
public string AppName { get; set; }
public string AppUrl { get; set; }
public bool? IsAuth { get; set; }
public bool IsAuth { get; set; } = false;
public string LicenseKey { get; set; }
public string LocalRepo { get; set; }
public string ManifestUrl { get; set; }
+270
View File
@@ -0,0 +1,270 @@
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace MP.AppAuth
{
/// <summary>
/// Object of this class gives you all the details about the update useful in handling the update logic yourself.
/// </summary>
public class UpdateInfoEventArgs : EventArgs
{
#region Public Properties
/// <summary>
/// URL of the webpage specifying changes in the new update.
/// </summary>
public string ChangelogURL { get; set; }
/// <summary>
/// Returns newest version of the application available to download.
/// </summary>
public Version CurrentVersion { get; set; }
/// <summary>
/// Download URL of the update file.
/// </summary>
public string DownloadURL { get; set; }
/// <summary>
/// Returns version of the application currently installed on the user's PC.
/// </summary>
public Version InstalledVersion { get; set; }
/// <summary>
/// If new update is available then returns true otherwise false.
/// </summary>
public bool IsUpdateAvailable { get; set; }
/// <summary>
/// Shows if the update is required or optional.
/// </summary>
public bool Mandatory { get; set; }
#endregion Public Properties
}
/// <summary>
/// Gestione update applicazioni
/// </summary>
public class UpdateMan
{
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Protected Fields
protected bool doAuth = false;
#endregion Protected Fields
#region Public Fields
/// <summary>
/// Init classe
/// </summary>
public static UpdateMan obj = new UpdateMan();
#endregion Public Fields
#region Public Constructors
/// <summary>
/// Init classe
/// </summary>
public UpdateMan()
{ }
/// <summary>
/// Init classe
/// </summary>
/// <param name="user"></param>
/// <param name="pwd"></param>
public UpdateMan(string user, string pwd)
{
userName = user;
passwd = pwd;
doAuth = !string.IsNullOrEmpty($"{userName}{passwd}");
}
#endregion Public Constructors
#region Protected Properties
protected string passwd { get; set; } = "";
protected string userName { get; set; } = "";
#endregion Protected Properties
#region Public Methods
/// <summary>
/// Effettua download ultima versione applicativo
/// </summary>
/// <param name="remoteUrl"></param>
/// <param name="localRepo"></param>
/// <param name="packName"></param>
public long downloadLatest(string remoteUrl, string localRepo, string packName)
{
long size = 0;
// verifico directory
if (!Directory.Exists(localRepo))
{
Directory.CreateDirectory(localRepo);
}
string localFile = "";
string localLast = "";
string DownloadURL = "";
try
{
// in primis scarico update info...
UpdateInfoEventArgs updateData = getUpdateInfo(remoteUrl);
if (updateData.IsUpdateAvailable)
{
DownloadURL = updateData.DownloadURL;
localFile = string.Format(@"{0}\{1}_Build_{2}.zip", localRepo, packName, updateData.CurrentVersion);
localLast = string.Format(@"{0}\{1}.zip", localRepo, packName);
// scarica file e salva in directory locale...
using (var http = new HttpClient())
{
//var client = new WebClient();
//bool doAuth = !string.IsNullOrEmpty($"{userName}{passwd}");
if (doAuth)
{
//client.Credentials = new System.Net.NetworkCredential(userName, passwd);
http.DefaultRequestHeaders.Accept.Clear();
var byteArray = System.Text.ASCIIEncoding.UTF8.GetBytes($"{userName}:{passwd}");
http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
}
//client.DownloadFile(updateData.DownloadURL, localFile);
// url da chiamare
http.BaseAddress = new Uri(DownloadURL);
// lettura
var data = http.GetAsync(DownloadURL).Result;
using (var myReader = data.Content.ReadAsStreamAsync())
{
//var myReader = data.Content.ReadAsStreamAsync();
if (data.StatusCode != HttpStatusCode.OK)
{
Log.Info($"Errore in chiamata getUpdateInfo per URL {remoteUrl}: status code: {data.StatusCode}");
}
else
{
using (Stream outStream = File.OpenWrite(localFile))
{
myReader.Result.CopyTo(outStream);
}
// ora lo copio come latest...
File.Copy(localFile, localLast, true);
// indico come fatto!
var thisFile = new FileInfo(localLast);
size = thisFile.Length;
}
}
}
}
else
{
localFile = string.Format(@"{0}\Error.log", localRepo);
// scrivo file in area target...
using (StreamWriter sw = File.AppendText(localFile))
{
sw.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ATTENZIONE! Installer NON disponibile | {remoteUrl}");
}
}
}
catch (Exception exc)
{
localFile = string.Format(@"{0}\Error.log", localRepo);
// scrivo file in area target...
using (StreamWriter sw = File.AppendText(localFile))
{
sw.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} Errore in fase di download installers{Environment.NewLine}XML: {remoteUrl}{Environment.NewLine}URL: {DownloadURL}");
sw.WriteLine(exc.ToString());
}
}
return size;
}
/// <summary>
/// Recupera l'ultima versione disponibile
/// </summary>
/// <param name="remoteUrl"></param>
/// <returns></returns>
public UpdateInfoEventArgs getUpdateInfo(string remoteUrl)
{
//bool doAuth = !string.IsNullOrEmpty($"{userName}{passwd}");
UpdateInfoEventArgs args = new UpdateInfoEventArgs();
Version CurrentVersion;
bool Mandatory;
XmlDocument recXml = new XmlDocument();
try
{
// recupero dati
using (var http = new HttpClient())
{
if (doAuth)
{
http.DefaultRequestHeaders.Accept.Clear();
var byteArray = System.Text.ASCIIEncoding.UTF8.GetBytes($"{userName}:{passwd}");
http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
}
// url da chiamare
http.BaseAddress = new Uri(remoteUrl);
// lettura
var data = http.GetAsync(remoteUrl).Result;
var myReader = data.Content.ReadAsStreamAsync();
if (data.StatusCode != HttpStatusCode.OK)
{
Log.Info($"Errore in chiamata getUpdateInfo per URL {remoteUrl}: status code: {data.StatusCode}");
}
else
{
recXml.Load(myReader.Result);
XmlNodeList recData = recXml.SelectNodes("item");
if (recData != null)
{
foreach (XmlNode item in recData)
{
XmlNode appCastVersion = item.SelectSingleNode("version");
Version.TryParse(appCastVersion?.InnerText, out CurrentVersion);
args.CurrentVersion = CurrentVersion;
XmlNode appCastChangeLog = item.SelectSingleNode("changelog");
args.ChangelogURL = appCastChangeLog?.InnerText;
XmlNode appCastUrl = item.SelectSingleNode("url");
args.DownloadURL = appCastUrl?.InnerText;
XmlNode mandatory = item.SelectSingleNode("mandatory");
Boolean.TryParse(mandatory?.InnerText, out Mandatory);
args.Mandatory = Mandatory;
args.IsUpdateAvailable = true;
}
}
}
}
}
catch (Exception exc)
{
Log.Info($"Eccezione in getUpdateInfo:{Environment.NewLine}{exc}");
// metto versione = 0 + errore...
args.IsUpdateAvailable = false;
args.CurrentVersion = new Version("0.0.0.0");
}
return args;
}
#endregion Public Methods
}
}
+1 -1
View File
@@ -67,7 +67,7 @@
protected bool authOk()
{
bool answ = !string.IsNullOrEmpty(CurrItem.LicenseKey) && Convert.ToBoolean(CurrItem.IsAuth);
bool answ = !string.IsNullOrEmpty(CurrItem.LicenseKey);
return answ;
}
+14
View File
@@ -0,0 +1,14 @@
<div class="row text-center">
@if (authOk())
{
<div class="col-12 mt-2">
<h3 class="mb-0">@CurrItem.AppName&nbsp;<i class="fas fa-download"></i></h3>
</div>
<div class="col-12">
<button class="btn btn-block btn-outline-secondary" @onclick="() => DownloadPack()">@updArgs.CurrentVersion</button>
</div>
<div class="col-12">
@outMessage
</div>
}
</div>
+111
View File
@@ -0,0 +1,111 @@
using Microsoft.AspNetCore.Components;
using MP.AppAuth;
using MP.AppAuth.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using MP.Land.Data;
using System.Diagnostics;
namespace MP.Land.Components
{
public partial class SingleDownload
{
#region Protected Fields
protected string outMessage = "";
protected UpdateInfoEventArgs updArgs = new UpdateInfoEventArgs();
protected UpdateMan updateManAuth = new UpdateMan("SWDownloader", "viaD@nte16");
#endregion Protected Fields
#region Protected Properties
[Inject]
protected IConfiguration Configuration { get; set; }
[Inject]
protected AppAuthService DataService { get; set; }
#endregion Protected Properties
#region Public Properties
[Parameter]
public UpdMan CurrItem { get; set; }
#endregion Public Properties
#region Protected Methods
protected bool authOk()
{
bool answ = !string.IsNullOrEmpty(CurrItem.LicenseKey);
return answ;
}
/// <summary>
/// effettua download del pacchetto indicato
/// </summary>
protected void DownloadPack()
{
long size = 0;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
if (CurrItem.IsAuth)
{
size = updateManAuth.downloadLatest(CurrItem.ManifestUrl, localPath(CurrItem.LocalRepo), CurrItem.PackName);
}
else
{
size = UpdateMan.obj.downloadLatest(CurrItem.ManifestUrl, localPath(CurrItem.LocalRepo), CurrItem.PackName);
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
if (size > 0)
{
outMessage = $"Scaricati {(double)size / (1024 * 1024):N2} Mb in {ts.TotalSeconds:N2} s";
}
else
{
outMessage = $"Download non riuscito per {CurrItem.AppName}";
}
}
protected string fullUrl(string relUrl)
{
return $"{Configuration["BaseUrl"]}{relUrl}";
}
protected string localPath(string localRepo)
{
return @$"{Configuration["downloadPath"]}\{localRepo}\{Configuration["appVers"]}"; ;
}
protected override void OnInitialized()
{
// Recupero info ADM...
if (CurrItem.IsAuth)
{
updArgs = updateManAuth.getUpdateInfo(CurrItem.ManifestUrl);
}
else
{
updArgs = UpdateMan.obj.getUpdateInfo(CurrItem.ManifestUrl);
}
}
protected MarkupString traduci(string lemma)
{
MarkupString answ;
string rawHtml = DataService.Traduci(lemma, "IT");
answ = new MarkupString(rawHtml);
return answ;
}
#endregion Protected Methods
}
}
+2 -2
View File
@@ -8,10 +8,10 @@
<div class="col-4 col-md-4">
<div class="badge badge-pill badge-light px-2 py-1">
<div class="px-1">
<span>EgalWare <img width="24" class="img-fluid" src="img/LogoBlu.svg" /></span>
<span>EgalWare <img width="24" class="img-fluid" src="img/LogoBluGreen.png" /></span>
</div>
</div>
@*<img src="img/LogoBlu.svg" class="img-fluid" width="32" /> EgalWare*@
@*<img src="img/LogoBluGreen.png" class="img-fluid" width="32" /> EgalWare*@
</div>
<div class="col-8 text-right text-light">
<h4 class="py-0 mb-0">@Environment</h4>
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>MP.Land</RootNamespace>
<Version>1.1.2109.2016</Version>
<Version>1.1.2109.2019</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -17,7 +17,7 @@
</div>
<div class="badge badge-pill badge-dark px-4 py-2">
<div class="px-1">
<a class="text-light" href="https://www.egalware.com/" target="_blank">powered by&nbsp;EgalWare <img width="24" class="img-fluid" src="img/LogoBlu.svg" /></a>
<a class="text-light" href="https://www.egalware.com/" target="_blank">powered by&nbsp;EgalWare <img width="24" class="img-fluid" src="img/LogoBluGreen.png" /></a>
</div>
</div>
</div>
-9
View File
@@ -24,12 +24,6 @@ namespace MP.Land.Pages
#endregion Protected Fields
#region Private Properties
private bool isLoading { get; set; } = false;
#endregion Private Properties
#region Protected Properties
[Inject]
@@ -56,14 +50,11 @@ namespace MP.Land.Pages
protected async Task ReloadAllData()
{
isLoading = true;
//MacList = await DataService.MacchineGetAll();
await ReloadData();
}
protected async Task ReloadData()
{
isLoading = true;
// importante altrimenti NON mostra update UI
await Task.Delay(1);
ListRecords = await DataService.UpdManList();
+48
View File
@@ -0,0 +1,48 @@
@page "/UpdateManager"
@using MP.Land.Data
@using MP.Land.Components
<div class="alert alert-secondary">
<div class="row">
<div class="col-12 col-md-3">
<img src="img/LogoMapoFull.png" class="img-fluid" width="200" />
</div>
<div class="col-12 col-md-6 text-center">
<h1>Aggiornamento Moduli</h1>
<div>
<b>Ultime release applicazioni</b>
</div>
<p>Scaricare uno o più pacchetti selezionando dall'elenco riportato.</p>
</div>
<div class="col-12 col-md-3 text-center">
<div class="h2">
ALL Packages <i class="fas fa-download"></i>
</div>
<button class="btn btn-success btn-block">Download ALL Latest</button>
</div>
</div>
</div>
<div class="card">
<div class="card-body">
@if (ListRecords == null)
{
<LoadingData></LoadingData>
}
else if (totalCount == 0)
{
<div class="alert alert-warning text-center display-4">Nessun record trovato</div>
}
else
{
<div class="row">
@foreach (var item in ListRecords)
{
<div class="col-4 mb-2">
<SingleDownload CurrItem="@item"></SingleDownload>
</div>
}
</div>
}
</div>
</div>
+64
View File
@@ -0,0 +1,64 @@
using Microsoft.AspNetCore.Components;
using MP.Land.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Land.Pages
{
public partial class UpdateManager
{
#region Private Fields
private List<MP.AppAuth.Models.UpdMan> ListRecords;
#endregion Private Fields
#region Protected Fields
protected int totalCount = 0;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected MessageService AppMService { get; set; }
[Inject]
protected AppAuthService DataService { get; set; }
#endregion Protected Properties
#region Protected Methods
protected override void OnInitialized()
{
AppMService.ShowSearch = false;
AppMService.PageName = "Update Manager";
AppMService.PageIcon = "fas fa-download pr-2";
}
protected override async Task OnInitializedAsync()
{
await ReloadAllData();
}
protected async Task ReloadAllData()
{
await ReloadData();
}
protected async Task ReloadData()
{
// importante altrimenti NON mostra update UI
await Task.Delay(1);
ListRecords = await DataService.UpdManList();
totalCount = ListRecords.Count();
await Task.Delay(1);
}
#endregion Protected Methods
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo gestione Programmi MAPO</i>
<h4>Versione: 1.1.2109.2016</h4>
<h4>Versione: 1.1.2109.2019</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
1.1.2109.2016
1.1.2109.2019
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.2109.2016</version>
<version>1.1.2109.2019</version>
<url>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Land.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+2 -2
View File
@@ -14,12 +14,12 @@
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="UserQr">
<span class="fas fa-qrcode fa-2x pr-2" aria-hidden="true"></span> QR User
<span class="fas fa-qrcode fa-2x pr-2" aria-hidden="true"></span> QR Card User
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="UpdateManager">
<span class="fas fa-download fa-2x pr-2" aria-hidden="true"></span> Update vers
<span class="fas fa-download fa-2x pr-2" aria-hidden="true"></span> Update Manager
</NavLink>
</li>
<li class="nav-item px-3">
+2
View File
@@ -16,6 +16,8 @@
"AllowedHosts": "*",
"BaseUrl": "https://localhost:44309/",
"Environment": "Steam DEV",
"downloadPath": "C:\\Steamware\\installers\\MP",
"appVers": "stable",
"ConnectionStrings": {
"DefaultConnection": "Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;MultipleActiveResultSets=true",
"MP.Land": "Server=SQL2016DEV;Database=MoonPro;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Land;",
Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB