public SoftwareStaticData GetSoftwareStaticData() { SoftwareStaticData data = new SoftwareStaticData(); data.Bios = this.SoftwareStaticBuilder.GetSoftwareStaticData <Bios>(); data.OperatingSystem = this.SoftwareStaticBuilder.GetSoftwareStaticData <OS>(); data.InstalledProgram = this.SoftwareStaticBuilder.GetSoftwareStaticData <InstalledProgram>(); data.StartupCommand = this.SoftwareStaticBuilder.GetSoftwareStaticData <StartupCommand>(); data.MicrosoftWindowsUpdate = this.SoftwareStaticBuilder.GetSoftwareStaticData <MicrosoftWindowsUpdate>(); data.LocalUser = this.SoftwareStaticBuilder.GetSoftwareStaticData <LocalUser>(); data.CurrentUser = this.SoftwareStaticBuilder.GetSoftwareStaticData <CurrentUser>(); return(data); }
public IAsyncCommand CreateSoftwareStaticDataCommand( WpfObservableRangeCollection <CurrentUser> currentUser, WpfObservableRangeCollection <OS> operatingSystem, WpfObservableRangeCollection <Bios> bios, WpfObservableRangeCollection <InstalledProgram> installedProgram, WpfObservableRangeCollection <MicrosoftWindowsUpdate> microsoftWindowsUpdate, WpfObservableRangeCollection <StartupCommand> startupCommand, WpfObservableRangeCollection <LocalUser> localUser) { return(new AsyncCommand <SoftwareStaticData>(async(cancellationToken) => { return await Task.Run(async() => { WorkstationMonitorServiceClient workstationMonitorServiceClient = null; SoftwareStaticData result = null; try { workstationMonitorServiceClient = await this.wcfClient.GetNewWorkstationMonitorServiceClient(); result = await this.wcfClient.ReadSoftwareStaticDataAsync(workstationMonitorServiceClient) .WithCancellation(cancellationToken) // Following statements will be processed in the same thread, won't use caught context (UI) .ConfigureAwait(false); if (cancellationToken.IsCancellationRequested) { workstationMonitorServiceClient.Abort(); } else { workstationMonitorServiceClient.Close(); } if (result != null && !cancellationToken.IsCancellationRequested) { currentUser.ReplaceRange(result.CurrentUser, new CurrentUserStaticComparer()); operatingSystem.ReplaceRange(result.OperatingSystem, new OSComparer()); bios.ReplaceRange(result.Bios, new BiosComparer()); installedProgram.ReplaceRange(result.InstalledProgram, new InstalledProgramComparer()); microsoftWindowsUpdate.ReplaceRange(result.MicrosoftWindowsUpdate, new MicrosoftWindowsUpdateComparer()); startupCommand.ReplaceRange(result.StartupCommand, new StartupCommandComparer()); localUser.ReplaceRange(result.LocalUser, new LocalUserComparer()); } } catch (InvalidOperationException ex) { this.messageSender.SendErrorMessage(ex.Message); // Rethrow exception in order to set correct Task state (Faulted) throw; } catch (EndpointNotFoundException) { this.messageSender.SendErrorMessageEndpointNotFound(); this.messageSender.SendCancelCommandMessage(this.wcfClient.MachineIdentifier); workstationMonitorServiceClient.Abort(); throw; } catch (TimeoutException) { this.messageSender.SendErrorMessageTimeout(); this.messageSender.SendCancelCommandMessage(this.wcfClient.MachineIdentifier); workstationMonitorServiceClient.Abort(); throw; } catch (CommunicationException ex) { this.messageSender.SendErrorMessage(ex.Message); this.messageSender.SendCancelCommandMessage(this.wcfClient.MachineIdentifier); workstationMonitorServiceClient.Abort(); throw; } return result; }); })); }