aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/MaintenanceCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/MaintenanceCommand.cs')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/MaintenanceCommand.cs81
1 files changed, 81 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/MaintenanceCommand.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/MaintenanceCommand.cs
new file mode 100644
index 000000000..5c74d92cd
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/MaintenanceCommand.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.Core.Commands;
+using Tango.Core.DI;
+using Tango.Integration.Operation;
+using Tango.PPC.Common.Connection;
+using Tango.PPC.Common.Notifications;
+
+namespace Tango.PPC.Maintenance
+{
+ public abstract class MaintenanceCommand<T> : ExtendedObject
+ {
+ private IMachineProvider _machineProvider;
+ [TangoInject(Mode = TangoInjectMode.WhenAvailable)]
+ protected IMachineProvider MachineProvider
+ {
+ get { return _machineProvider; }
+ set
+ {
+ _machineProvider = value; RaisePropertyChangedAuto();
+ _machineProvider.MachineOperator.StatusChanged += MachineOperator_StatusChanged;
+ }
+ }
+
+ [TangoInject(Mode = TangoInjectMode.WhenAvailable)]
+ protected INotificationProvider NotificationProvider { get; set; }
+
+ private RelayCommand _command;
+ public RelayCommand Command
+ {
+ get { return _command; }
+ set { _command = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _isEnabled;
+ public bool IsEnabled
+ {
+ get { return _isEnabled; }
+ set { _isEnabled = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private T _state;
+ public T State
+ {
+ get { return _state; }
+ set { _state = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private void MachineOperator_StatusChanged(object sender, MachineStatuses e)
+ {
+ InvalidateRelayCommands();
+ }
+
+ public MaintenanceCommand()
+ {
+ TangoIOC.Default.Inject(this);
+ IsEnabled = true;
+ Command = new RelayCommand(Execute, CanExecute);
+ }
+
+ protected virtual bool CanExecute()
+ {
+ if (!IsEnabled) return false;
+ if (MachineProvider == null) return false;
+ if (!MachineProvider.MachineOperator.CanPrint) return false;
+
+ return true;
+ }
+
+ private void Execute()
+ {
+ OnExecute();
+ }
+
+ protected abstract void OnExecute();
+ }
+}