public NetClient(Uri uri, ILogger <NetClient> logger, IInputManager inputManager, WorkspaceNetwork workspaceNetwork, Supervisor supervisor) : base(uri, logger) { this.logger = logger; this.workspaceNetwork = workspaceNetwork; connectionTaskCompletionSource = new TaskCompletionSource <object?>(TaskCreationOptions.RunContinuationsAsynchronously); this.Disconnected += (sender, e) => { if (!string.IsNullOrEmpty(serverName)) { supervisor.SetPeerStatus(serverName, Supervisor.PeerConnectionStatuses.IsServer, false); } connectionTaskCompletionSource.TrySetCanceled(); }; this.ConnectingStarted += (sender, e) => { connectionTaskCompletionSource = new TaskCompletionSource <object?>(TaskCreationOptions.RunContinuationsAsynchronously); }; this.Connected += async(sender, e) => { var serverIdentity = await Hub.Identify(Configuration.Config.Instance.Self, Configuration.Config.Instance.Desktops); if (!serverIdentity.IsValid()) { throw new InvalidOperationException("The server provided invalid identification data."); } serverName = serverIdentity.DesktopName; await Configuration.Desktop.AddFromServer(serverIdentity.Desktops !); await Hub.ChangeDisplays(inputManager.DisplayAdapter.GetDisplays().ToList()); if (!string.IsNullOrEmpty(serverName)) { supervisor.SetPeerStatus(serverName, Supervisor.PeerConnectionStatuses.IsServer, true); } connectionTaskCompletionSource.TrySetResult(null); }; }