aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d93733d4625ad329b2ba8237f445364b3f.tar.gz
Tango-00a491d93733d4625ad329b2ba8237f445364b3f.zip
merge
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs6
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs64
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs6
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs170
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs14
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs7
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs251
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs3
8 files changed, 110 insertions, 411 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs
index 30b2c83fd..16f6938a0 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs
@@ -95,11 +95,11 @@ namespace Tango.MachineStudio.UI.ViewModels
using (ObservablesContext db = ObservablesContext.CreateDefault())
{
- var jobRuns = await db.JobRuns.Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).ToListAsync();
+ var jobs = await db.Jobs.Include(x => x.JobRuns).Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).ToListAsync();
- TotalMachineWorkTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToStringUnlimitedHours();
+ TotalMachineWorkTime = TimeSpan.FromHours(jobs.SelectMany(x => x.JobRuns).Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss");
- int meters = (int)jobRuns.Select(x => x.EndPosition).Sum();
+ int meters = (int)jobs.SelectMany(x => x.JobRuns).Select(x => x.EndPosition).Sum();
TotalMachineMeters = $"{meters.ToString("N0")} meters";
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs
index e96f0ab62..f1f4f69c0 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs
@@ -3,76 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using System.Timers;
-using System.Windows.Threading;
using Tango.SharedUI;
namespace Tango.MachineStudio.UI.ViewModels
{
public class ConnectionLostViewVM : DialogViewVM
{
- private Timer _reconnectTimer;
-
public String Exception { get; set; }
-
- private int _reconnectinSeconds;
- public int ReconnectinSeconds
- {
- get { return _reconnectinSeconds; }
- set { _reconnectinSeconds = value; RaisePropertyChangedAuto(); }
- }
-
- private bool _autoReconnect;
- public bool AutoReconnect
- {
- get { return _autoReconnect; }
- set { _autoReconnect = value; RaisePropertyChangedAuto(); }
- }
-
-
- public ConnectionLostViewVM() : base()
- {
- ReconnectinSeconds = 10;
- _reconnectTimer = new Timer();
- _reconnectTimer.Interval = TimeSpan.FromSeconds(1).TotalMilliseconds;
- _reconnectTimer.Elapsed += _reconnectTimer_Elapsed;
- }
-
- private void _reconnectTimer_Elapsed(object sender, ElapsedEventArgs e)
- {
- ReconnectinSeconds--;
-
- if (ReconnectinSeconds == -1)
- {
- _reconnectTimer.Stop();
-
- InvokeUI(() =>
- {
- Accept();
- });
- }
- }
-
- public override void OnShow()
- {
- base.OnShow();
-
- if (AutoReconnect)
- {
- _reconnectTimer.Start();
- }
- }
-
- protected override void Accept()
- {
- _reconnectTimer.Stop();
- base.Accept();
- }
-
- protected override void Cancel()
- {
- base.Cancel();
- _reconnectTimer.Stop();
- }
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs
index 7d2d8b401..e45c29f73 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs
@@ -202,17 +202,11 @@ namespace Tango.MachineStudio.UI.ViewModels
{
IsFree = true;
CanClose = true;
- _stream?.Dispose();
UpgradeError = ex.FlattenMessage();
CurrentPage = 3;
}
}
- protected override bool CanOK()
- {
- return base.CanOK() && CanClose;
- }
-
private async void AbortUpgrade()
{
CanClose = true;
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
index f4645ecf2..cf34764d9 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
@@ -22,9 +22,6 @@ using Tango.MachineStudio.UI.Messages;
using Tango.Settings;
using Tango.SharedUI;
using Tango.Web;
-using SimpleValidator.Extensions;
-using Tango.BL.Entities;
-using System.Data.Entity;
namespace Tango.MachineStudio.UI.ViewModels
{
@@ -41,7 +38,6 @@ namespace Tango.MachineStudio.UI.ViewModels
private Rfc2898Cryptographer cryptographer;
private MachineStudioSettings _settings;
private MachineStudioWebClient _machineStudioWebClient;
- private TaskCompletionSource<object> _updatePasswordCompletionSource;
private String _email;
/// <summary>
@@ -86,14 +82,6 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _isLogging = value; RaisePropertyChangedAuto(); }
}
- private bool _showLogginDetails;
- public bool ShowLoggingDetails
- {
- get { return _showLogginDetails; }
- set { _showLogginDetails = value; RaisePropertyChangedAuto(); }
- }
-
-
private bool _rememberMe;
/// <summary>
/// Gets or sets a value indicating whether to remember the last user email and password.
@@ -114,47 +102,6 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _enableSlotSelection = value; RaisePropertyChangedAuto(); }
}
- private bool _isActiveDirectory;
- public bool IsActiveDirectory
- {
- get { return _isActiveDirectory; }
- set { _isActiveDirectory = value; RaisePropertyChangedAuto(); if (value) IsStandardUser = false; }
- }
-
- private bool _isStandardUser;
- public bool IsStandardUser
- {
- get { return _isStandardUser; }
- set { _isStandardUser = value; RaisePropertyChangedAuto(); if (value) IsActiveDirectory = false; }
- }
-
- private String _progressLog;
- public String ProgressLog
- {
- get { return _progressLog; }
- set { _progressLog = value; RaisePropertyChangedAuto(); }
- }
-
- private bool _isChangingPassword;
- public bool IsChangingPassword
- {
- get { return _isChangingPassword; }
- set { _isChangingPassword = value; RaisePropertyChangedAuto(); }
- }
-
- private String _newPassword1;
- public String NewPassword1
- {
- get { return _newPassword1; }
- set { _newPassword1 = value; RaisePropertyChangedAuto(); }
- }
-
- private String _newPassword2;
- public String NewPassword2
- {
- get { return _newPassword2; }
- set { _newPassword2 = value; RaisePropertyChangedAuto(); }
- }
/// <summary>
/// Gets or sets the login command.
@@ -162,11 +109,6 @@ namespace Tango.MachineStudio.UI.ViewModels
public RelayCommand LoginCommand { get; set; }
/// <summary>
- /// Gets or sets the update password command.
- /// </summary>
- public RelayCommand UpdatePasswordCommand { get; set; }
-
- /// <summary>
/// Initializes a new instance of the <see cref="LoginViewVM"/> class.
/// </summary>
/// <param name="authenticationProvider">The authentication provider.</param>
@@ -175,7 +117,6 @@ namespace Tango.MachineStudio.UI.ViewModels
public LoginViewVM(MachineStudioWebClient machineStudioWebClient, IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger)
{
EnableSlotSelection = true;
- ShowLoggingDetails = true;
_machineStudioWebClient = machineStudioWebClient;
_settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>();
@@ -185,22 +126,12 @@ namespace Tango.MachineStudio.UI.ViewModels
_authenticationProvider = authenticationProvider;
_eventLogger = eventLogger;
LoginCommand = new RelayCommand(Login, () => !IsLogging);
- UpdatePasswordCommand = new RelayCommand(UpdatePassword, () => IsChangingPassword);
cryptographer = new Rfc2898Cryptographer();
Email = _settings.LastLoginEmail;
DeploymentSlot = _settings.DeploymentSlot;
RememberMe = _settings.RememberMe;
- if (_settings.LastLoginMethod == LoginMethod.ActiveDirectory)
- {
- IsActiveDirectory = true;
- }
- else
- {
- IsStandardUser = true;
- }
-
try
{
Password = cryptographer.Decrypt(_settings.LastLoginPassword);
@@ -221,22 +152,13 @@ namespace Tango.MachineStudio.UI.ViewModels
try
{
IsLogging = true;
- ShowLoggingDetails = false;
- NewPassword1 = String.Empty;
- NewPassword2 = String.Empty;
-
InvalidateRelayCommands();
- LoginMethod loginMethod = IsActiveDirectory ? LoginMethod.ActiveDirectory : LoginMethod.StandardUser;
-
await Task.Factory.StartNew(() =>
{
_settings.DeploymentSlot = DeploymentSlot;
- LoginResponse result = _authenticationProvider.Login(Email, Password, loginMethod, _settings.ByPassEnvironmentVersionCheck, (progress) =>
- {
- ProgressLog = progress;
- }).Response;
+ LoginResponse result = _authenticationProvider.Login(Email, Password, _settings.ByPassEnvironmentVersionCheck).Response;
if (result.VersionChangeRequired && !_settings.ByPassEnvironmentVersionCheck)
{
@@ -255,113 +177,31 @@ namespace Tango.MachineStudio.UI.ViewModels
return;
}
- if (result.PasswordChangeRequired)
- {
- StartUpdatePassword().Task.GetAwaiter().GetResult();
- Password = NewPassword1;
- Login();
- return;
- }
-
- //_eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!");
+ _eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!");
_navigationManager.NavigateTo(NavigationView.MainView);
_settings.LastLoginEmail = Email;
_settings.RememberMe = RememberMe;
- _settings.LastLoginMethod = loginMethod;
_settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null;
_settings.Save();
- EnableSlotSelection = false;
+ _eventLogger.Log("User logged in.");
- IsLogging = false;
- ShowLoggingDetails = true;
- IsChangingPassword = false;
- InvalidateRelayCommands();
+ EnableSlotSelection = false;
});
}
catch (Exception ex)
{
- IsLogging = false;
- ShowLoggingDetails = true;
- IsChangingPassword = false;
- InvalidateRelayCommands();
LogManager.Log(ex, "Login Error.");
_notificationProvider.ShowError($"An error occurred while trying to perform the log-in operation.\n{ex.FlattenMessage()}");
}
- }
- }
-
- private TaskCompletionSource<object> StartUpdatePassword()
- {
- _updatePasswordCompletionSource = new TaskCompletionSource<object>();
-
- IsChangingPassword = true;
- ShowLoggingDetails = false;
- IsLogging = false;
- InvalidateRelayCommands();
-
- return _updatePasswordCompletionSource;
- }
-
- private async void UpdatePassword()
- {
- await Task.Factory.StartNew(() =>
- {
- try
- {
- if (!Validate())
- {
- return;
- }
-
- ProgressLog = "Updating your password...";
- IsChangingPassword = false;
- IsLogging = true;
- InvalidateRelayCommands();
-
- using (var db = ObservablesContext.CreateDefault())
- {
- var user = db.Users.SingleOrDefault(x => x.Email == Email);
- user.PasswordChangeRequired = false;
- user.Password = User.GetPasswordHash(NewPassword1);
- db.SaveChanges();
- }
-
- _updatePasswordCompletionSource.SetResult(true);
- }
- catch (Exception ex)
- {
- IsLogging = false;
- IsChangingPassword = false;
- ShowLoggingDetails = true;
- InvalidateRelayCommands();
- _updatePasswordCompletionSource.SetException(ex);
- }
finally
{
+ IsLogging = false;
InvalidateRelayCommands();
}
- });
- }
-
- protected override void OnValidating()
- {
- if (IsChangingPassword)
- {
- if (!NewPassword1.IsBetweenLength(6, 8))
- {
- InsertError(nameof(NewPassword1), "Password must be 6 to 8 characters long");
- }
-
- if (NewPassword1 != NewPassword2)
- {
- InsertError(nameof(NewPassword2), "Passwords do not match");
- }
}
-
- base.OnValidating();
}
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
index 5e44bf43d..d1f3cc69e 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
@@ -4,7 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
-using Tango.Core.DI;
using Tango.Emulations.ExternalBridge;
using Tango.Integration.ExternalBridge;
using Tango.MachineStudio.Common;
@@ -53,18 +52,7 @@ namespace Tango.MachineStudio.UI.ViewModels
{
if (_scanner == null)
{
- var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>();
_scanner = new ExternalBridgeScanner();
- _scanner.SignalRConfiguration.Enabled = settings.EnableExternalBridgeSignalR;
- if (App.StartupArgs.Contains("-webDebug"))
- {
- _scanner.SignalRConfiguration.Address = "http://localhost:1111/"; //settings.DeploymentSlot.ToAddress();
- }
- else
- {
- _scanner.SignalRConfiguration.Address = settings.DeploymentSlot.ToAddress();
- }
- _scanner.SignalRConfiguration.Hub = settings.ExternalBridgeSignalRHub;
}
EnableDiagnostics = true;
@@ -120,8 +108,6 @@ namespace Tango.MachineStudio.UI.ViewModels
catch (Exception ex)
{
LogManager.Log(ex, "Error starting external bridge scanner.");
- Cancel();
- TangoIOC.Default.GetInstance<INotificationProvider>().ShowError($"There is a problem with machine scanning.\n{ex.FlattenMessage()}");
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs
index 81d3f4243..7584617ed 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs
@@ -27,11 +27,6 @@ namespace Tango.MachineStudio.UI.ViewModels
public ExternalBridgeLoginIntent Intent { get; set; }
/// <summary>
- /// Gets or sets a value indicating whether to require safety level operations permission from the remote machine.
- /// </summary>
- public bool RequireSafetyOperations { get; set; }
-
- /// <summary>
/// Gets or sets the login command.
/// </summary>
public RelayCommand<String> LoginCommand { get; set; }
@@ -46,7 +41,7 @@ namespace Tango.MachineStudio.UI.ViewModels
/// </summary>
public MachineLoginViewVM()
{
- Intent = ExternalBridgeLoginIntent.Diagnostics;
+ Intent = ExternalBridgeLoginIntent.FullControl;
LoginCommand = new RelayCommand<string>(Login);
CancelCommand = new RelayCommand(Cancel);
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
index 4f8c8a9b1..90fe25c8f 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
@@ -58,9 +58,6 @@ namespace Tango.MachineStudio.UI.ViewModels
private IEventLogger _eventLogger;
private MachineStudioSettings _settings;
private MachineStudioWebClient _machineStudioWebClient;
- private IExternalBridgeClient _reconnectionMachine;
- private MachineLoginViewVM _reconnectionMachineConfig;
- private bool _lastUploadHardwareConfigLocal;
/// <summary>
/// Gets or sets the current loaded module.
@@ -347,20 +344,6 @@ namespace Tango.MachineStudio.UI.ViewModels
AboutCommand = new RelayCommand(ShowAboutDialog);
ChangeAppThemeCommand = new RelayCommand<MachineStudioTheme>(ChangeTheme);
-
- ApplicationManager.ReconnectionRequired += ApplicationManager_ReconnectionRequired;
- }
-
- private async void ApplicationManager_ReconnectionRequired(object sender, EventArgs e)
- {
- if (_reconnectionMachine is IExternalBridgeSecureClient client)
- {
- ConnectToMachineSecure(client, _reconnectionMachineConfig);
- }
- else
- {
- await ConnectToMachineLocal(_reconnectionMachine, _reconnectionMachine.Machine, _lastUploadHardwareConfigLocal);
- }
}
private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable<MachinesEvent> e)
@@ -418,11 +401,13 @@ namespace Tango.MachineStudio.UI.ViewModels
String serial = ApplicationManager.ConnectedMachine.SerialNumber;
await ApplicationManager.ConnectedMachine.Disconnect();
ApplicationManager.SetConnectedMachine(null);
+ _eventLogger.Log("Disconnected from machine " + serial);
PostMessage(new MachineConnectionChangedMessage() { Machine = null });
}
catch (Exception ex)
{
+ _eventLogger.Log(ex, "Error disconnecting from machine.");
LogManager.Log(ex, "Could not disconnect from machine.");
}
finally
@@ -470,23 +455,71 @@ namespace Tango.MachineStudio.UI.ViewModels
x.SelectedMachine.EnableEventsNotification = x.EnableDiagnostics;
x.SelectedMachine.UseKeepAlive = x.EnableKeepAlive;
x.SelectedMachine.JobUnitsMethod = _settings.JobUnitsMethod;
- x.SelectedMachine.JobRunsLogger.JobSource = BL.Enumerations.JobSource.Remote;
if (x.SelectedMachine is ExternalBridgeTcpClient)
{
x.SelectedMachine.As<ExternalBridgeTcpClient>().EnableApplicationLogs = x.EnableApplicationLogs;
x.SelectedMachine.RequestTimeout = _settings.ExternalBridgeRequestTimeout;
- x.SelectedMachine.ContinuousRequestTimeout = _settings.ExternalBridgeContinuousRequestTimeout;
- }
-
- if (x.SelectedMachine.Adapter is TcpTransportAdapter)
- {
- (x.SelectedMachine.Adapter as TcpTransportAdapter).WriteMode = _settings.TcpTransportAdapterWriteMode;
}
if (x.SelectedMachine.RequiresAuthentication)
{
- ConnectToMachineSecure(x.SelectedMachine as IExternalBridgeSecureClient);
+ //Check machine exist on my database first
+ if (x.SelectedMachine.Machine == null)
+ {
+ _notificationProvider.ShowError($"The specified machine '{x.SelectedMachine.SerialNumber}' could not be found on the database. Aborting connection.");
+ return;
+ }
+
+ _notificationProvider.ShowModalDialog<MachineLoginViewVM>(async (login) =>
+ {
+ using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.ToString() + "..."))
+ {
+ try
+ {
+ await x.SelectedMachine.As<IExternalBridgeSecureClient>().Connect(new PMR.Integration.ExternalBridgeLoginRequest()
+ {
+ AppID = "Machine Studio",
+ HostName = Environment.MachineName,
+ Password = login.Password,
+ UserGuid = AuthenticationProvider.CurrentUser.Guid,
+ Intent = login.Intent,
+ });
+
+ ApplicationManager.SetConnectedMachine(x.SelectedMachine);
+ (x.SelectedMachine as IExternalBridgeSecureClient).SessionClosed += (_, __) =>
+ {
+ InvokeUI(() =>
+ {
+ _notificationProvider.ShowError("The remote machine has closed the current session. Machine disconnected.");
+ ApplicationManager.SetConnectedMachine(null);
+ });
+ };
+ PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine });
+ _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber));
+
+ //if (x.UploadHardwareConfiguration)
+ //{
+ // UploadHardwareConfiguration(false);
+ //}
+
+ }
+ catch (ResponseErrorException ex)
+ {
+ LogManager.Log(ex);
+ _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber);
+ _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Container.ErrorMessage);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex);
+ _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber);
+ _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message);
+ }
+
+ InvalidateRelayCommands();
+ }
+ });
}
else
{
@@ -494,15 +527,47 @@ namespace Tango.MachineStudio.UI.ViewModels
{
if (vm.SelectedMachine != null)
{
- await ConnectToMachineLocal(x.SelectedMachine, vm.SelectedMachine, x.UploadHardwareConfiguration);
+ using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "..."))
+ {
+ try
+ {
+ await x.SelectedMachine.Connect();
+ x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber;
+ ApplicationManager.SetConnectedMachine(x.SelectedMachine);
+
+ PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine });
+ _eventLogger.Log(String.Format("Successfully connected to machine {0} via USB", x.SelectedMachine.SerialNumber));
+ _settings.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber;
+ _settings.Save();
+
+ if (x.UploadHardwareConfiguration)
+ {
+ UploadHardwareConfiguration(false);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex);
+
+ if (x.SelectedMachine != null)
+ {
+ _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber);
+ }
+
+ _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message);
+
+ }
+
+ InvalidateRelayCommands();
+ }
}
});
}
- base.InvalidateRelayCommands();
+ InvalidateRelayCommands();
}
- base.InvalidateRelayCommands();
+ InvalidateRelayCommands();
});
}
else
@@ -567,115 +632,6 @@ namespace Tango.MachineStudio.UI.ViewModels
InvalidateRelayCommands();
}
- private async Task ConnectToMachineLocal(IExternalBridgeClient client, Machine machine, bool uploadHardwareConfig)
- {
- using (NotificationProvider.PushTaskItem("Connecting to " + client.ToString() + "..."))
- {
- try
- {
- _reconnectionMachine = client;
-
- await client.Connect();
- client.SerialNumber = machine.SerialNumber;
- ApplicationManager.SetConnectedMachine(client);
-
- PostMessage(new MachineConnectionChangedMessage() { Machine = client });
- _settings.LastVirtualMachineSerialNumber = machine.SerialNumber;
- _settings.Save();
-
- _lastUploadHardwareConfigLocal = uploadHardwareConfig;
-
- if (uploadHardwareConfig)
- {
- UploadHardwareConfiguration(false);
- }
- }
- catch (Exception ex)
- {
- LogManager.Log(ex);
-
- _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message);
-
- }
-
- InvalidateRelayCommands();
- }
- }
-
- private async void ConnectToMachineSecure(IExternalBridgeSecureClient machine, MachineLoginViewVM config)
- {
- using (NotificationProvider.PushTaskItem("Connecting to machine " + machine.ToString() + "..."))
- {
- try
- {
- await machine.Connect(new PMR.Integration.ExternalBridgeLoginRequest()
- {
- AppID = "Machine Studio",
- HostName = Environment.MachineName,
- Password = config.Password,
- UserGuid = AuthenticationProvider.CurrentUser.Guid,
- Intent = config.Intent,
- UserName = AuthenticationProvider.CurrentUser.Contact.FullName,
- RequireSafetyLevelOperations = config.RequireSafetyOperations
- }, new PMR.Integration.ConfigureProtocolRequest()
- {
- EnableCompression = true,
- GenericProtocol = PMR.Integration.GenericMessageProtocol.Bson
- });
-
- _reconnectionMachine = machine;
- _reconnectionMachineConfig = config;
-
- ApplicationManager.SetConnectedMachine(machine);
- machine.SessionClosed -= Machine_SessionClosed;
- machine.SessionClosed += Machine_SessionClosed;
- PostMessage(new MachineConnectionChangedMessage() { Machine = machine });
-
- //if (x.UploadHardwareConfiguration)
- //{
- // UploadHardwareConfiguration(false);
- //}
-
- }
- catch (ResponseErrorException ex)
- {
- LogManager.Log(ex);
- _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Container.ErrorMessage);
- }
- catch (Exception ex)
- {
- LogManager.Log(ex);
- _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message);
- }
-
- InvalidateRelayCommands();
- }
- }
-
- private void ConnectToMachineSecure(IExternalBridgeSecureClient machine)
- {
- //Check machine exist on my database first
- if (machine.Machine == null)
- {
- _notificationProvider.ShowError($"The specified machine '{machine.SerialNumber}' could not be found on the database. Aborting connection.");
- return;
- }
-
- _notificationProvider.ShowModalDialog<MachineLoginViewVM>((login) =>
- {
- ConnectToMachineSecure(machine, login);
- });
- }
-
- private void Machine_SessionClosed(object sender, EventArgs e)
- {
- InvokeUI(() =>
- {
- _notificationProvider.ShowError("The remote machine has closed the current session. Machine disconnected.");
- ApplicationManager.SetConnectedMachine(null);
- });
- }
-
private async void UploadHardwareConfiguration(bool showSuccessMessage = true)
{
try
@@ -711,7 +667,7 @@ namespace Tango.MachineStudio.UI.ViewModels
/// Starts the specified module.
/// </summary>
/// <param name="module">The module.</param>
- internal async void StartModule(IStudioModule module)
+ internal void StartModule(IStudioModule module)
{
IsMenuOpened = false;
@@ -736,9 +692,10 @@ namespace Tango.MachineStudio.UI.ViewModels
m.IsLoaded = false;
}
+ CurrentModule = module;
+
if (module != null)
{
- CurrentModule = module;
CurrentModule.IsLoaded = true;
IsModuleLoaded = true;
@@ -749,10 +706,7 @@ namespace Tango.MachineStudio.UI.ViewModels
{
IsModuleLoaded = false;
LogManager.Log(String.Format("Navigating to Home..."));
- (MainView.Self as MainView).NavigationControl.NavigateTo("Home", () =>
- {
- CurrentModule = module;
- });
+ (MainView.Self as MainView).NavigationControl.NavigateTo("Home");
}
}
@@ -760,7 +714,7 @@ namespace Tango.MachineStudio.UI.ViewModels
/// Opens the module in a new window.
/// </summary>
/// <param name="module">The module.</param>
- private async void OpenModuleInWindow(IStudioModule module, Rect? bounds = null, WindowState? state = null, bool setHomeModule = true)
+ private void OpenModuleInWindow(IStudioModule module, Rect? bounds = null, WindowState? state = null)
{
if (module == null) return;
@@ -768,12 +722,7 @@ namespace Tango.MachineStudio.UI.ViewModels
{
module.InNewWindow = true;
- if (setHomeModule)
- {
- StartModule(null);
- }
-
- await Task.Delay(1000);
+ StartModule(null);
LogManager.Log(String.Format("Starting module '{0}' in new window...", module.Name));
@@ -969,7 +918,7 @@ namespace Tango.MachineStudio.UI.ViewModels
if (module != null && !module.InNewWindow)
{
- OpenModuleInWindow(module, item.Bounds, item.State, false);
+ OpenModuleInWindow(module, item.Bounds, item.State);
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
index 160041b5f..2ee8574b1 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs
@@ -179,7 +179,6 @@ namespace Tango.MachineStudio.UI.ViewModels
_updateInfo = new CheckForUpdatesResponse();
_updateInfo.BlobAddress = response.BlobAddress;
_updateInfo.Version = response.Version;
- _updateInfo.CdnAddress = response.CdnAddress;
LatestVersion = _updateInfo.Version;
StartUpdate();
@@ -271,7 +270,7 @@ namespace Tango.MachineStudio.UI.ViewModels
{
logManager.Log("Creating temporary file " + tempFile);
- using (AutoFileDownloader downloader = new AutoFileDownloader(_updateInfo.BlobAddress, _updateInfo.CdnAddress, tempFile.Path))
+ using (StorageBlobDownloader downloader = new StorageBlobDownloader(_updateInfo.BlobAddress, tempFile.Path))
{
downloader.Progress += (x, e) =>
{