aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner
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
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')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs89
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml16
2 files changed, 102 insertions, 3 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()
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml
index 86cc089e5..1c00397aa 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/Views/MainView.xaml
@@ -66,12 +66,26 @@
</ComboBox>
</StackPanel>
- <Button Margin="100,10,0,0" Cursor="Hand" Height="40" FontSize="12" ToolTip="Open Comparison Wizard" Command="{Binding OpenComparisonWizardCommand}">
+ <Button Margin="100 10 0 0" Cursor="Hand" Height="40" FontSize="12" ToolTip="Open Comparison Wizard" Command="{Binding OpenComparisonWizardCommand}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Width="24" Height="24" Kind="Compare"/>
<TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="16">Comparison Wizard</TextBlock>
</StackPanel>
</Button>
+
+ <Button Margin="10 10 0 0" Cursor="Hand" MinWidth="150" Height="40" FontSize="12" ToolTip="Import hardware version to file" Command="{Binding ImportHardwareVersionCommand}">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Width="24" Height="24" Kind="FileImport"/>
+ <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="16">IMPORT</TextBlock>
+ </StackPanel>
+ </Button>
+
+ <Button Margin="10 10 0 0" Cursor="Hand" MinWidth="150" Height="40" FontSize="12" ToolTip="Export hardware version to file" Command="{Binding ExportHardwareVersionCommand}">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Width="24" Height="24" Kind="FileExport"/>
+ <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="16">EXPORT</TextBlock>
+ </StackPanel>
+ </Button>
</StackPanel>
</Grid>