public async Task <SubscriptionOverview> GetSubscriptionsAsync(CancellationToken cancellationToken, IMachineStateService machineStateService)
        {
            async Task GetMachineState(SubscriptionOverview subscriptionOverview)
            {
                var tasks = (
                    from subscription in subscriptionOverview.Subscriptions
                    from assignedMachine in subscription.AssignedMachines
                    select Task.Run(async() =>
                {
                    var machineState =
                        await machineStateService.GetMachineStateAsync(assignedMachine.Id, cancellationToken);
                    assignedMachine.MachineState =
                        machineState.HasValues ? Models.MachineState.Running : Models.MachineState.Offline;
                }, cancellationToken)).ToList();
                await Task.WhenAll(tasks);
            }

            var token = await _tokenProvider.ReceiveTokenAsync(TapioScope.GlobalDiscovery);

            var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"{TargetUrl}{TargetRoute}{WebUtility.UrlEncode(_tapioEmail)}"));

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
            var responseMessage = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);

            responseMessage.EnsureSuccessStatusCode();
            var content = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

            var result = SubscriptionOverviewExtension.FromJson(content);

            await GetMachineState(result);

            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> GetMachineStateAsync(string machineId, CancellationToken cancellationToken)
        {
            var result = await _machineStateService.GetMachineStateAsync(machineId, cancellationToken);

            return(Ok(result));
        }