aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
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/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
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/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs159
1 files changed, 98 insertions, 61 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 b22d65192..2a00386dc 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
@@ -58,6 +58,8 @@ namespace Tango.MachineStudio.UI.ViewModels
private IEventLogger _eventLogger;
private MachineStudioSettings _settings;
private MachineStudioWebClient _machineStudioWebClient;
+ private IExternalBridgeSecureClient _reconnectionMachine;
+ private MachineLoginViewVM _reconnectionMachineConfig;
/// <summary>
/// Gets or sets the current loaded module.
@@ -344,6 +346,13 @@ namespace Tango.MachineStudio.UI.ViewModels
AboutCommand = new RelayCommand(ShowAboutDialog);
ChangeAppThemeCommand = new RelayCommand<MachineStudioTheme>(ChangeTheme);
+
+ ApplicationManager.ReconnectionRequired += ApplicationManager_ReconnectionRequired;
+ }
+
+ private void ApplicationManager_ReconnectionRequired(object sender, EventArgs e)
+ {
+ ConnectToMachineSecure(_reconnectionMachine, _reconnectionMachineConfig);
}
private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable<MachinesEvent> e)
@@ -455,70 +464,23 @@ 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.RequiresAuthentication)
+ if (x.SelectedMachine.Adapter is TcpTransportAdapter)
{
- //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);
- }
+ (x.SelectedMachine.Adapter as TcpTransportAdapter).WriteMode = _settings.TcpTransportAdapterWriteMode;
+ }
- InvalidateRelayCommands();
- }
- });
+ if (x.SelectedMachine.RequiresAuthentication)
+ {
+ ConnectToMachineSecure(x.SelectedMachine as IExternalBridgeSecureClient);
}
else
{
@@ -631,6 +593,77 @@ namespace Tango.MachineStudio.UI.ViewModels
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,
+ });
+
+ _reconnectionMachine = machine;
+ _reconnectionMachineConfig = config;
+
+ ApplicationManager.SetConnectedMachine(machine);
+ machine.SessionClosed -= Machine_SessionClosed;
+ machine.SessionClosed += Machine_SessionClosed;
+ PostMessage(new MachineConnectionChangedMessage() { Machine = machine });
+ _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", machine.SerialNumber));
+
+ //if (x.UploadHardwareConfiguration)
+ //{
+ // UploadHardwareConfiguration(false);
+ //}
+
+ }
+ catch (ResponseErrorException ex)
+ {
+ LogManager.Log(ex);
+ _eventLogger.Log(ex, "Error connecting to machine " + machine.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 " + machine.SerialNumber);
+ _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
@@ -666,7 +699,7 @@ namespace Tango.MachineStudio.UI.ViewModels
/// Starts the specified module.
/// </summary>
/// <param name="module">The module.</param>
- internal void StartModule(IStudioModule module)
+ internal async void StartModule(IStudioModule module)
{
IsMenuOpened = false;
@@ -691,10 +724,9 @@ namespace Tango.MachineStudio.UI.ViewModels
m.IsLoaded = false;
}
- CurrentModule = module;
-
if (module != null)
{
+ CurrentModule = module;
CurrentModule.IsLoaded = true;
IsModuleLoaded = true;
@@ -705,7 +737,10 @@ namespace Tango.MachineStudio.UI.ViewModels
{
IsModuleLoaded = false;
LogManager.Log(String.Format("Navigating to Home..."));
- (MainView.Self as MainView).NavigationControl.NavigateTo("Home");
+ (MainView.Self as MainView).NavigationControl.NavigateTo("Home", () =>
+ {
+ CurrentModule = module;
+ });
}
}
@@ -713,7 +748,7 @@ namespace Tango.MachineStudio.UI.ViewModels
/// Opens the module in a new window.
/// </summary>
/// <param name="module">The module.</param>
- private void OpenModuleInWindow(IStudioModule module, Rect? bounds = null, WindowState? state = null)
+ private async void OpenModuleInWindow(IStudioModule module, Rect? bounds = null, WindowState? state = null)
{
if (module == null) return;
@@ -723,6 +758,8 @@ namespace Tango.MachineStudio.UI.ViewModels
StartModule(null);
+ await Task.Delay(1000);
+
LogManager.Log(String.Format("Starting module '{0}' in new window...", module.Name));
if (!(MainView.Self as MainView).NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType))