aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-10-29 15:55:21 +0200
committerShlomo Hecht <shlomo@twine-s.com>2020-10-29 15:55:21 +0200
commit4b789f33eadfc5cc1d937a80ce03ea8425955ffe (patch)
tree7dbbd0529a24f9ca064cab688a0d6d2b8b762ea1 /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
parent8f3baa0d9097aa6ed800863a4680608e867c809a (diff)
parent11fb700fcbc4627162a9c3f84b03b5016248bd97 (diff)
downloadTango-4b789f33eadfc5cc1d937a80ce03ea8425955ffe.tar.gz
Tango-4b789f33eadfc5cc1d937a80ce03ea8425955ffe.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs173
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs67
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs8
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs44
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs146
5 files changed, 300 insertions, 138 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
index 2bb4e9286..562a3b659 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
@@ -3,11 +3,16 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Media;
using System.Windows.Threading;
+using Tango.Core;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.Integration.Operation;
+using Tango.PMR.IFS;
using Tango.PPC.Common;
+using Tango.PPC.Common.Connection;
using Tango.PPC.Common.Modules;
using Tango.PPC.Common.Navigation;
using Tango.PPC.UI.Views;
@@ -31,6 +36,86 @@ namespace Tango.PPC.UI.ViewModels
[TangoInject]
public IPPCModuleLoader ModuleLoader { get; set; }
+ #region Classes
+
+ public class CartridgeModel : ExtendedObject
+ {
+ private IMachineProvider _machineProvider;
+
+ public CartridgeStatus Status { get; set; }
+
+ public bool InProgress
+ {
+ get { return Status.State == CartridgeState.Filling || Status.State == CartridgeState.Emptying; }
+ }
+
+ public String Message
+ {
+ get { return Status.Cartridge.Slot == PMR.Diagnostics.CartridgeSlot.Ink ? "Ink filling is in progress..." : "Waste emptying is in progress..."; }
+ }
+
+ public Brush Brush
+ {
+ get
+ {
+ if (Status.Cartridge.Slot == PMR.Diagnostics.CartridgeSlot.Ink)
+ {
+ try
+ {
+ int index = Status.Cartridge.Index;
+
+ var idsPack = _machineProvider.Machine.Configuration.IdsPacks.FirstOrDefault(x => x.PackIndex == index);
+
+ if (idsPack != null)
+ {
+ switch (idsPack.LiquidType.Type)
+ {
+ case BL.Enumerations.LiquidTypes.Cyan:
+ return Application.Current.Resources["TangoCyanInkBrush"] as Brush;
+ case BL.Enumerations.LiquidTypes.Magenta:
+ return Application.Current.Resources["TangoMagentaInkBrush"] as Brush;
+ case BL.Enumerations.LiquidTypes.Yellow:
+ return Application.Current.Resources["TangoYellowInkBrush"] as Brush;
+ case BL.Enumerations.LiquidTypes.Black:
+ return Application.Current.Resources["TangoBlackInkBrush"] as Brush;
+ case BL.Enumerations.LiquidTypes.Lubricant:
+ return Application.Current.Resources["TangoLubricantBrush"] as Brush;
+ case BL.Enumerations.LiquidTypes.Cleaner:
+ return Application.Current.Resources["TangoCleanerBrush"] as Brush;
+ case BL.Enumerations.LiquidTypes.TransparentInk:
+ return Application.Current.Resources["TangoTransparentInkBrush"] as Brush;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error generating ink filling brush.");
+ }
+
+ return Application.Current.Resources["TangoPrimaryAccentBrush"] as Brush;
+ }
+ else
+ {
+ return Application.Current.Resources["TangoWasteBrush"] as Brush;
+ }
+ }
+ }
+
+ public CartridgeModel(IMachineProvider machineProvider)
+ {
+ _machineProvider = machineProvider;
+ Status = new CartridgeStatus();
+ }
+
+ public void Invalidate()
+ {
+ RaisePropertyChanged(nameof(InProgress));
+ RaisePropertyChanged(nameof(Status));
+ }
+ }
+
+ #endregion
+
#region Properties
private bool _isMenuOpened;
@@ -74,6 +159,23 @@ namespace Tango.PPC.UI.ViewModels
set { _isPowerOpened = value; RaisePropertyChangedAuto(); }
}
+ private bool _isInkFillingOrWasteEmptying;
+ /// <summary>
+ /// Gets or sets a value indicating whether ink filling or waste emptying is active.
+ /// </summary>
+ public bool IsInkFillingOrWasteEmptying
+ {
+ get { return _isInkFillingOrWasteEmptying; }
+ set { _isInkFillingOrWasteEmptying = value; RaisePropertyChangedAuto(); }
+ }
+
+ private List<CartridgeModel> _cartridges;
+ public List<CartridgeModel> Cartridges
+ {
+ get { return _cartridges; }
+ set { _cartridges = value; RaisePropertyChangedAuto(); }
+ }
+
#endregion
#region Commands
@@ -133,6 +235,11 @@ namespace Tango.PPC.UI.ViewModels
/// </summary>
public RelayCommand ResetCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the stand by command.
+ /// </summary>
+ public RelayCommand StandByCommand { get; set; }
+
#endregion
#region Constructors
@@ -149,17 +256,13 @@ namespace Tango.PPC.UI.ViewModels
StopPrintingCommand = new RelayCommand(StopPrinting);
SignOutCommand = new RelayCommand(SignOut);
- UpdateCommand = new RelayCommand(() =>
- {
- NavigationManager.NavigateTo(NavigationView.MachineUpdateView);
- TangoIOC.Default.GetInstance<MachineUpdateViewVM>().CheckForUpdates();
- IsMenuOpened = false;
- });
+ UpdateCommand = new RelayCommand(UpdateMachine);
PowerCommand = new RelayCommand(() => IsPowerOpened = true);
RestartApplicationCommand = new RelayCommand(RestartApplication);
PowerOffCommand = new RelayCommand(PowerOffMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected);
ResetCommand = new RelayCommand(ResetMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected);
+ StandByCommand = new RelayCommand(StandBy, () => MachineProvider.MachineOperator.CanPrint);
}
#endregion
@@ -301,6 +404,35 @@ namespace Tango.PPC.UI.ViewModels
}
}
+ private async void StandBy()
+ {
+ IsMenuOpened = false;
+
+ try
+ {
+ LogManager.Log("Executing stand-by command.");
+ await MachineProvider.MachineOperator.StandBy();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error switching to stand-by mode.");
+ await NotificationProvider.ShowError($"Error switching to stand-by mode.\n{ex.FlattenMessage()}");
+ }
+ }
+
+ private void UpdateMachine()
+ {
+ if (MachineProvider.MachineOperator.IsPrinting)
+ {
+ NotificationProvider.ShowInfo("Cannot perform a machine update while the machine is dyeing.");
+ return;
+ }
+
+ NavigationManager.NavigateTo(NavigationView.MachineUpdateView);
+ TangoIOC.Default.GetInstance<MachineUpdateViewVM>().CheckForUpdates();
+ IsMenuOpened = false;
+ }
+
#endregion
#region Override Methods
@@ -312,6 +444,34 @@ namespace Tango.PPC.UI.ViewModels
{
base.OnApplicationStarted();
MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted;
+ MachineProvider.MachineOperator.InkFillingStatusChanged += MachineOperator_InkFillingStatusChanged;
+ }
+
+ private void MachineOperator_InkFillingStatusChanged(object sender, InkFillingStatusChangedEventArgs e)
+ {
+ if (Cartridges == null)
+ {
+ Cartridges = MachineProvider.MachineOperator.InkFillingStatus.CartridgesStatuses.Select(x => new CartridgeModel(MachineProvider) { Status = x }).ToList();
+ }
+ else
+ {
+ foreach (var cartridgeStatus in e.Status.CartridgesStatuses)
+ {
+ var model = Cartridges.SingleOrDefault(x => x.Status == cartridgeStatus);
+
+ if (model != null)
+ {
+ model.Status = cartridgeStatus;
+ }
+ }
+ }
+
+ foreach (var cartridgeModel in Cartridges)
+ {
+ cartridgeModel.Invalidate();
+ }
+
+ IsInkFillingOrWasteEmptying = Cartridges.Any(x => x.Status.State == CartridgeState.Filling || x.Status.State == CartridgeState.Emptying);
}
/// <summary>
@@ -334,6 +494,7 @@ namespace Tango.PPC.UI.ViewModels
{
PowerOffCommand.RaiseCanExecuteChanged();
ResetCommand.RaiseCanExecuteChanged();
+ StandByCommand.RaiseCanExecuteChanged();
});
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
index e280d5f9d..38dd569e1 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs
@@ -74,39 +74,46 @@ namespace Tango.PPC.UI.ViewModels
/// </summary>
public async override void OnApplicationStarted()
{
- using (ObservablesContext db = ObservablesContext.CreateDefault())
- {
- var machine = await db.Machines.FirstAsync();
+ //We don't use authentication!
- if (db.Users.Count() == 1 || machine.AutoLogin)
- {
- var user = await new UserBuilder(db).SetFirst().WithRolesAndPermissions().BuildAsync();
+ //using (ObservablesContext db = ObservablesContext.CreateDefault())
+ //{
+ // var machine = await db.Machines.FirstAsync();
- if (!user.HasRole(Roles.PPCUser))
- {
- var role = db.Roles.Single(x => x.Code == (int)Roles.PPCUser);
- user.Roles.Add(role);
- db.UsersRoles.Add(new BL.Entities.UsersRole()
- {
- User = user,
- Role = role,
- });
- await db.SaveChangesAsync();
- }
+ // if (db.Users.Count() == 1 || machine.AutoLogin)
+ // {
+ // var user = await new UserBuilder(db).SetFirst().WithRolesAndPermissions().BuildAsync();
- LogManager.Log($"Application started. Single user/Auto login detected ({user.Email}). Skipping LoginView...");
- await AuthenticationProvider.Login(user.Email, user.Password, false);
- await Task.Delay(1000);
- IsLoading = false;
- }
- else
- {
- LogManager.Log("Application started. Navigating to LoginView...");
- await NavigationManager.NavigateTo(NavigationView.LoginView);
- await Task.Delay(1000);
- IsLoading = false;
- }
- }
+ // if (!user.HasRole(Roles.PPCUser))
+ // {
+ // var role = db.Roles.Single(x => x.Code == (int)Roles.PPCUser);
+ // user.Roles.Add(role);
+ // db.UsersRoles.Add(new BL.Entities.UsersRole()
+ // {
+ // User = user,
+ // Role = role,
+ // });
+ // await db.SaveChangesAsync();
+ // }
+
+ // LogManager.Log($"Application started. Single user/Auto login detected ({user.Email}). Skipping LoginView...");
+ // await AuthenticationProvider.Login(user.Email, user.Password, false);
+ // await Task.Delay(1000);
+ // IsLoading = false;
+ // }
+ // else
+ // {
+ // LogManager.Log("Application started. Navigating to LoginView...");
+ // await NavigationManager.NavigateTo(NavigationView.LoginView);
+ // await Task.Delay(1000);
+ // IsLoading = false;
+ // }
+ //}
+
+ LogManager.Log($"Application started with no authentication mode...");
+ await AuthenticationProvider.Login();
+ await Task.Delay(1000);
+ IsLoading = false;
}
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs
index aa9689ef3..ec316989f 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs
@@ -92,7 +92,13 @@ namespace Tango.PPC.UI.ViewModels
await Task.Delay(500);
- if (AuthenticationProvider.CurrentUser != null && AuthenticationProvider.CurrentUser.HasPermission(Permissions.RunPPC))
+ if (!AuthenticationProvider.AuthenticationRequired)
+ {
+ LogManager.Log("Application is ready! Navigating to home module...");
+ await NavigationManager.NavigateTo(NavigationView.HomeModule);
+ IsLoading = false;
+ }
+ else if (AuthenticationProvider.CurrentUser != null && AuthenticationProvider.CurrentUser.HasPermission(Permissions.RunPPC))
{
LogManager.Log("Application is ready! Navigating to home module...");
await NavigationManager.NavigateTo(NavigationView.HomeModule);
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
index 965584767..613c70809 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
@@ -167,7 +167,7 @@ namespace Tango.PPC.UI.ViewModels
return;
}
- var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber);
+ var response = await MachineUpdateManager.CheckForUpdate();
try
{
@@ -208,7 +208,7 @@ namespace Tango.PPC.UI.ViewModels
}
else
{
- _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber);
+ _db_compare_result = await MachineUpdateManager.UpdateDBCheck();
if (_db_compare_result.RequiresUpdate)
{
@@ -261,7 +261,7 @@ namespace Tango.PPC.UI.ViewModels
try
{
- await MachineUpdateManager.UpdateDB(_db_compare_result, MachineProvider.Machine.SerialNumber);
+ await MachineUpdateManager.UpdateDB(_db_compare_result);
LogManager.Log("Database update completed.");
await NavigateTo(MachineUpdateView.UpdateCompletedView);
}
@@ -408,8 +408,12 @@ namespace Tango.PPC.UI.ViewModels
#region Handle USB Update
- private async void HandleSoftwareUpdatePackageLoaded(ExplorerFileItem fileItem)
+ private async void HandleSoftwareUpdatePackageLoaded(List<ExplorerFileItem> fileItems)
{
+ var fileItem = fileItems.FirstOrDefault();
+
+ if (fileItem == null) return;
+
PublishInfo packageFile = null;
LogManager.Log("TUP file loaded from storage...");
@@ -456,8 +460,12 @@ namespace Tango.PPC.UI.ViewModels
}
}
- private async void HandleFirmwareUpgradeLoaded(ExplorerFileItem fileItem)
+ private async void HandleFirmwareUpgradeLoaded(List<ExplorerFileItem> fileItems)
{
+ var fileItem = fileItems.FirstOrDefault();
+
+ if (fileItem == null) return;
+
LogManager.Log("TFP file loaded from storage...");
VersionPackageDescriptor packageInfo;
@@ -470,12 +478,14 @@ namespace Tango.PPC.UI.ViewModels
packageInfo = await MachineProvider.MachineOperator.GetFirmwarePackageInfo(st);
}
- vm.Version = packageInfo.FileDescriptors.SingleOrDefault(x => x.Destination == VersionFileDestination.Mcu).Version;
+ packageInfo.Validate();
+
+ vm.Version = packageInfo.GetMcuVersion().ToString();
}
catch (Exception ex)
{
LogManager.Log(ex, $"Error loading package info from {fileItem.Path}.");
- await NotificationProvider.ShowError("An error occurred while trying to load the selected firmware upgrade package. Please make sure the package is valid.");
+ await NotificationProvider.ShowError($"An error occurred while trying to load the selected firmware upgrade package.\n{ex.FlattenMessage()}");
return;
}
@@ -529,6 +539,12 @@ namespace Tango.PPC.UI.ViewModels
_updateNotificationItem.IsDatabaseUpdate = e.IsDatabaseUpdateAvailable && !e.IsUpdateAvailable;
_updateNotificationItem.Pressed += (_, __) =>
{
+ if (MachineProvider.MachineOperator.IsPrinting)
+ {
+ NotificationProvider.ShowInfo("Cannot perform a machine update while the machine is dyeing.");
+ return;
+ }
+
_updateNotificationItem = null;
if (!IsVisible)
@@ -601,6 +617,7 @@ namespace Tango.PPC.UI.ViewModels
{
_update_result = await MachineUpdateManager.UpdateFromTUP(request.RemoteTupFilePath, request.SetupFirmware, request.SetupFPGA);
LogManager.Log("Machine update from package completed.");
+ stopReporting = true;
InvokeUI(() =>
{
@@ -616,6 +633,8 @@ namespace Tango.PPC.UI.ViewModels
{
NavigateTo(MachineUpdateView.UpdateFailedFromPackageView);
});
+
+ throw ex;
}
await receiver.SendGenericResponse(new StartRemoteApplicationUpgradeResponse()
@@ -638,10 +657,13 @@ namespace Tango.PPC.UI.ViewModels
}
catch (Exception ex)
{
+ stopReporting = true;
await receiver.SendErrorResponse(ex, token);
}
finally
{
+ stopReporting = true;
+
try
{
File.Delete(request.RemoteTupFilePath);
@@ -699,6 +721,7 @@ namespace Tango.PPC.UI.ViewModels
try
{
await MachineUpdateManager.UpdateFromTFP(request.RemoteTfpFilePath);
+ stopReporting = true;
LogManager.Log("Firmware upgrade from package completed.");
_update_result = new MachineUpdateResult()
{
@@ -712,6 +735,8 @@ namespace Tango.PPC.UI.ViewModels
}
catch (Exception ex)
{
+ stopReporting = true;
+
LogManager.Log(ex, "Firmware upgrade from package failed.");
FailedError = ex.FlattenMessage();
@@ -719,6 +744,8 @@ namespace Tango.PPC.UI.ViewModels
{
NavigateTo(MachineUpdateView.UpdateFailedFromPackageView);
});
+
+ throw ex;
}
await receiver.SendGenericResponse(new StartRemoteFirmwareUpgradeResponse()
@@ -741,10 +768,13 @@ namespace Tango.PPC.UI.ViewModels
}
catch (Exception ex)
{
+ stopReporting = true;
await receiver.SendErrorResponse(ex, token);
}
finally
{
+ stopReporting = true;
+
try
{
File.Delete(request.RemoteTfpFilePath);
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs
index b53a54682..05fb610c8 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs
@@ -21,6 +21,7 @@ using Tango.PPC.Common.WatchDog;
using Tango.PPC.UI.Dialogs;
using Tango.SharedUI;
using System.Data.Entity;
+using Tango.PPC.UI.AppBarItems;
namespace Tango.PPC.UI.ViewModels
{
@@ -33,6 +34,8 @@ namespace Tango.PPC.UI.ViewModels
private DispatcherTimer _date_timer;
private bool _isPowerUpDialogShown;
private bool _isThreadLoadingShown;
+ private PowerUpAppBarItem _powerUpAppBar;
+ private bool _started;
private DateTime _currentDateTime;
/// <summary>
@@ -64,11 +67,53 @@ namespace Tango.PPC.UI.ViewModels
{
base.OnApplicationReady();
MachineProvider.MachineOperator.CartridgeValidationRequestReceived += MachineOperator_CartridgeValidationRequestReceived;
- MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted;
+ MachineProvider.MachineOperator.FirmwareStarted += MachineOperator_FirmwareStarted;
MachineProvider.MachineOperator.ThreadLoadingStatusChanged += MachineOperator_ThreadLoadingStatusChanged;
MachineProvider.MachineOperator.ThreadLoadingConfirmationRequired += MachineOperator_ThreadLoadingConfirmationRequired;
+
+ MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted;
+ MachineProvider.MachineOperator.PowerUpProgress += MachineOperator_PowerUpProgress;
+ MachineProvider.MachineOperator.PowerUpEnded += MachineOperator_PowerUpEnded;
+ }
+
+ #region Power Up
+
+ private void MachineOperator_PowerUpEnded(object sender, EventArgs e)
+ {
+ _started = false;
+ _powerUpAppBar?.Close();
+ _powerUpAppBar = null;
+ }
+
+ private void MachineOperator_PowerUpProgress(object sender, PMR.Power.StartPowerUpResponse status)
+ {
+ if (_powerUpAppBar != null)
+ {
+ _powerUpAppBar.Status = status;
+ }
+ }
+
+ private void MachineOperator_PowerUpStarted(object sender, PMR.Power.StartPowerUpResponse e)
+ {
+ _started = true;
+
+ InvokeUI(() =>
+ {
+ if (_powerUpAppBar != null)
+ {
+ _powerUpAppBar.Close();
+ }
+
+ if (_started)
+ {
+ _powerUpAppBar = NotificationProvider.PushAppBarItem<PowerUpAppBarItem>();
+ _powerUpAppBar.Priority = AppBarPriority.Low;
+ }
+ });
}
+ #endregion
+
#region Event Handlers
/// <summary>
@@ -101,7 +146,7 @@ namespace Tango.PPC.UI.ViewModels
});
}
- private async void MachineOperator_PowerUpStarted(object sender, EventArgs e)
+ private async void MachineOperator_FirmwareStarted(object sender, EventArgs e)
{
if (_isPowerUpDialogShown)
{
@@ -191,102 +236,15 @@ namespace Tango.PPC.UI.ViewModels
private void MachineOperator_ThreadLoadingStatusChanged(object sender, PMR.ThreadLoading.StartThreadLoadingResponse e)
{
- if (e.State == PMR.ThreadLoading.ThreadLoadingState.Preparing)
- {
- DisplayThreadLoading();
- }
+ //if (e.State == PMR.ThreadLoading.ThreadLoadingState.Preparing)
+ //{
+ // DisplayThreadLoading();
+ //}
}
private void MachineOperator_ThreadLoadingConfirmationRequired(object sender, ThreadLoadingConfirmationRequiredEventArgs e)
{
- DisplayThreadLoading(e);
- }
-
- private async void DisplayThreadLoading(ThreadLoadingConfirmationRequiredEventArgs confirmationArgs = null)
- {
- if (_isThreadLoadingShown) return;
-
- _isThreadLoadingShown = true;
-
- LogManager.Log("Thread loading preparation/finalization detected, showing thread loading screen...");
-
- if (!Settings.DisplayAutomaticThreadLoadingScreen)
- {
- _isThreadLoadingShown = false;
- LogManager.Log("Thread loading screen disabled. skipping...");
- return;
- }
-
- ThreadLoadingViewVM vm;
-
- try
- {
- LogManager.Log("Loading site rmls...");
-
- List<Rml> rmls = new List<Rml>();
-
- using (ObservablesContext db = ObservablesContext.CreateDefault())
- {
- rmls = await new RmlsCollectionBuilder(db).SetAll().ForHeadType(MachineProvider.Machine.MachineHeadType).ForSite(MachineProvider.Machine.SiteGuid).WithActiveParametersGroup().BuildListAsync();
- }
-
- var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LoadedRmlGuid);
-
- if (confirmationArgs == null)
- {
- vm = new ThreadLoadingViewVM(MachineProvider);
- }
- else
- {
- vm = new ThreadLoadingViewVM(MachineProvider, confirmationArgs);
- }
-
- vm.Rmls = rmls;
- vm.SelectedRml = selectedRml != null ? selectedRml : rmls.FirstOrDefault();
- }
- catch (Exception ex)
- {
- _isThreadLoadingShown = false;
- LogManager.Log(ex, "Error initializing thread loading screen.");
- return;
- }
-
- InvokeUI(async () =>
- {
- await NotificationProvider.ShowDialog<ThreadLoadingViewVM>(vm);
-
- _isThreadLoadingShown = false;
-
- LogManager.Log("Thread loading screen closed.");
-
- if (!vm.DialogResult)
- {
- LogManager.Log("Thread loading screen aborted by user. No operation was performed.");
- return;
- }
-
- try
- {
- if (vm.Result.IsCompleted)
- {
- await NotificationProvider.ShowSuccess("Thread loading completed successfully.");
- }
- else
- {
- await NotificationProvider.ShowError($"Thread loading failed due to the following reason:\n{vm.Result.FailedException.FlattenException()}");
- }
-
- if (vm.SelectedRml != null)
- {
- Settings.LoadedRmlGuid = vm.SelectedRml.Guid;
- Settings.Save();
- }
- }
- catch (Exception ex)
- {
- LogManager.Log(ex, "Error occurred after thread loading screen closed.");
- }
- });
+// DisplayThreadLoading(e);
}
#endregion
}