初始化

This commit is contained in:
2025-11-20 14:07:55 +08:00
commit b9b1ff5ed4
318 changed files with 42662 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using CSRedis;
namespace ViewModels.Common
{
/// <summary>
/// Redis缓存辅助类
/// </summary>
public class CSRedisCacheHelper
{
public static CSRedisClient redis;
private static int SessionExpireMinutes = int.Parse(ReadConfig.Instance.get_session_expire_minutes);
//private static int RedisMaxReadPool = int.Parse(ConfigurationManager.AppSettings["redis_max_read_pool"]);
//private static int RedisMaxWritePool = int.Parse(ConfigurationManager.AppSettings["redis_max_write_pool"]);
//private const string ip = "127.0.0.1";
//private const string port = "6379";
//private const string preheat = "100"; // 设置预热连接数
//private const string connectTimeout = "100"; // 设置连接超时时间
//private const string tryit = "1"; // 设置重试次数
//private const string prefix = "CSRedisTest."; // 设置前缀
//private static readonly string _connectString = $"{ip}:{port},preheat={preheat},connectTimeout={connectTimeout},tryit={tryit},prefix={prefix}";
static CSRedisCacheHelper()
{
//var redisHostStr = ConfigurationManager.AppSettings["redis_server_session"];
var redisHostStr = ReadConfig.Instance.get_redis_server_session;
if (!string.IsNullOrEmpty(redisHostStr))
{
//redis = new CSRedisClient(redisHostStr);//+ ",password=,defaultDatabase=0,poolsize=500,ssl=false,writeBuffer=10240,prefix=");
//RedisHelper.Initialization(redis);
//redis = new CSRedisClient[2];
redis = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=1");
//redis[1] = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=1");
}
}
/// <summary>
/// 添加缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
public static void Set<T>(string key, T value)
{
redis.Set(key, value, SessionExpireMinutes * 60);
}
public static T Get<T>(string key)
{
return redis.Get<T>(key);
}
public static void Forever<T>(string key, T value)
{
redis.Set(key, value, -1);
}
public static void Del(string key)
{
redis.Del(key);
}
/// <summary>
/// 判断是否存在
/// </summary>
/// <param name="key"></param>
/// <param name="mac"></param>
/// <returns></returns>
public static bool Contains(string key, string mac)
{
bool result = redis.Exists(mac);
if (!result)
{
result = redis.Exists(key);
}
return result;
}
public static bool Contains(string key)
{
bool result = redis.Exists(key);
return result;
}
/// <summary>
/// 添加Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
public static void HMSet<T>(string key, T value)
{
redis.HMSet(key, value);
}
/// <summary>
/// 获取Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public static T[] HMGet<T>(string key)
{
return redis.HMGet<T>(key);
}
/// <summary>
/// 删除Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public static long HDel<T>(string key)
{
return redis.HDel(key);
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels.Common
{
public class CacheKey
{
public static string RoomIP_Port_Prefix = "Log_IP_Port";
public static string Key = "monitor_host";
public static string MonitorLogPrefix = "AllLogKey";
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace ViewModels.Common
{
public class ReadConfig
{
public static ReadConfig Instance = new ReadConfig();
public IConfiguration? Configuration { get; set; }
public string? MySQLConnectionString { get; set; }
public string? get_monitor_filter { get; set; }
public string? get_session_expire_minutes { get; set; }
public string? get_redis_server_session { get; set; }
public string? get_redis_max_read_pool { get; set; }
public string? get_redis_max_write_pool { get; set; }
public string? MQTT_ServerIP { get; set; }
public int? MQTT_ServerPort { get; set; }
public string? MQTT_User { get; set; }
public string? MQTT_PassWord { get; set; }
public ReadConfig()
{
Configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("app.json").Build();
MySQLConnectionString = Configuration.GetConnectionString("SQLServerConnectionString");
get_session_expire_minutes = Configuration.GetSection("session_expire_minutes").Value;
get_redis_server_session = Configuration.GetSection("redis_server_session").Value;
get_redis_max_read_pool = Configuration.GetSection("redis_max_read_pool").Value;
get_redis_max_write_pool = Configuration.GetSection("redis_max_write_pool").Value;
MQTT_ServerIP = Configuration.GetSection("MQTT_ServerIP").Value;
int p = 1883;
int.TryParse(Configuration.GetSection("MQTT_ServerPort").Value, out p);
MQTT_ServerPort = p;
MQTT_User = Configuration.GetSection("MQTT_User").Value;
MQTT_PassWord = Configuration.GetSection("MQTT_PWD").Value;
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels.RequestData
{
public class LoginData
{
public string username { get; set; }
public string password { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels.ResponseData
{
public class ResLoginData
{
public int ID { get; set; }
public string UserName { get; set; }
public bool IsAdmin { get; set; }
public string AccessToken { get; set; }
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels
{
public class ReturnResult
{
public int Status { get; set; }
public string Message { get; set; }
}
public class QueryAll_Or_Single
{
public bool IsAll { get; set; }
public int ID { get; set; }
}
public class ReturnInfo
{
public bool isok { set; get; } // 是否成功true成功
public string message { set; get; } // 传递接口信息or报错信息
public int status { set; get; } // 服务器报错信息正确为200错误404/500等
public object response { set; get; } // 获取到的信息本体若报错则为null
}
public class ReturnInfoPage : ReturnInfo
{
public long total { set; get; } // 总条数
}
}

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.8.804" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.3" />
<PackageReference Include="RestSharp" Version="112.1.0" />
</ItemGroup>
</Project>