aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/ColorCalibrationViewVM.cs10
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs30
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs45
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdateDetailsDialogVM.cs20
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs198
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs319
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs129
7 files changed, 724 insertions, 27 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/ColorCalibrationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/ColorCalibrationViewVM.cs
index b75fe7e03..d37fe1aaa 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/ColorCalibrationViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/ColorCalibrationViewVM.cs
@@ -180,6 +180,16 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
public void Save()
{
+ //Remove cats with deleted RMLS. (Can only happen when creating new machine from prototype)
+ foreach (var cat in Machine.Cats.ToList())
+ {
+ if (!Rmls.Any(x => x.Guid == cat.RmlGuid))
+ {
+ Machine.Cats.Remove(cat);
+ _dbContext.Cats.Remove(cat);
+ }
+ }
+
foreach (var calDataVM in ColorConversionViewVM.LiquidsCalibrationData)
{
var cat = calDataVM.IdsPack.LiquidType.Cats.FirstOrDefault(x => x.Machine == Machine && x.Rml == SelectedRML);
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs
index f7ae88f68..e29ba3b6f 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/HardwareConfigurationViewVM.cs
@@ -92,16 +92,19 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
HardwareVersion hardwareVersion = configuration.HardwareVersion;
- _hwConfig = configuration.GetHardwareConfiguration();
+ if (hardwareVersion != null)
+ {
+ _hwConfig = configuration.GetHardwareConfiguration();
- Collections.Clear();
- Collections.Add(CreateMotorsCollection(hardwareVersion));
- Collections.Add(CreateDancerCollection(hardwareVersion));
- Collections.Add(CreatePidCollection(hardwareVersion));
- Collections.Add(CreateWindersCollection(hardwareVersion));
- Collections.Add(CreateSpeedSensorsCollection(hardwareVersion));
- Collections.Add(CreateBlowersCollection(hardwareVersion));
- Collections.Add(CreateBreakSensorCollection(hardwareVersion));
+ Collections.Clear();
+ Collections.Add(CreateMotorsCollection(hardwareVersion));
+ Collections.Add(CreateDancerCollection(hardwareVersion));
+ Collections.Add(CreatePidCollection(hardwareVersion));
+ Collections.Add(CreateWindersCollection(hardwareVersion));
+ Collections.Add(CreateSpeedSensorsCollection(hardwareVersion));
+ Collections.Add(CreateBlowersCollection(hardwareVersion));
+ Collections.Add(CreateBreakSensorCollection(hardwareVersion));
+ }
}
private HardwareCollection CreateMotorsCollection(HardwareVersion hardwareVersion)
@@ -124,6 +127,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
collection.Components.Add(componentResult);
}
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.Description).ToSynchronizedObservableCollection();
return collection;
}
private HardwareCollection CreateDancerCollection(HardwareVersion hardwareVersion)
@@ -146,6 +150,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
collection.Components.Add(componentResult);
}
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.Description).ToSynchronizedObservableCollection();
return collection;
}
private HardwareCollection CreatePidCollection(HardwareVersion hardwareVersion)
@@ -168,6 +173,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
collection.Components.Add(componentResult);
}
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.Description).ToSynchronizedObservableCollection();
return collection;
}
private HardwareCollection CreateWindersCollection(HardwareVersion hardwareVersion)
@@ -190,6 +196,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
collection.Components.Add(componentResult);
}
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.Description).ToSynchronizedObservableCollection();
return collection;
}
private HardwareCollection CreateSpeedSensorsCollection(HardwareVersion hardwareVersion)
@@ -212,6 +219,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
collection.Components.Add(componentResult);
}
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.Description).ToSynchronizedObservableCollection();
return collection;
}
private HardwareCollection CreateBlowersCollection(HardwareVersion hardwareVersion)
@@ -234,6 +242,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
collection.Components.Add(componentResult);
}
}
+ collection.Components= collection.Components.OrderByAlphaNumeric(x => x.Description).ToSynchronizedObservableCollection();
return collection;
}
private HardwareCollection CreateBreakSensorCollection(HardwareVersion hardwareVersion)
@@ -256,6 +265,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
collection.Components.Add(componentResult);
}
}
+ collection.Components = collection.Components.OrderByAlphaNumeric(x => x.Description).ToSynchronizedObservableCollection();
return collection;
}
private HardwareComponent CreateComponent(String name, String description, List<PropertyInfo> properties, Object component)
@@ -265,7 +275,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
Description = description,
ComponentName = name
};
-
+
foreach (var prop in properties)
{
var hProp = new HardwareParameter();
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs
index 0f6ab3314..4584d3508 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs
@@ -13,5 +13,50 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
public List<MachineVersion> MachineVersions { get; set; }
public MachineVersion SelectedMachineVersion { get; set; }
+
+ private bool _isNewMachine;
+ public bool IsNewMachine
+ {
+ get { return _isNewMachine; }
+ set { _isNewMachine = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _serialNumber;
+ public String SerialNumber
+ {
+ get { return _serialNumber; }
+ set { _serialNumber = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private String _name;
+ public String Name
+ {
+ get { return _name; }
+ set { _name = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private bool _generateDispensers;
+ public bool GenerateDispensers
+ {
+ get { return _generateDispensers; }
+ set { _generateDispensers = value; RaisePropertyChangedAuto(); }
+ }
+
+ private double _dispenserFactor;
+ public double DispenserFactor
+ {
+ get { return _dispenserFactor; }
+ set { _dispenserFactor = value; RaisePropertyChangedAuto(); }
+ }
+
+ public MachineCreationDialogVM() : base()
+ {
+ DispenserFactor = 2.34;
+ }
+
+ protected override bool CanOK()
+ {
+ return base.CanOK() && !String.IsNullOrWhiteSpace(SerialNumber) && !String.IsNullOrWhiteSpace(Name);
+ }
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdateDetailsDialogVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdateDetailsDialogVM.cs
new file mode 100644
index 000000000..49d410cdf
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdateDetailsDialogVM.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.MachineDesigner.ViewModels
+{
+ public class MachineUpdateDetailsDialogVM : DialogViewVM
+ {
+ private TangoUpdate _update;
+ public TangoUpdate Update
+ {
+ get { return _update; }
+ set { _update = value; RaisePropertyChangedAuto(); }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs
new file mode 100644
index 000000000..6004dbe6e
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs
@@ -0,0 +1,198 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+using Tango.BL;
+using Tango.BL.Builders;
+using Tango.BL.Entities;
+using Tango.Core.Commands;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.MachineStudio.MachineDesigner.Views;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.MachineDesigner.ViewModels
+{
+ public class MachineUpdatesViewVM : ViewModel
+ {
+ private INotificationProvider _notification;
+ private ObservablesContext _context;
+ private const int MAX_UPDATE_ITEMS = 200;
+
+ #region Properties
+
+ private Machine _machine;
+ public Machine Machine
+ {
+ get { return _machine; }
+ set { _machine = value; RaisePropertyChangedAuto(); }
+ }
+
+ private List<TangoUpdate> _updates;
+ public List<TangoUpdate> Updates
+ {
+ get { return _updates; }
+ set { _updates = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ICollectionView _updatesView;
+ public ICollectionView UpdatesView
+ {
+ get { return _updatesView; }
+ set { _updatesView = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ private TangoUpdate _selectedUpdate;
+ public TangoUpdate SelectedUpdate
+ {
+ get { return _selectedUpdate; }
+ set { _selectedUpdate = value; RaisePropertyChangedAuto(); OnSelectedUpdateChanged(); }
+ }
+
+ private bool _displayMachineSetups;
+ public bool DisplayMachineSetups
+ {
+ get { return _displayMachineSetups; }
+ set { _displayMachineSetups = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
+ }
+
+ private bool _displayApplicationUpdates;
+ public bool DisplayApplicationUpdates
+ {
+ get { return _displayApplicationUpdates; }
+ set { _displayApplicationUpdates = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
+ }
+
+ private bool _displayDatabaseUpdates;
+ public bool DisplayDatabaseUpdates
+ {
+ get { return _displayDatabaseUpdates; }
+ set { _displayDatabaseUpdates = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
+ }
+
+ private bool _displaySynchronizations;
+ public bool DisplaySynchronizations
+ {
+ get { return _displaySynchronizations; }
+ set { _displaySynchronizations = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
+ }
+
+ private bool _displayOfflineUpdates;
+ public bool DisplayOfflineUpdates
+ {
+ get { return _displayOfflineUpdates; }
+ set { _displayOfflineUpdates = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
+ }
+
+ private bool _displayFirmwareUpgrades;
+ public bool DisplayFirmwareUpgrades
+ {
+ get { return _displayFirmwareUpgrades; }
+ set { _displayFirmwareUpgrades = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
+ }
+
+ #endregion
+
+ #region Commands
+
+ public RelayCommand RefreshCommand { get; set; }
+
+ #endregion
+
+ #region Constructors
+
+ public MachineUpdatesViewVM()
+ {
+ DisplayApplicationUpdates = true;
+ DisplayMachineSetups = true;
+ DisplayDatabaseUpdates = true;
+ DisplaySynchronizations = true;
+ DisplayOfflineUpdates = true;
+ DisplayFirmwareUpgrades = true;
+
+ RefreshCommand = new RelayCommand(Refresh, () => IsFree);
+ }
+
+ public MachineUpdatesViewVM(INotificationProvider notificationProvider) : this()
+ {
+ _notification = notificationProvider;
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public async Task Init(Machine machine, ObservablesContext context)
+ {
+ try
+ {
+ _context = context;
+ Machine = machine;
+ Updates = (await new TangoUpdatesCollectionBuilder(context).Set(x => x.MachineGuid == machine.Guid).Query(x => x.OrderByDescending(y => y.StartDate).Take(MAX_UPDATE_ITEMS)).BuildAsync()).ToList();
+ UpdatesView = CollectionViewSource.GetDefaultView(Updates);
+ UpdatesView.Filter = UpdatesFilter;
+ OnFilterChanged();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error loading machine updates.");
+ _notification.ShowError($"An error occurred while loading the history of machine updates.\n{ex.FlattenMessage()}");
+ }
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private async void Refresh()
+ {
+ IsFree = false;
+ using (_notification.PushTaskItem("Refreshing machine updates..."))
+ {
+ await Init(Machine, _context);
+ }
+ IsFree = true;
+ }
+
+ private void OnFilterChanged()
+ {
+ if (UpdatesView != null)
+ {
+ UpdatesView.Refresh();
+ }
+ }
+
+ private bool UpdatesFilter(object obj)
+ {
+ TangoUpdate update = obj as TangoUpdate;
+ if (update != null)
+ {
+ if (!DisplayMachineSetups && update.IsSetup) return false;
+ if (!DisplayApplicationUpdates && update.IsUpdate) return false;
+ if (!DisplayDatabaseUpdates && update.IsDataBase) return false;
+ if (!DisplaySynchronizations && update.IsSynchronization) return false;
+ if (!DisplayOfflineUpdates && update.IsOfflineUpdate) return false;
+ if (!DisplayFirmwareUpgrades && update.IsOfflineFirmwareUpgrade) return false;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ private void OnSelectedUpdateChanged()
+ {
+ if (SelectedUpdate != null && SelectedUpdate.ApplicationVersion != "Fake")
+ {
+ _notification.ShowModalDialog<MachineUpdateDetailsDialogVM, MachineUpdateDetailsDialog>(new MachineUpdateDetailsDialogVM() { Update = SelectedUpdate }, (vm) => { }, () => { });
+ SelectedUpdate = new TangoUpdate() { ApplicationVersion = "Fake"};
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
index 5f2dcd00d..0f439c83d 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
@@ -25,17 +25,32 @@ using Tango.Core.Threading;
using Tango.MachineStudio.RML.ViewModels;
using Tango.Settings;
using Tango.MachineStudio.RML.Models;
+using Tango.BL.ActionLogs;
+using Tango.MachineStudio.Common.Authentication;
+using Tango.BL.DTO;
+using Tango.Core.Cryptography;
namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
public class MainViewVM : StudioViewModel<IMainView>
{
private INotificationProvider _notification;
+ private IActionLogManager _actionLogManager;
+ private IAuthenticationProvider _authentication;
private ActionTimer _machines_action_timer;
private ActionTimer _dispensers_action_timer;
+ private MachineDTO _machineBeforeSave;
+ private List<Site> _all_sites;
#region Properties
+ private bool _isNewMachine;
+ public bool IsNewMachine
+ {
+ get { return _isNewMachine; }
+ set { _isNewMachine = value; RaisePropertyChangedAuto(); }
+ }
+
private ObservablesStaticCollections _machinesAdapter;
public ObservablesStaticCollections MachinesAdapter
{
@@ -115,6 +130,21 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
set { _selectedSpool = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
+ private Site _selectedSite;
+ public Site SelectedSite
+ {
+ get { return _selectedSite; }
+ set { _selectedSite = value; RaisePropertyChangedAuto(); }
+ }
+
+ private List<Site> _sites;
+ public List<Site> Sites
+ {
+ get { return _sites; }
+ set { _sites = value; RaisePropertyChangedAuto(); }
+ }
+
+
private ColorCalibrationViewVM _colorCalibrationViewVM;
public ColorCalibrationViewVM ColorCalibrationViewVM
{
@@ -123,7 +153,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
}
private HardwareConfigurationViewVM _hardwareConfigurationViewVM;
-
public HardwareConfigurationViewVM HardwareConfigurationViewVM
{
get { return _hardwareConfigurationViewVM; }
@@ -134,6 +163,19 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
}
}
+ private MachineUpdatesViewVM _machineUpdatesViewVM;
+ public MachineUpdatesViewVM MachineUpdatesViewVM
+ {
+ get { return _machineUpdatesViewVM; }
+ set { _machineUpdatesViewVM = value; RaisePropertyChangedAuto(); }
+ }
+
+ private TupViewVM _tupViewVM;
+ public TupViewVM TupViewVM
+ {
+ get { return _tupViewVM; }
+ set { _tupViewVM = value; RaisePropertyChangedAuto(); }
+ }
#endregion
@@ -188,6 +230,17 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
/// Gets or sets the clone machine command.
/// </summary>
public RelayCommand CloneMachineCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the reset device registration command.
+ /// </summary>
+ public RelayCommand ResetDeviceRegistrationCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the make prototype command.
+ /// </summary>
+ public RelayCommand MakePrototypeCommand { get; set; }
+
#endregion
#region Constructors
@@ -200,10 +253,12 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
/// <summary>
/// Initializes a new instance of the <see cref="MainViewVM"/> class.
/// </summary>
- public MainViewVM(INotificationProvider notification)
+ public MainViewVM(INotificationProvider notification, IAuthenticationProvider authentication, IActionLogManager actionLogManager)
{
MachinesAdapter = new ObservablesStaticCollections(ObservablesContext.CreateDefault());
_notification = notification;
+ _authentication = authentication;
+ _actionLogManager = actionLogManager;
_machines_action_timer = new ActionTimer(TimeSpan.FromMilliseconds(200));
_dispensers_action_timer = new ActionTimer(TimeSpan.FromMilliseconds(200));
@@ -218,7 +273,13 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
AddSpoolCommand = new RelayCommand(AddNewSpool);
RemoveSpoolCommand = new RelayCommand(RemoveSpool, () => SelectedSpool != null);
CloneMachineCommand = new RelayCommand(CloneMachine, () => SelectedMachine != null);
+ ResetDeviceRegistrationCommand = new RelayCommand(ResetDeviceRegistration);
+ MakePrototypeCommand = new RelayCommand(MakePrototype);
+
+ MachineUpdatesViewVM = new MachineUpdatesViewVM(_notification);
+ TupViewVM = new TupViewVM(_notification);
}
+
#endregion
#region Application Ready
@@ -239,7 +300,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
Task.Factory.StartNew(() =>
{
- ActiveMachineAdapter.Dispensers = ActiveMachineAdapter.Context.Dispensers.Where(x => x.SerialNumber.ToLower().StartsWith(DispensersFilter.ToLower())).ToSynchronizedObservableCollection();
+ ActiveMachineAdapter.Dispensers = ActiveMachineAdapter.Context.Dispensers.Where(x => x.SerialNumber.ToLower().StartsWith(DispensersFilter.ToLower())).OrderBy(x => x.SerialNumber).ToSynchronizedObservableCollection();
});
});
}
@@ -388,8 +449,10 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
InvalidateRelayCommands();
}
- private async void LoadSelectedMachine(bool newMachine = false, bool clone = false, MachineVersion selectedVersion = null)
+ private async void LoadSelectedMachine(bool newMachine = false, bool clone = false, MachineCreationDialogVM machineCreationDialogVM = null)
{
+ IsNewMachine = false;
+
using (_notification.PushTaskItem("Loading machine details..."))
{
try
@@ -413,7 +476,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
ActiveMachineAdapter.ApplicationOsVersions = (await ActiveMachineAdapter.Context.ApplicationOsVersions.ToListAsync()).ToObservableCollection();
ActiveMachineAdapter.EmbeddedFirmwareVersions = (await ActiveMachineAdapter.Context.EmbeddedFirmwareVersions.ToListAsync()).ToObservableCollection();
ActiveMachineAdapter.DispenserTypes = (await ActiveMachineAdapter.Context.DispenserTypes.ToListAsync()).ToObservableCollection();
- ActiveMachineAdapter.LiquidTypes = (await ActiveMachineAdapter.Context.LiquidTypes.ToListAsync()).ToObservableCollection();
+ ActiveMachineAdapter.LiquidTypes = (await ActiveMachineAdapter.Context.LiquidTypes.ToListAsync()).OrderBy(x => x.PreferredIndex).ToObservableCollection();
ActiveMachineAdapter.MidTankTypes = (await ActiveMachineAdapter.Context.MidTankTypes.ToListAsync()).ToObservableCollection();
ActiveMachineAdapter.CartridgeTypes = (await ActiveMachineAdapter.Context.CartridgeTypes.ToListAsync()).ToObservableCollection();
ActiveMachineAdapter.IdsPackFormulas = (await ActiveMachineAdapter.Context.IdsPackFormulas.ToListAsync()).ToObservableCollection();
@@ -421,32 +484,144 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
ActiveMachineAdapter.MachineVersions = (await ActiveMachineAdapter.Context.MachineVersions.ToListAsync()).ToObservableCollection();
ActiveMachineAdapter.Organizations = (await ActiveMachineAdapter.Context.Organizations.ToListAsync()).ToObservableCollection();
+ bool initHwConfig = true;
+
+ Configuration machineConfigBeforeClone = null;
+
if (!newMachine)
{
ActiveMachine = (await new MachineBuilder(ActiveMachineAdapter.Context).Set(SelectedMachine.Guid).WithOrganization().WithConfiguration().WithSpools().BuildAsync());
+ _machineBeforeSave = MachineDTO.FromObservable(ActiveMachine);
+
if (clone)
{
+ machineConfigBeforeClone = ActiveMachine.Configuration;
+
+ IsNewMachine = true;
ActiveMachine = ActiveMachine.Clone();
- ActiveMachine.Name = "";
- ActiveMachine.SerialNumber = "";
+ ActiveMachine.Name = machineCreationDialogVM.Name;
+ ActiveMachine.SerialNumber = machineCreationDialogVM.SerialNumber;
+ ActiveMachine.IsDeviceRegistered = false;
+ ActiveMachine.DeviceId = null;
+ ActiveMachine.DeviceName = null;
+ ActiveMachine.ActivationKey = null;
ActiveMachineAdapter.Context.Machines.Add(ActiveMachine);
}
}
else
{
- if (selectedVersion == null)
+ IsNewMachine = true;
+
+ if (machineCreationDialogVM.SelectedMachineVersion == null)
{
ActiveMachine = new Machine();
ActiveMachine.Configuration = new Configuration();
+ ActiveMachine.SerialNumber = machineCreationDialogVM.SerialNumber;
+ ActiveMachine.Name = machineCreationDialogVM.Name;
ActiveMachineAdapter.Context.Machines.Add(ActiveMachine);
}
else
{
- ActiveMachine = selectedVersion.CreatePrototypeMachine(ActiveMachineAdapter.Context);
- ActiveMachineAdapter.Context.Machines.Add(ActiveMachine);
+ try
+ {
+ initHwConfig = false;
+ ActiveMachine = await machineCreationDialogVM.SelectedMachineVersion.CreatePrototypeMachine(ActiveMachineAdapter.Context);
+ ActiveMachine.SerialNumber = machineCreationDialogVM.SerialNumber;
+ ActiveMachine.Name = machineCreationDialogVM.Name;
+ ActiveMachineAdapter.Context.Machines.Add(ActiveMachine);
+
+ HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification);
+ var version = await new HardwareVersionBuilder(ActiveMachineAdapter.Context).Set(ActiveMachine.Configuration.HardwareVersionGuid).WithHardwareComponents().BuildAsync();
+ HardwareConfigurationViewVM.Init(ActiveMachine.Configuration);
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Invalid machine version prototype.\n{ex.FlattenMessage()}");
+ View.NavigateTo(MachineDesignerNavigationView.MachinesView);
+ return;
+ }
+ }
+ }
+
+ if ((newMachine || clone) && machineCreationDialogVM.GenerateDispensers)
+ {
+ for (int i = 0; i < 8; i++)
+ {
+ var serial = machineCreationDialogVM.SerialNumber + "-" + (i + 1);
+
+ var existingDispenser = await ActiveMachineAdapter.Context.Dispensers.Include(x => x.IdsPacks).SingleOrDefaultAsync(x => x.SerialNumber == serial);
+
+ if (existingDispenser != null)
+ {
+ if (existingDispenser.IsInstalled)
+ {
+ _notification.ShowError($"Dispenser '{serial}' already exists. Cannot create machine.");
+ return;
+ }
+ else
+ {
+ if (!_notification.ShowErrorQuestion($"Dispenser '{serial}' already exists and is not installed. Do you wish to assign the existing dispenser to this machine?"))
+ {
+ return;
+ }
+ }
+ }
+
+ Dispenser dispenser = new Dispenser();
+
+ if (existingDispenser == null)
+ {
+ dispenser.SerialNumber = serial;
+
+ if (newMachine)
+ {
+ dispenser.NlPerPulse = machineCreationDialogVM.DispenserFactor;
+ dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.First().Guid;
+ }
+ else
+ {
+ var packBefore = machineConfigBeforeClone.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i);
+
+ if (packBefore != null)
+ {
+ dispenser.NlPerPulse = packBefore.Dispenser.NlPerPulse;
+ dispenser.DispenserTypeGuid = packBefore.Dispenser.DispenserType.Guid;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ dispenser.ProductionDate = DateTime.UtcNow;
+
+ ActiveMachineAdapter.Context.Dispensers.Add(dispenser);
+ }
+ else
+ {
+ dispenser = existingDispenser;
+ }
+
+ var idsPack = ActiveMachine.Configuration.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i);
+
+ if (idsPack != null)
+ {
+ idsPack.Dispenser = dispenser;
+ idsPack.DispenserGuid = dispenser.Guid;
+ }
}
}
+ ActiveMachine.OrganizationChanged -= ActiveMachine_OrganizationChanged;
+ ActiveMachine.OrganizationChanged += ActiveMachine_OrganizationChanged;
+
+ _all_sites = await ActiveMachineAdapter.Context.Sites.ToListAsync();
+
+ var sites = ActiveMachine.Organization != null ? _all_sites.Where(x => x.OrganizationGuid == ActiveMachine.OrganizationGuid).ToList() : new List<Site>();
+ sites.Insert(0, new Site() { Name = "NONE", ID = -1 });
+ Sites = sites;
+
+ SelectedSite = Sites.SingleOrDefault(x => x.Guid == ActiveMachine.SiteGuid);
ColorCalibrationViewVM = new ColorCalibrationViewVM(_notification, ActiveMachine, _activeMachineAdapter.Context)
{
@@ -455,11 +630,31 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
SelectedRML = ActiveMachineAdapter.Rmls.FirstOrDefault(),
};
- HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification);
- HardwareConfigurationViewVM.Init(ActiveMachine.Configuration);
+ if (initHwConfig)
+ {
+ HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification);
+ HardwareConfigurationViewVM.Init(ActiveMachine.Configuration);
+ }
+
+ if (!IsNewMachine)
+ {
+ await MachineUpdatesViewVM.Init(ActiveMachine, ActiveMachineAdapter.Context);
+ TupViewVM.Init(ActiveMachine);
+ }
ActiveMachine.Configuration.HardwareVersionChanged += Configuration_HardwareVersionChanged;
+ while (ActiveMachine.ActivationKey == null) //Generate a random password and make sure no machine matches it.
+ {
+ ActiveMachine.ActivationKey = PasswordGenerator.Generate(8, PasswordGenerator.PasswordType.Alpha, PasswordGenerator.PasswordCasing.Upper);
+ if (await ActiveMachineAdapter.Context.Machines.Where(x => x.ActivationKey == ActiveMachine.ActivationKey).CountAsync() == 0)
+ {
+ break;
+ }
+
+ ActiveMachine.ActivationKey = null;
+ }
+
View.NavigateTo(MachineDesignerNavigationView.MachineDetailsView);
}
catch (Exception ex)
@@ -485,6 +680,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
try
{
+ if (HardwareConfigurationViewVM == null)
+ {
+ HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification);
+ }
+
version = await new HardwareVersionBuilder(ActiveMachineAdapter.Context).Set(version.Guid).WithHardwareComponents().BuildAsync();
HardwareConfigurationViewVM.Init(ActiveMachine.Configuration);
}
@@ -620,15 +820,25 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
ActiveMachine.ConfigurationGuid = ActiveMachine.Configuration.Guid;
ActiveMachine.LastUpdated = DateTime.UtcNow;
- ActiveMachine.ProductionDate = DateTime.UtcNow;
+ ActiveMachine.SiteGuid = SelectedSite == null ? null : (SelectedSite.ID == -1 ? null : SelectedSite.Guid);
ColorCalibrationViewVM.Save();
var hwConfig = HardwareConfigurationViewVM.GetResultingHardwareConfiguration();
ActiveMachine.Configuration.SetHardwareConfiguration(hwConfig);
-
await ActiveMachineAdapter.Context.SaveChangesAsync();
+ if (IsNewMachine)
+ {
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.MachineCreated, _authentication.CurrentUser, ActiveMachine.Name, ActiveMachine, "New machine created using Machine Studio.");
+ }
+ else
+ {
+ var machineAfterDTO = MachineDTO.FromObservable(ActiveMachine);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.MachineSaved, _authentication.CurrentUser, _machineBeforeSave.Name, _machineBeforeSave, machineAfterDTO, "Machine saved using Machine Studio.");
+ _machineBeforeSave = machineAfterDTO;
+ }
+
if (SelectedMachine != null)
{
await SelectedMachine.Reload(MachinesAdapter.Context);
@@ -652,16 +862,23 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
private void AddNewMachine()
{
MachineCreationDialogVM vm = new MachineCreationDialogVM();
+ vm.IsNewMachine = true;
vm.MachineVersions = MachinesAdapter.MachineVersions.ToList();
_notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) =>
{
+ if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower()))
+ {
+ _notification.ShowError("Machine serial number or name already exists.");
+ return;
+ }
+
if (vm.SelectedMachineVersion != null && String.IsNullOrWhiteSpace(vm.SelectedMachineVersion.PrototypeMachineData))
{
_notification.ShowError("The selected version does not contain any prototype machine data.");
return;
}
- LoadSelectedMachine(true, false, vm.SelectedMachineVersion);
+ LoadSelectedMachine(true, false, vm);
}, () => { });
}
@@ -675,7 +892,9 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
IsFree = false;
await SelectedMachine.DeleteCascadeAsync(MachinesAdapter.Context);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.MachineDeleted, _authentication.CurrentUser, SelectedMachine.Name, SelectedMachine, "Machine deleted using Machine Studio.");
MachinesAdapter.Context.Machines.Remove(SelectedMachine);
+ MachinesAdapter.Machines.Remove(SelectedMachine);
}
catch (Exception ex)
{
@@ -690,11 +909,68 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
}
}
+ private void ResetDeviceRegistration()
+ {
+ if (_notification.ShowQuestion("Are you sure you wish to reset this machine device registration?"))
+ {
+ ActiveMachine.IsDeviceRegistered = false;
+ ActiveMachine.DeviceId = null;
+ ActiveMachine.DeviceName = null;
+ }
+ }
+
+ private async void MakePrototype()
+ {
+ if (ActiveMachine.MachineVersion == null)
+ {
+ _notification.ShowError("Machine version must be selected in order to make a prototype.");
+ return;
+ }
+
+ if (_notification.ShowQuestion($"Are you sure you wish to make this machine configuration as a prototype for version '{ActiveMachine.MachineVersion.Name}' ?"))
+ {
+ using (_notification.PushTaskItem($"Making prototype machine for '{ActiveMachine.MachineVersion.Name}'..."))
+ {
+ try
+ {
+ IsFree = false;
+
+ using (var db = ObservablesContext.CreateDefault())
+ {
+ var machineVersion = await db.MachineVersions.SingleOrDefaultAsync(x => x.Guid == ActiveMachine.MachineVersionGuid);
+ await machineVersion.ApplyPrototypeMachine(ActiveMachine, db);
+ await db.SaveChangesAsync();
+ }
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Error making machine version prototype\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ IsFree = true;
+ }
+ }
+ }
+ }
+
#endregion
private void CloneMachine()
{
- LoadSelectedMachine(false, true);
+ MachineCreationDialogVM vm = new MachineCreationDialogVM();
+ vm.IsNewMachine = false;
+ vm.MachineVersions = MachinesAdapter.MachineVersions.ToList();
+ _notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) =>
+ {
+ if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower()))
+ {
+ _notification.ShowError("Machine serial number or name already exists.");
+ return;
+ }
+
+ LoadSelectedMachine(false, true, vm);
+ }, () => { });
}
private void AddNewSpool()
@@ -725,7 +1001,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
try
{
IsFree = false;
- MachinesAdapter.Machines = MachinesAdapter.Context.Machines.Where(x => x.SerialNumber.StartsWith(Filter)).Include(x => x.Organization).Include(x => x.MachineVersion).ToSynchronizedObservableCollection();
+ MachinesAdapter.Machines = MachinesAdapter.Context.Machines.Where(x => x.SerialNumber.StartsWith(Filter)).Include(x => x.Organization).Include(x => x.MachineVersion).OrderBy(x => x.SerialNumber).ToSynchronizedObservableCollection();
}
catch
{
@@ -739,5 +1015,14 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
});
}
}
+
+ private void ActiveMachine_OrganizationChanged(object sender, Organization e)
+ {
+ var sites = ActiveMachine.Organization != null ? _all_sites.Where(x => x.OrganizationGuid == ActiveMachine.OrganizationGuid).ToList() : new List<Site>();
+ sites.Insert(0, new Site() { Name = "NONE", ID = -1 });
+ Sites = sites;
+
+ SelectedSite = Sites.SingleOrDefault(x => x.Guid == ActiveMachine.SiteGuid);
+ }
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs
new file mode 100644
index 000000000..5d1703dc3
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/TupViewVM.cs
@@ -0,0 +1,129 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+using Tango.Core.Commands;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.MachineStudio.Common.Tup;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.MachineDesigner.ViewModels
+{
+ public class TupViewVM : ViewModel
+ {
+ private INotificationProvider _notification;
+
+ private String _latestVersion;
+ public String LatestVersion
+ {
+ get { return _latestVersion; }
+ set { _latestVersion = value; RaisePropertyChangedAuto(); }
+ }
+
+ private Machine _machine;
+ public Machine Machine
+ {
+ get { return _machine; }
+ set { _machine = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _filePath;
+ public String FilePath
+ {
+ get { return _filePath; }
+ set { _filePath = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ private TupFileBuilderProgressEventArgs _progress;
+ public TupFileBuilderProgressEventArgs Progress
+ {
+ get { return _progress; }
+ set { _progress = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand CreateTupFileCommand { get; set; }
+
+ public RelayCommand SelectFileCommand { get; set; }
+
+ public TupViewVM()
+ {
+
+ }
+
+ public TupViewVM(INotificationProvider notification) : this()
+ {
+ _notification = notification;
+ CreateTupFileCommand = new RelayCommand(CreateTupFile, () => FilePath != null && IsFree);
+ SelectFileCommand = new RelayCommand(SelectFile);
+ }
+
+ public void Init(Machine machine)
+ {
+ Machine = machine;
+ DisplayLatestPPCVersion();
+ }
+
+ private async void DisplayLatestPPCVersion()
+ {
+ TupFileBuilder builder = new TupFileBuilder();
+
+ try
+ {
+ LatestVersion = await builder.GetLatestPPCVersion(Machine.SerialNumber);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error retrieving latest PPC version.");
+ await Task.Delay(5000);
+ DisplayLatestPPCVersion();
+ }
+ }
+
+ private void SelectFile()
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.Title = "Select package location";
+ dlg.Filter = "Tango Update Package Files|*.tup";
+ dlg.DefaultExt = ".tup";
+ dlg.FileName = LatestVersion == null ? $"{Machine.SerialNumber}_Update_{DateTime.Now.Date.ToFileName()}.tup" : $"{Machine.SerialNumber}_Update_{DateTime.Now.Date.ToFileName()}_v{LatestVersion}.tup";
+
+ if (dlg.ShowDialog().Value)
+ {
+ FilePath = dlg.FileName;
+ }
+ }
+
+ private async void CreateTupFile()
+ {
+ try
+ {
+ LogManager.Log($"Generating TUP file to '{FilePath}'...");
+
+ IsFree = false;
+ TupFileBuilder builder = new TupFileBuilder();
+ builder.Progress += Builder_Progress;
+ await builder.Build(Machine.SerialNumber, FilePath);
+
+ LogManager.Log("TUP file generated successfully.");
+ _notification.ShowInfo("Tango update package created successfuly.");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error generating tup file.");
+ _notification.ShowError($"An error occurred while generating the .tup file.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ IsFree = true;
+ }
+ }
+
+ private void Builder_Progress(object sender, TupFileBuilderProgressEventArgs e)
+ {
+ Progress = e;
+ }
+ }
+}