Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
 private static Lazy <T> ExceptionWrappedLazy <T>(Func <T> valueFactory)
 {
     return(new Lazy <T>(() =>
     {
         try
         {
             return valueFactory();
         }
         catch (Exception exception)
         {
             throw ExceptionConversion.ConvertException(exception);
         }
     }));
 }
Esempio n. 3
0
        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;
            }
        }