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.Notifications.NotificationItems;
using Tango.PPC.Jobs.NavigationObjects;
using Tango.PPC.Jobs.Views;
namespace Tango.PPC.Jobs.ViewModels
{
///
/// Represents the main view ViewModel.
///
///
public class MainViewVM : PPCViewModel
{
///
/// Called when the application has been started.
///
public override void OnApplicationStarted()
{
MachineProvider.MachineOperator.PrintingCompleted += MachineOperator_PrintingCompleted;
MachineProvider.MachineOperator.PrintingFailed += MachineOperator_PrintingFailed;
}
///
/// Handles the PrintingFailed event of the MachineOperator.
///
/// The source of the event.
/// The instance containing the event data.
private void MachineOperator_PrintingFailed(object sender, PrintingFailedEventArgs e)
{
NotificationProvider.PushNotification(new MessageNotificationItem(
String.Format("'{0}' failed.", e.Job.Name),
String.Format("The job '{1}' has failed due to unexpected error.{0}{2}{0}{0}Tap to view this job details.", Environment.NewLine, e.Job.Name, e.Exception), MessageNotificationItem.MessageNotificationItemTypes.Error, () =>
{
NavigationManager.NavigateWithObject(e.Job);
NavigationManager.ClearHistoryExcept();
}));
}
///
/// Handles the PrintingCompleted event of the MachineOperator.
///
/// The source of the event.
/// The instance containing the event data.
private void MachineOperator_PrintingCompleted(object sender, PrintingEventArgs e)
{
LogManager.Log($"'{e.Job.Name}' printing complete. Job designation is {e.Job.Designation}.");
if (e.Job.Designation == BL.Enumerations.JobDesignations.SampleDye)
{
NotificationProvider.PushNotification(new MessageNotificationItem(String.Format("'{0}' sample dye completed successfully", e.Job.Name), "Tap to approve or repeat.", MessageNotificationItem.MessageNotificationItemTypes.Success, () =>
{
NavigationManager.NavigateWithObject(new JobNavigationObject() { Job = e.Job, Intent = JobNavigationIntent.SampleDye });
NavigationManager.ClearHistoryExcept();
}));
}
else if (e.Job.Designation == BL.Enumerations.JobDesignations.FineTuning)
{
NotificationProvider.PushNotification(new MessageNotificationItem(String.Format("'{0}' fine tuning completed successfully", e.Job.Name), "Tap to approve or repeat.", MessageNotificationItem.MessageNotificationItemTypes.Success, () =>
{
NavigationManager.NavigateWithObject(new JobNavigationObject() { Job = e.Job, Intent = JobNavigationIntent.FineTuning });
NavigationManager.ClearHistoryExcept();
}));
}
else
{
NotificationProvider.PushNotification(new MessageNotificationItem(String.Format("'{0}' completed successfully", e.Job.Name), "Tap to view this job details.", MessageNotificationItem.MessageNotificationItemTypes.Success, () =>
{
NavigationManager.NavigateWithObject(new JobNavigationObject() { Job = e.Job });
NavigationManager.ClearHistoryExcept();
}));
}
}
}
}