diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-07 13:08:53 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-07 13:08:53 +0200 |
| commit | 942a428f90587a9ffdafaa593b780fb6ad06aabc (patch) | |
| tree | 4dd27cc98c494a57b8366b7beb9d9b4477b41409 /Software/Visual_Studio/Tango.Integration/Operators | |
| parent | ccacf23ab2f33f830a830dd2c938f1863335f01d (diff) | |
| download | Tango-942a428f90587a9ffdafaa593b780fb6ad06aabc.tar.gz Tango-942a428f90587a9ffdafaa593b780fb6ad06aabc.zip | |
Refactored dispensing formula naming.
Added code comments for integration & Dispensing namespaces.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Operators')
3 files changed, 171 insertions, 21 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Operators/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operators/IMachineOperator.cs index 58b19c914..bba5ff094 100644 --- a/Software/Visual_Studio/Tango.Integration/Operators/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operators/IMachineOperator.cs @@ -12,6 +12,10 @@ using Tango.Integration.Printing; namespace Tango.Integration.Operators { + /// <summary> + /// Represents a Tango machine operator. + /// </summary> + /// <seealso cref="Tango.Transport.ITransporter" /> public interface IMachineOperator : ITransporter { /// <summary> @@ -20,12 +24,12 @@ namespace Tango.Integration.Operators event EventHandler<PushDiagnosticsResponse> DiagnosticsDataAvailable; /// <summary> - /// Gets or sets a value indicating whether to enable diagnostics messages by requesting diagnostics messages. + /// Gets or sets a value indicating whether direct the embedded device to send diagnostics messages. /// </summary> - bool EnableSensorsUpdate { get; set; } + bool EnableDiagnostics { get; set; } /// <summary> - /// Prints the specified job. + /// Prints the specified job using the specified job parameters. /// </summary> /// <param name="job">The job.</param> /// <param name="processParameters">Process parameters table</param> 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 +{ + /// <summary> + /// Represents a <see cref="MachineOperator.Print(Observables.Job, Observables.ProcessParametersTable)"/> handler. + /// </summary> + public class JobHandler + { + private Action _cancelAction; + + #region Events + + /// <summary> + /// Occurs when a job status has been received. + /// </summary> + public event EventHandler<JobStatus> StatusReceived; + + /// <summary> + /// Occurs when the job has failed. + /// </summary> + public event EventHandler<Exception> Failed; + + /// <summary> + /// Occurs when the job has completed successfully. + /// </summary> + public event EventHandler Completed; + + /// <summary> + /// Occurs when the job has been canceled. + /// </summary> + public event EventHandler Canceled; + + #endregion + + #region Properties + + /// <summary> + /// Gets a value indicating whether this handler job has been canceled. + /// </summary> + public bool IsCanceled { get; internal set; } + + #endregion + + #region Constructors + + /// <summary> + /// Initializes a new instance of the <see cref="JobHandler"/> class. + /// </summary> + public JobHandler() + { + + } + + /// <summary> + /// Initializes a new instance of the <see cref="JobHandler"/> class. + /// </summary> + /// <param name="cancelAction">The cancel action.</param> + internal JobHandler(Action cancelAction) : this() + { + _cancelAction = () => { IsCanceled = true; cancelAction(); }; + } + + #endregion + + #region Internal Methods + + /// <summary> + /// Raises the status received event. + /// </summary> + /// <param name="status">The status.</param> + internal void RaiseStatusReceived(JobStatus status) + { + StatusReceived?.Invoke(this, status); + } + + /// <summary> + /// Raises the failed event. + /// </summary> + /// <param name="ex">The ex.</param> + internal void RaiseFailed(Exception ex) + { + Failed?.Invoke(this, ex); + } + + /// <summary> + /// Raises the completed event. + /// </summary> + internal void RaiseCompleted() + { + Completed?.Invoke(this, new EventArgs()); + } + + /// <summary> + /// Raises the canceled event. + /// </summary> + internal void RaiseCanceled() + { + Canceled?.Invoke(this, new EventArgs()); + } + + #endregion + + #region Public Methods + + /// <summary> + /// Cancels the associated job. + /// </summary> + public void Cancel() + { + _cancelAction(); + } + + #endregion + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs index 1ae4c078a..cc42b64ed 100644 --- a/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs @@ -18,18 +18,29 @@ using Tango.Integration.Printing; namespace Tango.Integration.Operators { + /// <summary> + /// Represents the Tango machine operator default implementation. + /// </summary> + /// <seealso cref="Tango.Transport.Transporters.BasicTransporter" /> + /// <seealso cref="Tango.Integration.Operators.IMachineOperator" /> public class MachineOperator : BasicTransporter, IMachineOperator { + #region Events + /// <summary> /// Occurs when there is new diagnostics data available. /// </summary> public event EventHandler<PushDiagnosticsResponse> DiagnosticsDataAvailable; + #endregion + + #region Properties + private bool _enableDiagnostics; /// <summary> - /// Gets or sets a value indicating whether to enable diagnostics messages by requesting diagnostics messages. + /// Gets or sets a value indicating whether direct the embedded device to send diagnostics messages. /// </summary> - public bool EnableSensorsUpdate + public bool EnableDiagnostics { get { return _enableDiagnostics; } set @@ -38,16 +49,20 @@ namespace Tango.Integration.Operators { _enableDiagnostics = value; RaisePropertyChangedAuto(); - OnEnableSensorsUpdateChanged(value); + OnEnableDiagnosticsChanged(value); } } } + #endregion + + #region Virtual Methods + /// <summary> /// Called when the enable sensors update property has been changed /// </summary> /// <param name="value">if set to <c>true</c> [value].</param> - protected virtual void OnEnableSensorsUpdateChanged(bool value) + protected virtual void OnEnableDiagnosticsChanged(bool value) { if (value && State == TransportComponentState.Connected) { @@ -81,6 +96,10 @@ namespace Tango.Integration.Operators DiagnosticsDataAvailable?.Invoke(this, data); } + #endregion + + #region Protected Methods + /// <summary> /// Called when the component state has changed. /// </summary> @@ -89,11 +108,15 @@ namespace Tango.Integration.Operators { base.OnStateChanged(state); - OnEnableSensorsUpdateChanged(EnableSensorsUpdate); + OnEnableDiagnosticsChanged(EnableDiagnostics); } + #endregion + + #region Public Methods + /// <summary> - /// Prints the specified job. + /// Prints the specified job using the specified job parameters. /// </summary> /// <param name="job">The job.</param> /// <param name="processParameters">Process parameters table</param> @@ -131,7 +154,7 @@ namespace Tango.Integration.Operators JobHandler handler = null; - handler = new JobHandler(async () => + handler = new JobHandler(async () => { try { @@ -144,21 +167,23 @@ namespace Tango.Integration.Operators } }); - SendContinuousRequest<JobRequest, JobResponse>(request).Subscribe((response) => + SendContinuousRequest<JobRequest, JobResponse>(request).Subscribe((response) => { handler.RaiseStatusReceived(response.Message.Status); - },(ex) => - { - if (!handler.IsCanceled) - { - handler.RaiseFailed(ex); - } - },() => - { - handler.RaiseCompleted(); - }); + }, (ex) => + { + if (!handler.IsCanceled) + { + handler.RaiseFailed(ex); + } + }, () => + { + handler.RaiseCompleted(); + }); return handler; } + + #endregion } } |
