private async Task FetchConfigurationAsync(CancellationToken cancellationToken) { try { FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs(0, "Connecting to demo system...")); // Check admin credentials (not actually required) var valid = await _client.CheckCredentialsAsync(_systemProperties.AdminUser, _systemProperties.AdminPassword); await Task.Delay(500, cancellationToken); // Delay a bit for show cancellationToken.ThrowIfCancellationRequested(); if (!valid) { FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs("Invalid credentials.")); return; } FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs(0.25, "Retrieving door controllers...")); var doorControllers = await _client.GetDoorControllersAsync(); await Task.Delay(500, cancellationToken); // Delay a bit for demonstration cancellationToken.ThrowIfCancellationRequested(); FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs(0.5, "Retrieving doors...")); var doors = await _client.GetDoorsAsync(); await Task.Delay(500, cancellationToken); // Delay a bit for demonstration cancellationToken.ThrowIfCancellationRequested(); FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs(0.75, "Retrieving event types...")); var eventTypes = await _client.GetEventTypesAsync(); await Task.Delay(500, cancellationToken); // Delay a bit for demonstration cancellationToken.ThrowIfCancellationRequested(); var configuration = BuildConfiguration(doorControllers, doors, eventTypes); if (configuration != null) { // Done FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs(configuration)); } else { FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs("Invalid configuration.")); } } catch (DemoApplicationClientException ex) { ACUtil.Log(true, "DemoACPlugin.ConfigurationManager", "Error fetching configuration: " + ex.Message); FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs("Error communicating with the Demo Application.")); } catch (OperationCanceledException) { FireFetchConfigurationStatusChanged(new ACFetchConfigurationStatusChangedEventArgs("Fetching configuration canceled.")); } }