public async Task <int> SendOutputReportAsync(Win32HidOutputReport report, CancellationToken cancellationToken = default(CancellationToken)) { if (report == null) { throw new ArgumentNullException(nameof(report)); } var outputBuffer = report.GetOutputBuffer(); log.Trace("Sending output report:\r\n\r\n " + outputBuffer.ToHexString()); log.Trace(outputBuffer.ToLoggableAsHex("Sending output report:")); try { return(await Kernel32Dll.WriteFileAsync(Handle, outputBuffer, cancellationToken)); } catch (Win32Exception exception) { log.Error("Sending output report failed", exception); throw ExceptionConversion.ConvertException(exception); } catch (Exception exception) { log.Error("Sending output report failed", exception); throw; } }
private static Lazy <T> ExceptionWrappedLazy <T>(Func <T> valueFactory) { return(new Lazy <T>(() => { try { return valueFactory(); } catch (Exception exception) { throw ExceptionConversion.ConvertException(exception); } })); }
public async Task <HidInputReport> GetInputReportAsync( CancellationToken cancellationToken = default(CancellationToken)) { try { var bytes = await Kernel32Dll.ReadFileAsync <byte>(Handle, Information.Capabilities.InputReportByteLength, cancellationToken); log.Trace(bytes.ToLoggableAsHex("Received input report:")); return(new HidInputReport(bytes)); } catch (Win32Exception exception) { log.Error("Receiving input report failed", exception); throw ExceptionConversion.ConvertException(exception); } catch (Exception exception) { log.Error("Receiving input report failed", exception); throw; } }