using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.Integration.Operation;
using Tango.PPC.Common;
using Tango.PPC.Common.Modules;
using Tango.PPC.Common.Navigation;
using Tango.PPC.UI.ViewsContracts;
using Tango.SharedUI;
namespace Tango.PPC.UI.ViewModels
{
///
/// Represents the layout view containing the main menu and all modules.
///
///
public class LayoutViewVM : PPCViewModel
{
private JobHandler _jobHandler;
///
/// Gets or sets the module loader.
///
[TangoInject]
public IPPCModuleLoader ModuleLoader { get; set; }
#region Properties
private bool _isMenuOpened;
///
/// Gets or sets a value indicating whether the side menu is opened.
///
public bool IsMenuOpened
{
get { return _isMenuOpened; }
set { _isMenuOpened = value; RaisePropertyChangedAuto(); }
}
private bool _isNotificationsOpened;
///
/// Gets or sets a value indicating whether to display all notifications.
///
public bool IsNotificationsOpened
{
get { return _isNotificationsOpened; }
set { _isNotificationsOpened = value; RaisePropertyChangedAuto(); }
}
#endregion
#region Commands
///
/// Gets or sets the module navigation command.
///
public RelayCommand ModuleNavigationCommand { get; set; }
///
/// Gets or sets the menu or back command.
///
public RelayCommand MenuOrBackCommand { get; set; }
///
/// Gets or sets the home command.
///
public RelayCommand HomeCommand { get; set; }
///
/// Gets or sets the notifications area pressed command.
///
public RelayCommand NotificationsAreaPressedCommand { get; set; }
///
/// Gets or sets the stop printing command.
///
public RelayCommand StopPrintingCommand { get; set; }
///
/// Gets or sets the sign-out command.
///
public RelayCommand SignOutCommand { get; set; }
///
/// Gets or sets the update command.
///
public RelayCommand UpdateCommand { get; set; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
public LayoutViewVM()
{
ModuleNavigationCommand = new RelayCommand(NavigateToModule);
HomeCommand = new RelayCommand(NavigateHome);
MenuOrBackCommand = new RelayCommand(OpenMenuOrNavigateBack);
NotificationsAreaPressedCommand = new RelayCommand(OpenFirstNotificationOrDisplayAll);
StopPrintingCommand = new RelayCommand(StopPrinting);
SignOutCommand = new RelayCommand(SignOut);
UpdateCommand = new RelayCommand(() =>
{
NavigationManager.NavigateTo(NavigationView.MachineUpdateView);
TangoIOC.Default.GetInstance().CheckForUpdates();
IsMenuOpened = false;
});
}
#endregion
#region Private Methods
///
/// Stops the printing.
///
private void StopPrinting()
{
LogManager.Log("Stop printing layout command pressed!");
if (_jobHandler != null)
{
_jobHandler.Cancel();
}
}
///
/// Opens the menu or navigate back.
///
private void OpenMenuOrNavigateBack()
{
if (NavigationManager.CanNavigateBack)
{
LogManager.Log("Back command pressed.");
NavigationManager.NavigateBack();
}
else
{
LogManager.Log("Menu command pressed.");
IsMenuOpened = true;
}
}
///
/// Handles the module navigation command.
///
/// Name of the module.
private void NavigateToModule(string moduleName)
{
LogManager.Log("Navigate to module command pressed.");
IsMenuOpened = false;
NavigationManager.NavigateTo(moduleName);
}
///
/// Handles the home command.
///
private void NavigateHome()
{
LogManager.Log("Navigate home command pressed.");
IsMenuOpened = false;
NavigationManager.NavigateTo(NavigationView.HomeModule);
}
///
/// Represents an event that is raised when the sign-out operation is complete.
///
private void SignOut()
{
LogManager.Log("SignOut command pressed.");
AuthenticationProvider.LogOut();
IsMenuOpened = false;
}
///
/// Opens the first notification or display all.
///
private void OpenFirstNotificationOrDisplayAll()
{
if (NotificationProvider.NotificationItems.Count == 1)
{
//Open first
}
else
{
IsNotificationsOpened = true;
}
}
#endregion
#region Override Methods
///
/// Called when the application has been started.
///
public override void OnApplicationStarted()
{
base.OnApplicationStarted();
MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted;
}
///
/// Called when the instance of IPPCView is available.
///
public override void OnViewAttached()
{
}
#endregion
#region Event Handlers
///
/// Handles the PrintingStarted event of the MachineOperator.
///
/// The source of the event.
/// The instance containing the event data.
private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e)
{
_jobHandler = e.JobHandler;
}
#endregion
}
}