Files
BeWoPlaner/BeWoLauncher/Logic/ViewController.cs
2022-08-30 09:12:20 +02:00

125 lines
3.6 KiB
C#

using BeWoLauncher.PageImp;
using BeWoLauncher.Utils;
using BeWoLauncher.WindowImp;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Threading;
namespace BeWoLauncher.Logic
{
public enum LauncherPageType
{
Login,
Update
}
public static class ViewController
{
public static LauncherWindow Window { get; set; }
public static Dispatcher Dispatcher => Window.Dispatcher;
public static void LoginLoaded(object sender, EventArgs e)
{
var autologin = bool.TryParse(ConfigurationManager.AppSettings.Get("AutoLogin"), out bool c) && c;
if (autologin)
if (sender is LoginPage 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.SetAndSaveInstallLocation(((LoginPage)sender).InstallLocation);
ShowPage(LauncherPageType.Update);
}
public static void UpdateSuccessful(object sender, EventArgs e)
{
ProcessController.StartPlanerProcess();
}
public static void UpdateFailed(object sender, EventArgs e)
{
throw new NotImplementedException();
}
public static UserControl GetNewPage(LauncherPageType type)
{
if (type == LauncherPageType.Login)
{
var login = new LoginPage();
login.Loaded += LoginLoaded;
login.LoginSuccessful += LoginSuccessful;
return login;
}
else if (type == LauncherPageType.Update)
{
bool showDelay = bool.TryParse(ConfigurationManager.AppSettings.Get("ShowUpdateDelay"), out bool b) && b;
bool forceUpdate = bool.TryParse(ConfigurationManager.AppSettings.Get("ForceUpdate"), out bool c) && c;
var update = new UpdatePage(showDelay, forceUpdate);
update.UpdateSuccessful += UpdateSuccessful;
update.UpdateFailed += UpdateFailed;
return update;
}
throw new NotImplementedException();
}
public static void ShowPage(LauncherPageType type)
{
var page = GetNewPage(type);
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(Action)delegate
{
Window.rootGrid.Children.Clear();
Window.rootGrid.Children.Add(page);
});
}
//public void ShowLoginPage()
//{
// var login = new LoginPage();
// login.LoginSuccessful += FinishLogin;
// login.Loaded += LoadedLogin;
// ShowPage(login);
//}
//private void ShowUpdatePage()
//{
// var update = new UpdatePage(bool.TryParse(ConfigurationManager.AppSettings.Get("ShowUpdateDelay"), out bool b) && b,
// bool.TryParse(ConfigurationManager.AppSettings.Get("ForceUpdate"), out bool c) && c);
// update.UpdateSuccessful += FinishUpdate;
// ShowPage(update);
//}
}
}