12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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<string, Task <ClientDevice>> clientDevice { get; } = new ConcurrentDictionary<string, Task<ClientDevice>>();
- public CoreDevice(IServiceProvider services, ILogger<CoreDevice> logger, IHostApplicationLifetime lifetime, IHttpClientFactory httpClientFactory)
- {
- _services = services;
- _logger = logger;
- _services=services;
- _httpClientFactory=httpClientFactory;
- _lifetime = lifetime;
-
-
- }
- public Task<ClientDevice> GetCoreDevice()
- {
- try
- {
- var server = _services.GetService<IServer>();
- var d = server?.Features.Get<IServerAddressesFeature>();
- IEnumerable<string> _url = server?.Features.Get<IServerAddressesFeature>()?.Addresses;
- var device = clientDevice.GetOrAdd("Device", x => DeviceHelper.GetClientInfo(_httpClientFactory, _logger, _url));
- return device;
- }
- catch (Exception e)
- {
- _logger?.LogWarning(e, e.Message);
- throw;
- }
- }
- }
- }
|