aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-10-28 16:52:47 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-10-28 16:52:47 +0200
commit68902601817604f65cc2ec67f28002e9c20f51c8 (patch)
treefef7b01f6ac92d6061e90ae35b47fde2c6737329 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels
parent521326ce426ed0cd5b8d92b280cdf0c7213e7b50 (diff)
downloadTango-68902601817604f65cc2ec67f28002e9c20f51c8.tar.gz
Tango-68902601817604f65cc2ec67f28002e9c20f51c8.zip
Added import /export to hardware version in machine studio.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs89
1 files changed, 87 insertions, 2 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
index 918eb02d4..40dc82d29 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
@@ -14,6 +14,8 @@ using System.Runtime.CompilerServices;
using Tango.MachineStudio.Common;
using Tango.Core.ExtensionMethods;
using Tango.MachineStudio.HardwareDesigner.Views;
+using Microsoft.Win32;
+using System.IO;
namespace Tango.MachineStudio.HardwareDesigner.ViewModels
{
@@ -87,7 +89,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
return name;
}
}
-
+
private ObservableCollection<HardwareVersion> _hardwareVersions;
public ObservableCollection<HardwareVersion> HardwareVersions
{
@@ -107,6 +109,10 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
public RelayCommand OpenComparisonWizardCommand { get; set; }
+ public RelayCommand ExportHardwareVersionCommand { get; set; }
+
+ public RelayCommand ImportHardwareVersionCommand { get; set; }
+
public MainViewVM(INotificationProvider notification)
{
_notification = notification;
@@ -122,7 +128,86 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
CopyParametersCommand = new RelayCommand(CopyParameters, (x) => SelectedVersion != null && IsFree);
CloneCommand = new RelayCommand(CloneCurrentVersion, () => SelectedVersion != null && IsFree);
- OpenComparisonWizardCommand = new RelayCommand(OpenComparisonWizard);
+ OpenComparisonWizardCommand = new RelayCommand(OpenComparisonWizard, () => IsFree);
+ ExportHardwareVersionCommand = new RelayCommand(ExportHardwareVersion, () => IsFree && SelectedVersion != null && CurrentVersion != null);
+ ImportHardwareVersionCommand = new RelayCommand(ImportHardwareVersion, () => IsFree);
+ }
+
+ private async void ExportHardwareVersion()
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.Title = "Export hardware version";
+ dlg.DefaultExt = ".hv";
+ dlg.Filter = "Hardware Version Files|*.hv";
+
+ if (dlg.ShowDialog().Value)
+ {
+ try
+ {
+ var json = await CurrentVersion.ToHardwareVersionFile();
+ File.WriteAllText(dlg.FileName, json);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error exporting hardware version.");
+ _notification.ShowError($"An error occurred while trying to export the selected hardware version.\n{ex.FlattenMessage()}");
+ }
+ }
+ }
+
+ private async void ImportHardwareVersion()
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Title = "Import hardware version";
+ dlg.DefaultExt = ".hv";
+ dlg.Filter = "Hardware Version Files|*.hv";
+
+ if (dlg.ShowDialog().Value)
+ {
+ try
+ {
+ var hv = await HardwareVersion.FromHardwareVersionFile(File.ReadAllText(dlg.FileName));
+
+ String name = _notification.ShowTextInput("Enter hardware version name", "Name", hv.Name);
+ if (!String.IsNullOrWhiteSpace(name))
+ {
+ using (_notification.PushTaskItem("Importing hardware version..."))
+ {
+ try
+ {
+ IsFree = false;
+
+ hv.Name = name;
+ hv.Version = HardwareVersions.Max(x => x.Version) + 1;
+
+ _db.HardwareVersions.Add(hv);
+ await _db.SaveChangesAsync();
+
+ RefreshVersions();
+
+ InvokeUI(() =>
+ {
+ SelectedVersion = HardwareVersions.SingleOrDefault(x => x.Guid == hv.Guid);
+ });
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error importing hardware version.");
+ _notification.ShowError($"An error occurred while trying to import the selected hardware version.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ IsFree = true;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error importing hardware version.");
+ _notification.ShowError($"An error occurred while trying to load the selected hardware version file.\n{ex.FlattenMessage()}");
+ }
+ }
}
public override void OnApplicationReady()