Files
BeWoPlaner/BeWoLauncher/View/Frames/ProgressFrame.xaml.cs
rene 4fbfdbaf2c Unit Tests erstellt
Informationen ausgelagert
Kleines Spy/Test Programm erstellt
Mehr Exceptions/InvalidUpdateFileRequestException.cs
Launcher Host in Download Server geändert
Download Server macht zusätzlich Abfrage an den Hauptserver
Download geht jetzt stückweise von statten
2022-12-28 16:36:59 +01:00

238 lines
8.2 KiB
C#

using BeWoLauncher.Logic.Controller;
using BS.SharedLauncher.Enums;
using BS.SharedLauncher.Update;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
namespace BeWoLauncher.View.Frames
{
/// <summary>
/// Interaktionslogik für UpdateView.xaml
/// </summary>
public partial class ProgressFrame : FrameBase
{
private static TimeSpan duration = TimeSpan.FromSeconds(1);
private int lastStep = -1;
private string[][] keywords = new string[][]
{
new string[]{"Installation", "Ungebrauchte Datei(en) gefunden." },
new string[]{"Update", "Ungebrauchte Datei(en) gefunden."},
new string[]{"Deinstallation", "Deinstallation startet..."},
};
private int keyword_mode;
public readonly BackgroundWorker Worker = new BackgroundWorker();
public event EventHandler Successful;
public event EventHandler Exception;
public LauncherMode LauncherMode { get; set; }
public ProgressFrame(LauncherMode mode)
{
InitializeComponent();
proBar1.IsIndeterminate = false;
proBar1.Minimum = 0;
proBar1.Maximum = 100;
proBar2.IsIndeterminate = false;
proBar2.Minimum = 0;
proBar2.Maximum = DownloadController.Manager.FilesToProcessTotal;
LauncherMode = mode;
keyword_mode = (int)mode;
Loaded += (s, e) => Start();
}
private string getKeyword(int pos) => keywords[keyword_mode][pos];
public string Message
{
get { return lblMessage.Content as string; }
set { lblMessage.Content = value; }
}
public string SubMessage
{
get { return lblSubmessage.Content as string; }
set { lblSubmessage.Content = value; }
}
public void Start()
{
var skipLock = bool.TryParse(ConfigurationManager.AppSettings.Get("SkipLock"), out bool c) && c;
Worker.DoWork += worker_DoWork;
Worker.ProgressChanged += worker_ProgressChanged;
Worker.RunWorkerCompleted += worker_completed;
Worker.WorkerReportsProgress = true;
Worker.RunWorkerAsync(skipLock);
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
var skipLock = (bool)e.Argument;
var worker = sender as BackgroundWorker;
DownloadController.Manager.SkipLock = skipLock;
DownloadController.Manager.Feedback = worker.ReportProgress;
DownloadController.Manager.StartProcess(worker);
}
private void worker_completed(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
ViewController.Error = e.Error;
Exception.Invoke(this, new EventArgs());
}
else
{
Successful.Invoke(this, new EventArgs());
}
}
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
var progress = (LauncherProgress)e.ProgressPercentage;
var obj = e.UserState;
switch (progress)
{
case LauncherProgress.ProgressStart:
Message = $"{getKeyword(0)} wird vorbereitet...";
SubMessage = "";
Bar2Activate();
break;
case LauncherProgress.DownloadStart:
Message = "Download startet...";
SubMessage = "";
Bar1Show();
Bar1Activate();
Bar1Reset();
Bar1SetLimit(DownloadController.Manager.FilesToDownloadCount);
break;
case LauncherProgress.DownloadUpdate:
var args = obj as DownloadProgressEventArgs;
Message = "Download wird ausgeführt...";
SubMessage = $"{args.File.RelativePath} ({args.Size})\n wurde heruntergeladen...";
Bar1MakeStep();
Bar2MakeStep();
break;
case LauncherProgress.DownloadFinish:
Message = "Download abgeschlossen!";
SubMessage = "";
Bar1Hide();
break;
case LauncherProgress.ApplyStart:
Message = "Füge Pakete hinzu...";
SubMessage = "";
Bar1Show();
Bar1Activate();
Bar1Reset();
Bar1SetLimit(DownloadController.Manager.FilesToApplyCount);
break;
case LauncherProgress.ApplyUpdate:
var args2 = obj as ApplyFileEventArgs;
SubMessage = $"{args2.RelativePath}\n wurde installiert...";
Bar1MakeStep();
Bar2MakeStep();
break;
case LauncherProgress.ApplyFinished:
Message = "Hinzufügen abgeschlossen!";
SubMessage = "";
Bar1Hide();
break;
case LauncherProgress.DeleteStart:
Message = getKeyword(1);
SubMessage = "";
Bar1Show();
Bar1Activate();
Bar1Reset();
Bar1SetLimit(DownloadController.Manager.FilesToDeleteInApplyCount);
break;
case LauncherProgress.DeleteUpdate:
var args3 = obj as string;
SubMessage = $"{args3}\n wurde entfernt!";
Bar1MakeStep();
Bar2MakeStep();
break;
case LauncherProgress.DeleteFinished:
Message = "Säuberung abgeschlossen!";
SubMessage = "";
Bar1Hide();
break;
case LauncherProgress.CleanupStart:
Message = "Räume hier noch eben auf...";
SubMessage = "";
Bar1Show();
Bar1Deactivate();
break;
case LauncherProgress.CleanupUpdate:
break;
case LauncherProgress.CleanupFinished:
Message = "Blitze blank...";
SubMessage = "";
break;
case LauncherProgress.ProgressEnd:
Message = $"{getKeyword(0)} abgeschlossen!";
SubMessage = "";
Bar2Fill();
break;
default:
break;
}
}
#region a
public void Bar1Activate() => proBar1.IsIndeterminate = false;
public void Bar1Deactivate() => proBar1.IsIndeterminate = true;
public void Bar1SetLimit(int max) => proBar1.Maximum = max;
public void Bar1Reset() => proBar1.Value = 0;
public void Bar1MakeStep() => proBar1.Value++;
public void Bar1Hide() => proBar1.Visibility = Visibility.Hidden;
public void Bar1Show() => proBar1.Visibility = Visibility.Visible;
public void Bar2Activate() => proBar2.IsIndeterminate = false;
public void Bar2Deactivate() => proBar2.IsIndeterminate = true;
public void Bar2SetLimit(int max) => proBar2.Maximum = max;
public void Bar2MakeStep() => proBar2.Value++;
public void Bar2MakeStep(int val) => proBar2.Value += val;
public void Bar2Fill() => proBar2.Value = proBar2.Maximum;
public void Bar2Hide() => proBar2.Visibility = Visibility.Hidden;
public void Bar2Show() => proBar2.Visibility = Visibility.Visible;
public void Bar2SetPercent(double percentage)
{
DoubleAnimation animation = new DoubleAnimation(percentage, duration);
proBar2.BeginAnimation(ProgressBar.ValueProperty, animation);
}
#endregion
}
}