1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using Microsoft.AspNetCore.Mvc;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Text.Json;
- using System.Threading.Tasks;
- using System;
- using TEAMModelOS.SDK;
- using System.IO;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.DI;
- using Microsoft.Extensions.Options;
- using System.Net.Http;
- using TEAMModelOS.Models;
- namespace TEAMModelBI.Controllers.BISystem
- {
- [Route("core")]
- [ApiController]
- public class CoreController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureStorageFactory _azureStorage;
- private readonly DingDing _dingDing;
- private readonly IPSearcher _searcher;
- private readonly Option _option;
- public CoreController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IPSearcher searcher, IHttpClientFactory httpClient)
- {
- _azureCosmos = azureCosmos;
- _azureRedis = azureRedis;
- _azureStorage= azureStorage;
- _dingDing = dingDing;
- _searcher = searcher;
- _option = option?.Value;
- }
- /// <summary>
- ///获取版本信息
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("system-info")]
- [RequestSizeLimit(100_000_000)] //最大100m左右
- public async Task<IActionResult> SystemInfo(JsonElement request)
- {
- Type attr = this.GetType();
- string currentDirectory = Path.GetDirectoryName(attr.Assembly.Location);
- Assembly assembly = Assembly.LoadFrom($"{currentDirectory}\\TEAMModelBI.dll");
- var description = assembly.GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
- //var v1 = Assembly.GetEntryAssembly().GetName().Version;
- //var v2 = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
- // var description = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
- var version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
- long nowtime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- //Console.WriteLine($"Assembly.GetEntryAssembly().GetName().Version: " +
- // $"{Assembly.GetEntryAssembly().GetName().Version}");5.2107.12.1
- //Console.WriteLine($"Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version:" +
- // $"{Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version}");5.2107.12.1
- //Console.WriteLine($"Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion:" +
- // $"{Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion}");5.2107.12
- var IpPort = HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
- if (string.IsNullOrEmpty(IpPort))
- {
- IpPort = HttpContext.Connection.RemoteIpAddress.ToString();
- }
- if (IpPort.Contains("::"))
- {
- IpPort = "127.0.0.1";
- }
- string ip = IpPort.Split(":")[0];
- string os = "";
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
- {//Linux
- os = "Linux";
- }
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {//Windows
- os = "Windows";
- }
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- {//OSX
- os = "OSX";
- }
- string region = await _searcher.SearchIpAsync(ip);
- return Ok(new { os, version, description, nowtime, region, ip });
- }
- }
- }
|