internal void OnDeviceHubConnected(string workstationId, IRemoteCommands caller) { Task.Run(async() => { RemoteDeviceDescription descr = null; try { _appConnections.TryGetValue(workstationId, out descr); if (descr != null) { var connectionContainer = _connectionContainers.GetOrAdd(workstationId, (c) => new DeviceConnectionContainer(caller, _deviceId)); var deviceConnection = new SignalRRemoteDeviceConnection(connectionContainer); var commandQueue = new CommandQueue(deviceConnection, null); var deviceCommands = new HesDeviceCommands(connectionContainer); var remoteDevice = new Device(commandQueue, channelNo, deviceCommands, null); descr.Device = remoteDevice; await remoteDevice.VerifyAndInitialize(); // Inform clients about connection ready descr.Tcs.TrySetResult(remoteDevice); } } catch (Exception ex) { descr.Device = null; // inform clients about connection fail descr.Tcs?.TrySetException(ex); } }); }
// Device hub connected. That means we need to create RemoteDevice public void OnDeviceHubConnected(string deviceId, string workstationId, IRemoteCommands caller) { GetDeviceRemoteConnections(deviceId).OnDeviceHubConnected(workstationId, caller); }
public DeviceConnectionContainer(IRemoteCommands caller, string deviceId) { Caller = caller; DeviceId = deviceId; }