public void ShowMessage(string msg) { if (qMessages.Count > 0) { SystemMsg systemMsg = qMessages.Peek(); if (systemMsg.Message == msg) { systemMsg.Reset(); return; } } qMessages.Enqueue(new SystemMsg(msg, 5f)); }
public void ShowMessage(string msg, float time) { if (qMessages.Count > 0) { SystemMsg systemMsg = qMessages.Peek(); if (systemMsg.Message == msg) { systemMsg.Reset(); systemMsg.Laptime = time; return; } } qMessages.Enqueue(new SystemMsg(msg, time)); }
private void AfterFirstResponse(MainMessage msg) { this._log.Info("Received response from Main Server."); SystemMsg sysMsg = msg.SystemMsg; if (sysMsg.SystemMsgTypeCase.Equals(SystemMsg.SystemMsgTypeOneofCase.ErrorMsg)) { throw new ServerException(sysMsg.ErrorMsg.ErrorMsg_); } _serverId = msg.ServerId; _serverIdFiller.SetId(_serverId); this._log.Info("Assigned ID: " + _serverId.ToString()); this._log.Info("Preparing Services..."); _serviceProvider = new ServiceProvider( new SystemServiceForwarder(), new EventServiceForwarder(), new TickRateServiceForwarder(), new RoomServiceForwarder(), new UserServiceForwarder(), new AppServiceForwarder()); int maxIndex = Enum.GetValues(typeof(MainMessage.MessageTypeOneofCase)) .OfType <MainMessage.MessageTypeOneofCase>() .Select(x => (int)x) .Max(); coreServices.InsertRange(0, Enumerable.Repeat <IServiceForwarder>(null, maxIndex + 1)); coreServices[(int)MainMessage.MessageTypeOneofCase.SystemMsg] = _serviceProvider.System; coreServices[(int)MainMessage.MessageTypeOneofCase.TickMsg] = _serviceProvider.TickRate; coreServices[(int)MainMessage.MessageTypeOneofCase.EventMsg] = _serviceProvider.Event; coreServices[(int)MainMessage.MessageTypeOneofCase.RoomMsg] = _serviceProvider.Room; coreServices[(int)MainMessage.MessageTypeOneofCase.UserMngMsg] = _serviceProvider.User; coreServices[(int)MainMessage.MessageTypeOneofCase.AppMsg] = _serviceProvider.App; // APIs _openAPI = new OpenAPI(udpListenner, _config); _closedAPI = new ClosedAPI(_openAPI, _serviceProvider); _openAPI.Init(_closedAPI); // Initialization of services foreach (IServiceForwarder service in coreServices) { service?.Init(_closedAPI); } this._log.Info("All services have been initialized."); udpListenner.StartListening(); }
public MainMessage HandleMessage(MainMessage msg) { SystemMsg sysMsg = msg.SystemMsg; switch (sysMsg.SystemMsgTypeCase) { case SystemMsg.SystemMsgTypeOneofCase.HiMsg: return(HandleHiMsg(sysMsg.HiMsg)); case SystemMsg.SystemMsgTypeOneofCase.StatMsg: return(HandleStatMsg(msg)); default: return(ISystemService.CreateErrorMessage(msg.MsgId, 0, 0, "Unknown message type")); } }
public override int GetHashCode() { int hash = 1; if (MsgId != 0UL) { hash ^= MsgId.GetHashCode(); } if (senderIdCase_ == SenderIdOneofCase.ServerId) { hash ^= ServerId.GetHashCode(); } if (senderIdCase_ == SenderIdOneofCase.ClientId) { hash ^= ClientId.GetHashCode(); } if (messageTypeCase_ == MessageTypeOneofCase.SystemMsg) { hash ^= SystemMsg.GetHashCode(); } if (messageTypeCase_ == MessageTypeOneofCase.TickMsg) { hash ^= TickMsg.GetHashCode(); } if (messageTypeCase_ == MessageTypeOneofCase.EventMsg) { hash ^= EventMsg.GetHashCode(); } if (messageTypeCase_ == MessageTypeOneofCase.RoomMsg) { hash ^= RoomMsg.GetHashCode(); } if (messageTypeCase_ == MessageTypeOneofCase.UserMngMsg) { hash ^= UserMngMsg.GetHashCode(); } if (messageTypeCase_ == MessageTypeOneofCase.AppMsg) { hash ^= AppMsg.GetHashCode(); } hash ^= (int)senderIdCase_; hash ^= (int)messageTypeCase_; return(hash); }
private void savesystemmsg(HttpContext context) { string liststr = context.Request["list"]; if (string.IsNullOrEmpty(liststr)) { WebUtil.WriteJson(context, new { status = false }); return; } Utility.SystemMsgModel[] list = new SystemMsgModel[] { }; try { string new_data = HttpUtility.UrlDecode(liststr, Encoding.UTF8); list = JsonConvert.DeserializeObject <Utility.SystemMsgModel[]>(new_data); } catch (Exception) { } var msg_list = Foresight.DataAccess.SystemMsg.GetSystemMsgs(); foreach (var item in list) { var msg = msg_list.FirstOrDefault(p => p.FromID == item.ID); if (msg == null) { msg = new SystemMsg(); msg.AddTime = item.AddTime; msg.FromID = item.ID; msg.Title = item.Title; msg.ContentSummary = item.ContentSummary; msg.SortOrder = item.SortOrder; msg.IsTopShow = item.IsTopShow; } else { msg.Title = item.Title; msg.ContentSummary = item.ContentSummary; msg.SortOrder = item.SortOrder; msg.IsTopShow = item.IsTopShow; } msg.Save(); } WebUtil.WriteJson(context, new { status = true }); }
private void InitStats() { uint cpuUsage = 0; long memoryTotal = 0; long memoryUsed = 0; bool firstRun = false; Task calculationT = new Task(() => { while (true) { cpuUsage = HwMonitor.GetCoreUsage(); Interlocked.Exchange(ref memoryTotal, (long)HwMonitor.GetTotalMemory()); Interlocked.Exchange(ref memoryUsed, (long)HwMonitor.GetUsedMemory()); firstRun = true; } }, TaskCreationOptions.LongRunning); Task sendingT = new Task(() => { while (!firstRun) { Thread.Sleep(1000); } while (true) { SystemMsg sysMsg = new SystemMsg(); StatMsg statMsg = new StatMsg(); statMsg.CpuUsage = cpuUsage; statMsg.MemoryTotal = (ulong)Interlocked.Read(ref memoryTotal); statMsg.MemoryUsed = (ulong)Interlocked.Read(ref memoryUsed); sysMsg.StatMsg = statMsg; MainMessage msg = new MainMessage(); msg.SystemMsg = sysMsg; Thread.Sleep((int)STATS_INTERVAL_MS); _api.OpenAPI.Networking.SendAsync(msg, _api.OpenAPI.Config.MainServer, (_) => { }, (err) => { _log.Error("There was an error during status sending to Main Server."); Environment.Exit(1); }); } }, TaskCreationOptions.LongRunning); calculationT.Start(); sendingT.Start(); }
/// <summary> /// 注册消息 /// </summary> /// <param name="group">组名</param> /// <param name="jobName">作业名,无特别要求的使用Guid</param> /// <param name="sendTime">发送时间</param> /// <param name="msg">消息详细</param> /// <returns></returns> public static bool SendSysMessage(Group group, string jobName, DateTime sendTime, SystemMsg msg) { try { Init(); register.SendSysMessageAsync(group, jobName, sendTime, msg); return(true); } catch (Exception ex) { return(false); } }