aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModule.cs
blob: b9e121f86a259b278a78752b173e2bcdfa3a9846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Tango.BL.Enumerations;
using Tango.PPC.Common;
using Tango.PPC.Jobs.Views;
using Tango.SharedUI.Helpers;

namespace Tango.PPC.Jobs
{
    /// <summary>
    /// Represents the PPC jobs module
    /// </summary>
    /// <seealso cref="Tango.PPC.Common.PPCModuleBase" />
    [PPCModule(1, nameof(JobsView))]
    public class JobsModule : PPCModuleBase
    {
        /// <summary>
        /// Gets the module name.
        /// </summary>
        public override string Name
        {
            get
            {
                return "Jobs";
            }
        }

        /// <summary>
        /// Gets the module description.
        /// </summary>
        public override string Description
        {
            get
            {
                return "Manage and run jobs";
            }
        }

        /// <summary>
        /// Gets the module cover image.
        /// </summary>
        public override BitmapSource Image
        {
            get
            {
                return ResourceHelper.GetImageFromResources("Images/jobs.png");
            }
        }

        /// <summary>
        /// Gets the module entry point view type.
        /// </summary>
        public override Type MainViewType
        {
            get
            {
                return typeof(MainView);
            }
        }

        /// <summary>
        /// Gets the permission required to see and load this module.
        /// </summary>
        public override Permissions Permission
        {
            get
            {
                return Permissions.RunPPC;
            }
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public override void Dispose()
        {

        }
    }
}
an class="w"> Tango.PPC.Jobs.AppButtons; using Tango.PPC.Jobs.Dialogs; using Tango.PPC.Jobs.NavigationObjects; using Tango.PPC.Jobs.Views; namespace Tango.PPC.Jobs.ViewModels { /// <summary> /// Represents the job progress view model. /// </summary> /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> public class JobProgressViewVM : PPCViewModel { private StopPrintingButton _stop_job_btn; private JobHandler _handler; #region Properties private Job _job; /// <summary> /// Gets or sets the job. /// </summary> public Job Job { get { return _job; } set { _job = value; RaisePropertyChangedAuto(); } } private RunningJobStatus _runningJobStatus; /// <summary> /// Gets or sets the running job status. /// </summary> public RunningJobStatus RunningJobStatus { get { return _runningJobStatus; } set { _runningJobStatus = value; RaisePropertyChangedAuto(); } } private bool _isDisplayJobOutline; /// <summary> /// Gets or sets a value indicating whether to display the job outline. /// </summary> public bool IsDisplayJobOutline { get { return _isDisplayJobOutline; } set { _isDisplayJobOutline = value; RaisePropertyChangedAuto(); } } private JobTicket _jobOutlineTicket; /// <summary> /// Gets or sets the job outline ticket. /// </summary> public JobTicket JobOutlineTicket { get { return _jobOutlineTicket; } set { _jobOutlineTicket = value; RaisePropertyChangedAuto(); } } #endregion #region Commands /// <summary> /// Gets or sets the go to job command. /// </summary> /// <value> /// The go to job command. /// </value> public RelayCommand GoToJobCommand { get; set; } /// <summary> /// Gets or sets the display job outline command. /// </summary> public RelayCommand DisplayJobOutlineCommand { get; set; } /// <summary> /// Gets or sets the hide job outline command. /// </summary> public RelayCommand HideJobOutlineCommand { get; set; } #endregion public JobProgressViewVM() { _stop_job_btn = new StopPrintingButton(); _stop_job_btn.Pressed += _stop_job_btn_Pressed; GoToJobCommand = new RelayCommand(GoToJob); DisplayJobOutlineCommand = new RelayCommand(DisplayJobOutline); HideJobOutlineCommand = new RelayCommand(HideJobOutline); } #region Private Methods private void HideJobOutline() { IsDisplayJobOutline = false; } private void DisplayJobOutline() { JobOutlineTicket = _handler.JobTicket; IsDisplayJobOutline = true; } private void GoToJob() { NavigationManager.NavigateWithObject<JobsModule, JobView, JobNavigationObject>(new JobNavigationObject() { Job = _handler.Job }); NavigationManager.ClearHistoryExcept<JobsView>(); } #endregion #region Override Methods /// <summary> /// Called when the application has been started. /// </summary> public override void OnApplicationStarted() { MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; MachineProvider.MachineOperator.PrintingEnded += MachineOperator_PrintingEnded; } /// <summary> /// Called when the navigation system has navigated to this VM view. /// </summary> public override void OnNavigatedTo() { base.OnNavigatedTo(); IsDisplayJobOutline = false; if (_handler != null && !_handler.Status.IsFailed) { _stop_job_btn.Push(); } } #endregion #region Event Handlers private void _stop_job_btn_Pressed() { if (_handler != null) { _handler.Cancel(); } } /// <summary> /// Handles the PrintingStarted event of the MachineOperator. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="PrintingEventArgs"/> instance containing the event data.</param> private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) { _handler = e.JobHandler; Job = e.Job; e.JobHandler.StatusChanged += JobHandler_StatusChanged; e.JobHandler.SpoolChangeRequired += JobHandler_SpoolChangeRequired; e.JobHandler.Stopped += JobHandler_Stopped; e.JobHandler.CanCancelChanged += JobHandler_CanCancelChanged; _stop_job_btn.Push(); _stop_job_btn.IsEnabled = true; } private void MachineOperator_PrintingEnded(object sender, PrintingEventArgs e) { LogManager.Log("Printing ended, popping job stop button..."); if (_stop_job_btn != null) { _stop_job_btn.Pop(); } else { LogManager.Log("Job stop button instance was null!", LogCategory.Warning); } } /// <summary> /// Handles the SpoolChangeRequired event of the JobHandler. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SpoolChangeRequiredEventArgs"/> instance containing the event data.</param> private void JobHandler_SpoolChangeRequired(object sender, SpoolChangeRequiredEventArgs e) { InvokeUI(async () => { if ((await NotificationProvider.ShowDialog(new SpoolChangeViewVM(e))).DialogResult) { e.Confirm(); } else { e.Abort(); } }); } /// <summary> /// Handles the Stopped event of the JobHandler. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void JobHandler_Stopped(object sender, EventArgs e) { if (_handler != null) { _handler.StatusChanged -= JobHandler_StatusChanged; _handler.SpoolChangeRequired -= JobHandler_SpoolChangeRequired; _handler.Stopped -= JobHandler_Stopped; _handler.CanCancelChanged -= JobHandler_CanCancelChanged; } } /// <summary> /// Handles the JobHandler StatusChanged event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void JobHandler_StatusChanged(object sender, RunningJobStatus e) { InvokeUI(() => { RunningJobStatus = e; }); } /// <summary> /// Handles the CanCancelChanged event of the JobHandler control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void JobHandler_CanCancelChanged(object sender, EventArgs e) { _stop_job_btn.IsEnabled = _handler.CanCancel; } #endregion } }