From 942a428f90587a9ffdafaa593b780fb6ad06aabc Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 7 Feb 2018 13:08:53 +0200 Subject: Refactored dispensing formula naming. Added code comments for integration & Dispensing namespaces. --- .../Tango.Integration/Operators/JobHandler.cs | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Software/Visual_Studio/Tango.Integration/Operators/JobHandler.cs (limited to 'Software/Visual_Studio/Tango.Integration/Operators/JobHandler.cs') diff --git a/Software/Visual_Studio/Tango.Integration/Operators/JobHandler.cs b/Software/Visual_Studio/Tango.Integration/Operators/JobHandler.cs new file mode 100644 index 000000000..4c2c9f3f4 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operators/JobHandler.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.Printing; + +namespace Tango.Integration.Operators +{ + /// + /// Represents a handler. + /// + public class JobHandler + { + private Action _cancelAction; + + #region Events + + /// + /// Occurs when a job status has been received. + /// + public event EventHandler StatusReceived; + + /// + /// Occurs when the job has failed. + /// + public event EventHandler Failed; + + /// + /// Occurs when the job has completed successfully. + /// + public event EventHandler Completed; + + /// + /// Occurs when the job has been canceled. + /// + public event EventHandler Canceled; + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether this handler job has been canceled. + /// + public bool IsCanceled { get; internal set; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + public JobHandler() + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The cancel action. + internal JobHandler(Action cancelAction) : this() + { + _cancelAction = () => { IsCanceled = true; cancelAction(); }; + } + + #endregion + + #region Internal Methods + + /// + /// Raises the status received event. + /// + /// The status. + internal void RaiseStatusReceived(JobStatus status) + { + StatusReceived?.Invoke(this, status); + } + + /// + /// Raises the failed event. + /// + /// The ex. + internal void RaiseFailed(Exception ex) + { + Failed?.Invoke(this, ex); + } + + /// + /// Raises the completed event. + /// + internal void RaiseCompleted() + { + Completed?.Invoke(this, new EventArgs()); + } + + /// + /// Raises the canceled event. + /// + internal void RaiseCanceled() + { + Canceled?.Invoke(this, new EventArgs()); + } + + #endregion + + #region Public Methods + + /// + /// Cancels the associated job. + /// + public void Cancel() + { + _cancelAction(); + } + + #endregion + } +} -- cgit v1.3.1