初始化

This commit is contained in:
2025-11-26 11:18:26 +08:00
commit 0564b8c1f3
579 changed files with 346253 additions and 0 deletions

89
WebUI/LIB/BadLink.cs Normal file
View File

@@ -0,0 +1,89 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace WebUI.LIB
{
public class BadLink
{
private readonly RequestDelegate _next;
private readonly IWebHostEnvironment _webHostEnvironment;
public BadLink(RequestDelegate next, IWebHostEnvironment webHostEnvironment)
{
_webHostEnvironment = webHostEnvironment;
_next = next;
}
public async Task Invoke(HttpContext context)
{
string url = context.Request.Path.Value;
if (!url.Contains(".jpg"))
{
await _next(context);//走正常流程
return;
}
// 访问来源 其他域名等会记录
string urlReferrer = context.Request.Headers["Referer"];
if (string.IsNullOrWhiteSpace(urlReferrer))//直接访问
{
await _next(context);//走正常流程
// await this.SetForbiddenImage(context, _webHostEnvironment);//返回404图片
}
else if (!urlReferrer.Contains("090"))//非当前域名
{
await this.SetForbiddenImage(context, _webHostEnvironment);//返回404图片
}
else
{
await _next(context);//走正常流程
}
}
/// <summary>
/// 设置拒绝图片
/// </summary>
/// <param name="context"></param>
/// <param name="webHostEnvironment"></param>
/// <returns></returns>
private async Task SetForbiddenImage(HttpContext context, IWebHostEnvironment webHostEnvironment)
{
// 获取访问的图片
string defaultImagePath = webHostEnvironment.WebRootPath + context.Request.Path.Value;// "wwwroot/Document/Img/Forbidden.jpg";
string path = Path.Combine(Directory.GetCurrentDirectory(), defaultImagePath);
// 没有图片
if (!File.Exists(path))
{
await _next(context);//走正常流程
}
Bitmap bmp = new Bitmap(path);
Graphics graph = Graphics.FromImage(bmp);
for (int i = 0; i < 30; i++)
{
var c1 = Color.FromArgb(200, 255, 255, 255);
var c2 = Color.FromArgb(100, 0, 0, 0);
int x = new Random().Next(0, bmp.Width);int y = new Random().Next(0, bmp.Height);
graph.DrawString("小希", new Font("微软雅黑",25), new SolidBrush(c1), new PointF(x-2,y));
graph.DrawString("小希", new Font("微软雅黑", 25), new SolidBrush(c1), new PointF(x +2, y));
graph.DrawString("小希", new Font("微软雅黑", 25), new SolidBrush(c1), new PointF(x , y - 2));
graph.DrawString("小希", new Font("微软雅黑", 25), new SolidBrush(c1), new PointF(x , y+ 2));
graph.DrawString("小希", new Font("微软雅黑", 25), new SolidBrush(c2), new PointF(x, y));
}
MemoryStream ms = null;
ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Jpeg);
byte[] byteImage = new Byte[ms.Length];
byteImage = ms.ToArray();
await context.Response.Body.WriteAsync(byteImage, 0, byteImage.Length);
}
}
}

33
WebUI/LIB/DateTimeStr.cs Normal file
View File

@@ -0,0 +1,33 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace WebUI.LIB
{
/// <summary>
/// 自定义 时间类型 json
/// </summary>
public class DateTimeStr : JsonConverter<DateTime>
{
/// <summary>
/// 格式化时间格式
/// </summary>
public string DateTimeFormat { get; set; } = "yyyy-MM-dd HH:mm:ss";
/// <summary>
/// 读取 父类方法
/// </summary>
/// <param name="reader"></param>
/// <param name="typeToConvert"></param>
/// <param name="options"></param>
/// <returns></returns>
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => DateTime.Parse(reader.GetString());
/// <summary>
/// 写入 格式化
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="options"></param>
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) => writer.WriteStringValue(value.ToString(this.DateTimeFormat));
}
}

89
WebUI/LIB/Jobs.cs Normal file
View File

@@ -0,0 +1,89 @@
using COMMON;
using Models;
using Quartz;
using Serilog;
using SERVER;
using SERVER.DataServer;
using SERVER.LIB;
using System;
using System.Threading.Tasks;
using TcpServer;
namespace WebUI.LIB
{
public class Jobs : IJob
{
// 检测tcp是否运行
public Task Execute(IJobExecutionContext context)
{
return Task.Run(() =>
{
try
{
Tcp.Listener();
//
// Client.Init();
// TestingServices.ISok("BLV RUCS", 1);
}
catch (Exception ex)
{
LogHelp.Error(ex.ToString());
}
});
}
}
public class JobsOne : IJob
{
// 同步数据
public Task Execute(IJobExecutionContext context)
{
return Task.Run(() =>
{
LogHelp.Warning("同步数据:" + DateTime.Now.ToString("G"));
SYNC_DATA.SYNC_DATA_ALL();
});
}
}
public class JobsTwo : IJob
{
public static DateTime first = ConfigEntity.Instance.STARTTIME;
// 统计小时的字节数据等
public Task Execute(IJobExecutionContext context)
{
return Task.Run(() =>
{
try
{
DateTime now = DateTime.Now;
// 阿里sls 的话 只需要定时执行 如下两个方法
if (1 == 1)
{
CHARTSSERVER.GetCHARTS(XC_Data.GetLogDataBase(), new[] { 1, 2, 3, 4 }, new[] { 1, 2, 3, 4 }, first.ToString("yyyy-MM-dd HH:mm:ss"), now.ToString("yyyy-MM-dd HH:mm:ss"));
CHARTSSERVER.GetErrorSucess(XC_Data.GetLogDataBase(), first.ToString("yyyy-MM-dd HH:mm:ss"), now.ToString("yyyy-MM-dd HH:mm:ss"));
}
else
{
CHARTSSERVER.GetProt(first, now);
CHARTSSERVER.GetProt(first, now, "RX");
CHARTSSERVER.GetPROCESSINGTIME(first, now);
CHARTSSERVER.GetRevDelayDateTime(first, now);
CHARTSSERVER.GetCMDpie(first, now);
CHARTSSERVER.GetCMDpie(first, now, "RX");
}
LogHelp.Warning("统计小时的字节数据等:" + first.ToString("G"));
first = now;
}
catch (Exception EX)
{
LogHelp.Warning("统计小时的字节数据等:" + EX.Message.ToString());
}
});
}
}
}