This commit is contained in:
CortexCore
2024-04-28 15:45:17 +08:00
commit 5ca9a8ee1b
6 changed files with 764 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
using BITKit;
using IDIS.Models;
using IDIS.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace IDIS_Server_SIM.Controllers;
[ApiController]
[Route("api")]
public class IDISController:Controller
{
private readonly IDIS_Service _service;
public IDISController(IDIS_Service service)
{
_service = service;
}
[HttpGet]
[Route("info")]
public IActionResult Info()
{
return new ContentResult
{
Content = Environment.MachineName
};
}
[HttpGet]
[Route("query")]
public async Task<IActionResult> Query(string key)
{
try
{
return Ok(await _service.QueryAsync(key));
}
catch (Exception e)
{
return BadRequest(ContextModel.Error(e.ToString()));
}
}
[HttpGet]
[Route("isExist")]
public async Task<bool> IsExist(string key)
{
return await _service.IsExistAsync(key);
}
[HttpGet]
[Route("register")]
public string Register([FromBody] string json)
{
return "err:0";
}
[HttpGet]
[Route("update")]
public string Update([FromBody] string json)
{
return "err:0";
}
[HttpGet]
[Route("delete")]
public async Task<bool> Delete (string handle)
{
await _service.DeleteAsync(handle);
return true;
}
}

View File

@@ -0,0 +1,61 @@
#pragma warning disable SYSLIB1045
using System.Text.RegularExpressions;
using BITKit;
using IDIS.Services;
await BITAppForNet.InitializeAsync("IDIS");
var builder = WebApplication.CreateBuilder(args);
var cancellationTokenSource = new System.Threading.CancellationTokenSource();
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddTransient<IDIS_Service, IDIS_Service_SQLiteBased>();
var app = builder.Build();
var logger = app.Services.GetRequiredService<ILogger<Program>>();
#region
logger.LogInformation("请输入二级节点地址,例如:88.123.99");
string? str;
while (string.IsNullOrEmpty(str = Console.ReadLine()) is false)
{
const string pattern =@"^\d{1,3}\.\d{1,3}\.\d{1,3}$"; // 正则表达式模式
if (Regex.IsMatch(str,pattern))
{
logger.LogInformation("输入的地址符合要求。");
break;
}
logger.LogInformation("错误的地址格式,请按照正确格式输入,例如:88.123.99");
}
#endregion
var idis_Service = app.Services.GetRequiredService<IDIS_Service>();
//idis_Service.PreAddress = str!;
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapGet("/", () => "Hello World!");
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,40 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:39555",
"sslPort": 44303
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false, "launchUrl": "swagger",
"applicationUrl": "http://localhost:5242;http://localhost:5243",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7254;http://localhost:5242",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Urls": "http://+:5242",
"AllowedHosts": "*"
}