Feature: Download Server ignoreren, wenn nicht vorhanden
Client macht vorm Update Checken eine Anfrage an den Download Server und prüft dessen Verfügbarkeit. Sollte keine vorhanden sein, so wird der Client direkt gestartet.
This commit is contained in:
@@ -70,13 +70,15 @@ namespace BeWoLauncher.Logic.Behavior
|
||||
{
|
||||
try
|
||||
{
|
||||
DownloadController.Manager.GetUpdatePlan();
|
||||
DownloadController.Manager.CheckForConnection();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
DownloadController.CanStartWithoutDownloadServer = true;
|
||||
}
|
||||
|
||||
DownloadController.Manager.GetUpdatePlan();
|
||||
|
||||
if (!DownloadController.CanStartWithoutDownloadServer && DownloadController.Manager.UpdatePlanResponse.HasToDo())
|
||||
LaunchUpdateInfo();
|
||||
else
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using BeWoLauncher.ServiceProxy;
|
||||
using BS.SharedLauncher;
|
||||
using BS.SharedLauncher.DataContract;
|
||||
using BS.SharedLauncher.Enums;
|
||||
using BS.SharedLauncher.Exceptions;
|
||||
@@ -9,16 +8,9 @@ using BS.SharedLauncher.Logic;
|
||||
using BS.SharedLauncher.Update;
|
||||
using BS.SharedLauncher.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace BeWoLauncher.Logic.Utils.Download
|
||||
{
|
||||
@@ -30,7 +22,7 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
public string RootFolder => LauncherPaths.GetRootPath();
|
||||
public string DownloadFolder => LauncherPaths.GetDownloadPath();
|
||||
public string ApplyFolder => LauncherPaths.GetApplyPath();
|
||||
|
||||
|
||||
public bool SkipLock { get; set; }
|
||||
public Action<int, object> Feedback { get; set; }
|
||||
|
||||
@@ -41,7 +33,7 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
|
||||
public DownloadManager()
|
||||
{
|
||||
CanStartWithoutDownloadServer = false;
|
||||
|
||||
}
|
||||
|
||||
public void GetUpdatePlan()
|
||||
@@ -63,6 +55,8 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
if (!ApplyFolder.IsFolderEmpty())
|
||||
UpdatePlanResponse.FilesToDeleteInApply = FileController.GetAppliedFiles(ApplyFolder, false);
|
||||
}
|
||||
|
||||
UpdatePlanResponse.IsUninstall = true;
|
||||
}
|
||||
|
||||
public void StartProcess(BackgroundWorker worker)
|
||||
@@ -72,7 +66,7 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
worker.ReportProgress((int)progress);
|
||||
Thread.Sleep(waitms);
|
||||
});
|
||||
|
||||
|
||||
report(LauncherProgress.ProgressStart, 1000);
|
||||
|
||||
if (FilesToDownloadCount > 0)
|
||||
@@ -119,19 +113,32 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
|
||||
DownloadFolder.SaveCurrentInfo("current");
|
||||
|
||||
UpdateFileRequest req = new UpdateFileRequest(UpdatePlanResponse.CurrentPackage.Version);
|
||||
UpdateFileRequest req = new UpdateFileRequest(UpdatePlanResponse);
|
||||
foreach (var file2request in UpdatePlanResponse.FilesToRequest)
|
||||
{
|
||||
req.UpdateFile = file2request;
|
||||
|
||||
var res = AskForFile(req);
|
||||
UpdateFileResponse response = null;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
response = AskForFile(req);
|
||||
|
||||
//if (response is object)
|
||||
// break;
|
||||
}
|
||||
|
||||
if (response is null)
|
||||
{
|
||||
throw new DownloadFileFailedException($"file: {file2request.RelativePath}");
|
||||
}
|
||||
|
||||
var download_path = DownloadFolder.Combine(file2request.RelativePath);
|
||||
|
||||
Path.GetDirectoryName(download_path).CreateFolder();
|
||||
download_path.SaveFile(res.FileData);
|
||||
download_path.SaveFile(response.FileData);
|
||||
|
||||
var size = NonspecificTools.SizeSuffix((ulong)res.FileData.Length);
|
||||
var size = NonspecificTools.SizeSuffix((ulong)response.FileData.Length);
|
||||
|
||||
Feedback((int)LauncherProgress.DownloadUpdate, new DownloadProgressEventArgs(size, file2request));
|
||||
}
|
||||
@@ -146,7 +153,7 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
|
||||
if (UpdatePlanResponse.FilesToApply is object)
|
||||
UpdatePlanResponse.FilesToApply.ForEach(ApplyFile);
|
||||
|
||||
|
||||
if (UpdatePlanResponse.FilesToRequest is object)
|
||||
UpdatePlanResponse.FilesToRequest.ForEach(ApplyFile);
|
||||
|
||||
@@ -180,6 +187,12 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
DownloadFolder.ClearFolder();
|
||||
|
||||
ApplyFolder.Unlock(SkipLock);
|
||||
|
||||
if (UpdatePlanResponse.IsUninstall)
|
||||
{
|
||||
ApplyFolder.DeleteFolder();
|
||||
DownloadFolder.ClearFolder();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUpdatePlanRequest()
|
||||
@@ -220,5 +233,10 @@ namespace BeWoLauncher.Logic.Utils.Download
|
||||
|
||||
// UpdatePlanResponse.FilesToApply.AddRange(UpdatePlanResponse.FilesToRequest);
|
||||
}
|
||||
|
||||
public void CheckForConnection()
|
||||
{
|
||||
LauncherServiceFacade.DoDownloadBeWoServiceSyncWithException(x => x.DownloadInfo(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace BeWoLauncher.Logic
|
||||
|
||||
private FrameBase getUninstallProgressFrame()
|
||||
{
|
||||
var progress = new ProgressFrame(LauncherMode.Update);
|
||||
var progress = new ProgressFrame(LauncherMode.Uninstall);
|
||||
|
||||
progress.Successful += ViewBehavior.UninstallSuccess;
|
||||
progress.Exception += ViewBehavior.UninstallFailed;
|
||||
@@ -151,7 +151,7 @@ namespace BeWoLauncher.Logic
|
||||
|
||||
return updateError;
|
||||
}
|
||||
|
||||
|
||||
private FrameBase getUpdateProgressFrame()
|
||||
{
|
||||
var progress = new ProgressFrame(LauncherMode.Update);
|
||||
|
||||
@@ -66,7 +66,11 @@ namespace BeWo.Service.ServiceImplementations
|
||||
{
|
||||
var exception = UpdateRequestValidator.Validate(request, Tenant);
|
||||
if (exception is object)
|
||||
{
|
||||
UpdateServerSessionManager.CloseSession(request.UpdateSessionId);
|
||||
|
||||
throw new InvalidUpdateFileRequestException(exception);
|
||||
}
|
||||
|
||||
UpdateServerSessionManager.LoadAbsolutePath(request);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace BeWo.Service.ServiceUtils.Update
|
||||
if (session.Tenant != tenant)
|
||||
return "Tenant konnte nicht bestätigt werden.";
|
||||
|
||||
if (session.FileLimiterDict.ContainsKey(
|
||||
if (!session.FileLimiterDict.ContainsKey(
|
||||
request.UpdateFile.RelativePath))
|
||||
return $"Angefragte Datei nicht verfügbar. Anfrage an \"{request.UpdateFile.RelativePath}\"";
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ namespace BeWo.Service.ServiceUtils.Update
|
||||
};
|
||||
|
||||
_UpdateServerSessions.Add(session_id, session);
|
||||
|
||||
res.Session_Id = session_id;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -111,16 +113,18 @@ namespace BeWo.Service.ServiceUtils.Update
|
||||
{
|
||||
Monitor.Enter(_Lock);
|
||||
|
||||
var file_id = request.UpdateFile.RelativePath;
|
||||
|
||||
var session_id = request.UpdateSessionId;
|
||||
var session = _UpdateServerSessions[session_id];
|
||||
var limiter = session.FileLimiterDict[request.UpdateFile.RelativePath];
|
||||
var limiter = session.FileLimiterDict[file_id];
|
||||
|
||||
request.UpdateFile.AbsolutePath = limiter.UpdateFile.AbsolutePath;
|
||||
|
||||
limiter.RequestsLeft--;
|
||||
|
||||
if (!limiter.CanRequestMore)
|
||||
_UpdateServerSessions.Remove(session_id);
|
||||
session.FileLimiterDict.Remove(file_id);
|
||||
|
||||
if (!session.FileLimiterDict.Any())
|
||||
CloseSession(session_id);
|
||||
|
||||
@@ -18,11 +18,17 @@ namespace BS.SharedLauncher.DataContract
|
||||
|
||||
}
|
||||
|
||||
public UpdateFileRequest(string version) : base()
|
||||
public UpdateFileRequest(string version, string session_id) : base()
|
||||
{
|
||||
Version = version;
|
||||
UpdateSessionId = session_id;
|
||||
}
|
||||
|
||||
public UpdateFileRequest(UpdatePlanResponse response) : this(response.CurrentPackage.Version, response.Session_Id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public string Version { get; set; }
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace BS.SharedLauncher.DataContract
|
||||
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public string Session_Id { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public UpdatePlanDC CurrentPackage { get; set; }
|
||||
|
||||
@@ -31,5 +34,6 @@ namespace BS.SharedLauncher.DataContract
|
||||
|
||||
[DataMember]
|
||||
public long DownloadSize { get; set; }
|
||||
public bool IsUninstall { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
23
SharedLauncher/Exceptions/DownloadFileFailedException.cs
Normal file
23
SharedLauncher/Exceptions/DownloadFileFailedException.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BS.SharedLauncher.Exceptions
|
||||
{
|
||||
public class DownloadFileFailedException : UpdateException
|
||||
{
|
||||
public DownloadFileFailedException()
|
||||
{
|
||||
}
|
||||
|
||||
public DownloadFileFailedException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public DownloadFileFailedException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ namespace BS.SharedLauncher.Extensions
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
public static void DeleteFolder(this string path)
|
||||
{
|
||||
Directory.Delete(path);
|
||||
}
|
||||
public static bool Exists(this string path)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
<Compile Include="DataContract\UpdatePlanRequest.cs" />
|
||||
<Compile Include="DataContract\UpdateFileDC.cs" />
|
||||
<Compile Include="DataContract\UpdatePlanDC.cs" />
|
||||
<Compile Include="Exceptions\DownloadFileFailedException.cs" />
|
||||
<Compile Include="Exceptions\InvalidUpdateFileRequestException.cs" />
|
||||
<Compile Include="Exceptions\InvalidUpdatePlanRequestException.cs" />
|
||||
<Compile Include="Exceptions\ServerConfigException.cs" />
|
||||
|
||||
Reference in New Issue
Block a user