aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs251
1 files changed, 100 insertions, 151 deletions
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);
}
}