public IAsyncOperation <HIDInputChannel> ConnectAsync(DeviceInformation deviceInfo) { if (this.currentChannel != null) { this.currentChannel.Dispose(); this.currentChannel = null; } Func <Task <HIDInputChannel> > helper = async() => { if (this.connectedDevices == null) { return(null); } var device = await this.connectAsync(deviceInfo.Id); if (device == null) { return(null); } this.StoreHIDId(deviceInfo.Id); this.currentChannel = new HIDInputChannel(deviceInfo, device) { Services = this.services }; return(this.currentChannel); }; return(helper().AsAsyncOperation()); }
public IAsyncOperation <HIDInputChannel> ReconnectAsync() { Func <Task <HIDInputChannel> > resumeHelper = async() => { string id = this.currentChannel.DeviceId; if (id == null) { return(null); } var device = await this.connectAsync(id); if (device == null) { return(null); } this.currentChannel.Resume(device); return(this.currentChannel); }; Func <Task <HIDInputChannel> > restartHelper = async() => { string id = this.GetStoredHIDId(); if (id == null) { return(null); } var deviceInfo = await DeviceInformation.CreateFromIdAsync(id); var device = await this.connectAsync(id); if (device == null) { this.ResetStoredHIDId(); return(null); } this.currentChannel = new HIDInputChannel(deviceInfo, device) { Services = this.services }; return(this.currentChannel); }; if (this.currentChannel != null) { return(resumeHelper().AsAsyncOperation()); } else { return(restartHelper().AsAsyncOperation()); } }