aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-01-27 09:19:11 +0200
committerShlomo Hecht <shlomo@twine-s.com>2020-01-27 09:19:11 +0200
commitddda6089bff56e80703c8d2dce297919edc58bf1 (patch)
tree7702c5cf169124d522eacc7f1a9e0878373baedd /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels
parent1d4d327571d4c0c9f4e17411551bd4dae1e2aed0 (diff)
parentbf2f3245339b9fd9148a2ad25b5ba3320e970cc1 (diff)
downloadTango-ddda6089bff56e80703c8d2dce297919edc58bf1.tar.gz
Tango-ddda6089bff56e80703c8d2dce297919edc58bf1.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/ComparisonWizardViewVM.cs8
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs134
2 files changed, 130 insertions, 12 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/ComparisonWizardViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/ComparisonWizardViewVM.cs
index 47a40ade4..a58d69a93 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/ComparisonWizardViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/ComparisonWizardViewVM.cs
@@ -281,6 +281,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
collection.Components.Add(componentResult);
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.ComponentName).ToSynchronizedObservableCollection();
return collection;
}
@@ -303,6 +304,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
collection.Components.Add(componentResult);
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.ComponentName).ToSynchronizedObservableCollection();
return collection;
}
@@ -325,6 +327,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
collection.Components.Add(componentResult);
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.ComponentName).ToSynchronizedObservableCollection();
return collection;
}
@@ -347,6 +350,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
collection.Components.Add(componentResult);
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.ComponentName).ToSynchronizedObservableCollection();
return collection;
}
@@ -369,6 +373,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
collection.Components.Add(componentResult);
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.ComponentName).ToSynchronizedObservableCollection();
return collection;
}
@@ -391,6 +396,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
collection.Components.Add(componentResult);
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.ComponentName).ToSynchronizedObservableCollection();
return collection;
}
@@ -413,6 +419,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
collection.Components.Add(componentResult);
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.ComponentName).ToSynchronizedObservableCollection();
return collection;
}
@@ -432,7 +439,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
result.Properties.Add(hProp);
}
-
return result;
}
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..0a8780346 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,11 @@ using System.Runtime.CompilerServices;
using Tango.MachineStudio.Common;
using Tango.Core.ExtensionMethods;
using Tango.MachineStudio.HardwareDesigner.Views;
+using Microsoft.Win32;
+using System.IO;
+using Tango.BL.ActionLogs;
+using Tango.MachineStudio.Common.Authentication;
+using Tango.BL.DTO;
namespace Tango.MachineStudio.HardwareDesigner.ViewModels
{
@@ -22,6 +27,9 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
private INotificationProvider _notification;
private bool _isNew;
private ObservablesContext _db;
+ private IActionLogManager _actionLogManager;
+ private IAuthenticationProvider _authentication;
+ private HardwareVersionDTO _hwBeforeSave;
private HardwareVersion _selectedVersion;
public HardwareVersion SelectedVersion
@@ -43,6 +51,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
get { return _selectedHardwareObject; }
set
{
+ _selectedHardwareObject = null;
+ RaisePropertyChangedAuto();
_selectedHardwareObject = value;
RaisePropertyChangedAuto();
RaisePropertyChanged(nameof(SelectedHardwareObjectTypeName));
@@ -87,7 +97,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
return name;
}
}
-
+
private ObservableCollection<HardwareVersion> _hardwareVersions;
public ObservableCollection<HardwareVersion> HardwareVersions
{
@@ -107,9 +117,15 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
public RelayCommand OpenComparisonWizardCommand { get; set; }
- public MainViewVM(INotificationProvider notification)
+ public RelayCommand ExportHardwareVersionCommand { get; set; }
+
+ public RelayCommand ImportHardwareVersionCommand { get; set; }
+
+ public MainViewVM(INotificationProvider notification, IActionLogManager actionLogManager, IAuthenticationProvider authentication)
{
_notification = notification;
+ _actionLogManager = actionLogManager;
+ _authentication = authentication;
CurrentVersion = new HardwareVersion();
@@ -122,7 +138,88 @@ 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();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionImported, _authentication.CurrentUser, CurrentVersion.Name, CurrentVersion, "New hardware version imported using Machine Studio.");
+
+ 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()
@@ -136,7 +233,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
private void CopyParameters(object obj)
{
- obj.MapPrimitivesTo(SelectedHardwareObject,
+ obj.MapPropertiesTo(SelectedHardwareObject, MappingFlags.PrimitivesOnly,
(prop) =>
!prop.PropertyType.IsEnum
&&
@@ -151,13 +248,13 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
_db = ObservablesContext.CreateDefault();
- CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).ToSynchronizedObservableCollection();
- CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).ToSynchronizedObservableCollection();
- CurrentVersion.HardwarePidControls = _db.HardwarePidControlTypes.ToList().Select(x => new HardwarePidControl() { HardwarePidControlType = x }).ToSynchronizedObservableCollection();
- CurrentVersion.HardwareWinders = _db.HardwareWinderTypes.ToList().Select(x => new HardwareWinder() { HardwareWinderType = x }).ToSynchronizedObservableCollection();
- CurrentVersion.HardwareSpeedSensors = _db.HardwareSpeedSensorTypes.ToList().Select(x => new HardwareSpeedSensor() { HardwareSpeedSensorType = x }).ToSynchronizedObservableCollection();
- CurrentVersion.HardwareBlowers = _db.HardwareBlowerTypes.ToList().Select(x => new HardwareBlower() { HardwareBlowerType = x }).ToSynchronizedObservableCollection();
- CurrentVersion.HardwareBreakSensors = _db.HardwareBreakSensorTypes.ToList().Select(x => new HardwareBreakSensor() { HardwareBreakSensorType = x }).ToSynchronizedObservableCollection();
+ CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).OrderByAlphaNumeric(x => x.HardwareMotorType.Description).ToSynchronizedObservableCollection();
+ CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).OrderByAlphaNumeric(x => x.HardwareDancerType.Description).ToSynchronizedObservableCollection();
+ CurrentVersion.HardwarePidControls = _db.HardwarePidControlTypes.ToList().Select(x => new HardwarePidControl() { HardwarePidControlType = x }).OrderByAlphaNumeric(x => x.HardwarePidControlType.Description).ToSynchronizedObservableCollection();
+ CurrentVersion.HardwareWinders = _db.HardwareWinderTypes.ToList().Select(x => new HardwareWinder() { HardwareWinderType = x }).OrderByAlphaNumeric(x => x.HardwareWinderType.Description).ToSynchronizedObservableCollection();
+ CurrentVersion.HardwareSpeedSensors = _db.HardwareSpeedSensorTypes.ToList().Select(x => new HardwareSpeedSensor() { HardwareSpeedSensorType = x }).OrderByAlphaNumeric(x => x.HardwareSpeedSensorType.Description).ToSynchronizedObservableCollection();
+ CurrentVersion.HardwareBlowers = _db.HardwareBlowerTypes.ToList().Select(x => new HardwareBlower() { HardwareBlowerType = x }).OrderByAlphaNumeric(x => x.HardwareBlowerType.Description).ToSynchronizedObservableCollection();
+ CurrentVersion.HardwareBreakSensors = _db.HardwareBreakSensorTypes.ToList().Select(x => new HardwareBreakSensor() { HardwareBreakSensorType = x }).OrderByAlphaNumeric(x => x.HardwareBreakSensorType.Description).ToSynchronizedObservableCollection();
}
private void RefreshVersions()
@@ -252,6 +349,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
});
CurrentVersion.HardwareBreakSensors = CurrentVersion.HardwareBreakSensors.OrderBy(x => x.HardwareBreakSensorType.Code).ToSynchronizedObservableCollection();
+
+ _hwBeforeSave = HardwareVersionDTO.FromObservable(CurrentVersion);
});
}
@@ -306,6 +405,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
_db.HardwareVersions.Add(CurrentVersion);
_db.SaveChanges();
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionCreated, _authentication.CurrentUser, CurrentVersion.Name, CurrentVersion, "New hardware version created using Machine Studio.");
+
RefreshVersions();
InvokeUI(() =>
@@ -333,7 +434,13 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
await Task.Factory.StartNew(() =>
{
+ CurrentVersion.LastUpdated = DateTime.UtcNow;
_db.SaveChanges();
+
+ var dtoAfter = HardwareVersionDTO.FromObservable(CurrentVersion);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionSaved, _authentication.CurrentUser, _hwBeforeSave.Name, _hwBeforeSave, dtoAfter, "Hardware Version saved using Machine Studio.");
+ _hwBeforeSave = dtoAfter;
+
RefreshVersions();
InvokeUI(() =>
@@ -375,6 +482,9 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
cloned.Version = HardwareVersions.Max(x => x.Version) + 1;
_db.HardwareVersions.Add(cloned);
_db.SaveChanges();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionCreated, _authentication.CurrentUser, cloned.Name, cloned, "New hardware version cloned using Machine Studio.");
+
RefreshVersions();
InvokeUI(() =>
@@ -410,6 +520,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
await CurrentVersion.DeleteCascadeAsync(_db);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionDeleted, _authentication.CurrentUser, CurrentVersion.Name, _hwBeforeSave, "Hardware version deleted using Machine Studio.", true);
+
await Task.Factory.StartNew(() =>
{
SelectedVersion = null;