using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.Azure.Cosmos; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; namespace TEAMModelOS.SDK.DI.Device { public class CoreDevice { private readonly IServiceProvider _services; private readonly ILogger _logger; private readonly IHttpClientFactory _httpClientFactory; private readonly IHostApplicationLifetime _lifetime; private ConcurrentDictionary> clientDevice { get; } = new ConcurrentDictionary>(); public CoreDevice(IServiceProvider services, ILogger logger, IHostApplicationLifetime lifetime, IHttpClientFactory httpClientFactory) { _services = services; _logger = logger; _services=services; _httpClientFactory=httpClientFactory; _lifetime = lifetime; } public Task GetCoreDevice() { try { var server = _services.GetService(); var d = server?.Features.Get(); IEnumerable? _url = server?.Features.Get()?.Addresses; var device = clientDevice.GetOrAdd("Device", x => DeviceHelper.GetClientInfo(_httpClientFactory, _logger, _url)); return device; } catch (Exception e) { _logger?.LogWarning(e, e.Message); throw; } } } }