- Version wird aktuell im Client angezeigt LoadingScreen statt StartPlanerProcess UI verschönert Fehler im Host/web.config behoben
371 lines
12 KiB
C#
371 lines
12 KiB
C#
using BeWoLauncher.Logic.Controller;
|
|
using BeWoLauncher.Utils;
|
|
using BeWoLauncher.View;
|
|
using BeWoLauncher.View.Frames;
|
|
using BeWoLauncher.WindowImp;
|
|
using BS.SharedLauncher.Extensions;
|
|
using BS.SharedLauncher.Information;
|
|
using BS.SharedLauncher.Logic;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Threading;
|
|
|
|
namespace BeWoLauncher.Logic.Controller
|
|
{
|
|
public static class ViewController
|
|
{
|
|
private static UserControl _currentView;
|
|
private static FrameBase _currentFrame;
|
|
private static Exception error;
|
|
|
|
public enum LauncherPageType
|
|
{
|
|
Login,
|
|
InstallInfo,
|
|
InstallProgress,
|
|
InstallFailed,
|
|
UpdateInfo,
|
|
UpdateProgress,
|
|
UpdateFailed,
|
|
UninstallInfo,
|
|
UninstallProgress,
|
|
UninstallFailed,
|
|
UninstallSuccessful,
|
|
LoadingScreen,
|
|
NoPermissionInfo
|
|
}
|
|
|
|
public static LauncherWindow CurrentWindow { get; set; }
|
|
public static UserControl CurrentView
|
|
{
|
|
get => _currentView;
|
|
set
|
|
{
|
|
_currentView = value;
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Render,
|
|
(Action)delegate
|
|
{
|
|
CurrentWindow.SetMainContent(value);
|
|
});
|
|
}
|
|
}
|
|
public static FrameBase CurrentFrame
|
|
{
|
|
get => _currentFrame; set
|
|
{
|
|
_currentFrame = value;
|
|
|
|
if (CurrentView is FrameView frameview)
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Render,
|
|
(Action)delegate
|
|
{
|
|
frameview.SetFrame(value);
|
|
});
|
|
else
|
|
CurrentView = new FrameView(value);
|
|
}
|
|
}
|
|
|
|
public static Dispatcher Dispatcher => CurrentWindow.Dispatcher;
|
|
|
|
public static void StartView()
|
|
{
|
|
ShowPage(LauncherPageType.Login);
|
|
}
|
|
public static void RestartView()
|
|
{
|
|
ShowPage(LauncherPageType.Login);
|
|
CurrentWindow.Show();
|
|
CurrentWindow.Activate();
|
|
}
|
|
|
|
public static void StartWaiting() => CurrentWindow.StartWaiting();
|
|
public static void EndWaiting() => CurrentWindow.EndWaiting();
|
|
|
|
public static bool CheckForPermissions(string path)
|
|
{
|
|
return FileController.IsDirectoryWritable(path, false);
|
|
}
|
|
public static void CheckForNewestVersion()
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
DownloadController.Start();
|
|
DownloadController.Manager.StartDownloadInfo();
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Render,
|
|
(Action)delegate
|
|
{
|
|
if (DownloadController.Manager.ResponseInfo.HasSomethingToDo)
|
|
{
|
|
if (BeWoLocalConfig.GetFirstInstallationSuccess() &&
|
|
File.Exists(BeWoPaths.GetPlanerExePath()))
|
|
{
|
|
ShowPage(LauncherPageType.UpdateInfo);
|
|
}
|
|
else
|
|
{
|
|
ShowPage(LauncherPageType.InstallInfo);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowPage(LauncherPageType.LoadingScreen);
|
|
}
|
|
|
|
EndWaiting();
|
|
});
|
|
});
|
|
}
|
|
|
|
public static void InstallationFailed(Exception exception)
|
|
{
|
|
error = exception;
|
|
ShowPage(LauncherPageType.InstallFailed);
|
|
}
|
|
public static void UpdateFailed(Exception exception)
|
|
{
|
|
error = exception;
|
|
ShowPage(LauncherPageType.UpdateFailed);
|
|
}
|
|
public static void UninstallFailed(Exception exception)
|
|
{
|
|
error = exception;
|
|
ShowPage(LauncherPageType.UninstallFailed);
|
|
}
|
|
|
|
public static void CheckForAutoLogin(object sender, EventArgs e)
|
|
{
|
|
var autologin = bool.TryParse(ConfigurationManager.AppSettings.Get("AutoLogin"), out bool c) && c;
|
|
|
|
if (autologin)
|
|
if (sender is LoginView loginPage)
|
|
loginPage.ClickLogin();
|
|
}
|
|
public static void LoginSuccessful(object sender, EventArgs e)
|
|
{
|
|
#region confirm demo
|
|
#if DEBUG
|
|
//if (ConnectionInformation.Tenant == "demo")
|
|
//{
|
|
// var dlg = new ConfirmDemoDialog();
|
|
// dlg.ShowDialog();
|
|
//}
|
|
#else
|
|
if (ConnectionInformation.Tenant == "demo")
|
|
{
|
|
var dlg = new ConfirmDemoDialog();
|
|
dlg.ShowDialog();
|
|
}
|
|
#endif
|
|
#endregion
|
|
|
|
BeWoPaths.ActualPlanerLocation = BeWoPaths.GetInstallLocationFromSetting();
|
|
|
|
if (BeWoPaths.ActualPlanerLocation is object && !CheckForPermissions(BeWoPaths.ActualPlanerLocation))
|
|
{
|
|
ShowPage(LauncherPageType.NoPermissionInfo);
|
|
EndWaiting();
|
|
}
|
|
else
|
|
{
|
|
CheckForNewestVersion();
|
|
}
|
|
}
|
|
|
|
private static UserControl GetNewPage(LauncherPageType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case LauncherPageType.Login:
|
|
var login = new LoginView();
|
|
|
|
login.Loaded += CheckForAutoLogin;
|
|
login.LoginSuccessful += LoginSuccessful;
|
|
|
|
return login;
|
|
|
|
case LauncherPageType.InstallInfo:
|
|
var install = new InstallInfoFrame();
|
|
|
|
install.Accept += (s, e) =>
|
|
{
|
|
if (CheckForPermissions(install.InstallLocation))
|
|
{
|
|
BeWoPaths.SetAndSaveInstallLocation(install.InstallLocation);
|
|
BeWoLocalConfig.SetFirstInstallationSuccess(true);
|
|
ShowPage(LauncherPageType.InstallProgress);
|
|
}
|
|
else
|
|
{
|
|
ShowPage(LauncherPageType.NoPermissionInfo);
|
|
}
|
|
};
|
|
install.Abort += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(install);
|
|
|
|
case LauncherPageType.InstallProgress:
|
|
var installprogress = new InstallProgressInfoFrame();
|
|
|
|
installprogress.InstallSuccessful += (s, e) =>
|
|
{
|
|
BeWoLocalConfig.SetFirstInstallationSuccess(true);
|
|
ShowPage(LauncherPageType.LoadingScreen);
|
|
};
|
|
|
|
return GetControlInFrameView(installprogress);
|
|
|
|
|
|
case LauncherPageType.InstallFailed:
|
|
var installError = new InfoFrame();
|
|
|
|
installError.Title = "Installation fehlgeschlagen!";
|
|
installError.Text = error.ToString();
|
|
|
|
installError.Button1Click += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(installError);
|
|
|
|
case LauncherPageType.UpdateInfo:
|
|
var update = new UpdateInfoFrame();
|
|
|
|
update.Accept += (s, e) => { ShowPage(LauncherPageType.UpdateProgress); };
|
|
update.Abort += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(update);
|
|
|
|
|
|
case LauncherPageType.UpdateProgress:
|
|
var updateProgress = new UpdateProgressInfoFrame();
|
|
|
|
updateProgress.UpdateSuccessful += (s, e) => { ShowPage(LauncherPageType.LoadingScreen); };
|
|
|
|
return GetControlInFrameView(updateProgress);
|
|
|
|
|
|
case LauncherPageType.UpdateFailed:
|
|
var updateError = new InfoFrame();
|
|
|
|
updateError.Title = "Update fehlgeschlagen!";
|
|
updateError.Text = error.ToString();
|
|
|
|
updateError.Button1Click += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(updateError);
|
|
|
|
|
|
case LauncherPageType.UninstallInfo:
|
|
var uninstall = new UninstallInfoFrame();
|
|
|
|
uninstall.Accept += (s, e) => { ShowPage(LauncherPageType.UpdateProgress); };
|
|
uninstall.Abort += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(uninstall);
|
|
|
|
|
|
case LauncherPageType.UninstallProgress:
|
|
var uninstallProgress = new UninstallProgressInfoFrame();
|
|
|
|
uninstallProgress.UninstallSuccessful += (s, e) => { ShowPage(LauncherPageType.UninstallSuccessful); };
|
|
|
|
return GetControlInFrameView(uninstallProgress);
|
|
|
|
|
|
case LauncherPageType.UninstallFailed:
|
|
var uninstallFailed = new InfoFrame();
|
|
|
|
uninstallFailed.Title = "Deinstallation fehlgeschlagen!";
|
|
uninstallFailed.Text = error.ToString();
|
|
|
|
uninstallFailed.Button1Click += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(uninstallFailed);
|
|
|
|
|
|
case LauncherPageType.UninstallSuccessful:
|
|
var uninstallSuccessful = new InfoFrame();
|
|
|
|
uninstallSuccessful.Title = "Deinstallation erfolgreich!";
|
|
uninstallSuccessful.Text = "Kehre zum Login zurück...";
|
|
uninstallSuccessful.CollapseCopyButton();
|
|
|
|
|
|
uninstallSuccessful.Button1Click += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(uninstallSuccessful);
|
|
|
|
|
|
case LauncherPageType.LoadingScreen:
|
|
var loading = new LoadingScreen();
|
|
|
|
loading.Loaded += (s, e) =>
|
|
{
|
|
Task.Run(() => ProcessController.StartPlanerProcess());
|
|
};
|
|
|
|
return GetControlInFrameView(loading);
|
|
|
|
|
|
case LauncherPageType.NoPermissionInfo:
|
|
var noper = new InfoFrame();
|
|
|
|
noper.Title = "Keine Rechte auf Speicherort!";
|
|
noper.Text = "Es liegt eine neue Version. Sie besitzen aber nicht die benötigten Rechte, um diese anzuwenden. Bitte wenden Sie sich an Ihren System-Administrator!";
|
|
|
|
noper.Button1Click += (s, e) => { ShowPage(LauncherPageType.Login); };
|
|
|
|
return GetControlInFrameView(noper);
|
|
}
|
|
|
|
throw new NotImplementedException();
|
|
}
|
|
private static UserControl GetControlInFrameView(UserControl uc)
|
|
{
|
|
if (CurrentView is FrameView)
|
|
return uc;
|
|
|
|
var frame = uc as FrameBase;
|
|
|
|
if (frame is null)
|
|
{
|
|
throw new NotImplementedException("uc ist kein Frame");
|
|
}
|
|
|
|
var view = new FrameView();
|
|
|
|
view.SetFrame(frame);
|
|
|
|
return view;
|
|
}
|
|
private static void ShowPage(LauncherPageType type)
|
|
{
|
|
var page = GetNewPage(type);
|
|
|
|
if (page is LoginView login)
|
|
{
|
|
CurrentView = login;
|
|
}
|
|
else if (page is FrameView frameview)
|
|
{
|
|
CurrentView = frameview;
|
|
}
|
|
else if(page is FrameBase frame)
|
|
{
|
|
CurrentFrame = frame;
|
|
}
|
|
else
|
|
{
|
|
throw new NotImplementedException("Page Error 1063");
|
|
}
|
|
}
|
|
}
|
|
}
|