using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR.Printing;
namespace Tango.Integration.Operation
{
///
/// 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
}
}