Check result of Connect in MainWindowViewModel.

This commit is contained in:
Jared Goodwin 2021-07-19 14:29:42 -07:00
parent f570b8ab3f
commit d487b15f56
2 changed files with 75 additions and 65 deletions

View File

@ -206,48 +206,51 @@ namespace Remotely.Desktop.Win.ViewModels
try
{
await _casterSocket.Connect(_conductor.Host);
var result = await _casterSocket.Connect(_conductor.Host);
if (_casterSocket.Connection is null)
if (result)
{
_casterSocket.Connection.Closed += (ex) =>
{
App.Current?.Dispatcher?.Invoke(() =>
{
Viewers.Clear();
SessionID = "Disconnected";
});
return Task.CompletedTask;
};
_casterSocket.Connection.Reconnecting += (ex) =>
{
App.Current?.Dispatcher?.Invoke(() =>
{
Viewers.Clear();
SessionID = "Reconnecting";
});
return Task.CompletedTask;
};
_casterSocket.Connection.Reconnected += async (arg) =>
{
await GetSessionID();
};
await DeviceInitService.GetInitParams();
ApplyBranding();
await GetSessionID();
return;
}
_casterSocket.Connection.Closed += async (ex) =>
{
await App.Current?.Dispatcher?.InvokeAsync(() =>
{
Viewers.Clear();
SessionID = "Disconnected";
});
};
_casterSocket.Connection.Reconnecting += async (ex) =>
{
await App.Current?.Dispatcher?.InvokeAsync(() =>
{
Viewers.Clear();
SessionID = "Reconnecting";
});
};
_casterSocket.Connection.Reconnected += async (arg) =>
{
await GetSessionID();
};
await DeviceInitService.GetInitParams();
ApplyBranding();
await GetSessionID();
}
catch (Exception ex)
{
Logger.Write(ex);
SessionID = "Failed";
MessageBox.Show(Application.Current.MainWindow, "Failed to connect to server.", "Connection Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// If we got here, something went wrong.
SessionID = "Failed";
MessageBox.Show(Application.Current.MainWindow, "Failed to connect to server.", "Connection Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
}
public void PromptForHostName()

View File

@ -163,48 +163,55 @@ namespace Remotely.Desktop.XPlat.ViewModels
_conductor.ProcessArgs(new string[] { "-mode", "Normal", "-host", Host });
await _casterSocket.Connect(_conductor.Host);
var result = await _casterSocket.Connect(_conductor.Host);
if (_casterSocket.Connection is null)
if (result)
{
if (_casterSocket.Connection is null)
{
return;
}
_casterSocket.Connection.Closed += async (ex) =>
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
SessionID = "Disconnected";
});
};
_casterSocket.Connection.Reconnecting += async (ex) =>
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
SessionID = "Reconnecting";
});
};
_casterSocket.Connection.Reconnected += async (arg) =>
{
await GetSessionID();
};
await DeviceInitService.GetInitParams();
ApplyBranding();
await _casterSocket.SendDeviceInfo(_conductor.ServiceID, Environment.MachineName, _conductor.DeviceID);
await _casterSocket.GetSessionID();
return;
}
_casterSocket.Connection.Closed += async (ex) =>
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
SessionID = "Disconnected";
});
};
_casterSocket.Connection.Reconnecting += async (ex) =>
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
SessionID = "Reconnecting";
});
};
_casterSocket.Connection.Reconnected += async (arg) =>
{
await GetSessionID();
};
await DeviceInitService.GetInitParams();
ApplyBranding();
await _casterSocket.SendDeviceInfo(_conductor.ServiceID, Environment.MachineName, _conductor.DeviceID);
await _casterSocket.GetSessionID();
}
catch (Exception ex)
{
Logger.Write(ex);
_sessionID = "Failed";
await MessageBox.Show("Failed to connect to server.", "Connection Failed", MessageBoxType.OK);
return;
}
// If we got here, something went wrong.
_sessionID = "Failed";
await MessageBox.Show("Failed to connect to server.", "Connection Failed", MessageBoxType.OK);
}
public async Task PromptForHostName()