/// <summary> /// 定时器计时 /// </summary> private static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (!Activity.hasInitialize) { return; } bool hasSend = false; lock (Activity.dataList) { for (int i = 0; i < Activity.dataList.Count;) { ActivityData data = Activity.dataList[i]; if ((DateTime.Now - data.UpdateTime).TotalDays >= 7) { hasSend = true; Activity.dataList.RemoveAt(i); Log.AddLog(data.ServerId + " 活动更新时间太早 " + data.UpdateTime.ToShortDateString()); continue; } if (DateTime.Now >= data.UpdateTime && GMCommand.Execute(data.Address, data.ServerId, "0", Encoding.UTF8.GetBytes("2"), data.Buffer) && GMCommand.Execute(data.Address, data.ServerId, "0", string.Format("SDATE({0},{1},{2})", data.UpdateTime.Year, data.UpdateTime.Month, data.UpdateTime.Day), "")) { Log.AddLog("定时更新:" + DateTime.Now); Log.AddLog("年:" + data.UpdateTime.Year); Log.AddLog("月:" + data.UpdateTime.Month); Log.AddLog("日:" + data.UpdateTime.Day); hasSend = true; Activity.dataList.RemoveAt(i); } else { ++i; } } if (hasSend) { Activity.SendUpdate(); } } }
/// <summary> /// 消息处理:更新 /// </summary> /// <param name="type">消息类型</param> /// <param name="reader">读取器</param> private static void ProcessUpdate(ushort type, BinaryReader reader) { lock (Activity.dataList) { Activity.dataList.Clear(); ushort count = reader.ReadUInt16(); for (int i = 0; i < count; ++i) { ActivityData data = new ActivityData(); data.Address = reader.ReadString(); data.ServerId = reader.ReadString(); //data.UpdateTime = new DateTime(reader.ReadUInt16(), reader.ReadByte(), reader.ReadByte()); //5点更新 data.UpdateTime = new DateTime(reader.ReadUInt16(), reader.ReadByte(), reader.ReadByte(), 5, 0, 0); data.Buffer = reader.ReadBytes(reader.ReadUInt16()); Activity.dataList.Add(data); } } Activity.hasInitialize = true; }