using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Entities; using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Navigation; using Tango.PPC.Jobs.AppBarItems; using Tango.PPC.Jobs.Views; namespace Tango.PPC.Jobs.ViewModels { /// /// Represents the job progress view model. /// /// public class JobProgressViewVM : PPCViewModel { #region Properties private Job _job; /// /// Gets or sets the job. /// public Job Job { get { return _job; } set { _job = value; RaisePropertyChangedAuto(); } } private RunningJobStatus _runningJobStatus; /// /// Gets or sets the running job status. /// public RunningJobStatus RunningJobStatus { get { return _runningJobStatus; } set { _runningJobStatus = value; RaisePropertyChangedAuto(); } } #endregion #region Override Methods /// /// Called when the application has been started. /// public override void OnApplicationStarted() { MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; } /// /// Called when the navigation system has navigated from this VM view. /// public override void OnNavigatedFrom() { base.OnNavigatedFrom(); if (MachineProvider.MachineOperator.IsPrinting) { NotificationProvider.PushAppBarItem().Pressed += (_, __) => { NotificationProvider.CurrentAppBarItem.Close(); NavigationManager.NavigateTo(nameof(JobProgressView)); }; } } /// /// Called when the navigation system has navigated to this VM view. /// public override void OnNavigatedTo() { base.OnNavigatedTo(); if (NotificationProvider.HasAppBarItem && NotificationProvider.CurrentAppBarItem is JobProgressAppBarItem) { NotificationProvider.CurrentAppBarItem.Close(); } } #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) { Job = e.Job; e.JobHandler.StatusChanged += JobHandler_StatusChanged; e.JobHandler.Stopped += JobHandler_Stopped; } /// /// Handles the Stopped event of the JobHandler. /// /// The source of the event. /// The instance containing the event data. private void JobHandler_Stopped(object sender, EventArgs e) { if (NotificationProvider.HasAppBarItem && NotificationProvider.CurrentAppBarItem is JobProgressAppBarItem) { NotificationProvider.CurrentAppBarItem.Close(); } } /// /// Handles the JobHandler StatusChanged event. /// /// The sender. /// The e. private void JobHandler_StatusChanged(object sender, RunningJobStatus e) { InvokeUI(() => { RunningJobStatus = e; }); } #endregion } }