aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs211
1 files changed, 193 insertions, 18 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs
index 131476c9e..937a76f94 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs
@@ -27,6 +27,9 @@ using Tango.PPC.UI.Graphs;
using Tango.BL;
using System.Data.Entity;
using System.Windows.Media;
+using Tango.PPC.Common.Resume;
+using Tango.Core.ExtensionMethods;
+using Tango.PPC.Common.Printing;
namespace Tango.PPC.UI.ViewModels
{
@@ -44,6 +47,13 @@ namespace Tango.PPC.UI.ViewModels
Motor = 3
}
+ public enum ShowSetButtonsEnum
+ {
+ ShowDefault,
+ ShowROnErrorsJob,
+ ShowOnCompleteJob
+ }
+
public class TimeToDyeValueItem
{
public DateTime startTime;
@@ -62,6 +72,7 @@ namespace Tango.PPC.UI.ViewModels
};
private DispatcherTimer _productiondata_timer;
+ private bool startingJob = false;
#region Properties
@@ -80,10 +91,11 @@ namespace Tango.PPC.UI.ViewModels
set
{
_job = value;
+ RaisePropertyChangedAuto();
if (_job == null)
IsDyeingProcess = false;
- RaisePropertyChangedAuto();
InvalidateRelayCommands();
+ ShowSetButtons = ShowSetButtonsEnum.ShowDefault;
}
}
@@ -97,6 +109,7 @@ namespace Tango.PPC.UI.ViewModels
set
{
_runningJobStatus = value;
+
RaisePropertyChangedAuto();
}
}
@@ -109,14 +122,14 @@ namespace Tango.PPC.UI.ViewModels
set { _isJobStatusViewEnable = value; RaisePropertyChangedAuto(); }
}
- private bool _isEnabledStopButton;
+ private bool _isPrinting;
/// <summary>
/// Gets or sets a value indicating whether this instance is enabled stop button.
/// </summary>
- public bool IsEnabledStopButton
+ public bool IsPrinting
{
- get { return _isEnabledStopButton; }
- set { _isEnabledStopButton = value; RaisePropertyChangedAuto(); }
+ get { return _isPrinting; }
+ set { _isPrinting = value; RaisePropertyChangedAuto(); }
}
private bool _isSpoolView;
@@ -330,6 +343,29 @@ namespace Tango.PPC.UI.ViewModels
public WpfGraphController<DateTimeDataPoint, DoubleDataPoint> JobController { get; set; }
+ private JobResumeModel _resumeModel;
+ public JobResumeModel ResumeModel
+ {
+ get { return _resumeModel; }
+ set { _resumeModel = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasResumeModel)); }
+ }
+
+ public bool HasResumeModel
+ {
+ get { return ResumeModel != null; }
+ }
+
+ private ShowSetButtonsEnum _showSetButtons;
+
+ public ShowSetButtonsEnum ShowSetButtons
+ {
+ get { return _showSetButtons; }
+ set {
+ _showSetButtons = value;
+ RaisePropertyChangedAuto();}
+ }
+
+
#endregion
#region Commands
@@ -362,6 +398,8 @@ namespace Tango.PPC.UI.ViewModels
public RelayCommand HideJobOutlineCommand { get; set; }
+ public RelayCommand DropResumeCommand { get; set; }
+
#endregion
public MachineStatusViewVM()
@@ -374,10 +412,10 @@ namespace Tango.PPC.UI.ViewModels
StopCommand = new RelayCommand(StopJob, () => CanStopped());
AbortCommand = new RelayCommand(AbortJob, () => CanStopped());
- ResumeCommand = new RelayCommand(ResumeJob, () => CanStopped());
- CaancelJobCommand = new RelayCommand(CaancelJob, () => CanStopped());
- RestartJobCommand = new RelayCommand(RestartJob, () => CanStopped());
- ClearJobCommand = new RelayCommand(ClearJob, () => CanStopped());
+ ResumeCommand = new RelayCommand(ResumeJob, () => MachineProvider.MachineOperator.CanPrint);
+ CaancelJobCommand = new RelayCommand(CaancelJob);
+ RestartJobCommand = new RelayCommand(RestartJob, () => MachineProvider.MachineOperator.CanPrint);
+ ClearJobCommand = new RelayCommand(ClearJob);
GoToJobCommand = new RelayCommand(GoToJob, () => IsEnableGoToJob());
@@ -387,8 +425,10 @@ namespace Tango.PPC.UI.ViewModels
DisplayJobOutlineCommand = new RelayCommand(DisplayJobOutline);
HideJobOutlineCommand = new RelayCommand(HideJobOutline);
+ DropResumeCommand = new RelayCommand(DropResume);
+
IsJobStatusViewEnable = true;
- IsEnabledStopButton = false;
+ IsPrinting = false;
IsSpoolView = false;
IsWeghtView = false;
@@ -399,6 +439,7 @@ namespace Tango.PPC.UI.ViewModels
SelectedStatisticTabIndex = 0;
JobController = CreateController(CreateSeries("Total", GraphHelper.GraphColor.Green));
+ ShowSetButtons = ShowSetButtonsEnum.ShowDefault;
}
public override void OnApplicationReady()
@@ -563,10 +604,15 @@ namespace Tango.PPC.UI.ViewModels
{
MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted;
MachineProvider.MachineOperator.PrintingEnded += MachineOperator_PrintingEnded;
+ MachineProvider.MachineOperator.StatusChanged += MachineOperator_StatusChanged;
DefaultDiagnosticsFrameProvider.FrameReceived += DefaultDiagnosticsFrameProvider_FrameReceived;
+
+ JobResumeManager.JobResumeUpdated += JobResumeManager_JobResumeUpdated;
+ JobResumeManager.JobResumeDropped += JobResumeManager_JobResumeDropped;
}
+
private void DefaultDiagnosticsFrameProvider_FrameReceived(object sender, PMR.Diagnostics.StartDiagnosticsResponse e)
{
OverviewModel.Update(e, this.Job != null ? Job.Rml : null, null);
@@ -576,13 +622,27 @@ namespace Tango.PPC.UI.ViewModels
{
_handler = e.JobHandler;
Job = e.Job;
+ try
+ {
+ ResumeModel = JobResumeManager.GetJobResumeModel(Job.Guid);
+
+ if (ResumeModel != null)
+ {
+ LogManager.Log($"Job resume info found:\n{ResumeModel.ToJsonString()}");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error retrieving job resume info from db.");
+ }
+
e.JobHandler.StatusChanged += JobHandler_StatusChanged;
//e.JobHandler.SpoolChangeRequired += JobHandler_SpoolChangeRequired;
e.JobHandler.Stopped += JobHandler_Stopped;
e.JobHandler.CanCancelChanged += JobHandler_CanCancelChanged;
InvokeUI(() =>
{
- IsEnabledStopButton = true;
+ IsPrinting = true;
StopCommand.RaiseCanExecuteChanged();
AbortCommand.RaiseCanExecuteChanged();
});
@@ -607,7 +667,7 @@ namespace Tango.PPC.UI.ViewModels
LogManager.Log("Printing ended");
InvokeUI(() =>
{
- IsEnabledStopButton = false;
+ IsPrinting = false;
StopCommand.RaiseCanExecuteChanged();
AbortCommand.RaiseCanExecuteChanged();
});
@@ -616,6 +676,15 @@ namespace Tango.PPC.UI.ViewModels
private void JobHandler_StatusChanged(object sender, RunningJobStatus e)
{
RunningJobStatus = e;
+ if(RunningJobStatus != null && RunningJobStatus.IsFailed)
+ {
+ ShowSetButtons = ShowSetButtonsEnum.ShowROnErrorsJob;
+ }
+ else if(RunningJobStatus != null && RunningJobStatus.IsCompleted)
+ {
+ ShowSetButtons = ShowSetButtonsEnum.ShowOnCompleteJob;
+ }
+
IsDyeingProcess = (RunningJobStatus != null && RunningJobStatus.CurrentSegment != null);
if (RunningJobStatus != null && RunningJobStatus.CurrentSegment != null)
{
@@ -658,12 +727,21 @@ namespace Tango.PPC.UI.ViewModels
{
InvokeUI(() =>
{
- IsEnabledStopButton = _handler.CanCancel;
+ IsPrinting = _handler.CanCancel;
StopCommand.RaiseCanExecuteChanged();
AbortCommand.RaiseCanExecuteChanged();
});
}
+ private void MachineOperator_StatusChanged(object sender, MachineStatuses e)
+ {
+ InvokeUI(() =>
+ {
+ ResumeCommand.RaiseCanExecuteChanged();
+ RestartJobCommand.RaiseCanExecuteChanged();
+ });
+ }
+
#endregion
#region Methods
@@ -721,7 +799,7 @@ namespace Tango.PPC.UI.ViewModels
private bool CanStopped()
{
- return IsEnabledStopButton;
+ return IsPrinting;
}
private void StopJob()
@@ -732,26 +810,92 @@ namespace Tango.PPC.UI.ViewModels
private void AbortJob()
{
_handler?.Cancel();
- //Job = null;
+ if (Job != null && HasResumeModel)
+ {
+ JobResumeManager.DropResume(Job.Guid);
+
+ }
+ }
+
+ private void ResumeJob()
+ {
+ ShowSetButtons = ShowSetButtonsEnum.ShowDefault;
+ if (Job != null && HasResumeModel)
+ {
+ StartJob();
+ }
}
- private void ResumeJob()
+ private async void StartJob()
{
+ if (startingJob) return;
+
+ RunningJobStatus = null;
+
+ try
+ {
+ startingJob = true;
+ LogManager.Log("Start job command pressed. Starting job and navigating to job progress view...");
+
+ var printConfig = new PrintingConfiguration();
+
+ if (HasResumeModel)
+ {
+ printConfig.FirstUnitStartPosition = ResumeModel.FirstUnitStartPosition;
+ printConfig.GlobalStartPosition = ResumeModel.GlobalStartPosition;
+ printConfig.RemainingUnits = ResumeModel.RemainingUnits;
+ }
+ using (var db = ObservablesContext.CreateDefault())
+ {
+ var handler = await PrintingManager.Print(Job, db, printConfig);
+ }
+
+ startingJob = false;
+ }
+ catch (InsufficientLiquidQuantityException)
+ {
+ //Ignore..
+ }
+ catch (OperationCanceledException)
+ {
+ //Ignore..
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Could not start the current job.");
+ await NotificationProvider.ShowError($"{ex.Message}.");
+ }
+ finally
+ {
+ startingJob = false;
+ }
}
private void CaancelJob()
{
- Job = null;
+ ClearJob();
}
private void RestartJob()
{
-
+ ShowSetButtons = ShowSetButtonsEnum.ShowDefault;
+ if (Job != null )
+ {
+ if(HasResumeModel)
+ {
+ DropResume();
+ }
+ RunningJobStatus = null;
+ StartJob();
+ }
}
private void ClearJob()
{
+ ShowSetButtons = ShowSetButtonsEnum.ShowDefault;
+ DropResume();
+ RunningJobStatus = null;
Job = null;
}
@@ -851,5 +995,36 @@ namespace Tango.PPC.UI.ViewModels
}
}
#endregion
+
+ #region Resume
+
+ private void JobResumeManager_JobResumeUpdated(object sender, Common.Resume.JobResumeUpdatedEventArgs e)
+ {
+ if (Job != null && Job.Guid == e.JobGuid)
+ {
+ ResumeModel = e.ResumeModel;
+ }
+ }
+
+ private void JobResumeManager_JobResumeDropped(object sender, Common.Resume.JobResumeDroppedEventArgs e)
+ {
+ if (Job != null && Job.Guid == e.JobGuid)
+ {
+ ResumeModel = null;
+ }
+ }
+
+ private async void DropResume()
+ {
+ if (Job != null && HasResumeModel)
+ {
+ // if (await NotificationProvider.ShowQuestion("Drop resume information and enable job editing?"))
+ {
+ JobResumeManager.DropResume(Job.Guid);
+ }
+ }
+ }
+
+ #endregion
}
}