初始化
This commit is contained in:
122
SERVER/CacheData.cs
Normal file
122
SERVER/CacheData.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using COMMON;
|
||||
using DB_Server;
|
||||
using Models;
|
||||
using Models.Models;
|
||||
using Models.Models.LOGDB;
|
||||
using SERVER.LIB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存信息列表
|
||||
/// </summary>
|
||||
public class CacheData
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存枚举
|
||||
/// </summary>
|
||||
public enum CacheDataEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 酒店组缓存
|
||||
/// </summary>
|
||||
TBL_HOTEL_GROUP_INFO,
|
||||
/// <summary>
|
||||
/// 酒店缓存
|
||||
/// </summary>
|
||||
TBL_HOTEL_BASIC_INFO,
|
||||
/// <summary>
|
||||
/// 房型列表
|
||||
/// </summary>
|
||||
TBL_ROOM_TYPE_LIST,
|
||||
/// <summary>
|
||||
/// 模型文件数据
|
||||
/// </summary>
|
||||
TBL_MODEL_FILE_DATA,
|
||||
/// <summary>
|
||||
/// ruc
|
||||
/// </summary>
|
||||
TBL_RCU_BASIC_INFO
|
||||
}
|
||||
/// <summary>
|
||||
/// UDPlog 数量 10 分钟有效
|
||||
/// </summary>
|
||||
public static int UDPcount => int.Parse(
|
||||
XC_Redis.Redis.GET("Getudplogcount", () =>
|
||||
{
|
||||
return new ASLS().GetLogs_(0, "* | select count(*) sum", ConfigEntity.Instance.STARTTIME, DateTime.Now).Result[0]["sum"];
|
||||
}
|
||||
, 60 * 10));
|
||||
|
||||
/// <summary>
|
||||
/// TBL_HOTEL_GROUP_INFO 酒店分组
|
||||
/// </summary>
|
||||
public static List<TBL_HOTEL_GROUP_INFO> TBL_HOTEL_GROUP_INFO { get { return GetData<TBL_HOTEL_GROUP_INFO>("TBL_HOTEL_GROUP_INFO", DbHelperSQL.DBSel.BLV_RCU_DB); } }
|
||||
|
||||
/// <summary>
|
||||
/// rcu
|
||||
/// </summary>
|
||||
public static List<TBL_RCU_BASIC_INFO> TBL_RCU_BASIC_INFO { get { return GetData<TBL_RCU_BASIC_INFO>("TBL_RCU_BASIC_INFO", DbHelperSQL.DBSel.BLV_RCU_DB); } }
|
||||
|
||||
/// <summary>
|
||||
/// 模型文件数据
|
||||
/// </summary>
|
||||
public static List<TBL_MODEL_FILE_DATA> TBL_MODEL_FILE_DATA { get { return GetData<TBL_MODEL_FILE_DATA>("TBL_MODEL_FILE_DATA", DbHelperSQL.DBSel.BLV_RCU_DB,10); } }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 酒店表
|
||||
/// </summary>
|
||||
public static List<TBL_HOTEL_BASIC_INFO> TBL_HOTEL_BASIC_INFO { get { return GetData<TBL_HOTEL_BASIC_INFO>("TBL_HOTEL_BASIC_INFO", DbHelperSQL.DBSel.BLV_RCU_DB); } }
|
||||
/// <summary>
|
||||
/// TBL_ROOM_TYPE_LIST 房型表
|
||||
/// </summary>
|
||||
public static List<TBL_ROOM_TYPE_LIST> TBL_ROOM_TYPE_LIST { get { return GetData<TBL_ROOM_TYPE_LIST>("TBL_ROOM_TYPE_LIST", DbHelperSQL.DBSel.BLV_RCU_DB); } }
|
||||
|
||||
/// <summary>
|
||||
/// 公共的获取缓存方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="dB"></param>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
private static List<T> GetData<T>(string name, DbHelperSQL.DBSel dB,int time = -1) where T : new()
|
||||
{
|
||||
return XC_Redis.Redis.GET(name, () =>
|
||||
{
|
||||
var data = new DbHelperSQL(dB);
|
||||
return UtilsSharp.DataTableHelper.ToEntities<T>(data.ExecuteTable("select * from " + name));
|
||||
}, time
|
||||
);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 清除指定缓存 或者全部缓存
|
||||
/// </summary>
|
||||
/// <param name="cache"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Clear(CacheDataEnum? cache)
|
||||
{
|
||||
if (cache == null)
|
||||
{
|
||||
foreach (int myCode in Enum.GetValues(typeof(CacheDataEnum)))
|
||||
{
|
||||
string strName = Enum.GetName(typeof(CacheDataEnum), myCode);//获取名称
|
||||
if (!XC_Redis.Redis.Remove(strName))
|
||||
{
|
||||
return false;
|
||||
};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return XC_Redis.Redis.Remove(cache.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
115
SERVER/ConvertFile.cs
Normal file
115
SERVER/ConvertFile.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件帮助类
|
||||
/// </summary>
|
||||
public static class ConvertFile
|
||||
{
|
||||
/// <summary>
|
||||
/// 转换二进制(Bin文件)
|
||||
/// </summary>
|
||||
/// <param name="Path"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadDat(Stream Path)
|
||||
{
|
||||
try
|
||||
{
|
||||
//FileStream myStream = new FileStream(Path, FileMode.Open, FileAccess.Read);
|
||||
//使用FileStream对象实例化BinaryReader二进制写入流对象
|
||||
BinaryReader myReader = new BinaryReader(Path);
|
||||
if (myReader.PeekChar() != -1)
|
||||
{
|
||||
//以二进制方式读取文件中的内容
|
||||
return Convert.ToString(myReader.ReadString());
|
||||
}
|
||||
//关闭当前二进制读取流
|
||||
myReader.Close();
|
||||
//关闭当前文件流
|
||||
Path.Close();
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件
|
||||
/// </summary>
|
||||
/// <param name="stream"></param>
|
||||
/// <returns></returns>
|
||||
public static string StreamToString(Stream stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转成二进制
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
public static string bianma(string s)
|
||||
{
|
||||
byte[] data = Encoding.Unicode.GetBytes(s);
|
||||
StringBuilder result = new StringBuilder(data.Length * 8);
|
||||
|
||||
foreach (byte b in data)
|
||||
{
|
||||
result.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 对hex文件处理
|
||||
/// </summary>
|
||||
/// <param name="RE"></param>
|
||||
public static string hexData(string RE)
|
||||
{
|
||||
//存储总数据
|
||||
string data = "";
|
||||
//获取每行
|
||||
var setd = RE.Split(":");
|
||||
|
||||
for (int i = 0; i < setd.Length; i++)
|
||||
{
|
||||
if (setd[i] != "")
|
||||
|
||||
{
|
||||
if (setd[i].Substring(6, 2) == "00")
|
||||
{
|
||||
|
||||
|
||||
int hand = int.Parse(setd[i].Substring(0, 2)) * 2;
|
||||
if(int.Parse(setd[i].Substring(0, 2)) == 10)
|
||||
{
|
||||
hand = 32;
|
||||
}
|
||||
data += setd[i].Substring(8, hand);
|
||||
}
|
||||
//for (int j = 0; j < int.Parse(setd[i].Substring(0,1)); j++)
|
||||
//{
|
||||
// setd[i].Substring(2 * j + 9, 2);
|
||||
//}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
1911
SERVER/DataServer/CHARTSSERVER.cs
Normal file
1911
SERVER/DataServer/CHARTSSERVER.cs
Normal file
File diff suppressed because it is too large
Load Diff
161
SERVER/FTPOperation.cs
Normal file
161
SERVER/FTPOperation.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using COMMON;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
public class FTPOperation
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从FTP中获取文件
|
||||
/// </summary>
|
||||
/// <param name="url">路径</param>
|
||||
/// <returns></returns>
|
||||
public byte[] GetFile(string url)
|
||||
{
|
||||
//Logs.WriteLog("222获取图片开始"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"));
|
||||
|
||||
url = "ftp://auth.blv-oa.com:50/BLV_Studio/Data/"+ url;
|
||||
FtpWebRequest ftpWeb;
|
||||
try
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
new RemoteCertificateValidationCallback(ValidateServerCertificate);
|
||||
try
|
||||
{
|
||||
ftpWeb = (FtpWebRequest)FtpWebRequest.Create(url);//创建ftp连接
|
||||
ftpWeb.Credentials = new NetworkCredential("uts_manager", "uts_Inhaos@all");//账号,密码
|
||||
ftpWeb.KeepAlive = false;
|
||||
ftpWeb.EnableSsl = false;
|
||||
ftpWeb.Method = WebRequestMethods.Ftp.DownloadFile;
|
||||
ftpWeb.UseBinary = true;
|
||||
ftpWeb.UsePassive = true;
|
||||
WebResponse ftpResponse = (FtpWebResponse)ftpWeb.GetResponse();
|
||||
Stream ftpStream = ftpResponse.GetResponseStream();//获取流
|
||||
MemoryStream outstream = new MemoryStream();//转成MS流
|
||||
int bufferLen = 4096;//缓冲区
|
||||
byte[] buffer = new byte[bufferLen];
|
||||
int count = 0;
|
||||
while ((count = ftpStream.Read(buffer, 0, bufferLen)) > 0)
|
||||
{
|
||||
outstream.Write(buffer, 0, count);
|
||||
}
|
||||
var FileLiu = outstream.ToArray();
|
||||
ftpResponse.Close();
|
||||
ftpStream.Close();
|
||||
outstream.Close();
|
||||
return FileLiu;
|
||||
//return BytesToStream(FileLiu);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// 将 byte[] 转成 Stream
|
||||
public Stream BytesToStream(byte[] bytes)
|
||||
{
|
||||
Stream stream = new MemoryStream(bytes);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public string UnHexs(string hex)
|
||||
{
|
||||
if (hex == null)
|
||||
throw new ArgumentNullException("hex");
|
||||
hex = hex.Replace(",", "");
|
||||
hex = hex.Replace("\n", "");
|
||||
hex = hex.Replace("\\", "");
|
||||
hex = hex.Replace(" ", "");
|
||||
if (hex.Length % 2 != 0)
|
||||
{
|
||||
hex += "20";//空格
|
||||
}
|
||||
// 需要将 hex 转换成 byte 数组。
|
||||
byte[] bytes = new byte[hex.Length / 2];
|
||||
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 每两个字符是一个 byte。
|
||||
bytes[i] = byte.Parse(hex.Substring(i * 2, 2),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Rethrow an exception with custom message.
|
||||
throw new ArgumentException("hex is not a valid hex number!", "hex");
|
||||
}
|
||||
}
|
||||
System.Text.Encoding chs = System.Text.Encoding.GetEncoding("UTF-8");
|
||||
return chs.GetString(bytes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 字节数组转换成十六进制字符串
|
||||
/// </summary>
|
||||
/// <param name="bytes">要转换的字节数组</param>
|
||||
|
||||
/// <returns></returns>
|
||||
public string ByteArrayToHexStr(byte[] byteArray)
|
||||
{
|
||||
int capacity = byteArray.Length * 2;
|
||||
StringBuilder sb = new StringBuilder(capacity);
|
||||
|
||||
if (byteArray != null)
|
||||
{
|
||||
for (int i = 0; i < byteArray.Length; i++)
|
||||
{
|
||||
sb.Append(byteArray[i].ToString("X2"));
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 无证书时跳过不报错
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="certificate"></param>
|
||||
/// <param name="chain"></param>
|
||||
/// <param name="sslPolicyErrors"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ValidateServerCertificate
|
||||
(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
591
SERVER/HexFile.cs
Normal file
591
SERVER/HexFile.cs
Normal file
@@ -0,0 +1,591 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
/// <summary>
|
||||
/// Hex文件处理
|
||||
/// </summary>
|
||||
public class HexFile
|
||||
{
|
||||
/// <summary> 加载文件大小 </summary>
|
||||
private const int _loadFileSize = 1024 * 1024 * 2;
|
||||
|
||||
/// <summary> 加载数据大小 </summary>
|
||||
private const int _loadDataSize = 1024 * 1024 * 2;
|
||||
|
||||
/// <summary> 加载Hex文件数据 </summary>
|
||||
private byte[] _LoadHexFileData = new byte[_loadFileSize];
|
||||
|
||||
/// <summary> 加载数据Buff </summary>
|
||||
private byte[] _LoadDataBuff = new byte[_loadDataSize];
|
||||
|
||||
/// <summary> 加载结束地址 </summary>
|
||||
private int _LoadEndAddr;
|
||||
|
||||
/// <summary> C1-Hex文件起始值 </summary>
|
||||
private int _HexStart_C1 = 0;
|
||||
|
||||
/// <summary> 解析出的文件数据 </summary>
|
||||
private byte[] _ParseData;
|
||||
|
||||
/// <summary> 解析出的配置数据 </summary>
|
||||
private byte[] _ParseConfigData;
|
||||
|
||||
|
||||
/// <summary> 匹配起始值 </summary>
|
||||
private int _matchingValue;
|
||||
|
||||
private readonly int _matchingAddr = 49152; //0xC000 匹配数据起始地址
|
||||
|
||||
|
||||
|
||||
/// <summary> 匹配数据 </summary>
|
||||
private byte[] _matchingData = new byte[512];
|
||||
|
||||
/// <summary>
|
||||
/// 解析Hex文件
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
public byte[] DealHexFile(Stream filePath)
|
||||
{
|
||||
|
||||
bool tmpRet = LoadDataFromFile(filePath);
|
||||
byte[] checkSum = new byte[4];
|
||||
|
||||
int tmpIdx = 0;
|
||||
int tmpLineCnt = 1;
|
||||
int tmpHexValidLenght = _LoadEndAddr - _HexStart_C1;
|
||||
|
||||
if (tmpRet)
|
||||
{
|
||||
StringBuilder parse = new StringBuilder();
|
||||
//Dim tmpStrBuffer As String
|
||||
for (tmpIdx = _HexStart_C1; tmpIdx < _LoadEndAddr; tmpIdx++)
|
||||
{
|
||||
parse.Append(HexByteStr(_LoadDataBuff[tmpIdx])); //<10ms
|
||||
}
|
||||
_ParseData = ConvertHexStringToBytes(parse.ToString());
|
||||
|
||||
Array.Copy(_ParseData, _matchingValue, _matchingData, 0, _matchingData.Length);
|
||||
//Console.WriteLine($"——解析匹配数据——:{vbCrLf}{BitConverter.ToString(_matchingData)}")
|
||||
|
||||
|
||||
|
||||
//'Dim a() As Byte = {&H0}
|
||||
//'Dim b As String = Encoding.GetEncoding("GBK").GetString(a)
|
||||
|
||||
|
||||
////_matchingData
|
||||
//byte[] project = new byte[2]; //项目编码 2 Bytes
|
||||
//Array.Copy(_matchingData, 0, project, 0, project.Length);
|
||||
////Dim projects As String = Encoding.GetEncoding("GBK").GetString(project)
|
||||
//string projects = $"{project[0] + project[1] * 256}";
|
||||
//projects = projects.Replace("\0", "");
|
||||
|
||||
//byte[] roomId = new byte[4]; //房型Id 4 Bytes
|
||||
//Array.Copy(_matchingData, project.Length, roomId, 0, roomId.Length);
|
||||
////Dim roomIds As String = Encoding.GetEncoding("GBK").GetString(roomId)
|
||||
//string roomIds = $"{BitConverter.ToUInt32(roomId, 0)}";
|
||||
//roomIds = roomIds.Replace("\0", "");
|
||||
|
||||
//byte[] version = new byte[20]; //版本号 20 Bytes
|
||||
//Array.Copy(_matchingData, (project.Length + roomId.Length), version, 0, version.Length);
|
||||
//string versions = Encoding.GetEncoding("GBK").GetString(version);
|
||||
//versions = versions.Replace("\0", "");
|
||||
|
||||
//byte[] mcu = new byte[16]; //MCU型号 16 Bytes
|
||||
//Array.Copy(_matchingData, (project.Length + roomId.Length + version.Length), mcu, 0, mcu.Length);
|
||||
//string mcus = Encoding.GetEncoding("GBK").GetString(mcu);
|
||||
//mcus = mcus.Replace("\0", "");
|
||||
|
||||
//byte[] central = new byte[16]; //中控型号 16 Bytes
|
||||
//Array.Copy(_matchingData, (project.Length + roomId.Length + version.Length + mcu.Length), central, 0, central.Length);
|
||||
//string centrals = Encoding.GetEncoding("GBK").GetString(central);
|
||||
//centrals = centrals.Replace("\0", "");
|
||||
|
||||
//byte[] remark = new byte[64]; //备注 64 Bytes
|
||||
//Array.Copy(_matchingData, (project.Length + roomId.Length + version.Length + mcu.Length + central.Length), remark, 0, remark.Length);
|
||||
// string remarks = Encoding.GetEncoding("GBK").GetString(remark);
|
||||
//remarks = remarks.Replace("\0", "");
|
||||
|
||||
////MatchingInfo(projects, roomIds, versions, mcus, centrals, remarks);
|
||||
}
|
||||
return _ParseData;
|
||||
}
|
||||
|
||||
public string Get_HexStart_C1()
|
||||
{
|
||||
return HexStringToBytes(_HexStart_C1);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取Hex文件中信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetHexInfo()
|
||||
{
|
||||
//_matchingData
|
||||
byte[] project = new byte[2]; //项目编码 2 Bytes
|
||||
Array.Copy(_matchingData, 0, project, 0, project.Length);
|
||||
//Dim projects As String = Encoding.GetEncoding("GBK").GetString(project)
|
||||
string projects = $"{project[0] + project[1] * 256}";
|
||||
projects = projects.Replace("\0", "");
|
||||
|
||||
byte[] roomId = new byte[4]; //房型Id 4 Bytes
|
||||
Array.Copy(_matchingData, project.Length, roomId, 0, roomId.Length);
|
||||
//Dim roomIds As String = Encoding.GetEncoding("GBK").GetString(roomId)
|
||||
string roomIds = $"{BitConverter.ToUInt32(roomId, 0)}";
|
||||
roomIds = roomIds.Replace("\0", "");
|
||||
|
||||
byte[] version = new byte[20]; //版本号 20 Bytes
|
||||
Array.Copy(_matchingData, (project.Length + roomId.Length), version, 0, version.Length);
|
||||
string versions = Encoding.GetEncoding("GBK").GetString(version);
|
||||
versions = versions.Replace("\0", "");
|
||||
|
||||
byte[] mcu = new byte[16]; //MCU型号 16 Bytes
|
||||
Array.Copy(_matchingData, (project.Length + roomId.Length + version.Length), mcu, 0, mcu.Length);
|
||||
string mcus = Encoding.GetEncoding("GBK").GetString(mcu);
|
||||
mcus = mcus.Replace("\0", "");
|
||||
|
||||
byte[] central = new byte[16]; //中控型号 16 Bytes
|
||||
Array.Copy(_matchingData, (project.Length + roomId.Length + version.Length + mcu.Length), central, 0, central.Length);
|
||||
string centrals = Encoding.GetEncoding("GBK").GetString(central);
|
||||
centrals = centrals.Replace("\0", "");
|
||||
|
||||
byte[] remark = new byte[64]; //备注 64 Bytes
|
||||
Array.Copy(_matchingData, (project.Length + roomId.Length + version.Length + mcu.Length + central.Length), remark, 0, remark.Length);
|
||||
string remarks = Encoding.GetEncoding("GBK").GetString(remark);
|
||||
remarks = remarks.Replace("\0", "");
|
||||
|
||||
return centrals;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载hex文件数据
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
private bool LoadDataFromFile(Stream path)
|
||||
{
|
||||
Array.Clear(_LoadHexFileData, 0, _LoadHexFileData.Length);
|
||||
try
|
||||
{
|
||||
//System.IO.Stream fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||
if (path.Length <= _loadFileSize)
|
||||
{
|
||||
path.Read(_LoadHexFileData, 0, (int)path.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
path.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return HexFileToData(_LoadHexFileData, _LoadDataBuff, ref _LoadEndAddr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private string HexByteStr(byte hexByte)
|
||||
{
|
||||
if (hexByte < 16)
|
||||
{
|
||||
return "0" + Convert.ToString(hexByte, 16).ToUpper();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Convert.ToString(hexByte, 16).ToUpper();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 解析Hex文件到Byte数组
|
||||
/// </summary>
|
||||
/// <param name="hexBuffer"></param>
|
||||
/// <param name="dataBuffer"></param>
|
||||
/// <param name="endAddr"></param>
|
||||
/// <returns></returns>
|
||||
private bool HexFileToData(byte[] hexBuffer, byte[] dataBuffer, ref int endAddr)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
//行数
|
||||
int LineCnt = 0;
|
||||
int DataType_00_Idx = 0;
|
||||
|
||||
//清空数据缓存区域
|
||||
for (i = 0; i < dataBuffer.Length; i++)
|
||||
{
|
||||
dataBuffer[i] = 0xFF;
|
||||
}
|
||||
|
||||
//本行数据缓存
|
||||
byte[] dataStrBuf = new byte[32];
|
||||
byte[] dataValBuf = new byte[16];
|
||||
|
||||
//首地址标记
|
||||
bool headAddrFlag = true;
|
||||
|
||||
//本行地址值
|
||||
int tmpLineAdd = 0;
|
||||
|
||||
//偏移地址 0x04 数据类型指示偏移地址
|
||||
int LineAddOffestBase = 0;
|
||||
|
||||
//结束地址
|
||||
endAddr = 0;
|
||||
|
||||
byte[] flashAddressBuf = new byte[4];
|
||||
int flashAddress = 0;
|
||||
|
||||
//INSTANT C# NOTE: The ending condition of VB 'For' loops is tested only on entry to the loop. Instant C# has created a temporary variable in order to use the initial value of hexBuffer.Length for every iteration:
|
||||
int tempVar = hexBuffer.Length;
|
||||
for (i = 0; i < tempVar; i++)
|
||||
{
|
||||
//首先找到冒号
|
||||
if (hexBuffer[i] == 0x3A) //&H3A = ":"
|
||||
{
|
||||
LineCnt += 1;
|
||||
//B0:数据长度
|
||||
int dataLen = (StrToHex(hexBuffer[i + 1]) * 16 + StrToHex(hexBuffer[i + 2]));
|
||||
if (dataLen > 0)
|
||||
{
|
||||
//By:CheckSum
|
||||
byte checkSum = (byte)(StrToHex(hexBuffer[i + 9 + dataLen * 2]) * 16 + StrToHex(hexBuffer[i + 10 + dataLen * 2]));
|
||||
|
||||
//取出整行数据
|
||||
byte[] rowDataStrBuf = new byte[42];
|
||||
byte[] rowDataValBuf = new byte[21];
|
||||
int rowLen = 0;
|
||||
Array.Clear(rowDataStrBuf, 0, 42);
|
||||
Array.Clear(rowDataValBuf, 0, 21);
|
||||
|
||||
rowLen = (dataLen * 2) + 10;
|
||||
Array.Copy(hexBuffer, i + 1, rowDataStrBuf, 0, rowLen);
|
||||
StrToHex(rowDataValBuf, rowDataStrBuf, Convert.ToUInt16(rowLen / 2.0));
|
||||
|
||||
//using System;
|
||||
|
||||
int tempVar2 = Convert.ToInt32(rowLen / 2.0);
|
||||
byte tempCheckSum = GetSumChecks(rowDataValBuf, ref tempVar2);
|
||||
|
||||
if (tempCheckSum != 0xFF)
|
||||
{
|
||||
return false; //CheckSum校验不通过,返回错误
|
||||
}
|
||||
|
||||
//B4~Bx:数据内容
|
||||
Array.Clear(dataStrBuf, 0, 32);
|
||||
Array.Clear(dataValBuf, 0, 16);
|
||||
Array.Copy(hexBuffer, i + 9, dataStrBuf, 0, dataLen * 2);
|
||||
StrToHex(dataValBuf, dataStrBuf, (UInt16)dataLen);
|
||||
}
|
||||
|
||||
//B1~B2:取出地址位的值
|
||||
Array.Copy(hexBuffer, i + 3, flashAddressBuf, 0, 4);
|
||||
|
||||
//本行地址取出来放在 flashAddress中’
|
||||
UInt16 tempVar3 = (UInt16)tmpLineAdd;
|
||||
StrToHex(ref tempVar3, flashAddressBuf);
|
||||
tmpLineAdd = tempVar3;
|
||||
flashAddress = LineAddOffestBase + tmpLineAdd;
|
||||
|
||||
//B3:数据类型
|
||||
var dataType = StrToHex(hexBuffer[i + 8]);
|
||||
switch (dataType)
|
||||
{
|
||||
case 0: //数据记录
|
||||
DataType_00_Idx = DataType_00_Idx + 1;
|
||||
//将第一个00类型数据的地址作为起始地址, 保存到 _HexStart_C1
|
||||
if (DataType_00_Idx == 1)
|
||||
{
|
||||
_HexStart_C1 = flashAddress;
|
||||
_matchingValue = _matchingAddr - _HexStart_C1;
|
||||
}
|
||||
Array.Copy(dataValBuf, 0, dataBuffer, flashAddress, dataLen);
|
||||
endAddr = flashAddress + dataLen;
|
||||
break;
|
||||
case 1: //文件结束
|
||||
if (endAddr == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 5: //扩展段地址, 开始段地址, 开始线性地址’
|
||||
continue;
|
||||
case 4: //扩展线性地址
|
||||
if (dataLen == 2)
|
||||
{
|
||||
LineAddOffestBase = (dataValBuf[0] * 256 + dataValBuf[1]) * 65536;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; //确认DataLen必须是2,否则报错
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static void StrToHex(byte[] pbDest, byte[] pbSrc, UInt16 nLen)
|
||||
{
|
||||
byte h1 = 0;
|
||||
byte h2 = 0;
|
||||
byte s1 = 0;
|
||||
byte s2 = 0;
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < nLen; i++)
|
||||
{
|
||||
h1 = pbSrc[2 * i];
|
||||
h2 = pbSrc[2 * i + 1];
|
||||
|
||||
s1 = (byte)(toupper(h1) - 0x30);
|
||||
if (s1 > 9)
|
||||
{
|
||||
s1 -= 7;
|
||||
}
|
||||
|
||||
s2 = (byte)(toupper(h2) - 0x30);
|
||||
if (s2 > 9)
|
||||
{
|
||||
s2 -= 7;
|
||||
}
|
||||
|
||||
pbDest[i] = (byte)(s1 * 16 + s2);
|
||||
}
|
||||
}
|
||||
|
||||
private void StrToHex(ref UInt16 pbDest, byte[] pbSrc)
|
||||
{
|
||||
byte[] pBufDest = new byte[2];
|
||||
byte h1 = 0;
|
||||
byte h2 = 0;
|
||||
byte s1 = 0;
|
||||
byte s2 = 0;
|
||||
UInt16 i = 0;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
h1 = pbSrc[2 * i];
|
||||
h2 = pbSrc[2 * i + 1];
|
||||
|
||||
s1 = (byte)(toupper(h1) - 0x30);
|
||||
if (s1 > 9)
|
||||
{
|
||||
s1 -= 7;
|
||||
}
|
||||
|
||||
s2 = (byte)(toupper(h2) - 0x30);
|
||||
if (s2 > 9)
|
||||
{
|
||||
s2 -= 7;
|
||||
}
|
||||
|
||||
pBufDest[i] = (byte)(s1 * 16 + s2);
|
||||
}
|
||||
//pbDest = (pBufDest(0) << 8) + pBufDest(1)
|
||||
pbDest = (UInt16)(pBufDest[0] * 256 + pBufDest[1]);
|
||||
}
|
||||
|
||||
private byte StrToHex(/*object*/ int src)
|
||||
{
|
||||
if (Convert.ToInt32(src) >= 0x30 && Convert.ToInt32(src) <= 0x39)
|
||||
{
|
||||
return Convert.ToByte((src - 0x30));
|
||||
}
|
||||
else if (Convert.ToInt32(src) >= 0x41 && Convert.ToInt32(src) <= 0x46)
|
||||
{
|
||||
return Convert.ToByte((src - 0x41 + 10));
|
||||
}
|
||||
else if (Convert.ToInt32(src) >= 0x61 && Convert.ToInt32(src) <= 0x66)
|
||||
{
|
||||
return Convert.ToByte((src - 0x61 + 10));
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public static byte toupper(byte val)
|
||||
{
|
||||
if (val >= 0x61 && val <= 0x7A)
|
||||
{
|
||||
return (byte)(val - 0x20);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 和校验
|
||||
/// 求Byte数组的和校验
|
||||
/// </summary>
|
||||
/// <param name="dataPacket">Byte数组</param>
|
||||
/// <returns></returns>
|
||||
public byte GetSumChecks(byte[] dataPacket, ref int len)
|
||||
{
|
||||
int sum = 0;
|
||||
for (var idx = 0; idx < len; idx++)
|
||||
{
|
||||
sum += dataPacket[idx];
|
||||
sum &= 0xFF;
|
||||
}
|
||||
|
||||
sum = (~sum) & 0xFF;
|
||||
return (byte)sum;
|
||||
}
|
||||
|
||||
|
||||
//&H
|
||||
public byte[] GetStringToDataByte(string str)
|
||||
{
|
||||
List<byte> dataList = new List<byte>();
|
||||
|
||||
for (int index = 0; index < str.Length; index += 2)
|
||||
{
|
||||
dataList.Add(Convert.ToByte($"{str.Substring(index, 2)}"));
|
||||
}
|
||||
return dataList.ToArray();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 16进制原码字符串转字节数组
|
||||
/// </summary>
|
||||
/// <param name="hexString">"AABBCC"或"AA BB CC"格式的字符串</param>
|
||||
/// <returns></returns>
|
||||
public static byte[] ConvertHexStringToBytes(string hexString)
|
||||
{
|
||||
hexString = hexString.Replace(" ", "");
|
||||
if (hexString.Length % 2 != 0)
|
||||
{
|
||||
throw new ArgumentException("参数长度不正确,必须是偶数位。");
|
||||
}
|
||||
byte[] returnBytes = new byte[hexString.Length / 2];
|
||||
for (int i = 0; i < returnBytes.Length; i++)
|
||||
{
|
||||
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
|
||||
}
|
||||
|
||||
return returnBytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Byte[] 转 File
|
||||
/// </summary>
|
||||
/// <param name="fileData"></param>
|
||||
public void ByteToFile(byte[] fileData)
|
||||
{
|
||||
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".bin";
|
||||
string dirPath = @"D:\测试";
|
||||
|
||||
if (!Directory.Exists(dirPath))
|
||||
Directory.CreateDirectory(dirPath);
|
||||
|
||||
string filePath = Path.Combine(dirPath, fileName);
|
||||
FileStream fileStream = new(filePath, FileMode.Create);
|
||||
fileStream.Write(fileData, 0, fileData.Length);
|
||||
fileStream.Close();
|
||||
}
|
||||
|
||||
|
||||
public string HexStringToBytes(int set)
|
||||
{
|
||||
string str = set.ToString("X6");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// Name: CRC-16/IBM x16+x15+x2+1
|
||||
/// Poly: 0x8005
|
||||
/// Init: 0x0000
|
||||
/// Refin: true
|
||||
/// Refout: true
|
||||
/// Xorout: 0x0000
|
||||
///*************************************************************************
|
||||
public static byte[] Crc16(byte[] buffer, int start = 0, int len = 0)
|
||||
{
|
||||
if (buffer == null || buffer.Length == 0) return null;
|
||||
if (start < 0) return null;
|
||||
if (len == 0) len = buffer.Length - start;
|
||||
int length = start + len;
|
||||
if (length > buffer.Length) return null;
|
||||
ushort crc = 0;// Initial value
|
||||
for (int i = start; i < length; i++)
|
||||
{
|
||||
crc ^= buffer[i];
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
if ((crc & 1) > 0)
|
||||
crc = (ushort)((crc >> 1) ^ 0xA001);// 0xA001 = reverse 0x8005
|
||||
else
|
||||
crc = (ushort)(crc >> 1);
|
||||
}
|
||||
}
|
||||
byte[] ret = BitConverter.GetBytes(crc);
|
||||
Array.Reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static int NetCRC16_Data(byte[] aStr, int len, int crc_id)
|
||||
{
|
||||
int xda, xdapoly;
|
||||
int i, j, xdabit;
|
||||
xda = 0xFFFF;
|
||||
xdapoly = 0xA001; // (X**16 + X**15 + X**2 + 1)
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if ((i == crc_id) || (i == (crc_id + 1)))
|
||||
{
|
||||
xda ^= 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
xda ^= aStr[i];
|
||||
}
|
||||
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
xdabit = (byte)(xda & 0x01);
|
||||
xda >>= 1;
|
||||
if (xdabit!=0) xda ^= xdapoly;
|
||||
}
|
||||
}
|
||||
return xda;
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
47
SERVER/MD5Verify.cs
Normal file
47
SERVER/MD5Verify.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using COMMON;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
/// <summary>
|
||||
/// MD5校验
|
||||
/// </summary>
|
||||
public static class MD5Verify
|
||||
{
|
||||
public static string getMD5Hash(Stream oFileStream)
|
||||
{
|
||||
string strResult = "";
|
||||
string strHashData = "";
|
||||
byte[] arrbytHashValue;
|
||||
//System.IO.FileStream oFileStream = null;
|
||||
System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
||||
try
|
||||
{
|
||||
//oFileStream = new System.IO.FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
|
||||
|
||||
arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);//计算指定Stream 对象的哈希值
|
||||
|
||||
oFileStream.Close();
|
||||
|
||||
//由以连字符分隔的十六进制对构成的String,其中每一对表示value 中对应的元素;例如“F-2C-4A”
|
||||
|
||||
strHashData = System.BitConverter.ToString(arrbytHashValue);
|
||||
//替换-
|
||||
strHashData = strHashData.Replace("-", "");
|
||||
|
||||
strResult = strHashData;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
LogHelp.Error("MD5校验失败"+ex.ToString());
|
||||
}
|
||||
return strResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
SERVER/Model/ReturnResult.cs
Normal file
14
SERVER/Model/ReturnResult.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER.Model
|
||||
{
|
||||
public class ReturnResult
|
||||
{
|
||||
public bool Status { get; set; }
|
||||
public string messages { get; set; }
|
||||
}
|
||||
}
|
||||
188
SERVER/ModelFile.cs
Normal file
188
SERVER/ModelFile.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using COMMON;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Models;
|
||||
using Models.Models;
|
||||
using SERVER.LIB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件数据
|
||||
/// </summary>
|
||||
public class ModelFile
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件数据
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="count_"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<TBL_MODEL_FILE_DATA> SelModelFile(out int count,out int count_,string type = "", int start = 0, int length = 0)
|
||||
{
|
||||
count = CacheData.TBL_MODEL_FILE_DATA.Count();
|
||||
count_ = CacheData.TBL_MODEL_FILE_DATA.Where(x =>string.IsNullOrEmpty(type) || x.Directory.Contains(type)).Count();
|
||||
return CacheData.TBL_MODEL_FILE_DATA.Where(x=> string.IsNullOrEmpty(type) || x.Directory.Contains(type)).OrderByDescending(x=>x.UploadDateTime).Skip(start).Take(length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件数据删除
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DelModelFile(int id, HotelServiceContext db = null)
|
||||
{
|
||||
if (db == null)
|
||||
// 一般情况下都会从控制器传入过来
|
||||
db = XC_Data.GetMinDataBase();
|
||||
TBL_MODEL_FILE_DATA tump = db.TBL_MODEL_FILE_DATAS.First(x => x.MFD_ID == id);
|
||||
db.Entry(tump).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
|
||||
// 删除文件标记
|
||||
bool isdel = false;
|
||||
if (FtpHelper.GetFileSize(Path.Combine(tump.Directory, tump.XML_FileName)) > 0)
|
||||
if(FtpHelper.DeleteFileName(Path.Combine(tump.Directory, tump.XML_FileName)))
|
||||
isdel = true;
|
||||
else
|
||||
isdel = false;
|
||||
else
|
||||
isdel = true;
|
||||
// 执行数据库数据删除
|
||||
if (isdel)
|
||||
{
|
||||
CacheData.Clear(CacheData.CacheDataEnum.TBL_MODEL_FILE_DATA);
|
||||
return db.SaveChanges() > 0;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 文件数据添加
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="Author"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Dictionary<string, int>> AddModelFile(int type, List<IFormFile> files, string Author, HotelServiceContext db = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
Dictionary<string, int> res = new Dictionary<string, int>();
|
||||
|
||||
if (db == null)
|
||||
// 一般情况下都会从控制器传入过来
|
||||
db = XC_Data.GetMinDataBase();
|
||||
string path = "485Model";
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
path = "485Model";
|
||||
break;
|
||||
case 1:
|
||||
path = "BaseModel";
|
||||
break;
|
||||
case 2:
|
||||
path = "RCUModel";
|
||||
break;
|
||||
default:
|
||||
return res;
|
||||
}
|
||||
long size = files.Sum(f => f.Length);
|
||||
|
||||
|
||||
foreach (IFormFile formFile in files)
|
||||
{
|
||||
if (formFile.Length > 0)
|
||||
{
|
||||
TBL_MODEL_FILE_DATA data = new TBL_MODEL_FILE_DATA();
|
||||
data.Author = Author;
|
||||
data.Available = 1;
|
||||
data.Directory = @$"\Data\Model\{path}";
|
||||
data.XLM_MD5 = "555";
|
||||
data.Remark = "Web上传~";
|
||||
data.XML_FileName = formFile.FileName;
|
||||
|
||||
var filePath = Path.GetTempFileName();
|
||||
|
||||
using (var stream = System.IO.File.Create(filePath))
|
||||
{
|
||||
await formFile.CopyToAsync(stream);
|
||||
}
|
||||
//xml md5
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
//Encoding.ASCII.GetBytes()
|
||||
data.XLM_MD5 = BitConverter.ToString(md5.ComputeHash(System.IO.File.ReadAllBytes(filePath))).Replace("-", "").ToUpper();
|
||||
}
|
||||
db.TBL_MODEL_FILE_DATAS.Add(data);
|
||||
//文件存在 /BLV_Studio//Data/Model/485Model444BLV-C5_测试.xml
|
||||
if (FtpHelper.GetFileSize(data.Directory + "/" + formFile.FileName) > -1)
|
||||
{
|
||||
res.Add(data.XML_FileName, -1);
|
||||
continue;
|
||||
}
|
||||
if (FtpHelper.FileUpLoad(filePath, formFile.FileName, data.Directory))
|
||||
{
|
||||
|
||||
System.IO.File.Delete(filePath);
|
||||
res.Add(data.XML_FileName, db.SaveChanges());
|
||||
}
|
||||
else
|
||||
{
|
||||
//FtpHelper.DeleteFileName(data.Directory + formFile.FileName);
|
||||
res.Add(data.XML_FileName, -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error("ftp file : " + ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static dynamic GetFtp(out int count, out int count_,int start = 0, int length = 0, string type = "")
|
||||
{
|
||||
|
||||
List<dynamic> res = new List<dynamic>();
|
||||
try
|
||||
{
|
||||
var data = SelModelFile(out count,out count_, type, start, length);
|
||||
foreach (var item in data)
|
||||
{
|
||||
int size = FtpHelper.GetFileSize(Path.Combine(item.Directory, item.XML_FileName));
|
||||
res.Add(new { data = item, size });
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error("ftp file : " + ex.ToString());
|
||||
count_ = 0;
|
||||
count = 0;
|
||||
res = null;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
84
SERVER/RcuServer.cs
Normal file
84
SERVER/RcuServer.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using COMMON;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
/// <summary>
|
||||
/// ruc 服务 数据查询处理中心
|
||||
/// </summary>
|
||||
public class RcuServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询 rcu 的连接 信息 绑定房间酒店信息
|
||||
/// </summary>
|
||||
/// <param name="hotel_id"></param>
|
||||
/// <param name="count_"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="roomnumber"></param>
|
||||
/// <param name="room_type"></param>
|
||||
/// <param name="room_online_satatus"></param>
|
||||
/// <param name="db"></param>
|
||||
/// <returns></returns>
|
||||
public static List<dynamic> SetRucServer(out int count, out int count_, int hotel_id,int start, int length,int room_online_satatus, string roomnumber, int room_type, HotelServiceContext db = null)
|
||||
{
|
||||
// 房态判断
|
||||
var room_type_ = new int[] { };
|
||||
if (room_type == -1)
|
||||
room_type_ = new int[] {2,4,8,16 };
|
||||
IEnumerable<dynamic> res = new List<dynamic>();
|
||||
if (db == null)
|
||||
// 一般情况下都会从控制器传入过来
|
||||
db = XC_Data.GetMinDataBase();
|
||||
// 通过连接信息表 查询出在线的 rcu 每个 mac 应该只是出现一次
|
||||
var tBL_RCU_CONN_INFO = db.TBL_RCU_CONN_INFOS.Where(x => x.ONLINE_SATATUS == 1).Select(x => x.MAC.ToUpper()).Distinct();
|
||||
res =
|
||||
(
|
||||
from r in db.TBL_ROOM_BASIC_INFOS
|
||||
join h in db.TBL_HOTEL_BASIC_INFOS on r.HOTEL_OLD_ID
|
||||
equals h.IDOLD
|
||||
join rcu in db.TBL_RCU_BASIC_INFOS on r.MAC
|
||||
equals rcu.MAC
|
||||
where r.HOTEL_OLD_ID == hotel_id && (string.IsNullOrEmpty(roomnumber) || r.ROOM_NUMBER.Contains(roomnumber)) && (r.RoomStatusID == room_type || room_type==0 || (room_type == -1 && !room_type_.Contains(r.RoomStatusID)))
|
||||
select new
|
||||
{
|
||||
rcu.REGISTER_DATE,
|
||||
r.RoomStatusID,
|
||||
rcu.REGISTER_STATUS,
|
||||
rcu.UDP_KEY,
|
||||
rcu.UPDATE_TIMEMARK,
|
||||
rcu.IsImport,
|
||||
rcu.RCU_ID,
|
||||
rcu.MAC,
|
||||
rcu.CORE_MODUEL,
|
||||
rcu.UUID,
|
||||
rcu.BRAND,
|
||||
rcu.MODEL,
|
||||
r.HOTEL_OLD_ID,
|
||||
r.ROOM_NUMBER,
|
||||
h.HOTEL_NAME_CN,
|
||||
ONLINE_SATATUS =
|
||||
// 如果在连接信息表查询出有信息 那么 就是在线
|
||||
tBL_RCU_CONN_INFO.Contains(r.MAC.ToUpper())? 1 : 0 ,
|
||||
COMM_TIMEMARK = db.TBL_RCU_CONN_INFOS.Where(x => x.MAC.ToUpper() == r.MAC.ToUpper()).Select(x => x.COMM_TIMEMARK).FirstOrDefault()
|
||||
}).Where(x=> room_online_satatus == -1 || x.ONLINE_SATATUS == room_online_satatus).OrderByDescending(x=>x.ONLINE_SATATUS);
|
||||
// 取出数据到内存后 根据mac 只取出前一条 因为mac 可能出现重复 一个是自己注册 一个是 mac 导入
|
||||
// 暂时不考虑 重复mac 就不需要分组
|
||||
// 如果一次取出全部数据 那么又失去了分页的必要性
|
||||
//.AsEnumerable()
|
||||
//.GroupBy(x=>x.MAC).Select(x=>x.First())
|
||||
|
||||
count = db.TBL_ROOM_BASIC_INFOS.Where(x => x.HOTEL_OLD_ID == hotel_id && x.MAC.Length > 0).Count();
|
||||
count_ = res.Count();
|
||||
return res.Skip(start).Take(length)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
29
SERVER/SERVER.csproj
Normal file
29
SERVER/SERVER.csproj
Normal file
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController" Version="6.0.0" />
|
||||
<PackageReference Include="UtilsSharp" Version="2.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Aliyun.Api.LogService\Aliyun.Api.LogService.csproj" />
|
||||
<ProjectReference Include="..\COMMON\COMMON.csproj" />
|
||||
<ProjectReference Include="..\DB_Server\DB_Server.csproj" />
|
||||
<ProjectReference Include="..\Models\Models.csproj" />
|
||||
<ProjectReference Include="..\TcpServer\TcpServer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="log4net.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
9
SERVER/SERVER.csproj.user
Normal file
9
SERVER/SERVER.csproj.user
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<ItemGroup>
|
||||
<Compile Update="LIB\WEBHELP.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
1312
SERVER/SYNC_DATA.cs
Normal file
1312
SERVER/SYNC_DATA.cs
Normal file
File diff suppressed because it is too large
Load Diff
41
SERVER/Send_Cmd.cs
Normal file
41
SERVER/Send_Cmd.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TcpServer;
|
||||
|
||||
namespace SERVER
|
||||
{
|
||||
/// <summary>
|
||||
/// 下发命令的帮助类
|
||||
/// </summary>
|
||||
public class Send_Cmd
|
||||
{
|
||||
/// <summary>
|
||||
/// 下发固件
|
||||
/// </summary>
|
||||
/// <param name="mac"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static bool[] Send_File(int type = 1, params string [] mac)
|
||||
{
|
||||
var res = new List<bool>();
|
||||
foreach (var item in mac)
|
||||
{
|
||||
res.Add(Send_File(item,type));
|
||||
}
|
||||
return res.ToArray();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="mac"></param>
|
||||
/// <returns></returns>
|
||||
private static bool Send_File(string mac,int type = 1)
|
||||
{
|
||||
return SendHelp.Send_Control_UPGRADE_ISSUED(mac, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
277
SERVER/log4net.config
Normal file
277
SERVER/log4net.config
Normal file
@@ -0,0 +1,277 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
|
||||
|
||||
|
||||
<log4net debug="false">
|
||||
|
||||
<!-- name属性指定其名称,type则是log4net.Appender命名空间的一个类的名称,意思是,指定使用哪种介质-->
|
||||
|
||||
<appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
|
||||
|
||||
<!--日志缓存写入条数 设置为0时只要有一条就立刻写到数据库-->
|
||||
|
||||
<bufferSize value="0" />
|
||||
|
||||
<!--日志数据库连接串-->
|
||||
|
||||
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
|
||||
<connectionString value="DATABASE=GoodLook;SERVER=xx.xx.140.170;UID=sa;PWD=123456a;Connect Timeout=30;" />
|
||||
|
||||
<!--日志数据库脚本-->
|
||||
|
||||
<commandText value="INSERT INTO LogDetails ([LogDate],[LogThread],[LogLevel],[LogLogger],[LogActionClick],[LogMessage],[UserName],[UserIP]) VALUES (@log_date, @thread, @log_level, @logger, @ActionsClick, @message,@UserName,@UserIP)" />
|
||||
|
||||
<!--日志时间LogDate -->
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@log_date" />
|
||||
|
||||
<dbType value="DateTime" />
|
||||
|
||||
<layout type="log4net.Layout.RawTimeStampLayout" />
|
||||
|
||||
</parameter>
|
||||
|
||||
<!--线程号-->
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@thread" />
|
||||
|
||||
<dbType value="String" />
|
||||
|
||||
<size value="100" />
|
||||
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
|
||||
<conversionPattern value="%t" />
|
||||
|
||||
</layout>
|
||||
|
||||
</parameter>
|
||||
|
||||
<!--日志类型LogLevel -->
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@log_level" />
|
||||
|
||||
<dbType value="String" />
|
||||
|
||||
<size value="200" />
|
||||
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
|
||||
<conversionPattern value="%p" />
|
||||
|
||||
</layout>
|
||||
|
||||
</parameter>
|
||||
|
||||
<!--日志名称-->
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@logger" />
|
||||
|
||||
<dbType value="String" />
|
||||
|
||||
<size value="500" />
|
||||
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
|
||||
<conversionPattern value="%logger" />
|
||||
|
||||
</layout>
|
||||
|
||||
</parameter>
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@message" />
|
||||
|
||||
<dbType value="String" />
|
||||
|
||||
<size value="3000" />
|
||||
|
||||
<layout type="Log4NetApply.MyLayout">
|
||||
|
||||
<conversionPattern value="%property{Message}" />
|
||||
|
||||
</layout>
|
||||
|
||||
</parameter>
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@ActionsClick" />
|
||||
|
||||
<dbType value="String" />
|
||||
|
||||
<size value="4000" />
|
||||
|
||||
<layout type="Log4NetApply.MyLayout" >
|
||||
|
||||
<conversionPattern value = "%property{ActionsClick}"/>
|
||||
|
||||
</layout>
|
||||
|
||||
</parameter>
|
||||
|
||||
<!--自定义UserName -->
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@UserName" />
|
||||
|
||||
<dbType value="String" />
|
||||
|
||||
<size value="30" />
|
||||
|
||||
<layout type="Log4NetApply.MyLayout" >
|
||||
|
||||
<!--log4net.MDC.Set("UserName", "asdfasdf");
|
||||
|
||||
<conversionPattern value = "%X{UserName}"/>-->
|
||||
|
||||
<conversionPattern value = "%property{UserName}"/>
|
||||
|
||||
</layout>
|
||||
|
||||
</parameter>
|
||||
|
||||
<parameter>
|
||||
|
||||
<parameterName value="@UserIP" />
|
||||
|
||||
<dbType value="String" />
|
||||
|
||||
<size value="20" />
|
||||
|
||||
<layout type="Log4NetApply.MyLayout" >
|
||||
|
||||
<conversionPattern value = "%property{UserIP}"/>
|
||||
|
||||
</layout>
|
||||
|
||||
</parameter>
|
||||
|
||||
</appender>
|
||||
|
||||
<!-- setup the root category, add the appenders and set the default level -->
|
||||
|
||||
<root>
|
||||
|
||||
<level value="Warn"/><!-- 定义记录的日志级别-->
|
||||
|
||||
<level value="Info"/>
|
||||
|
||||
<level value="Debug"/>
|
||||
|
||||
<level value="Fine"/>
|
||||
|
||||
<appender-ref ref="ADONetAppender" /><!-- 记录到什么介质中-->
|
||||
|
||||
</root>
|
||||
|
||||
<!-- specify the level for some specific categories -->
|
||||
|
||||
<!--//关于上边root到logger这块,如果同时出现,有可能会出现重复插入记录的情况:-->
|
||||
|
||||
<!--<logger name="iNotes">
|
||||
|
||||
<level value="WARN"/>
|
||||
|
||||
<level value="INFO"/>
|
||||
|
||||
<level value="DEBUG"/>
|
||||
|
||||
<level value="FINE"/>
|
||||
|
||||
<appender-ref ref="ADONetAppender"/>
|
||||
|
||||
</logger>
|
||||
|
||||
<logger name="StellaLogger">
|
||||
|
||||
<level value="ALL"/>
|
||||
|
||||
<appender-ref ref="AdoNetAppender" />
|
||||
|
||||
</logger>-->
|
||||
|
||||
<appender name="ReflectionLayout" type="log4net.Appender.RollingFileAppender,log4net">
|
||||
|
||||
|
||||
|
||||
<!--日志文件路径,按文件大小方式输出时在这里指定文件名,并且前面的日志按天在文件名后自动添加当天日期形成文件-->
|
||||
|
||||
<param name="File" value="D:/Log/" />
|
||||
|
||||
|
||||
|
||||
<!--是否追加到文件-->
|
||||
|
||||
<param name="AppendToFile" value="true" />
|
||||
|
||||
|
||||
|
||||
<!--记录日志写入文件时,不锁定文本文件-->
|
||||
|
||||
<!--<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />-->
|
||||
|
||||
|
||||
|
||||
<!--Unicode编码-->
|
||||
|
||||
<!--<Encoding value="UTF-8" />-->
|
||||
|
||||
|
||||
|
||||
<!--最多产生的日志文件数,value="-1"为不限文件数-->
|
||||
|
||||
<!--<param name="MaxSizeRollBackups" value="10" />-->
|
||||
|
||||
|
||||
|
||||
<!--是否只写到一个文件中-->
|
||||
|
||||
<param name="StaticLogFileName" value="false" />
|
||||
|
||||
|
||||
|
||||
<!--按照何种方式产生多个日志文件(日期[Date],文件大小[Size],混合[Composite])-->
|
||||
|
||||
<param name="RollingStyle" value="Composite" />
|
||||
|
||||
|
||||
|
||||
<!--按日期产生文件夹,文件名[在日期方式与混合方式下使用]-->
|
||||
|
||||
<param name="DatePattern" value="yyyy-MM-dd/" ReflectionLayout.log="" />
|
||||
|
||||
<!--<param name="DatePattern" value="yyyyMMdd/yyyyMMdd"-TimerServer.log"" />-->
|
||||
|
||||
<!--<param name="DatePattern" value="yyyyMMdd/"TimerServer/TimerServer.log"" />-->
|
||||
|
||||
|
||||
|
||||
<!--每个文件的大小。只在混合方式与文件大小方式下使用,超出大小的在文件名后自动增加1重新命名-->
|
||||
|
||||
<param name="maximumFileSize" value="500KB" />
|
||||
|
||||
|
||||
<!--记录的格式。-->
|
||||
|
||||
<layout type="TGLog.ExpandLayout2.ReflectionLayout,TGLog">
|
||||
|
||||
<param name="ConversionPattern" value="记录时间:%date 线程ID:[%thread] 日志级别:%-5level 记录类:%logger 操作者ID:%property{Operator} 操作类型:%property{Action}%n 当前机器名:%property%n当前机器名及登录用户:%username %n 记录位置:%location%n 消息描述:%property{Message}%n 异常:%exception%n 消息:%message%newline%n%n" />
|
||||
|
||||
</layout>
|
||||
|
||||
</appender>
|
||||
|
||||
|
||||
</log4net>
|
||||
Reference in New Issue
Block a user