private async Task <(bool isDataCollector, bool registered, bool approved, string id)> RegistrationAsync(CancellationToken cancellationToken) { try { var(_, isDataCollectorSetting) = await _settingsService.GetSettingAsync("IsDataCollector", cancellationToken); if (!bool.TryParse(isDataCollectorSetting, out var isDataCollector) || !isDataCollector) { return(isDataCollector, registered : false, approved : false, id : null); } _logger.LogInformation("Checking for registration"); var(_, id) = await _settingsService.GetSettingAsync("CollectorId", cancellationToken); if (id == null) { string token; _logger.LogInformation("Registering as data collector"); (id, token) = await _serverService.RegisterAsCollectorAsync(cancellationToken); await _settingsService.UpdateSettingAsync("CollectorId", id, cancellationToken); await _settingsService.UpdateSettingAsync("ServerToken", token, cancellationToken); } _logger.LogInformation("Checking approval"); var approved = await _serverService.CheckApprovalAsync(id, cancellationToken); return(isDataCollector : true, registered : true, approved, id); } catch (Exception ex) { _logger.LogError(ex, "Error occured during registration check"); throw; } }