using System; using System.Collections.Generic; using System.Linq; using System.Text; using Common; using System.Collections.Concurrent; using System.Threading; namespace CommonEntity { public class DataTongJi { public static ConcurrentDictionary TotalCount = new ConcurrentDictionary(); public static ConcurrentBag CPU_Data = new ConcurrentBag(); /// /// 下位机黑名单 /// //public static UDPPackageBlockFilter BlockLowerMachineList = new UDPPackageBlockFilter(); public static ConcurrentDictionary> BlockLowerMachineList = new ConcurrentDictionary>(); private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(DataTongJi)); /// /// 0x19数据 /// public static ConcurrentBag ZeroX19_PassHotelCode = new ConcurrentBag(); /// /// RCU在线数量 /// public static ConcurrentDictionary ONLINERCU = new ConcurrentDictionary(); /// /// 取电开关 /// public static ConcurrentDictionary TakeCardOnLine = new ConcurrentDictionary(); /// /// 在线用户 /// public static ConcurrentDictionary OnLineUserList_IP = new ConcurrentDictionary(); //public static ConcurrentDictionary OnLineUserList_Account = new ConcurrentDictionary(); public class MTakeCardData { public string HostNUMBER { get; set; } public string HotelCode { get; set; } public byte Status { get; set; } public DateTime LastUpdateTime { get; set; } } public class OtherServiceInfo { public string HotelCode { get; set; } public string HostNumber { get; set; } public string Address { get; set; } public ushort StatusReceiver { get; set; } public DateTime LastUpdateTime { get; set; } } public static long DefineLostPackage = 0; /// /// 记录丢失的数据 /// public static long RecordLostPackage = 0; public static int LostPackage_Interval = 60; /// /// 判断 A数组是否包含B数组 /// /// /// /// /// public static bool ContainsSubsequence(List source, List subsequence) { if (subsequence.Count == 0) return true; if (source.Count < subsequence.Count) return false; for (int i = 0; i <= source.Count - subsequence.Count; i++) { var subList = source.GetRange(i, subsequence.Count); if (subList.SequenceEqual(subsequence)) return true; } return false; } public static void CeShi() { List A = new List { 0x01, 0x02, 0x04, 0x00, 0x01, 0xff, 0xff, 0xff, 0x04, 0x00, 0x01, 0xAA, 0xBB, 0xCC, 0x04, 0x00, 0x01, 0xCC, 0xDD, 0x01 }; List target = new List { 0x04, 0x00, 0x01 }; // 查找所有匹配的位置 List matchIndices = FindAllMatches(A, target); if (matchIndices.Count > 0) { Console.WriteLine("找到匹配的序列:"); foreach (int index in matchIndices) { // 提取匹配序列及其后两个字节 int start = index; int end = Math.Min(index + target.Count + 3, A.Count); List extracted = A.GetRange(start, end - start); } } else { Console.WriteLine("未找到匹配的序列"); } } /// /// 查找匹配的位置 /// /// /// /// public static List FindAllMatches(List source, List target) { List indices = new List(); if (target.Count == 0 || source.Count < target.Count) return indices; for (int i = 0; i <= source.Count - target.Count; i++) { bool match = true; for (int j = 0; j < target.Count; j++) { if (source[i + j] != target[j]) { match = false; break; } } if (match) { indices.Add(i); } } return indices; } /// /// 给某个模块添加 调用次数统计,统计是每个小时 调用的总数 /// /// public static void InvokeCount(string ModuleName) { try { DateTime DDT = DateTime.Now; int Year = DDT.Year; int MM = DDT.Month; int dd = DDT.Day; int HH = DDT.Hour; string Key = ModuleName + Year + "-" + MM + "-" + dd + "#" + HH; //string hotelid = Session["CurrentHotelID"].ToString(); //string HotelName = Session["CurrentHotelName"].ToString(); long data = CSRedisCacheHelper.Get_Partition(Key, 1); if (data == 0) { CSRedisCacheHelper.Set_PartitionWithTime(Key, 1, 120, 1); } else { CSRedisCacheHelper.Set_PartitionWithTime(Key, data += 1, 120, 1); } } catch (Exception) { } } } public class RCUOnLineExtra { public DateTime CurrentDateTime { get; set; } public string HotelCode { get; set; } } public class StepInfo { public long EveryMessageId { get; set; } public long Monitor_0E_01 { get; set; } public string HotelCode { get; set; } public string HostNumber { get; set; } public string MessageId { get; set; } public string TriggerTime { get; set; } public double Step { get; set; } public string StepDescription { get; set; } public byte[] Content { get; set; } } public class OnLineUser { public string Account { get; set; } public string IP { get; set; } public string HotelCode { get; set; } public int HotelId { get; set; } public DateTime LastUpdateTime { get; set; } } public class NengHao { public long HotelCode { get; set; } public string HostNumber { get; set; } public string RoomNumber { get; set; } public string Mac { get; set; } public string EndPoint { get; set; } public string Version { get; set; } public bool IsTakeCard { get; set; } public int CarbonVIP { get; set; } public double V { get; set; } public double A { get; set; } public double P { get; set; } public double KW_H { get; set; } public double Sum_KW_H { get; set; } public long CreateTime { get; set; } public DateTime ReportTime { get; set; } } public class NengHao4BaoJing { public long HotelCode { get; set; } public string HostNumber { get; set; } public string RoomNumber { get; set; } public string Mac { get; set; } public string EndPoint { get; set; } public string Version { get; set; } public bool IsTakeCard { get; set; } public int CarbonVIP { get; set; } public double V { get; set; } public double A { get; set; } public double P { get; set; } public double Energy_Consumption { get; set; } public double Sum_Energy_Consumption { get; set; } public long CreateTime { get; set; } public string ReportTime { get; set; } public List AllDeviceData { get; set; } public int IdentityInfo {get;set;} } public class Interface3Log { public string HotelCode { get; set; } public string HostNumber { get; set; } public string RoomNumber { get; set; } public HttpActionData ActionData { get; set; } public DateTime TriggerTime { get; set; } public string CommandType { get; set; } } public class HttpActionData { public double Step { get; set; } public string RequestData { get; set; } public string ResponseData { get; set; } } public class WelcomeAction { public string CUID { get; set; } public string VoiceDeviceClass { get; set; } public string CommandType { get; set; } } public class StepTongJi { /// /// 每一条消息都有一个ID /// public static long EveryMessageIDNo = 0; /// /// 每一个01和0E的编号 /// public static long Every_0E_01_MessageID = 0; /// /// 每 一条消息都有一个ID /// public static string EveryMessageID = ""; /// /// 1000包抓取一包,抓包计数器 /// public static long LookDataCounter = 0; /// /// 要监听的数据包编号 /// public static string GlobalListenID = ""; public static string GlobalListenIDNo = ""; /// /// 是否要锁定 /// public static int IsLocked = 0; private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(StepTongJi)); /// /// 发送Redis广播 /// /// /// /// public static void SendInfo(double step, string desc, string context_messageid, bool ismonitor) { try { if (ismonitor) { StepInfo s = new StepInfo(); s.MessageId = context_messageid; s.Step = step; s.StepDescription = desc; //string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"); string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff"); s.TriggerTime = ti; string NNN = Newtonsoft.Json.JsonConvert.SerializeObject(s); CSRedisCacheHelper.Publish("redis-roomstatus-monitor", NNN); } } catch (Exception ex) { logger.Error("StepTongJi Error:" + ex.Message); } } } }