private static async Task Main(string[] args) { Setup(); var searchInformationCategories = new[] { InformationCategory.All }; var devices = new List <Device>(); var localAccessService = new WMIAccessService(); var connected = await localAccessService.TryConnectAsync().ConfigureAwait(false); if (connected) { var device = await new Device() .WithInformationCategories(searchInformationCategories) .WithWMIAccessService(localAccessService) .InitializeAsync() .ConfigureAwait(false); devices.Add(device); if (devices.Any()) { Summarize(devices); } } Console.ReadLine(); }
private Task <WMIAccessService> TryGetAccessAsync(WMIConnectionOption wmiConnectionOption) { return(Task.Run(async() => { WMIAccessService connectedWMIConnectedAccessService = null; if (wmiConnectionOption != null) { try { var wmiAccessService = new WMIAccessService(); var connected = await wmiAccessService.TryConnectAsync(wmiConnectionOption).ConfigureAwait(false); if (connected) { connectedWMIConnectedAccessService = wmiAccessService; } } catch (Exception exception) { var endPoint = string.IsNullOrEmpty(wmiConnectionOption.EndPoint) ? wmiConnectionOption.DeviceName : wmiConnectionOption.EndPoint; var wmiException = new WMIGeneralException(endPoint, exception); LogEventHandler.Exception(wmiException); } } return connectedWMIConnectedAccessService; })); }
private async Task <Device> FetchDeviceAsync(InformationType[] searchInformationTypes) { var localAccessService = new WMIAccessService(); var connected = await localAccessService.TryConnectAsync().ConfigureAwait(false); connected.Should().BeTrue(); var device = await new Device() .WithWMIAccessService(localAccessService) .WithInformationTypes(searchInformationTypes) .InitializeAsync() .ConfigureAwait(false); _device = device; return(device); }