diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-10-02 16:59:05 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-10-02 16:59:05 +0300 |
| commit | ebd971a77a5fdabdf4040f07ac0e63e687abb8aa (patch) | |
| tree | f3a8cee479a4a43ecbe1f9712a18a3e759aa9982 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | |
| parent | b8a170ddc60d2bcb06db9f88680ae632c7d646d8 (diff) | |
| download | Tango-ebd971a77a5fdabdf4040f07ac0e63e687abb8aa.tar.gz Tango-ebd971a77a5fdabdf4040f07ac0e63e687abb8aa.zip | |
Another fix for SetLiquidVolumes.
Changed JobFile PMR.
Implemented new JobFile with Liquid Volume awareness.
Implemented Import/Export jobs on research module.
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.cs | 120 |
1 files changed, 120 insertions, 0 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 2d04866d8..27d43bd20 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 @@ using Tango.MachineStudio.Common.Navigation; using System.Diagnostics; using Tango.Core.ExtensionMethods; using Tango.ColorConversion; +using Tango.PMR.Exports; +using Microsoft.WindowsAPICodePack.Dialogs; namespace Tango.MachineStudio.Developer.ViewModels { @@ -725,6 +727,16 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> public RelayCommand ResetProcessParametersCommand { get; set; } + /// <summary> + /// Gets or sets the import job file command. + /// </summary> + public RelayCommand ImportJobFileCommand { get; set; } + + /// <summary> + /// Gets or sets the export job file command. + /// </summary> + public RelayCommand ExportJobFileCommand { get; set; } + #endregion #region Constructors @@ -786,6 +798,8 @@ namespace Tango.MachineStudio.Developer.ViewModels DisplayJobEmbroideryFileCommand = new RelayCommand<Job>(DisplayJobEmbroideryFile, () => CanWork); ReloadMachinesCommand = new RelayCommand(() => LoadMachine(), () => CanWork && SelectedMachine != null); ResetProcessParametersCommand = new RelayCommand(ResetProcessParameters, () => CanWork && MachineOperator != null); + ImportJobFileCommand = new RelayCommand(ImportJobFile, () => SelectedMachine != null && CanWork); + ExportJobFileCommand = new RelayCommand(ExportJobFile, () => SelectedMachine != null && SelectedMachineJob != null && CanWork); ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; @@ -2488,6 +2502,112 @@ namespace Tango.MachineStudio.Developer.ViewModels #endregion + #region Job Import/Export + + private async void ExportJobFile() + { + if (SelectedJobs != null && SelectedJobs.Count > 1) + { + CommonOpenFileDialog dlg = new CommonOpenFileDialog(); + dlg.Title = "Select a folder to place all job files."; + dlg.IsFolderPicker = true; + + if (dlg.ShowDialog() == CommonFileDialogResult.Ok) + { + foreach (var job in SelectedJobs) + { + using (_notification.PushTaskItem($"Exporting job '{job.Name}'...")) + { + try + { + LogManager.Log($"Exporting job file {job.Name}"); + + var jobFile = await job.ToJobFile(); + File.WriteAllBytes(Path.Combine(dlg.FileName, job.Name + ".job"), jobFile.ToBytes()); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting job file."); + _notification.ShowError($"An error occurred while trying to export job '{job.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + } + } + else + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Export Job File"; + dlg.Filter = "Twine Job Files|*.job"; + dlg.DefaultExt = ".job"; + dlg.FileName = SelectedMachineJob.Name; + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem($"Exporting job '{SelectedMachineJob.Name}'...")) + { + try + { + LogManager.Log($"Exporting job file {SelectedMachineJob.Name}"); + + var jobFile = await SelectedMachineJob.ToJobFile(); + File.WriteAllBytes(dlg.FileName, jobFile.ToBytes()); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting job file."); + _notification.ShowError($"An error occurred while trying to export job '{SelectedMachineJob.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + } + } + + private async void ImportJobFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Import Job File"; + dlg.Filter = "Twine Job Files|*.job"; + dlg.Multiselect = true; + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem($"Importing job files...")) + { + try + { + IsFree = false; + + LogManager.Log($"Importing job files..."); + + 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); + + _machineDbContext.Jobs.Add(job); + } + + await _machineDbContext.SaveChangesAsync(); + + IsFree = true; + + _notification.ShowInfo($"Jobs imported successfully."); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error importing job file."); + _notification.ShowError($"An error occurred while trying to import the selected job file.\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } + } + } + } + + #endregion + #region Override Methods protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) |
