初始化
This commit is contained in:
113
SERVER/LIB/AESHELP.cs
Normal file
113
SERVER/LIB/AESHELP.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
using System.IO;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace SERVER.LIB
|
||||
{
|
||||
/// <summary>
|
||||
/// 暂未使用
|
||||
/// </summary>
|
||||
public class AESHELP
|
||||
{
|
||||
/// <summary>
|
||||
/// AES解密
|
||||
/// <param name="input">密文字节数组</param>
|
||||
/// <param name="key">密钥(16位)</param>
|
||||
/// <returns>返回解密后的字符串</returns>
|
||||
/// </summary>
|
||||
public static string DecryptByAES(string input, string key)
|
||||
{
|
||||
byte[] inputBytes = Convert.FromBase64String(input);
|
||||
byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 16));
|
||||
using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider())
|
||||
{
|
||||
aesAlg.Padding = PaddingMode.PKCS7;
|
||||
aesAlg.Mode = CipherMode.ECB;
|
||||
aesAlg.Key = keyBytes;
|
||||
aesAlg.IV = keyBytes;
|
||||
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
|
||||
using (MemoryStream msEncrypt = new MemoryStream(inputBytes))
|
||||
{
|
||||
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, decryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
using (StreamReader srEncrypt = new StreamReader(csEncrypt))
|
||||
{
|
||||
return srEncrypt.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AES加密算法
|
||||
/// </summary>
|
||||
/// <param name="input">明文字符串</param>
|
||||
/// <param name="key">密钥(16位)</param>
|
||||
/// <returns>字符串</returns>
|
||||
public static string EncryptByAES(string input, string key)
|
||||
{
|
||||
byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 16));
|
||||
using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider())
|
||||
{
|
||||
aesAlg.Padding = PaddingMode.PKCS7;
|
||||
aesAlg.Mode = CipherMode.ECB;
|
||||
aesAlg.Key = keyBytes;
|
||||
aesAlg.IV = keyBytes;
|
||||
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
|
||||
using (MemoryStream msEncrypt = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
|
||||
{
|
||||
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
|
||||
{
|
||||
swEncrypt.Write(input);
|
||||
}
|
||||
byte[] bytes = msEncrypt.ToArray();
|
||||
var ddc = Convert.ToBase64String(bytes);
|
||||
|
||||
byte[] inputBytes = Convert.FromBase64String(ddc);
|
||||
return ddc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 将指定的16进制字符串转换为byte数组
|
||||
/// </summary>
|
||||
/// <param name="s">16进制字符串(如:“7F 2C 4A”或“7F2C4A”都可以)</param>
|
||||
/// <returns>16进制字符串对应的byte数组</returns>
|
||||
public static byte[] HexStringToByteArray(string s)
|
||||
{
|
||||
s = s.Replace(" ", "");
|
||||
byte[] buffer = new byte[s.Length / 2];
|
||||
for (int i = 0; i < s.Length; i += 2)
|
||||
buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将一个byte数组转换成一个格式化的16进制字符串
|
||||
/// </summary>
|
||||
/// <param name="data">byte数组</param>
|
||||
/// <returns>格式化的16进制字符串</returns>
|
||||
public static string ByteArrayToHexString(byte[] data)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(data.Length * 3);
|
||||
foreach (byte b in data)
|
||||
{
|
||||
//16进制数字
|
||||
sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));
|
||||
//16进制数字之间以空格隔开
|
||||
//sb.Append(Convert.ToString(b, 16).PadLeft(2, '0').PadRight(3, ' '));
|
||||
}
|
||||
return sb.ToString().ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
47
SERVER/LIB/DicObject.cs
Normal file
47
SERVER/LIB/DicObject.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER.LIB
|
||||
{
|
||||
public class DicObject<T> where T : new()
|
||||
{
|
||||
public static List<T> GetList(params IDictionary<string, string>[] dic)
|
||||
{
|
||||
List<T> res = new List<T>();
|
||||
Type tp = typeof(T);
|
||||
var info = tp.GetProperties();
|
||||
foreach (var item in dic)
|
||||
{
|
||||
var tump = new T();
|
||||
foreach (var item1 in item)
|
||||
{
|
||||
var v = info.FirstOrDefault(x => x.Name.ToLower() == item1.Key.ToLower());
|
||||
if (v != null && v.CanRead && v.CanWrite && item1.Value != null && item1.Value.ToLower() != "null")
|
||||
{
|
||||
if (!v.PropertyType.IsGenericType)
|
||||
{
|
||||
var val = v.PropertyType.Name == 1.GetType().Name? item1.Value.Split(".")[0]: item1.Value;
|
||||
v.SetValue(tump, string.IsNullOrEmpty(val) ? null : Convert.ChangeType(val, v.PropertyType),null);
|
||||
}
|
||||
else
|
||||
{
|
||||
//泛型Nullable<>
|
||||
Type genericTypeDefinition = v.PropertyType.GetGenericTypeDefinition();
|
||||
if (genericTypeDefinition == typeof(Nullable<>))
|
||||
{
|
||||
v.SetValue(tump, string.IsNullOrEmpty(item1.Value) ? null : Convert.ChangeType(item1.Value, Nullable.GetUnderlyingType(v.PropertyType)), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
res.Add(tump);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
104
SERVER/LIB/HOTEL_GROUPHelp.cs
Normal file
104
SERVER/LIB/HOTEL_GROUPHelp.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER.LIB
|
||||
{
|
||||
/// <summary>
|
||||
/// 大部分方法已经弃用
|
||||
/// </summary>
|
||||
public class HOTEL_GROUPHelp
|
||||
{
|
||||
static List<TBL_HOTEL_GROUP_INFO> data => CacheData.TBL_HOTEL_GROUP_INFO;
|
||||
static List<TBL_HOTEL_BASIC_INFO> tBL_HOTEL_s => CacheData.TBL_HOTEL_BASIC_INFO;
|
||||
|
||||
public static List<TBL_HOTEL_GROUP_INFO> Children(int data)
|
||||
{
|
||||
List<TBL_HOTEL_GROUP_INFO> res = new List<TBL_HOTEL_GROUP_INFO>();
|
||||
var resdata = CacheData.TBL_HOTEL_GROUP_INFO.Where(x => x.PARENT_ID == data).ToList();
|
||||
res.AddRange(resdata);
|
||||
foreach (var item in resdata)
|
||||
{
|
||||
res.AddRange(Children(item.HOTEL_GROUP_ID));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static List<TBL_HOTEL_GROUP_INFO> GetTreemap(IList<HotelDataItem> dataItems)
|
||||
{
|
||||
List<TBL_HOTEL_GROUP_INFO> treemaps = new List<TBL_HOTEL_GROUP_INFO>();
|
||||
|
||||
foreach (var tump in dataItems)
|
||||
{
|
||||
if (treemaps.FirstOrDefault(X => X.HOTEL_GROUP_ID == tump.HotelGroupsId) == null)
|
||||
{
|
||||
treemaps.AddRange(Parent(tump.HotelGroupsId));
|
||||
};
|
||||
|
||||
}
|
||||
return treemaps.GroupBy(x => x.HOTEL_GROUP_ID).Select(y => y.First()).ToList();
|
||||
}
|
||||
|
||||
public static List<TBL_HOTEL_GROUP_INFO> Parent(int ID)
|
||||
{
|
||||
|
||||
List<TBL_HOTEL_GROUP_INFO> res = new List<TBL_HOTEL_GROUP_INFO>();
|
||||
var item = data.Single(x => x.HOTEL_GROUP_ID == ID);
|
||||
res.Add(item);
|
||||
if (item.PARENT_ID != 0)
|
||||
{
|
||||
res.AddRange(Parent(item.PARENT_ID));
|
||||
}
|
||||
return res.GroupBy(x => x.HOTEL_GROUP_ID).Select(y => y.First()).ToList();
|
||||
}
|
||||
|
||||
|
||||
public static List<TBL_HOTEL_BASIC_INFO> GetHotels(List<HotelsItem> hoteldata, int GroupId)
|
||||
{
|
||||
List<TBL_HOTEL_BASIC_INFO> res = new List<TBL_HOTEL_BASIC_INFO>();
|
||||
var Group = Children(GroupId);
|
||||
foreach (var item in Group)
|
||||
{
|
||||
res.AddRange(GetHotels(item.HOTEL_GROUP_ID).Where(x=> hoteldata.FirstOrDefault(y=>y.HotelId == x.IDOLD)!=null));
|
||||
}
|
||||
res = res.GroupBy(x => x.HOTEL_ID).Select(y => y.First()).ToList();
|
||||
for (int i = 0; i < res.Count; i++)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
throw new Exception();
|
||||
|
||||
}
|
||||
// 获取酒店组下面的所有直属酒店
|
||||
public static IEnumerable< TBL_HOTEL_BASIC_INFO > GetHotels( int GroupId)
|
||||
{
|
||||
return tBL_HOTEL_s.Where(x => x.HOTEL_GROUP == GroupId);
|
||||
}
|
||||
|
||||
public static string Getgrouppath(TBL_HOTEL_BASIC_INFO hot )
|
||||
{
|
||||
string res = string.Empty;
|
||||
int group = hot.HOTEL_GROUP;
|
||||
while (true)
|
||||
{
|
||||
if(group == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (res == string.Empty)
|
||||
{
|
||||
res += data.First(X => X.HOTEL_GROUP_ID == group).HOTEL_GROUP_NAME;
|
||||
}
|
||||
else
|
||||
{
|
||||
res += "-";
|
||||
res += data.First(X => X.HOTEL_GROUP_ID == group).HOTEL_GROUP_NAME;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
SERVER/LIB/LogHelp.cs
Normal file
63
SERVER/LIB/LogHelp.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
using System.IO;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using log4net;
|
||||
|
||||
namespace SERVER.LIB
|
||||
{
|
||||
public static class LogHelp_
|
||||
{
|
||||
private static object locks = new object();
|
||||
private static string path = Directory.GetCurrentDirectory();
|
||||
public static string time = string.Empty;
|
||||
private static ILog log = LogManager.GetLogger("All");
|
||||
public static void Init()
|
||||
{
|
||||
if (time == string.Empty) {
|
||||
lock (locks)
|
||||
{
|
||||
if (time == string.Empty)
|
||||
{
|
||||
time = DateTime.Now.ToString("yyyy_MM_dd");
|
||||
string pathurl = path + "\\App_Data\\Log\\XC.log";
|
||||
Directory.CreateDirectory(path + "\\App_Data\\Log");
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Warning()
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File(pathurl, // 日志文件名
|
||||
outputTemplate: // 设置输出格式,显示详细异常信息
|
||||
@"{Timestamp:yyyy-MM-dd HH:mm-ss.fff }[{Level:u3}] {Message:lj}{NewLine}{Exception}",
|
||||
rollingInterval: RollingInterval.Day, // 日志按day保存
|
||||
rollOnFileSizeLimit: true, // 限制单个文件的最大长度
|
||||
encoding: Encoding.UTF8, // 文件字符编码
|
||||
retainedFileCountLimit: 10, // 最大保存文件数
|
||||
fileSizeLimitBytes: 5000 * 1024) // 最大单个文件长度 5m
|
||||
.CreateLogger();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Error(string msg)
|
||||
{
|
||||
Init();
|
||||
Log.Error(msg);
|
||||
log.Error(msg);
|
||||
}
|
||||
|
||||
public static void Warning(string msg)
|
||||
{
|
||||
Init();
|
||||
Log.Warning(msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
71
SERVER/LIB/TestingServices.cs
Normal file
71
SERVER/LIB/TestingServices.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceProcess;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using COMMON;
|
||||
|
||||
namespace SERVER.LIB
|
||||
{
|
||||
public class TestingServices
|
||||
{
|
||||
public static object lockers = new object();
|
||||
/// <summary>
|
||||
/// 检测本机指定服务 仅仅 windows
|
||||
/// </summary>
|
||||
/// <param name="type">0 只是返回状态 1 启动 2 重启 3 停止</param>
|
||||
/// <param name="name">名字</param>
|
||||
/// <returns>0 不存在 2 未运行 1 已经运行</returns>
|
||||
public static int ISok(string name = "", int type = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
#region RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
//获取指定服务,若服务状态不是Runing就Start该服务
|
||||
#pragma warning disable CA1416 // 验证平台兼容性
|
||||
var server = ServiceController.GetServices().FirstOrDefault(service => service.ServiceName == name);
|
||||
if (server == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (type != 0)
|
||||
{
|
||||
lock (lockers)
|
||||
{
|
||||
string path = Directory.GetCurrentDirectory() + "\\App_Data\\Server";
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 1:
|
||||
if (server.Status != ServiceControllerStatus.Running)
|
||||
{
|
||||
File.WriteAllText(path + "\\Server.xcljj", type.ToString());
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
File.WriteAllText(path + "\\Server.xcljj", type.ToString());
|
||||
break;
|
||||
case 3:
|
||||
File.WriteAllText(path + "\\Server.xcljj", type.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//开启后再检测一次
|
||||
return type != 0 ? ISok() : (server.Status == ServiceControllerStatus.Running ? 1 : 2);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error("服务操作失败!" + ex.ToString());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
89
SERVER/LIB/WEBHELP.cs
Normal file
89
SERVER/LIB/WEBHELP.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using COMMON;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER.LIB
|
||||
{
|
||||
public class WEBHELP: UtilsSharp.WebHelper
|
||||
{
|
||||
public T Get<T>(string url, int Timeout = 10000)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = "GET";
|
||||
request.ContentType = "text/html;charset=UTF-8";
|
||||
request.UserAgent = null;
|
||||
request.Timeout = Timeout;
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
Stream myResponseStream = response.GetResponseStream();
|
||||
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
||||
string retString = myStreamReader.ReadToEnd();
|
||||
myStreamReader.Close();
|
||||
myResponseStream.Close();
|
||||
if (!string.IsNullOrEmpty(retString))
|
||||
return JsonConvert.DeserializeObject<T>(retString);
|
||||
else
|
||||
return default(T);
|
||||
}
|
||||
/// <summary>
|
||||
/// 指定Post地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求后台地址</param>
|
||||
/// <param name="dic">请求后台地址</param>
|
||||
/// <returns></returns>
|
||||
public T Post<T>(string url, Dictionary<string, object> dic)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
else
|
||||
{
|
||||
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user