aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs90
1 files changed, 60 insertions, 30 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
index 267f0bb0c..2e5d42296 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
@@ -48,6 +48,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
private int _fullScreenGraphIndex;
private JobHandler _jobHandler;
private DeveloperNavigationManager _navigation;
+ private ObservablesContext _dbJobContext;
+ private Job _jobFromList;
#region Properties
@@ -399,9 +401,14 @@ namespace Tango.MachineStudio.Developer.ViewModels
public RelayCommand RemoveBrushStopCommand { get; set; }
/// <summary>
- /// Gets or sets the save jobs command.
+ /// Gets or sets the save job command.
/// </summary>
- public RelayCommand SaveJobsCommand { get; set; }
+ public RelayCommand SaveJobCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the discard job command.
+ /// </summary>
+ public RelayCommand DiscardJobCommand { get; set; }
/// <summary>
/// Gets or sets the start job command.
@@ -478,7 +485,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
RemoveJobCommand = new RelayCommand(RemoveJob, () => SelectedJob != null);
AddBrushStopCommand = new RelayCommand(AddBrushStop, () => SelectedSegment != null);
RemoveBrushStopCommand = new RelayCommand(RemoveBrushStop, () => SelectedBrushStop != null);
- SaveJobsCommand = new RelayCommand(SaveJobs, () => SelectedMachine != null);
+ SaveJobCommand = new RelayCommand(SaveJob, () => SelectedMachine != null);
+ DiscardJobCommand = new RelayCommand(DiscardJob, () => SelectedMachine != null);
StartJobCommand = new RelayCommand(StartJob, () => SelectedJob != null && !IsJobRunning);
StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning);
CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar);
@@ -615,22 +623,53 @@ namespace Tango.MachineStudio.Developer.ViewModels
#region Private Methods
- private void LoadJob()
+ private async void LoadJob()
{
if (SelectedJob != null)
{
- Task.Factory.StartNew(() =>
+ using (_notification.PushTaskItem("Loading job details..."))
{
- SelectedSegment = SelectedJob.Segments.FirstOrDefault();
+ await Task.Factory.StartNew(() =>
+ {
+ _dbJobContext = ObservablesContext.CreateDefault();
- SelectedJob.LengthChanged -= SelectedJob_LengthChanged;
- SelectedJob.LengthChanged += SelectedJob_LengthChanged;
+ _jobFromList = SelectedJob;
+ SelectedJob = _dbJobContext.Jobs.SingleOrDefault(x => x.Guid == SelectedJob.Guid);
+ SelectedRML = SelectedJob.Rml;
- UpdateEstimatedDuration();
- });
+ SelectedSegment = SelectedJob.Segments.FirstOrDefault();
- _navigation.NavigateTo(DeveloperNavigationView.JobView);
+ SelectedJob.LengthChanged -= SelectedJob_LengthChanged;
+ SelectedJob.LengthChanged += SelectedJob_LengthChanged;
+
+ UpdateEstimatedDuration();
+ });
+
+ _navigation.NavigateTo(DeveloperNavigationView.JobView);
+ }
+ }
+ }
+ private async void SaveJob()
+ {
+ if (SelectedJob != null)
+ {
+ using (_notification.PushTaskItem("Saving machine jobs..."))
+ {
+ SelectedJob.LastUpdated = DateTime.UtcNow;
+ SelectedJob.Rml = SelectedRML;
+ await _dbJobContext.SaveChangesAsync();
+ await _jobFromList.Reload();
+ }
+ }
+ }
+
+ private void DiscardJob()
+ {
+ if (_notification.ShowQuestion("This will discard the current job changes. Are you sue?"))
+ {
+ _dbJobContext.Dispose();
+ _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView);
}
}
@@ -689,6 +728,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
private void CloseJobCompletionStatusBar()
{
+ _navigation.NavigateTo(DeveloperNavigationView.JobView);
IsJobCompleted = false;
IsJobFailed = false;
IsJobCanceled = false;
@@ -723,6 +763,12 @@ namespace Tango.MachineStudio.Developer.ViewModels
return;
}
+ if (SelectedProcessParametersTable == null)
+ {
+ _notification.ShowError("No process parameters table selected. Could not execute the specified job.");
+ return;
+ }
+
RunningJobRemainingTime = TimeSpan.Zero;
RunningJobProgress = 0;
IsJobFailed = false;
@@ -735,6 +781,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
RunningJobSegments = CreateRunningJobEffectiveSegments(RunningJob);
+ _navigation.NavigateTo(DeveloperNavigationView.RunningJobView);
+
_jobHandler = MachineOperator.Print(SelectedJob, SelectedProcessParametersTable);
_jobHandler.StatusReceived += (x, status) =>
@@ -785,18 +833,6 @@ namespace Tango.MachineStudio.Developer.ViewModels
};
}
- private async void SaveJobs()
- {
- if (SelectedJob != null)
- {
- using (_notification.PushTaskItem("Saving machine jobs..."))
- {
- SelectedJob.CreationDate = DateTime.UtcNow;
- await SelectedJob.SaveAsync();
- }
- }
- }
-
private void UpdateEstimatedDuration()
{
if (SelectedJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0)
@@ -957,7 +993,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
if (SelectedMachine != null)
{
- SelectedMachine.Jobs.Add(new Job()
+ SelectedMachine.Jobs.Add(new Job(DateTime.UtcNow)
{
Name = "Untitled Job",
CreationDate = DateTime.UtcNow,
@@ -1158,7 +1194,6 @@ namespace Tango.MachineStudio.Developer.ViewModels
}
SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null;
- SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedRMLGuid = SelectedRML != null ? SelectedRML.Guid : null;
SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = SelectedJob != null ? SelectedJob.Guid : null;
return Task.FromResult(true);
@@ -1177,11 +1212,6 @@ namespace Tango.MachineStudio.Developer.ViewModels
SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid);
}
- if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedRMLGuid != null)
- {
- SelectedRML = Adapter.Rmls.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedRMLGuid);
- }
-
if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null)
{
SelectedJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid);