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.cs342
1 files changed, 217 insertions, 125 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 3a1f3fb11..fc0680d9c 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
@@ -50,6 +50,9 @@ using Tango.Core.ExtensionMethods;
using Tango.ColorConversion;
using Tango.PMR.Exports;
using Microsoft.WindowsAPICodePack.Dialogs;
+using Tango.BL.Enumerations;
+using Tango.BL.DTO;
+using Tango.BL.ActionLogs;
namespace Tango.MachineStudio.Developer.ViewModels
{
@@ -85,6 +88,9 @@ namespace Tango.MachineStudio.Developer.ViewModels
private TaskItem _preparingTaskItem;
private IColorConverter _converter;
private string _current_job_string;
+ private JobDTO _beforeSaveJobDTO;
+ private IActionLogManager _actionLogManager;
+ private RmlDTO _selectedRMLBeforeLiquidFactorsSaves;
#region Properties
@@ -747,7 +753,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
/// </summary>
/// <param name="applicationManager">The application manager.</param>
/// <param name="notificationProvider">The notification provider.</param>
- public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, INavigationManager navigationManager, IAuthenticationProvider authentication, IEventLogger eventLogger, ISpeechProvider speech)
+ public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, INavigationManager navigationManager, IAuthenticationProvider authentication, IEventLogger eventLogger, ISpeechProvider speech, IActionLogManager actionLogManager)
{
_converter = new DefaultColorConverter();
@@ -756,6 +762,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
AuthenticationProvider = authentication;
+ _actionLogManager = actionLogManager;
_notification = notificationProvider;
_speech = speech;
_navigation = navigation;
@@ -873,7 +880,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
foreach (var stop in stops)
{
- if (stop.ColorSpace.Code == BL.Enumerations.ColorSpaces.Volume.ToInt32() && !stop.IsLiquidVolumesOutOfRange)
+ if (stop.ColorSpace.Code == BL.Enumerations.ColorSpaces.Volume.ToInt32())
{
try
{
@@ -1034,6 +1041,11 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
var percent = (e.Progress / e.Total * 100d);
+ if (_preparingTaskItem != null)
+ {
+ _preparingTaskItem.Message = $"Preparing job for printing {(e.Progress / e.Total * 100d).ToString("0.0")}%...";
+ }
+
if (_preparingTaskItem == null && percent == 0)
{
_preparingTaskItem = _notification.PushTaskItem("Preparing job for printing...");
@@ -1043,13 +1055,6 @@ namespace Tango.MachineStudio.Developer.ViewModels
_preparingTaskItem.Pop();
_preparingTaskItem = null;
}
- else
- {
- if (_preparingTaskItem != null)
- {
- _preparingTaskItem.Message = $"Preparing job for printing {(e.Progress / e.Total * 100d).ToString("0.0")}%...";
- }
- }
}
private void MachineOperator_ResumingJob(object sender, ResumingJobEventArgs e)
@@ -1252,7 +1257,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
||
j.Name.ToLower().Contains(filter) //Job name
||
- j.User.Contact.FirstName.ToLower().Contains(filter) // User first name
+ (j.User != null && j.User.Contact.FirstName.ToLower().Contains(filter)) // User first name
||
j.Length.ToString().Contains(filter); //Job length
};
@@ -1371,7 +1376,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
/// <summary>
/// Starts the job.
/// </summary>
- private async void StartJob(Func<Job, JobHandler> resumeFunc = null)
+ private async void StartJob(Func<JobHandler> resumeFunc = null)
{
SettingsManager.Default.Save();
@@ -1436,15 +1441,13 @@ namespace Tango.MachineStudio.Developer.ViewModels
}
else
{
- JobHandler = resumeFunc(ActiveJob);
+ JobHandler = resumeFunc();
}
_navigation.NavigateTo(DeveloperNavigationView.RunningJobView);
IsJobRunning = true;
ShowJobStatus = true;
- _eventLogger.Log(String.Format("Job '{0}' started...", ActiveJob.Name));
-
JobHandler.StatusChanged += (x, status) =>
{
if (IsJobRunning)
@@ -1464,25 +1467,21 @@ namespace Tango.MachineStudio.Developer.ViewModels
if (!segment.IsInterSegment)
{
_speech.SpeakInfo(String.Format("Segment {0} Started.", segment.SegmentIndex));
- _eventLogger.Log(String.Format("Segment {0} Started.", segment.SegmentIndex) + Environment.NewLine + segment.ToJsonString());
}
else
{
_speech.SpeakInfo(String.Format("Inter Segment Started."));
- _eventLogger.Log("Inter Segment Started.");
}
};
JobHandler.UnitCompleted += (x, unit) =>
{
_speech.SpeakInfo(String.Format("{0} Units Completed.", unit + 1));
- _eventLogger.Log(String.Format("{0} Units Completed.", unit + 1));
};
JobHandler.Failed += (x, ex) =>
{
LogManager.Log(ex, String.Format("Job {0} has failed.", RunningJob.Name));
- _eventLogger.Log(ex, String.Format("Job {0} has failed.", RunningJob.Name));
SetJobFailed();
InvokeUI(() =>
@@ -1496,13 +1495,11 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
_speech.SpeakInfo("Finalizing job...");
LogManager.Log(String.Format("Finalizing job {0}.", RunningJob.Name));
- _eventLogger.Log(String.Format("Finalizing job {0}.", RunningJob.Name));
};
JobHandler.Completed += (x, e) =>
{
LogManager.Log(String.Format("Job {0} has completed.", RunningJob.Name));
- _eventLogger.Log(String.Format("Job {0} has completed.", RunningJob.Name));
SetJobCompleted();
StopRecordingIfInProgress();
};
@@ -1516,7 +1513,6 @@ namespace Tango.MachineStudio.Developer.ViewModels
}
LogManager.Log(String.Format("Job {0} has been canceled.", RunningJob.Name));
- _eventLogger.Log(String.Format("Job {0} has been canceled.", RunningJob.Name));
StopRecordingIfInProgress();
//Finally Canceled..
};
@@ -1534,7 +1530,6 @@ namespace Tango.MachineStudio.Developer.ViewModels
catch (Exception ex)
{
LogManager.Log(ex);
- _eventLogger.Log(ex, "An error occurred while starting the job.");
_notification.ShowError("An error occurred while starting the job. " + Environment.NewLine + ex.Message);
SetJobFailed();
StopRecordingIfInProgress();
@@ -1594,8 +1589,12 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
LogManager.Log(String.Format("Saving liquid factors for RML {0}...", SelectedRML.Name));
await SelectedRML.SaveAsync(_activeJobDbContext);
+ var rmlAfterChange = RmlDTO.FromObservable(SelectedRML);
+ _actionLogManager.InsertLog(ActionLogType.RmlSaved, AuthenticationProvider.CurrentUser, SelectedRML.Name, _selectedRMLBeforeLiquidFactorsSaves, rmlAfterChange, "RML liquid factors changed from Machine Studio Research module.");
+ _selectedRMLBeforeLiquidFactorsSaves = rmlAfterChange;
LiquidTypesRmls = ActiveJob.Machine.Configuration.GetSupportedIdsPacks(SelectedRML).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList();
+
foreach (var segment in ActiveJob.Segments)
{
SetSegmentBrushStopsLiquidVolumes(segment);
@@ -1623,7 +1622,9 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
LogManager.Log("Invalidating liquid factors, process parameters and process group history...");
- _selectedRML = new RmlBuilder(_activeJobDbContext).Set(SelectedRML.Guid).WithAllParametersGroup().WithCAT(SelectedMachine.Guid).WithCCT().WithLiquidFactors().Build();
+ _selectedRML = new RmlBuilder(_activeJobDbContext).Set(SelectedRML.Guid).WithAllParametersGroup().WithCAT(SelectedMachine.Guid).WithCCT().WithLiquidFactors().WithSpools().Build();
+
+ _selectedRMLBeforeLiquidFactorsSaves = RmlDTO.FromObservable(_selectedRML);
if (_selectedRML.Cct == null)
{
@@ -1672,7 +1673,17 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
await Task.Factory.StartNew(() =>
{
- InvalidateLiquidFactorsAndProcessTables();
+ try
+ {
+ IsFree = false;
+ InvalidateLiquidFactorsAndProcessTables();
+ }
+ catch
+ {}
+ finally
+ {
+ IsFree = true;
+ }
});
}
}
@@ -1680,6 +1691,23 @@ namespace Tango.MachineStudio.Developer.ViewModels
#endregion
+ #region Color Space
+
+ public void OnBrushStopColorSpaceChanged(BrushStop stop)
+ {
+ if (stop != null && stop.ColorSpace != null && stop.BrushColorSpace != BL.Enumerations.ColorSpaces.Volume)
+ {
+ var lubricant = stop.LiquidVolumes.SingleOrDefault(x => x.LiquidType == LiquidTypes.Lubricant);
+
+ if (lubricant != null)
+ {
+ lubricant.Volume = 100;
+ }
+ }
+ }
+
+ #endregion
+
#region Process Parameters Management
/// <summary>
@@ -1691,12 +1719,12 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
try
{
- LogManager.Log(String.Format("Uploading process parameters table {0}...", SelectedProcessParametersTable.Name));
+ LogManager.Log($"Uploading process parameters table {SelectedProcessParametersTable.Name}...");
await MachineOperator.UploadProcessParameters(SelectedProcessParametersTable);
}
catch (Exception ex)
{
- LogManager.LogFormat(ex, "Failed to upload process parameters table {0}", SelectedProcessParametersTable.Name);
+ LogManager.Log(ex, $"Failed to upload process parameters table {SelectedProcessParametersTable.Name}");
_notification.ShowError("Failed to upload the selected process parameters." + Environment.NewLine + ex.Message);
}
}
@@ -1715,6 +1743,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
using (_notification.PushTaskItem("Saving Parameters Group..."))
{
+ var processGroupBefore = ProcessParametersTablesGroupDTO.FromObservable(SelectedRML.GetActiveProcessGroup());
+
using (var db = ObservablesContext.CreateDefault())
{
var active_groups = db.ProcessParametersTablesGroups.Where(x => x.RmlGuid == SelectedRML.Guid && x.Active).ToList();
@@ -1756,6 +1786,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
SelectedRML.ProcessParametersTablesGroups.Add(group);
await SelectedRML.SaveAsync(_activeJobDbContext);
+ _actionLogManager.InsertLog(ActionLogType.RmlActiveProcessParametersChanged, AuthenticationProvider.CurrentUser, SelectedRML.Name, processGroupBefore, ProcessParametersTablesGroupDTO.FromObservable(SelectedRML.GetActiveProcessGroup()), "RML Active process parameters changed from Machine Studio Research module.");
+
InvalidateLiquidFactorsAndProcessTables();
}
@@ -1800,97 +1832,110 @@ namespace Tango.MachineStudio.Developer.ViewModels
using (_notification.PushTaskItem("Loading job details..."))
{
- await Task.Factory.StartNew(() =>
+ try
{
- _disable_gamut_check = true;
+ await Task.Factory.StartNew(() =>
+ {
+ _disable_gamut_check = true;
- LogManager.Log(String.Format("Loading job {0}...", SelectedMachineJob.Name));
- SelectedSegments = new ObservableCollection<Segment>();
- SelectedBrushStops = new ObservableCollection<BrushStop>();
- SelectedRML = null;
- SelectedSegment = null;
- SelectedGroupHistory = null;
- SelectedBrushStop = null;
- SelectedProcessParametersTable = null;
- RmlProcessParametersTableGroup = null;
+ LogManager.Log(String.Format("Loading job {0}...", SelectedMachineJob.Name));
+ SelectedSegments = new ObservableCollection<Segment>();
+ SelectedBrushStops = new ObservableCollection<BrushStop>();
+ SelectedRML = null;
+ SelectedSegment = null;
+ SelectedGroupHistory = null;
+ SelectedBrushStop = null;
+ SelectedProcessParametersTable = null;
+ RmlProcessParametersTableGroup = null;
- _blockInvalidateCommands = false;
+ _blockInvalidateCommands = false;
- LogManager.Log("Creating active job DB context...");
- _activeJobDbContext = ObservablesContext.CreateDefault();
+ LogManager.Log("Creating active job DB context...");
+ _activeJobDbContext = ObservablesContext.CreateDefault();
- LogManager.Log("Initializing available color spaces, RMLs & Winding methods...");
+ LogManager.Log("Initializing available color spaces, RMLs & Winding methods...");
- //var processParamsGroups = _activeJobDbContext.ProcessParametersTablesGroups.ToList();
- //var processParams = _activeJobDbContext.ProcessParametersTables.ToList();
+ //var processParamsGroups = _activeJobDbContext.ProcessParametersTablesGroups.ToList();
+ //var processParams = _activeJobDbContext.ProcessParametersTables.ToList();
- ColorSpaces = _activeJobDbContext.ColorSpaces.ToObservableCollection();
- Rmls = _activeJobDbContext.Rmls.ToObservableCollection();
- WindingMethods = _activeJobDbContext.WindingMethods.ToObservableCollection();
- SpoolTypes = _activeJobDbContext.SpoolTypes.ToObservableCollection();
+ ColorSpaces = _activeJobDbContext.ColorSpaces.ToObservableCollection();
+ Rmls = _activeJobDbContext.Rmls.OrderBy(i => i.Name).ToObservableCollection();
+ WindingMethods = _activeJobDbContext.WindingMethods.ToObservableCollection();
+ SpoolTypes = _activeJobDbContext.SpoolTypes.ToObservableCollection();
- LogManager.Log("Loading machine spools...");
- _activeJobDbContext.Spools.Where(x => x.MachineGuid == SelectedMachine.Guid).Load();
+ LogManager.Log("Loading machine spools...");
+ _activeJobDbContext.Spools.Where(x => x.MachineGuid == SelectedMachine.Guid).Load();
- LogManager.Log("Setting active job...");
- ActiveJob = new JobBuilder(_activeJobDbContext).Set(SelectedMachineJob.Guid).WithUser().WithSegments().WithBrushStops().WithConfiguration().WithRML().Build();
+ LogManager.Log("Setting active job...");
+ ActiveJob = new JobBuilder(_activeJobDbContext).Set(SelectedMachineJob.Guid).WithUser().WithSegments().WithBrushStops().WithConfiguration().WithRML().Build();
- //_activeJobDbContext.Ccts.Where(x => x.RmlGuid == ActiveJob.RmlGuid).ToList();
- //_activeJobDbContext.Cats.Where(x => x.RmlGuid == ActiveJob.RmlGuid).ToList();
- //_activeJobDbContext.Machines.SingleOrDefault(x => x.Guid == ActiveJob.MachineGuid);
- //_activeJobDbContext.Configurations.SingleOrDefault(x => x.Guid == ActiveJob.Machine.ConfigurationGuid);
+ //_activeJobDbContext.Ccts.Where(x => x.RmlGuid == ActiveJob.RmlGuid).ToList();
+ //_activeJobDbContext.Cats.Where(x => x.RmlGuid == ActiveJob.RmlGuid).ToList();
+ //_activeJobDbContext.Machines.SingleOrDefault(x => x.Guid == ActiveJob.MachineGuid);
+ //_activeJobDbContext.Configurations.SingleOrDefault(x => x.Guid == ActiveJob.Machine.ConfigurationGuid);
- //_activeJobDbContext.LiquidTypesRmls.ToList();
+ //_activeJobDbContext.LiquidTypesRmls.ToList();
- //_activeJobDbContext.IdsPackFormulas.ToList();
- //_activeJobDbContext.LiquidTypes.ToList();
- //_activeJobDbContext.MidTankTypes.ToList();
- //_activeJobDbContext.DispenserTypes.ToList();
+ //_activeJobDbContext.IdsPackFormulas.ToList();
+ //_activeJobDbContext.LiquidTypes.ToList();
+ //_activeJobDbContext.MidTankTypes.ToList();
+ //_activeJobDbContext.DispenserTypes.ToList();
- //_activeJobDbContext.IdsPacks.Where(x => x.ConfigurationGuid == ActiveJob.Machine.ConfigurationGuid).ToList();
+ //_activeJobDbContext.IdsPacks.Where(x => x.ConfigurationGuid == ActiveJob.Machine.ConfigurationGuid).ToList();
+ _beforeSaveJobDTO = JobDTO.FromObservable(ActiveJob);
- LogManager.Log("Setting selected segment...");
- _selectedSegment = ActiveJob.OrderedSegments.FirstOrDefault();
+ LogManager.Log("Setting selected segment...");
+ _selectedSegment = ActiveJob.OrderedSegments.FirstOrDefault();
- ActiveJob.LengthChanged -= ActiveJob_LengthChanged;
- ActiveJob.LengthChanged += ActiveJob_LengthChanged;
+ ActiveJob.LengthChanged -= ActiveJob_LengthChanged;
+ ActiveJob.LengthChanged += ActiveJob_LengthChanged;
- _selectedRML = ActiveJob.Rml;
- InvalidateLiquidFactorsAndProcessTables();
- RaisePropertyChanged(nameof(SelectedRML));
+ _selectedRML = ActiveJob.Rml;
+ InvalidateLiquidFactorsAndProcessTables();
+ RaisePropertyChanged(nameof(SelectedRML));
- UpdateEstimatedDuration();
+ UpdateEstimatedDuration();
- _blockInvalidateCommands = false;
- InvalidateRelayCommands();
+ _blockInvalidateCommands = false;
+ InvalidateRelayCommands();
- _disable_gamut_check = false;
+ _disable_gamut_check = false;
- _settings.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null;
- _settings.LastSelectedJobGuid = SelectedMachineJob != null ? SelectedMachineJob.Guid : null;
+ _settings.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null;
+ _settings.LastSelectedJobGuid = SelectedMachineJob != null ? SelectedMachineJob.Guid : null;
- _settings.Save();
- });
+ _settings.Save();
+ });
- SegmentsCollectionView = CollectionViewSource.GetDefaultView(ActiveJob.Segments);
- SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending));
+ SegmentsCollectionView = CollectionViewSource.GetDefaultView(ActiveJob.Segments);
+ SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending));
- foreach (var segment in ActiveJob.Segments)
- {
- SetSegmentBrushStopsLiquidVolumes(segment);
- }
+ foreach (var segment in ActiveJob.Segments)
+ {
+ SetSegmentBrushStopsLiquidVolumes(segment);
+ }
- SelectedSegment = _selectedSegment;
+ SelectedSegment = _selectedSegment;
+
+ if (ActiveJob != null)
+ {
+ _current_job_string = ActiveJob.ToJobFileWhenLoaded().ToString();
+ }
- if (ActiveJob != null)
+ UIHelper.DoEvents();
+ _navigation.NavigateTo(DeveloperNavigationView.JobView);
+ }
+ catch (Exception ex)
{
- _current_job_string = ActiveJob.ToJobFileWhenLoaded().ToString();
+ LogManager.Log(ex, "Error loading job.");
+ _notification.ShowError($"An error occurred while trying to load the selected job.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ CanWork = true;
}
-
- UIHelper.DoEvents();
- _navigation.NavigateTo(DeveloperNavigationView.JobView);
}
CanWork = true;
@@ -1908,50 +1953,65 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
CanWork = false;
- using (_notification.PushTaskItem("Saving job details..."))
+ try
{
- await Task.Factory.StartNew(() =>
+ using (_notification.PushTaskItem("Saving job details..."))
{
- LogManager.Log(String.Format("Saving the active job {0}...", ActiveJob.Name));
- ActiveJob.LastUpdated = DateTime.UtcNow;
- ActiveJob.Rml = SelectedRML;
- ActiveJob.EstimatedDurationMili = (int)EstimatedDuration.TotalMilliseconds;
- _activeJobDbContext.SaveChanges();
-
- _machineDbContext.Entry(SelectedMachineJob).Reload();
+ await Task.Factory.StartNew(() =>
+ {
+ LogManager.Log(String.Format("Saving the active job {0}...", ActiveJob.Name));
+ ActiveJob.LastUpdated = DateTime.UtcNow;
+ ActiveJob.IsSynchronized = false;
+ ActiveJob.Rml = SelectedRML;
+ ActiveJob.EstimatedDurationMili = (int)EstimatedDuration.TotalMilliseconds;
+ ActiveJob.MarkModified(_activeJobDbContext);
+ _activeJobDbContext.SaveChanges();
+ var afterJobDTO = JobDTO.FromObservable(ActiveJob);
+ _actionLogManager.InsertLog(ActionLogType.JobSaved, AuthenticationProvider.CurrentUser, _beforeSaveJobDTO.Name, _beforeSaveJobDTO, afterJobDTO, "Job saved from research module in Machine Studio.");
+ _beforeSaveJobDTO = afterJobDTO;
- _machineDbContext.Entry(SelectedMachineJob).Collection(x => x.Segments).Load();
+ _machineDbContext.Entry(SelectedMachineJob).Reload();
- foreach (var segment in SelectedMachineJob.Segments.ToList())
- {
- _machineDbContext.Entry(segment).Collection(x => x.BrushStops).Load();
+ _machineDbContext.Entry(SelectedMachineJob).Collection(x => x.Segments).Load();
- foreach (var brushStop in segment.BrushStops.ToList())
+ foreach (var segment in SelectedMachineJob.Segments.ToList())
{
- _machineDbContext.Entry(brushStop).Reload();
- }
+ _machineDbContext.Entry(segment).Collection(x => x.BrushStops).Load();
- _machineDbContext.Entry(segment).Reload();
- }
+ foreach (var brushStop in segment.BrushStops.ToList())
+ {
+ _machineDbContext.Entry(brushStop).Reload();
+ }
- InvokeUI(() =>
- {
- SelectedMachineJob.Segments = SelectedMachineJob.Segments;
- });
+ _machineDbContext.Entry(segment).Reload();
+ }
- var settings = SettingsManager.Default.GetOrCreate<DeveloperModuleSettings>();
- settings.DefaultJobRmlGuid = ActiveJob.RmlGuid;
- settings.Save();
+ InvokeUI(() =>
+ {
+ SelectedMachineJob.Segments = SelectedMachineJob.Segments;
+ });
- if (ActiveJob != null)
- {
- _current_job_string = ActiveJob.ToJobFileWhenLoaded().ToString();
- }
- });
- }
+ var settings = SettingsManager.Default.GetOrCreate<DeveloperModuleSettings>();
+ settings.DefaultJobRmlGuid = ActiveJob.RmlGuid;
+ settings.Save();
- CanWork = true;
+ if (ActiveJob != null)
+ {
+ _current_job_string = ActiveJob.ToJobFileWhenLoaded().ToString();
+ }
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error saving active job.");
+ _notification.ShowError($"An error occurred while trying to save the current job.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ CanWork = true;
+ }
}
}
@@ -2139,7 +2199,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
if (ActiveJob != null)
{
- LogManager.LogFormat("Adding new segment to job {0}...", ActiveJob.Name);
+ LogManager.Log($"Adding new segment to job {ActiveJob.Name}...");
Segment seg = new Segment();
seg.Job = ActiveJob;
seg.Name = "SEGMENT";
@@ -2171,6 +2231,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
if (_notification.ShowQuestion("Are you sure you want to delete the selected jobs?"))
{
+ var jobsToReport = SelectedJobs.Select(x => JobDTO.FromObservable(x)).ToList();
+
LogManager.Log(String.Format("Removing {0} jobs...", SelectedJobs.Count));
SelectedJobs.ToList().ForEach(x =>
{
@@ -2182,6 +2244,11 @@ namespace Tango.MachineStudio.Developer.ViewModels
LogManager.Log("Saving selected machine to database...");
await SelectedMachine.SaveAsync(_machineDbContext);
}
+
+ foreach (var job in jobsToReport)
+ {
+ _actionLogManager.InsertLog(ActionLogType.JobDeleted, AuthenticationProvider.CurrentUser, job.Name, job, "Job deleted using Machine Studio.", true);
+ }
}
}
}
@@ -2202,6 +2269,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
var settings = SettingsManager.Default.GetOrCreate<DeveloperModuleSettings>();
Job newJob = new Job();
+ newJob.LastUpdated = DateTime.UtcNow;
+ newJob.JobSource = JobSource.Remote;
newJob.Name = jobName;
newJob.CreationDate = DateTime.UtcNow;
newJob.UserGuid = AuthenticationProvider.CurrentUser.Guid;
@@ -2236,6 +2305,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
LogManager.Log("Saving selected machine to database...");
await SelectedMachine.SaveAsync(_machineDbContext);
+ _actionLogManager.InsertLog(ActionLogType.JobCreated, AuthenticationProvider.CurrentUser, newJob.Name, newJob, "Job created using Machine Studio.");
SelectedMachineJob = newJob;
LoadSelectedJob();
}
@@ -2261,6 +2331,13 @@ namespace Tango.MachineStudio.Developer.ViewModels
return;
}
SelectedSegment.BrushStops.Remove(x);
+ var existingBrushStop = _activeJobDbContext.BrushStops.FirstOrDefault(y => y.Guid == x.Guid);
+ if(existingBrushStop != null)
+ {
+ _activeJobDbContext.BrushStops.Remove(existingBrushStop);
+ }
+
+
});
ArrangeBrushStopsIndices();
@@ -2275,7 +2352,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
if (SelectedSegment != null)
{
- LogManager.LogFormat("Adding new brush stop to segment...", SelectedSegment.SegmentIndex.ToString());
+ LogManager.Log($"Adding new brush stop to segment '{SelectedSegment.SegmentIndex}'...");
var stop = new BrushStop();
@@ -2295,6 +2372,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
stop.SetAllDispensingStepDivisions(BL.Dispensing.DispenserStepDivisions.D8);
stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable);
SelectedSegment.BrushStops.Add(stop);
+ // _activeJobDbContext.BrushStops.Add(stop);
SelectedSegment.BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged());
ArrangeBrushStopsIndices();
}
@@ -2305,7 +2383,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
/// </summary>
private void DuplicateSelectedBrushStops()
{
- LogManager.LogFormat("Duplicating {0} brush stops...", SelectedBrushStops.Count);
+ LogManager.Log($"Duplicating {SelectedBrushStops.Count} brush stops...");
foreach (var stop in SelectedBrushStops.OrderBy(x => x.StopIndex))
{
@@ -2323,7 +2401,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
/// </summary>
private void DuplicateSelectedSegments()
{
- LogManager.LogFormat("Duplicating {0} segments...", SelectedSegments.Count);
+ LogManager.Log($"Duplicating {SelectedSegments.Count} segments...");
int start_index = SelectedSegments.Max(x => x.SegmentIndex);
@@ -2351,7 +2429,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
CanWork = false;
- LogManager.LogFormat("Duplicating {0} jobs...", SelectedJobs.Count);
+ LogManager.Log($"Duplicating {SelectedJobs.Count} jobs...");
int index = SelectedMachine.Jobs.Max(x => x.JobIndex);
@@ -2365,6 +2443,11 @@ namespace Tango.MachineStudio.Developer.ViewModels
LogManager.Log("Saving selected machine to database...");
await SelectedMachine.SaveAsync(_machineDbContext);
+ foreach (var job in SelectedJobs)
+ {
+ _actionLogManager.InsertLog(ActionLogType.JobCreated, AuthenticationProvider.CurrentUser, job.Name, job, "Job cloned using Machine Studio.");
+ }
+
CanWork = true;
}
}
@@ -2588,17 +2671,26 @@ namespace Tango.MachineStudio.Developer.ViewModels
LogManager.Log($"Importing job files...");
+ List<Job> jobsToReport = new List<Job>();
+
foreach (var file in dlg.FileNames)
{
var bytes = File.ReadAllBytes(file);
var jobFile = JobFile.Parser.ParseFrom(bytes);
var job = await Job.FromJobFile(jobFile, SelectedMachine.Guid, AuthenticationProvider.CurrentUser.Guid);
+ job.JobSource = JobSource.Remote;
_machineDbContext.Jobs.Add(job);
+ jobsToReport.Add(job);
}
await _machineDbContext.SaveChangesAsync();
+ foreach (var job in jobsToReport)
+ {
+ _actionLogManager.InsertLog(ActionLogType.JobImported, AuthenticationProvider.CurrentUser, job.Name, job, "Job imported using Machine Studio.");
+ }
+
IsFree = true;
_notification.ShowInfo($"Jobs imported successfully.");