From c8adcff8ccef1c7654e791dc917c68b50c6358a5 Mon Sep 17 00:00:00 2001 From: rene Date: Mon, 19 Dec 2022 13:54:51 +0100 Subject: [PATCH] =?UTF-8?q?Progress=20Info=20Fehler=20behoben,=20spezielle?= =?UTF-8?q?=20Exceptions=20aufm=20Server=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeWo/app.config | 6 +- BeWoLauncher/Logic/Behavior/LaunchBehavior.cs | 31 ++-- .../Logic/Behavior/ViewSwitchBehavior.cs | 9 + .../Logic/Controller/ViewController.cs | 3 +- .../ServiceProxy/LauncherServiceFacade.cs | 12 ++ .../Logic/Utils/Download/DownloadManager.cs | 39 +++-- BeWoLauncher/Logic/ViewBuilder.cs | 14 ++ .../View/Frames/InstallProgressInfoFrame.cs | 162 +++++++++++------ .../View/Frames/UpdateProgressInfoFrame.cs | 163 +++++++++++------- BeWoLauncher/View/LoginView.xaml.cs | 3 +- LauncherHost/Web.config | 9 +- .../DownloadBeWoServiceImp.cs | 38 ++-- Service/ServiceUtils/Paths/ServerFilePaths.cs | 2 +- .../Update/DownloadPlanerResponseBuilder.cs | 21 ++- .../DataContract/DownloadPlanerResponseDC.cs | 7 + .../Exceptions/ServerConfigException.cs | 23 +++ .../Extensions/PlanerPackageExtension.cs | 11 +- .../Information/ConnectionInformation.cs | 2 +- SharedLauncher/LauncherEnums.cs | 15 ++ SharedLauncher/Logic/FileController.cs | 42 ++++- SharedLauncher/SharedLauncher.csproj | 4 +- ...FileEventArgs.cs => ApplyFileEventArgs.cs} | 4 +- .../Update/DownloadProgressEventArgs.cs | 18 ++ 23 files changed, 454 insertions(+), 184 deletions(-) create mode 100644 SharedLauncher/Exceptions/ServerConfigException.cs rename SharedLauncher/Update/{FileEventArgs.cs => ApplyFileEventArgs.cs} (75%) create mode 100644 SharedLauncher/Update/DownloadProgressEventArgs.cs diff --git a/BeWo/app.config b/BeWo/app.config index 2bad135a7..da18d8e34 100644 --- a/BeWo/app.config +++ b/BeWo/app.config @@ -8,17 +8,17 @@ - + - + - + diff --git a/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs b/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs index 12ac4cee7..e4849e8c3 100644 --- a/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs +++ b/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs @@ -1,5 +1,8 @@ -using BeWoLauncher.Logic.Controller; +using BeWoLauncher.Components; +using BeWoLauncher.Logic.Controller; using BeWoLauncher.Logic.Utils; +using BS.SharedLauncher.Information; +using System; using System.Threading.Tasks; using static BeWoLauncher.Logic.Controller.ViewController; @@ -46,18 +49,24 @@ namespace BeWoLauncher.Logic.Behavior else Task.Run(() => { - DownloadController.Start(); - DownloadController.Manager.StartDownloadInfo(); - - if (DownloadController.Manager.ResponseInfo.HasSomethingToDo) + try { - ViewBehavior.ShowInfo(); - } - else - { - ViewBehavior.ShowLoading(); - } + DownloadController.Start(); + DownloadController.Manager.StartDownloadInfo(); + if (DownloadController.Manager.ResponseInfo.HasSomethingToDo) + { + ViewBehavior.ShowInfo(); + } + else + { + ViewBehavior.ShowLoading(); + } + } + catch(Exception ex) + { + ViewBehavior.ShowError(ex); + } EndWaiting(); }); } diff --git a/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs b/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs index 7ea9c4bb6..cf589467b 100644 --- a/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs +++ b/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs @@ -77,6 +77,15 @@ namespace BeWoLauncher.Logic.Behavior })); } + public void ShowError(Exception exception) + { + ViewController.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + Error = exception; + ShowFrame(FrameType.GenericFail); + })); + } + public void ShowUninstallInfo() { ViewController.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => diff --git a/BeWoLauncher/Logic/Controller/ViewController.cs b/BeWoLauncher/Logic/Controller/ViewController.cs index 34edc24cb..691b92333 100644 --- a/BeWoLauncher/Logic/Controller/ViewController.cs +++ b/BeWoLauncher/Logic/Controller/ViewController.cs @@ -31,7 +31,8 @@ namespace BeWoLauncher.Logic.Controller UninstallFailed, UninstallSuccessful, LoadingScreen, - NoPermissionInfo + NoPermissionInfo, + GenericFail } public static class ViewController diff --git a/BeWoLauncher/Logic/ServiceProxy/LauncherServiceFacade.cs b/BeWoLauncher/Logic/ServiceProxy/LauncherServiceFacade.cs index 2f73c6d8a..4ed1571ab 100644 --- a/BeWoLauncher/Logic/ServiceProxy/LauncherServiceFacade.cs +++ b/BeWoLauncher/Logic/ServiceProxy/LauncherServiceFacade.cs @@ -159,6 +159,18 @@ namespace BeWoLauncher.ServiceProxy ShowErrorMessage(e); } } + public static T DoDownloadBeWoServiceSyncWithException(Func pFunc) + { + try + { + return pFunc.Invoke(GetInstance()); + } + catch (Exception e) + { + throw e; + } + return default(T); + } public static T DoDownloadBeWoServiceSync(Func pFunc) { try diff --git a/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs b/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs index fe683502d..553ef6e12 100644 --- a/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs +++ b/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs @@ -1,6 +1,7 @@ using BeWoLauncher.ServiceProxy; using BS.SharedLauncher; using BS.SharedLauncher.DataContract; +using BS.SharedLauncher.Enums; using BS.SharedLauncher.Exceptions; using BS.SharedLauncher.Extensions; using BS.SharedLauncher.Information; @@ -44,7 +45,7 @@ namespace BeWoLauncher.Logic.Utils.Download ConnectionInformation.Version = ResponseInfo.Version; } - public void StartDownload(bool skipLock) + public void StartDownload(bool skipLock, Action download) { GetDownloadResponse(); @@ -52,6 +53,8 @@ namespace BeWoLauncher.Logic.Utils.Download { // Macht das Sinn? // Ne, wahrsch. Fehler + throw new NotImplementedException("#45419873274"); + return; } @@ -63,6 +66,7 @@ namespace BeWoLauncher.Logic.Utils.Download LauncherPaths.CurrentDownloadZipLocation = FileController.GetNewZipPath(LauncherPaths.GetDownloadPath()); + //FileController.SaveDZipStream(LauncherPaths.CurrentDownloadZipLocation, Response.NewZipStream, Response.NewZipData.LongLength, download); FileController.SaveDZip(LauncherPaths.CurrentDownloadZipLocation, Response.NewZipData); FileController.SaveInfo(LauncherPaths.CurrentDownloadZipLocation, Response.NewZipInfo); FileController.SaveInfo(LauncherPaths.GetRootPath().Combine("latest"), Response.LatestApplicationInfo); @@ -87,36 +91,37 @@ namespace BeWoLauncher.Logic.Utils.Download { FileController.ApplyDZip(LauncherPaths.CurrentDownloadZipLocation, ApplyFolder, apply); } - + } + public void StartCleanup(Action feedback) + { if (Response.HasToRemoveFiles) { - apply(3, null); - - Thread.Sleep(500); - - FileController.RemoveUnsuedFiles(Response.LatestApplicationInfo, ApplyFolder, apply); + StartRemoveFiles(feedback, Response.LatestApplicationInfo); } DownloadFolder.ClearFolder(); ApplyFolder.Unlock(); - apply(5, null); - Thread.Sleep(1000); } - public void StartUninstall(Action apply) + public void StartUninstall(Action feedback) { - apply(3, null); - - Thread.Sleep(500); - var t = new PlanerPackageInfoDC() { Files = new List() }; - - FileController.RemoveUnsuedFiles(t, LauncherPaths.ActualPlanerLocation, apply); + + StartRemoveFiles(feedback, t); + } + + private void StartRemoveFiles(Action feedback, PlanerPackageInfoDC newPackage) + { + feedback((int)LauncherProgress.DeleteStart, null); + + Thread.Sleep(500); + + FileController.RemoveUnsuedFiles(newPackage, ApplyFolder, feedback); } private void CreateDownloadRequest() @@ -155,7 +160,7 @@ namespace BeWoLauncher.Logic.Utils.Download private void GetDownloadResponseInfo() { var t = ConnectionInformation.Tenant; - ResponseInfo = LauncherServiceFacade.DoDownloadBeWoServiceSync(x => x.DownloadInfo(Request)); + ResponseInfo = LauncherServiceFacade.DoDownloadBeWoServiceSyncWithException(x => x.DownloadInfo(Request)); } } } diff --git a/BeWoLauncher/Logic/ViewBuilder.cs b/BeWoLauncher/Logic/ViewBuilder.cs index 7f615f89a..018f0a772 100644 --- a/BeWoLauncher/Logic/ViewBuilder.cs +++ b/BeWoLauncher/Logic/ViewBuilder.cs @@ -31,6 +31,8 @@ namespace BeWoLauncher.Logic { switch (type) { + case FrameType.GenericFail: + return getGenericFailedFrame(); case FrameType.InstallInfo: return getInstallInfoFrame(); case FrameType.InstallProgress: @@ -178,6 +180,18 @@ namespace BeWoLauncher.Logic return installError; } + private FrameBase getGenericFailedFrame() + { + var genError = new InfoFrame(); + + genError.Title = "Loader fehlgeschlagen!"; + genError.Text = Error.ToString(); + + genError.Button1Click += ViewBehavior.BackToLogin; + + return genError; + } + private FrameBase getInstallProgressFrame() { var installprogress = new InstallProgressInfoFrame(); diff --git a/BeWoLauncher/View/Frames/InstallProgressInfoFrame.cs b/BeWoLauncher/View/Frames/InstallProgressInfoFrame.cs index b432e25f6..639c8bfcc 100644 --- a/BeWoLauncher/View/Frames/InstallProgressInfoFrame.cs +++ b/BeWoLauncher/View/Frames/InstallProgressInfoFrame.cs @@ -1,5 +1,6 @@ using BeWoLauncher.Logic.Controller; using BeWoLauncher.Logic.Utils.Download; +using BS.SharedLauncher.Enums; using BS.SharedLauncher.Update; using System; using System.ComponentModel; @@ -17,8 +18,9 @@ namespace BeWoLauncher.View.Frames public InstallProgressInfoFrame() : base() { Bar1SetLimit(Manager.ResponseInfo.FileCount); - - Bar1Deactivate(); + Bar1Hide(); + + Bar2SetLimit(100); } public override void Start() @@ -40,21 +42,53 @@ namespace BeWoLauncher.View.Frames BackgroundWorker worker = sender as BackgroundWorker; - worker.ReportProgress(0); + // UI: 0 + worker.ReportProgress((int)LauncherProgress.ProgressStart); + // Wait Thread.Sleep(1000); - DownloadController.Manager.StartDownload(skipLock); - - worker.ReportProgress(10); - - Thread.Sleep(1000); - - worker.ReportProgress(1); + // UI: 1 + worker.ReportProgress((int)LauncherProgress.DownloadStart); + // Wait Thread.Sleep(500); + // Process: 2 + DownloadController.Manager.StartDownload(skipLock, worker.ReportProgress); + + // UI: 3 + worker.ReportProgress((int)LauncherProgress.DownloadFinish); + + // Wait + Thread.Sleep(1000); + + // UI: 4 + worker.ReportProgress((int)LauncherProgress.ApplyStart); + + // Wait + Thread.Sleep(500); + + // Process: 5 DownloadController.Manager.StartApply(skipLock, worker.ReportProgress); + + // UI: 6 + worker.ReportProgress((int)LauncherProgress.ApplyFinished); + + // Wait + Thread.Sleep(1000); + + // Process: 7, Wait, 8 + DownloadController.Manager.StartCleanup(worker.ReportProgress); + + // UI: 9 + worker.ReportProgress((int)LauncherProgress.DeleteFinished); + + // Wait + Thread.Sleep(500); + + // UI: 10 + worker.ReportProgress((int)LauncherProgress.ProgressEnd); } private void worker_completed(object sender, RunWorkerCompletedEventArgs e) @@ -71,64 +105,78 @@ namespace BeWoLauncher.View.Frames private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { - Bar2SetLimit(100); + var progress = (LauncherProgress)e.ProgressPercentage; + var obj = e.UserState; - if (e.ProgressPercentage == 0) + switch (progress) { - // Download begonnen + case LauncherProgress.ProgressStart: + Message = "Installation wird vorbereitet..."; + SubMessage = "Lade benötigte Pakete herunter..."; + break; - Message = "Installation wird vorbereitet..."; - SubMessage = "Lade benötigte Pakete herunter..."; - } - else if (e.ProgressPercentage == 10) - { - // Download fertig + case LauncherProgress.DownloadStart: + Message = "Download startet..."; + SubMessage = ""; + Bar1Show(); + Bar1Deactivate(); + Bar2SetPercent(10); + break; - Message = "Download abgeschlossen!"; - SubMessage = ""; + case LauncherProgress.DownloadUpdate: + throw new NotImplementedException("#fd42398"); + var args = obj as DownloadProgressEventArgs; + SubMessage = $"{args.Progress.ToString("0.##")}% fertig"; + break; - Bar2SetPercent(30); - } - else if (e.ProgressPercentage == 1) - { - // Installation beginnen + case LauncherProgress.DownloadFinish: + Message = "Download abgeschlossen!"; + SubMessage = ""; + Bar2SetPercent(40); + break; - Message = "Installiere Pakete..."; - SubMessage = ""; + case LauncherProgress.ApplyStart: + Message = "Füge Pakete hinzu..."; + SubMessage = ""; + Bar1Activate(); + break; - Bar1Activate(); - } - else if (e.ProgressPercentage == 2) - { - // Installation Fortschritt + case LauncherProgress.ApplyUpdate: + var args2 = obj as ApplyFileEventArgs; + SubMessage = $"{args2.Name} wurde erfolgreich von \n{args2.AbsolutePath} hinzugefügt!"; + Bar1MakeStep(); + break; - var args = e.UserState as FileEventArgs; - SubMessage = $"{args.Name} wurde erfolgreich von {args.AbsolutePath} installiert!"; + case LauncherProgress.ApplyFinished: + Message = "Hinzufügen abgeschlossen!"; + SubMessage = ""; + Bar2SetPercent(80); + Bar1Deactivate(); + break; - Bar1MakeStep(); - } - else if (e.ProgressPercentage == 3) - { - // Löschen begonnen + case LauncherProgress.DeleteStart: + Message = "Ungebrauchte Datei(en) gefunden."; + SubMessage = ""; + break; + case LauncherProgress.DeleteUpdate: + var args3 = obj as string; + SubMessage = $"{args3} wurde entfernt!"; + break; - Bar1Deactivate(); + case LauncherProgress.DeleteFinished: + Message = "Säuberung abgeschlossen!"; + SubMessage = ""; + Bar2SetPercent(95); + Bar1Deactivate(); + break; - Message = "Alte Dateien werden entfernt."; - SubMessage = ""; - - Bar2SetPercent(75); - } - else if (e.ProgressPercentage == 4) - { - // Löschen Fortschrittt - - var args = e.UserState as string; - SubMessage = $"{args} wurde entfernt!"; - } - else if (e.ProgressPercentage == 5) - { - // Fertig mitm Löschen - Bar2Fill(); + case LauncherProgress.ProgressEnd: + Message = "Installation abgeschlossen!"; + SubMessage = ""; + Bar2Fill(); + break; + default: + break; } } } diff --git a/BeWoLauncher/View/Frames/UpdateProgressInfoFrame.cs b/BeWoLauncher/View/Frames/UpdateProgressInfoFrame.cs index 7f0d4fea7..4a9004803 100644 --- a/BeWoLauncher/View/Frames/UpdateProgressInfoFrame.cs +++ b/BeWoLauncher/View/Frames/UpdateProgressInfoFrame.cs @@ -1,5 +1,6 @@ using BeWoLauncher.Logic.Controller; using BeWoLauncher.Logic.Utils.Download; +using BS.SharedLauncher.Enums; using BS.SharedLauncher.Update; using System; using System.ComponentModel; @@ -17,8 +18,9 @@ namespace BeWoLauncher.View.Frames public UpdateProgressInfoFrame() { Bar1SetLimit(Manager.ResponseInfo.FileCount); - - Bar1Deactivate(); + Bar1Hide(); + + Bar2SetLimit(100); } public override void Start() @@ -40,21 +42,53 @@ namespace BeWoLauncher.View.Frames BackgroundWorker worker = sender as BackgroundWorker; - worker.ReportProgress(0); + // UI: 0 + worker.ReportProgress((int)LauncherProgress.ProgressStart); + // Wait Thread.Sleep(1000); - DownloadController.Manager.StartDownload(skipLock); - - worker.ReportProgress(10); - - Thread.Sleep(1000); - - worker.ReportProgress(1); + // UI: 1 + worker.ReportProgress((int)LauncherProgress.DownloadStart); + // Wait Thread.Sleep(500); + // Process: 2 + DownloadController.Manager.StartDownload(skipLock, worker.ReportProgress); + + // UI: 3 + worker.ReportProgress((int)LauncherProgress.DownloadFinish); + + // Wait + Thread.Sleep(1000); + + // UI: 4 + worker.ReportProgress((int)LauncherProgress.ApplyStart); + + // Wait + Thread.Sleep(500); + + // Process: 5 DownloadController.Manager.StartApply(skipLock, worker.ReportProgress); + + // UI: 6 + worker.ReportProgress((int)LauncherProgress.ApplyFinished); + + // Wait + Thread.Sleep(1000); + + // Process: 7, Wait, 8 + DownloadController.Manager.StartCleanup(worker.ReportProgress); + + // UI: 9 + worker.ReportProgress((int)LauncherProgress.DeleteFinished); + + // Wait + Thread.Sleep(500); + + // UI: 10 + worker.ReportProgress((int)LauncherProgress.ProgressEnd); } private void worker_completed(object sender, RunWorkerCompletedEventArgs e) @@ -71,65 +105,78 @@ namespace BeWoLauncher.View.Frames private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { - Bar2SetLimit(100); + var progress = (LauncherProgress)e.ProgressPercentage; + var obj = e.UserState; - if (e.ProgressPercentage == 0) + switch (progress) { - // Download begonnen + case LauncherProgress.ProgressStart: + Message = "Update wird vorbereitet..."; + SubMessage = "Lade benötigte Pakete herunter..."; + break; - Message = "Update wird vorbereitet..."; - SubMessage = "Lade benötigte Pakete herunter..."; - } - else if (e.ProgressPercentage == 10) - { - // Download fertig + case LauncherProgress.DownloadStart: + Message = "Download startet..."; + SubMessage = ""; + Bar1Show(); + Bar1Deactivate(); + Bar2SetPercent(5); + break; - Message = "Download abgeschlossen!"; - SubMessage = ""; + case LauncherProgress.DownloadUpdate: + throw new NotImplementedException("#fd42398"); + var args = obj as DownloadProgressEventArgs; + SubMessage = $"{args.Progress.ToString("0.##")}% fertig"; + break; - Bar2SetPercent(30); - } - else if (e.ProgressPercentage == 1) - { - // Installation beginnen + case LauncherProgress.DownloadFinish: + Message = "Download abgeschlossen!"; + SubMessage = ""; + Bar2SetPercent(40); + break; - Message = "Aktualisiere Pakete..."; - SubMessage = ""; + case LauncherProgress.ApplyStart: + Message = "Füge Pakete hinzu..."; + SubMessage = ""; + Bar1Activate(); + break; - Bar1Activate(); - } - else if (e.ProgressPercentage == 2) - { - // Installation Fortschritt + case LauncherProgress.ApplyUpdate: + var args2 = obj as ApplyFileEventArgs; + SubMessage = $"{args2.Name} wurde erfolgreich von \n{args2.AbsolutePath} hinzugefügt!"; + Bar1MakeStep(); + break; - var args = e.UserState as FileEventArgs; - SubMessage = $"{args.Name} wurde erfolgreich von {args.AbsolutePath} installiert!"; + case LauncherProgress.ApplyFinished: + Message = "Hinzufügen abgeschlossen!"; + SubMessage = ""; + Bar2SetPercent(80); + Bar1Deactivate(); + break; - Bar1MakeStep(); - } - else if (e.ProgressPercentage == 3) - { - // Löschen begonnen + case LauncherProgress.DeleteStart: + Message = "Ungebrauchte Datei(en) gefunden."; + SubMessage = ""; + break; + case LauncherProgress.DeleteUpdate: + var args3 = obj as string; + SubMessage = $"{args3} wurde entfernt!"; + break; - Bar1Deactivate(); + case LauncherProgress.DeleteFinished: + Message = "Säuberung abgeschlossen!"; + SubMessage = ""; + Bar2SetPercent(95); + Bar1Deactivate(); + break; - Message = "Alte Dateien werden entfernt."; - SubMessage = ""; - - Bar2SetPercent(75); - } - else if (e.ProgressPercentage == 4) - { - // Löschen Fortschrittt - - var args = e.UserState as string; - SubMessage = $"{args} wurde entfernt!"; - } - else if (e.ProgressPercentage == 5) - { - // Fertig mitm Löschen - - Bar2Fill(); + case LauncherProgress.ProgressEnd: + Message = "Installation abgeschlossen!"; + SubMessage = ""; + Bar2Fill(); + break; + default: + break; } } } diff --git a/BeWoLauncher/View/LoginView.xaml.cs b/BeWoLauncher/View/LoginView.xaml.cs index 74290d300..6bb6cd0df 100644 --- a/BeWoLauncher/View/LoginView.xaml.cs +++ b/BeWoLauncher/View/LoginView.xaml.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; +using System.Deployment.Application; using System.IO; using System.Linq; using System.Net; @@ -351,7 +352,7 @@ namespace BeWoLauncher.View ReadProfileList(); #if DEBUG - var uri = new Uri("https://localhost/Host/?k=demo&s=localhost/service"); + var uri = new Uri("http://localhost/Host/?k=demo&s=localhost/service"); var paramDic = LauncherUtils.ParseQuery(uri.Query); string v1, v2; diff --git a/LauncherHost/Web.config b/LauncherHost/Web.config index 82eda0f97..96e9fb899 100644 --- a/LauncherHost/Web.config +++ b/LauncherHost/Web.config @@ -83,13 +83,16 @@ - + - + - + diff --git a/Service/ServiceImplementations/DownloadBeWoServiceImp.cs b/Service/ServiceImplementations/DownloadBeWoServiceImp.cs index 88bce7e3f..e98f37bdc 100644 --- a/Service/ServiceImplementations/DownloadBeWoServiceImp.cs +++ b/Service/ServiceImplementations/DownloadBeWoServiceImp.cs @@ -12,6 +12,7 @@ using BeWo.Service.ServiceUtils.Paths; using BeWo.Service.ServiceUtils.Update; using BS.SharedLauncher.DataContract; using BS.SharedLauncher.Enums; +using BS.SharedLauncher.Exceptions; using BS.SharedLauncher.Extensions; using BS.SharedLauncher.Logic; using BS.SharedLauncher.Update; @@ -25,19 +26,30 @@ namespace BeWo.Service.ServiceImplementations public DownloadPlanerResponseDC Download2(DownloadPlanerRequestDC request) { - DownloadPlanerResponseBuilder builder = new DownloadPlanerResponseBuilder(request); + try + { + DownloadPlanerResponseBuilder builder = new DownloadPlanerResponseBuilder(request); - builder.Calculate(Tenant); + builder.Calculate(Tenant); - if (!request.ApplyFolderIsEmpty) - if (request.ApplyPackage is object) - builder.Substract(request.ApplyPackage.ToPlanerPackageInfo()); + if (!request.ApplyFolderIsEmpty) + if (request.ApplyPackage is object) + builder.Substract(request.ApplyPackage.ToPlanerPackageInfo()); - if (!request.DownloadFolderIsEmpty) - if (request.DownloadedPackages is object) - builder.AnalyseDownload(request.DownloadedPackages.ToDictionary(pair => pair.Key, pair => pair.Value.ToPlanerPackageInfo())); + if (!request.DownloadFolderIsEmpty) + if (request.DownloadedPackages is object) + builder.AnalyseDownload(request.DownloadedPackages.ToDictionary(pair => pair.Key, pair => pair.Value.ToPlanerPackageInfo())); - return builder.CreateResponse(request); + return builder.CreateResponse(request); + } + catch (UpdateException update) + { + throw update; + } + catch (Exception ex) + { + throw new UpdateException("Update - Download - Exception", ex); + } } public DownloadPlanerResponseInfoDC DownloadInfo(DownloadPlanerRequestDC request) @@ -66,9 +78,13 @@ namespace BeWo.Service.ServiceImplementations return responseInfo; } - catch (Exception e) + catch (UpdateException update) { - throw Core.Utils.CreateBeWoFaultException(e); + throw update; + } + catch (Exception ex) + { + throw new UpdateException("Update - DownloadInfo - Exception", ex); } } } diff --git a/Service/ServiceUtils/Paths/ServerFilePaths.cs b/Service/ServiceUtils/Paths/ServerFilePaths.cs index 0cf378a65..eff05b45a 100644 --- a/Service/ServiceUtils/Paths/ServerFilePaths.cs +++ b/Service/ServiceUtils/Paths/ServerFilePaths.cs @@ -32,7 +32,7 @@ namespace BeWo.Service.ServiceUtils.Paths private static string _LogFolderPath; public static string DownloadVersionFilePath => GetAppSettings(_DownloadVersionFilePath, "DownloadVersionFilePath"); - public static string DownloadFolderPath => GetAppSettings(_DownloadVersionFilePath, "DownloadVersionFilePath"); + public static string DownloadFolderPath => GetAppSettings(_DownloadFolderPath, "DownloadFolderPath"); public static string LogFolderPath => GetAppSettings(_LogFolderPath, "LogFolderPath"); static ServerFilePaths() diff --git a/Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs b/Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs index 2180dce8c..88af9e978 100644 --- a/Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs +++ b/Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs @@ -1,5 +1,6 @@ using BeWo.Service.ServiceUtils.Paths; using BS.SharedLauncher.DataContract; +using BS.SharedLauncher.Exceptions; using BS.SharedLauncher.Extensions; using BS.SharedLauncher.Logic; using BS.SharedLauncher.Update; @@ -112,6 +113,9 @@ namespace BeWo.Service.ServiceUtils.Update res.NewZipData = ZipArchiveBuilder.CreateZipArray(currentUpdatePackageInfo.Files, (file) => file.AbsolutePath, (file) => file.RelativePath); res.NewZipInfo = currentUpdatePackageInfo.ToPlanerPackageInfoDC(); + //res.NewZipStream = ZipArchiveBuilder.CreateZipStream(currentUpdatePackageInfo.Files, + // (file) => file.AbsolutePath, (file) => file.RelativePath); + //res.NewZipStreamLength = res.NewZipStream.Length; } res.HasToRemoveFiles = request.ApplyPackage?.Files?.Any(x => !res.LatestApplicationInfo.Files.Any(y => x.EqualsFile(y))) ?? false; @@ -121,15 +125,18 @@ namespace BeWo.Service.ServiceUtils.Update return res; } - private List getVersionDefaultFiles(string version) => getPlanerFiles(ServerFilePaths.GetVersionDefaultFolderPath(version)); - private List getVersionTenantFiles(string version, string tenant) => getPlanerFiles(ServerFilePaths.GetVersionTenantFolderPath(version, tenant)); - private List getSpecialTenantFiles(string tenant) => getPlanerFiles(ServerFilePaths.GetOverrideTenantFolderPath(tenant)); + private List getVersionDefaultFiles(string version) => getPlanerFiles(ServerFilePaths.GetVersionDefaultFolderPath(version), false); + private List getVersionTenantFiles(string version, string tenant) => getPlanerFiles(ServerFilePaths.GetVersionTenantFolderPath(version, tenant), true); + private List getSpecialTenantFiles(string tenant) => getPlanerFiles(ServerFilePaths.GetOverrideTenantFolderPath(tenant), true); - private List getPlanerFiles(string path) + private List getPlanerFiles(string path, bool ignore) { - if (!Directory.Exists(path)) - return new List(); - + if (!Directory.Exists(path)) { + if (ignore) + return new List(); + else + throw new ServerConfigException($"{path} konnte nicht gefunden werden"); + } var res = FileController.GetPlanerFiles(path); //res.ForEach(x => x.Source = source); diff --git a/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs b/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs index 000c63f0c..c88ac36a6 100644 --- a/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs +++ b/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs @@ -1,6 +1,7 @@ using BS.SharedLauncher.Update; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Text; @@ -24,6 +25,12 @@ namespace BS.SharedLauncher.DataContract [DataMember] public byte[] NewZipData { get; set; } + [DataMember] + public Stream NewZipStream { get; set; } + + [DataMember] + public long NewZipStreamLength { get; set; } + /// /// Nur neue Dateien /// diff --git a/SharedLauncher/Exceptions/ServerConfigException.cs b/SharedLauncher/Exceptions/ServerConfigException.cs new file mode 100644 index 000000000..744c18e51 --- /dev/null +++ b/SharedLauncher/Exceptions/ServerConfigException.cs @@ -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 ServerConfigException : UpdateException + { + public ServerConfigException() + { + } + + public ServerConfigException(string message) : base(message) + { + } + + public ServerConfigException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/SharedLauncher/Extensions/PlanerPackageExtension.cs b/SharedLauncher/Extensions/PlanerPackageExtension.cs index df63ec3b5..54fa46eb3 100644 --- a/SharedLauncher/Extensions/PlanerPackageExtension.cs +++ b/SharedLauncher/Extensions/PlanerPackageExtension.cs @@ -41,6 +41,10 @@ namespace BS.SharedLauncher.Extensions { return planerFileInfo.Files.Find(x => x.RelativePath == relative); } + public static PlanerFileInfo FirstOrDefaultPlanerFile(this PlanerPackageInfo planerFileInfo, string relative) + { + return planerFileInfo.Files.FirstOrDefault(x => x.RelativePath == relative); + } public static PlanerFileInfo FirstOrDefaultPlanerFile(this PlanerPackageInfo planerFileInfo, PlanerFileInfo file) { return planerFileInfo.Files.FirstOrDefault(x => x.EqualsFile(file)); @@ -53,9 +57,12 @@ namespace BS.SharedLauncher.Extensions } private static void OverrideFile(this PlanerPackageInfo planerFileInfo, PlanerFileInfo newFile) { - var oldFile = planerFileInfo.FindPlanerFile(newFile.RelativePath); + var oldFile = planerFileInfo.FirstOrDefaultPlanerFile(newFile.RelativePath); - oldFile.AbsolutePath = newFile.AbsolutePath; + if (oldFile is object) + oldFile.AbsolutePath = newFile.AbsolutePath; + else + planerFileInfo.Files.Add(newFile); //oldFile.Source = newFile.Source; } public static void OverrideFiles(this PlanerPackageInfo planerFileInfo, List files) diff --git a/SharedLauncher/Information/ConnectionInformation.cs b/SharedLauncher/Information/ConnectionInformation.cs index dd019c2da..309ad7fb6 100644 --- a/SharedLauncher/Information/ConnectionInformation.cs +++ b/SharedLauncher/Information/ConnectionInformation.cs @@ -42,7 +42,7 @@ namespace BS.SharedLauncher.Information public string[] ToArray() { - return new string[] { Tenant, Username, Password, IpAddress, "5", ChatServerAddress, Version }; + return new string[] { "demo", "demo", "demo", IpAddress, ConnectionInformation.CoreServerAddressOrigin.ToString(), ChatServerAddress, Version }; } //public static bool TryParse(string input, out Connection connection) diff --git a/SharedLauncher/LauncherEnums.cs b/SharedLauncher/LauncherEnums.cs index 99a17e678..1a0e2c40b 100644 --- a/SharedLauncher/LauncherEnums.cs +++ b/SharedLauncher/LauncherEnums.cs @@ -39,6 +39,21 @@ namespace BS.SharedLauncher.Enums AreTheSame } + public enum LauncherProgress + { + ProgressStart = 0, + DownloadStart = 1, + DownloadUpdate = 2, + DownloadFinish = 3, + ApplyStart = 4, + ApplyUpdate = 5, + ApplyFinished = 6, + DeleteStart = 7, + DeleteUpdate = 8, + DeleteFinished = 9, + ProgressEnd = 10, + } + //public enum PlanerUpdateSource //{ // Invalid = 0, diff --git a/SharedLauncher/Logic/FileController.cs b/SharedLauncher/Logic/FileController.cs index 4d9380c79..8adedd92d 100644 --- a/SharedLauncher/Logic/FileController.cs +++ b/SharedLauncher/Logic/FileController.cs @@ -1,4 +1,5 @@ using BS.SharedLauncher.DataContract; +using BS.SharedLauncher.Enums; using BS.SharedLauncher.Extensions; using BS.SharedLauncher.Information; using BS.SharedLauncher.Update; @@ -20,7 +21,7 @@ namespace BS.SharedLauncher.Logic public static string GetDZipPath(string root, int number) => Path.Combine(root, string.Format(ZipFormatName, getFileNumberCountString(number))); public static string GetDZipInfoPath(string root, int number) => GetDZipPath(root, number) + DotBeWoInfo; - + public static void ApplyDZip(Dictionary> zip2keepfiles, string destinationfolder, Action apply) { foreach (var pair in zip2keepfiles) @@ -41,7 +42,7 @@ namespace BS.SharedLauncher.Logic var path = destinationfolder.Combine(entry.FullName); Directory.CreateDirectory(Path.GetDirectoryName(path)); entry.ExtractToFile(path, true); - apply(2, new FileEventArgs(entry.FullName, path)); + apply((int)LauncherProgress.ApplyUpdate, new ApplyFileEventArgs(entry.FullName, path)); Thread.Sleep(100); } } @@ -60,15 +61,10 @@ namespace BS.SharedLauncher.Logic continue; File.Delete(file.AbsolutePath); - status(4, file); + status((int)LauncherProgress.DeleteUpdate, file); } } - public static void RemoveFiles(string folder) - { - - } - public static List GetValidDZipPaths(string path) { var res = new List(); @@ -97,6 +93,36 @@ namespace BS.SharedLauncher.Logic return temp; } + + public static void SaveDZipStream(string path, Stream filebytestream, long length, Action download) + { + long startlength = 0; + FileInfo finfo = new FileInfo(path); + if (finfo.Exists) + startlength = finfo.Length; // If File exists, + // we need to send the Start length to the server + + using (FileStream writeStream = + new System.IO.FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) + { + int chunkSize = 2048; + byte[] buffer = new byte[chunkSize]; + + do + { + int bytesRead = filebytestream.Read(buffer, 0, chunkSize); + if (bytesRead == 0) break; + + writeStream.Write(buffer, 0, bytesRead); + + download(11, new DownloadProgressEventArgs(writeStream.Position * 100 / length)); + } + while (true); + + writeStream.Close(); + } + filebytestream.Dispose(); + } public static void SaveDZip(string path, byte[] data) { File.WriteAllBytes(path, data); diff --git a/SharedLauncher/SharedLauncher.csproj b/SharedLauncher/SharedLauncher.csproj index fc9088b80..32749c241 100644 --- a/SharedLauncher/SharedLauncher.csproj +++ b/SharedLauncher/SharedLauncher.csproj @@ -54,6 +54,7 @@ + @@ -65,7 +66,8 @@ - + + diff --git a/SharedLauncher/Update/FileEventArgs.cs b/SharedLauncher/Update/ApplyFileEventArgs.cs similarity index 75% rename from SharedLauncher/Update/FileEventArgs.cs rename to SharedLauncher/Update/ApplyFileEventArgs.cs index 6e9ac0270..86d454cf4 100644 --- a/SharedLauncher/Update/FileEventArgs.cs +++ b/SharedLauncher/Update/ApplyFileEventArgs.cs @@ -6,12 +6,12 @@ using System.Threading.Tasks; namespace BS.SharedLauncher.Update { - public class FileEventArgs : EventArgs + public class ApplyFileEventArgs : EventArgs { public string Name { get; set; } public string AbsolutePath { get; set; } - public FileEventArgs(string name, string path) + public ApplyFileEventArgs(string name, string path) { Name = name; AbsolutePath = path; diff --git a/SharedLauncher/Update/DownloadProgressEventArgs.cs b/SharedLauncher/Update/DownloadProgressEventArgs.cs new file mode 100644 index 000000000..6157994ae --- /dev/null +++ b/SharedLauncher/Update/DownloadProgressEventArgs.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BS.SharedLauncher.Update +{ + public class DownloadProgressEventArgs : EventArgs + { + public double Progress { get; set; } + + public DownloadProgressEventArgs(double progress) + { + Progress = progress; + } + } +}