From 20b54cfc2b40bb69d1d6558c7fac6cc412c98da0 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 7 Oct 2019 14:42:44 +0300 Subject: Implemented RML import/export. Fixed issue with MS in 1920x1080. Added IP Address & Up Time to PPC. Added ExternalBridge Icon IsInSession Indication. Fixed issue with ExternalBridgeService disconnection. --- .../ViewModels/MainViewVM.cs | 91 ++++++++++++++++++++++ .../Tango.MachineStudio.RML/Views/RmlsView.xaml | 76 +++++++++++------- 2 files changed, 139 insertions(+), 28 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index a76799881..ee21b9ac3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -181,6 +181,10 @@ namespace Tango.MachineStudio.RML.ViewModels public RelayCommand CloneRmlCommand { get; set; } + public RelayCommand ExportRMLFileCommand { get; set; } + + public RelayCommand ImportRMLFileCommand { get; set; } + public MainViewVM(INotificationProvider notificationProvider) { _notification = notificationProvider; @@ -199,6 +203,9 @@ namespace Tango.MachineStudio.RML.ViewModels ImportForwardDataCommand = new RelayCommand(ImportCCTData, () => ActiveRML != null && IsFree); ExportForwardDataCommand = new RelayCommand(ExportCCTData, () => ActiveRML != null && SelectedCCT != null && IsFree); + + ExportRMLFileCommand = new RelayCommand(ExportRmlFile, () => SelectedRML != null && IsFree); + ImportRMLFileCommand = new RelayCommand(ImportRmlFile, () => IsFree); } public override void OnApplicationReady() @@ -769,5 +776,89 @@ namespace Tango.MachineStudio.RML.ViewModels } #endregion + + #region RML Import / Export + + private async void ImportRmlFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Import Thread Files"; + dlg.Filter = "Twine Thread Files|*.rml"; + dlg.Multiselect = true; + + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem($"Importing thread files...")) + { + try + { + IsFree = false; + + LogManager.Log($"Importing thread files..."); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + foreach (var file in dlg.FileNames) + { + var json = File.ReadAllText(file); + var rmlFile = await Rml.FromRmlFile(db, json); + + db.Rmls.Add(rmlFile); + } + + await db.SaveChangesAsync(); + } + + IsFree = true; + + _notification.ShowInfo($"Threads imported successfully."); + + LoadRmls(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error importing thread file."); + _notification.ShowError($"An error occurred while trying to import the selected thread file.\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } + } + } + } + + private async void ExportRmlFile() + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Export Thread File"; + dlg.Filter = "Twine Thread Files|*.rml"; + dlg.DefaultExt = ".rml"; + dlg.FileName = SelectedRML.Name; + + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem($"Exporting Thread '{SelectedRML.Name}'...")) + { + try + { + LogManager.Log($"Exporting Thread file {SelectedRML.Name}"); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var rmlJsonFile = await SelectedRML.ToRmlFile(db); + File.WriteAllText(dlg.FileName, rmlJsonFile); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting Thread file."); + _notification.ShowError($"An error occurred while trying to export thread '{SelectedRML.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + } + + #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml index fdfc00ba6..288f00a3d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml @@ -19,38 +19,58 @@ - + - - + + - - - - - - - + + + + + + + @@ -63,11 +83,11 @@ - + - + -- cgit v1.3.1