public AutomationUnit(IAutomation automation, AutomationContext context, DelegateAutomationDone callback, object stateObject, AutomationUnit callingUnit) { _automation = automation; _context = context; _callback = callback; _callbackStateObject = stateObject; _callingUnit = callingUnit; }
/// <summary> /// 执行自动化作业 /// </summary> /// <remarks>作业上下文会在这个函数内部被复制,从而保证作业各自的上下文不会互相干扰,而只能对各自的后续作业产生影响</remarks> public void Do(IAutomation automation, AutomationContext context, DelegateAutomationDone callback, object stateObject, AutomationUnit callingUnit) { if (automation == null) { throw new ArgumentNullException("automation"); } if (context == null) { throw new ArgumentNullException("context"); } _toBeAddList.Add(new AutomationUnit(automation, (AutomationContext)context.Clone(), callback, stateObject, callingUnit)); }
//发生事件 public void OnEvent(FSEyeEvent fsEyeEvent, AutomationContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (_on) { foreach (Strategy strategy in _strategyList) { if (strategy.Enabled && strategy.Event == fsEyeEvent) { AdminServer.TheInstance.AutomationManager.Do(strategy.Automation, context); } } } }
public object Clone() { AutomationContext cloneObj = new AutomationContext(); cloneObj.Server = Server; if (ServerList != null) { cloneObj.ServerList = new List <GameServer>(ServerList); } cloneObj.Group = Group; if (ServerGroupList != null) { cloneObj.ServerGroupList = new List <ServerGroup>(ServerGroupList); } cloneObj.Message = Message; if (AdditionalObject != null) { cloneObj.AdditionalObject = (ICloneable)AdditionalObject.Clone(); } return(cloneObj); }
public override void Do(AutomationContext context) { GameServerManager gsm = AdminServer.TheInstance.GameServerManager; IList<GameServer> checkSuccessServerList = new List<GameServer>(); IList<GameServer> allServerList = context.GetAllServers(); foreach (GameServer server in allServerList) { switch (_checkType) { case CheckTypeConnected: { if (server.IsConnected) { checkSuccessServerList.Add(server); } } break; case CheckTypeDisconnected: { if (!server.IsConnected) { checkSuccessServerList.Add(server); } } break; case CheckTypeGameRunning: { if (server.GameServiceState == GameServer.ServiceState.Running) { checkSuccessServerList.Add(server); } } break; case CheckTypeGameNotRunning: { if (server.GameServiceState != GameServer.ServiceState.Running) { checkSuccessServerList.Add(server); } } break; case CheckTypeGameStopped: { if (server.GameServiceState == GameServer.ServiceState.ErrorStopped) { checkSuccessServerList.Add(server); } } break; } } context.ClearAllServers(); foreach (GameServer server in checkSuccessServerList) { context.ServerList.Add(server); } _state = AutomationState.Done; _result = AutomationResult.Success; }
public override void Do(AutomationContext context) { try { switch (_state) { case AutomationState.Init: string serverListFilePath = SystemConfig.Current.ServerListFileDir + SystemConfig.Current.PakFileName; string serverListCRCFilePath = SystemConfig.Current.ServerListFileDir + SystemConfig.Current.ServerListCRCFileName; if ((File.Exists(serverListFilePath)) && (File.Exists(serverListCRCFilePath))) { if (_ftpServerIdIList != null) { foreach (int ftpServerId in _ftpServerIdIList) { FTPServer ftpServer = AdminServer.TheInstance.FTPClient.GetFTPServer(ftpServerId); if (ftpServer != null) { try { FileInfo serverListFile = new FileInfo(serverListFilePath); UploadFile(serverListFile, ftpServer, _timeOutSeconds); FileInfo serverListCRCFile = new FileInfo(serverListCRCFilePath); UploadFile(serverListCRCFile, ftpServer, _timeOutSeconds); } catch (Exception ex) { Util.DebugLog(ex.ToString() + SystemConfig.Current.DefaultNewLine + "FTPServerIP: " + ftpServer.Address); } } else { Util.DebugLog("the ftpServer whose serverId is " + ftpServerId.ToString() + " does not exist, deleted maybe?"); } } } } _result = AutomationResult.Success; _state = AutomationState.Done; break; } } catch(Exception ex) { Util.DebugLog(ex.ToString()); _state = AutomationState.Done; _result = AutomationResult.Failure; } }
public override void Do(AutomationContext context) { switch (_state) { case AutomationState.Init: string postData = string.Empty; HttpWebRequest webreq = null; HttpWebResponse webres = null; Stream responseStream = null; StreamReader sr = null; String resContent = string.Empty; _url = SystemConfig.Current.SMSUrl; _command = SystemConfig.Current.SMSCommand; postData = string.Format("command={0}&phone={1}&content={2}", _command, _phone, System.Web.HttpUtility.UrlEncode(context.Message + _content,Encoding.GetEncoding("gb2312"))); postData = _url + "?" + postData; webreq = (HttpWebRequest)HttpWebRequest.Create(postData); webreq.Method = "GET"; webreq.KeepAlive = false; try { webres = (HttpWebResponse)webreq.GetResponse(); } catch (WebException ex) { webres = (HttpWebResponse)ex.Response; } if (((int)webres.StatusCode) >= 400) { //出错 Util.DebugLog("SMS WEB FAILURE!" + webres.StatusCode.ToString()); } else { responseStream = webres.GetResponseStream(); sr = new StreamReader(responseStream, Encoding.Default); resContent = sr.ReadToEnd(); Util.DebugLog("SMS: " + resContent + " " + postData); webres.Close(); sr.Close(); } _state = AutomationState.Done; break; } }
public override void Do(AutomationContext context) { switch (_state) { case AutomationState.Init: { _createLordConfigUnitList = new List<CreateLordConfigUnit>(); IList<GameServer> serverList = context.GetAllServers(); FileStream fileStream = null; string fileName = string.Empty; foreach (GameServer server in serverList) { CreateLordConfigUnit unit = new CreateLordConfigUnit(server); _createLordConfigUnitList.Add(unit); try { fileName = SystemConfig.Current.AdminServerUploadFileRootPath + unit.Server.Id + "_" + unit.Server.Name + "_guard.cfg"; fileStream = new FileStream(fileName, FileMode.OpenOrCreate); server.LordConfig.WriteLordConfig(fileStream); unit.IsDone = true; unit.IsSuccess = true; } catch (Exception) { unit.IsDone = true; unit.IsSuccess = false; } finally { if (fileStream != null) fileStream.Close(); } } _state = AutomationState.Doing; } break; case AutomationState.Doing: { for (int i = _createLordConfigUnitList.Count - 1; i >= 0; i--) { if (_createLordConfigUnitList[i].IsDone) { if (!_createLordConfigUnitList[i].IsSuccess) ++_failCount; _createLordConfigUnitList.RemoveAt(i); } } if (_createLordConfigUnitList.Count == 0) { _state = AutomationState.Done; if (_failCount == 0) _result = AutomationResult.Success; else _result = AutomationResult.Failure; } } break; } }
public override void Do(AutomationContext context) { switch (_state) { case AutomationState.Init: _fileDownloadUnitHashtable = new Hashtable(); IList<GameServer> serverList = context.GetAllServers(); foreach (GameServer server in serverList) { FileDownloadUnit unit = new FileDownloadUnit(server); _fileDownloadUnitHashtable.Add(server.Id, unit); //生成一个Automation相关的FileDownloadTask然后加入File队列中,传输默认为覆盖选项。 server.AddFMTask(new FileDownloadTask(this, _sourceFileName, _targetFileName, true)); } _state = AutomationState.Doing; break; case AutomationState.Doing: foreach (GameServer server in context.GetAllServers()) { FileDownloadUnit unit = _fileDownloadUnitHashtable[server.Id] as FileDownloadUnit; if (unit != null && unit.IsDone) { if (!unit.IsSuccess) ++_failCount; _fileDownloadUnitHashtable.Remove(unit.Server.Id); } } if (_fileDownloadUnitHashtable.Count == 0) { _state = AutomationState.Done; if (_failCount == 0) _result = AutomationResult.Success; else _result = AutomationResult.Failure; } break; } }
public override void Do(AutomationContext context) { IList<GameServer> servers = context.GetAllServers(); foreach(GameServer server in servers) { //################################################ server.DoPlugInAction(SecurityManager.SystemAutomationId, LordControl.PlugInGuid, LordControl.ActionKeySayToWorld, _message); } _state = AutomationState.Done; _result = AutomationResult.Success; }
public object Clone() { AutomationContext cloneObj = new AutomationContext(); cloneObj.Server = Server; if (ServerList != null) { cloneObj.ServerList = new List<GameServer>(ServerList); } cloneObj.Group = Group; if (ServerGroupList != null) { cloneObj.ServerGroupList = new List<ServerGroup>(ServerGroupList); } cloneObj.Message = Message; if (AdditionalObject != null) { cloneObj.AdditionalObject = (ICloneable)AdditionalObject.Clone(); } return cloneObj; }
public abstract void Do(AutomationContext context);
/// <summary> /// 执行自动化作业 /// </summary> /// <remarks>简化版,免回调</remarks> public void Do(IAutomation automation, AutomationContext context, DelegateAutomationDone callback, object stateObject) { Do(automation, context, callback, stateObject, null); }
/// <summary> /// 执行自动化作业 /// </summary> /// <remarks>简化版,免回调</remarks> public void Do(IAutomation automation, AutomationContext context, AutomationUnit callingUnit) { Do(automation, context, null, null, callingUnit); }
/// <summary> /// 执行自动化作业 /// </summary> /// <remarks>简化版,免回调</remarks> public void Do(IAutomation automation, AutomationContext context) { Do(automation, context, null, null, null); }
public override void Do(AutomationContext context) { bool success = true; IList<GameServer> serverList = context.GetAllServers(); foreach (GameServer server in serverList) { object outArg = null; //######################################################### if (!server.DoPlugInAction(SecurityManager.SystemAutomationId, GameServerControl.PlugInGuid, GameServerControl.ActionKeyUpdateGame, ref outArg, new object[] { _patchName })) { success = false; } } if (success) _result = AutomationResult.Success; else _result = AutomationResult.Failure; _state = AutomationState.Done; }
public override void Do(AutomationContext context) { int operatorId = AdminServer.TheInstance.AutomationManager.SecurityObject.Id; int targetId = 0; GameServer server = context.Server; if (server != null) { targetId = server.SecurityObject.Id; } string desc = context.Message; if (desc == null) desc = string.Empty; LogSystem.TheInstance.WriteLog(operatorId, OpType.READ, targetId, desc); _state = AutomationState.Done; _result = AutomationResult.Success; }
public override void Do(AutomationContext context) { try { switch (_state) { case AutomationState.Init: AdminServer.TheInstance.GameServerManager.CreateServerListFiles( AdminServer.TheInstance.GameServerManager.ServerMap.NetList, SystemConfig.Current.ServerListFileDir, SystemConfig.Current.DefaultEncoding ); _result = AutomationResult.Success; _state = AutomationState.Done; break; } } catch (Exception ex) { Util.DebugLog(ex.ToString()); _state = AutomationState.Done; _result = AutomationResult.Failure; } }
public override void Do(AutomationContext context) { switch (_state) { case AutomationState.Init: { _checkingGameServerList = new List<GetStackTraceUnit>(); IList<GameServer> serverList = context.GetAllServers(); foreach (GameServer server in serverList) { object outArg = null; //######################################################### if (server.DoPlugInAction(SecurityManager.SystemAutomationId, GameServerControl.PlugInGuid, GameServerControl.ActionKeyGetStackTrace, ref outArg)) { GetStackTraceUnit unit = new GetStackTraceUnit(server); unit.StartTime = DateTime.Now; unit.IsDone = false; _checkingGameServerList.Add(unit); } } _state = AutomationState.Doing; } break; case AutomationState.Doing: { foreach (GetStackTraceUnit unit in _checkingGameServerList) { //################################################ GameServerControl.GetStackTraceState getStackTraceState = (GameServerControl.GetStackTraceState)unit.Server.GetPlugInData(-1,GameServerControl.PlugInGuid, GameServerControl.DataKeyGetStackTraceState); if (getStackTraceState == GameServerControl.GetStackTraceState.Done) { unit.IsDone = true; context.Message += string.Format("\nStackTrace of {0}:\n{1}", unit.Server.ToString(), unit.Server.GetPlugInData(-1,GameServerControl.PlugInGuid, GameServerControl.DataKeyStackTrace) as string); } else if (DateTime.Now.Subtract(unit.StartTime) > GetStackTraceTimeout) { unit.IsDone = true; } } for (int i = _checkingGameServerList.Count - 1; i >= 0; i--) { if (_checkingGameServerList[i].IsDone) { _checkingGameServerList.RemoveAt(i); } } if (_checkingGameServerList.Count == 0) { _state = AutomationState.Done; _result = AutomationResult.Success; } } break; } }
public override void Do(AutomationContext context) { IList<GameServer> toDelServerList = new List<GameServer>(); IList<GameServer> servers = context.GetAllServers(); foreach (GameServer server in servers) { bool matchGameState = true; bool matchServerState = true; if (_gameState != null && _gameState.Length > 0) { matchGameState = false; foreach (GameServer.ServiceState gameState in _gameState) { if (server.GameServiceState == gameState) { matchGameState = true; break; } } } if (_serverState != null && _serverState.Length > 0) { matchServerState = false; foreach (GameServer.ServerState serverState in _serverState) { if (server.GameServerState == serverState) { matchServerState = true; break; } } } if (!(matchServerState && matchGameState)) toDelServerList.Add(server); } foreach (GameServer server in toDelServerList) { context.RemoveGameServer(server); } _result = AutomationResult.Success; _state = AutomationState.Done; }
public override void Do(AutomationContext context) { try { switch (_state) { case AutomationState.Init: { _exeSysCmdCompleted = false; _completeCount = 0; IList<GameServer> serverList = context.GetAllServers(); _unitList = new List<ExeSysCmdUnit>(); foreach (GameServer server in serverList) { string script, input; if (CreateScript(server, out script, out input)) { if (server.DoPlugInAction( SecurityManager.SystemAutomationId, GameServerControl.PlugInGuid, GameServerControl.ActionKeyExeSysCmd, script, input, FSEye.PlugIn.GameServerControl.GuardTask.DoNormalSysCmd, new GameServerControl.ExeSysCmdComplete(ExeSysCmdComplete))) { OnCommandSent(server); ExeSysCmdUnit exeunit = new ExeSysCmdUnit(); exeunit.Server = server; _unitList.Add(exeunit); } } } _result = (_unitList.Count == serverList.Count) ? AutomationResult.Success : AutomationResult.Failure; if (_unitList.Count > 0) _state = AutomationState.Doing; else _state = AutomationState.Done; } break; case AutomationState.Doing: { if (_exeSysCmdCompleted) { bool allSuccess = true; StringBuilder exeCmdOuput = new StringBuilder(); foreach (ExeSysCmdUnit unit in _unitList) { if (unit.Done) { exeCmdOuput.AppendLine(unit.Output); if (!unit.Success) { allSuccess = false; } } } context.Message = exeCmdOuput.ToString(); if (!allSuccess) _result = AutomationResult.Failure; _state = AutomationState.Done; } } break; } } catch (Exception) { _result = AutomationResult.Failure; _state = AutomationState.Done; } }
/// <summary> /// 处理 /// </summary> private void Process() { while (!_dispose) { if (_working) { //执行每个自动化作业单元 foreach (AutomationUnit automationUnit in _workingList) { IAutomation automation = automationUnit.Automation; AutomationContext context = automationUnit.Context; switch (automation.State) { case AutomationState.Init: //开始执行 automation.Do(context); break; case AutomationState.Doing: //正在执行中 automation.Do(context); break; case AutomationState.Done: //执行完毕 { bool completed = true; if (automation.Result == AutomationResult.Success && automation.Success != null) { completed = false; Do(automation.Success, context, automationUnit); } if (automation.Result == AutomationResult.Failure && automation.Failure != null) { completed = false; Do(automation.Failure, context, automationUnit); } if (automation.Complete != null) { completed = false; Do(automation.Complete, context, automationUnit); } if (completed) { Remove(automationUnit); if (automationUnit.Callback != null) { automationUnit.Callback.Invoke(automationUnit.CallbackStateObject); } if (automationUnit.CallingUnit != null) { NotifyWaitUnit(automation, automationUnit.CallingUnit); } } else { WaitForComplete(automationUnit); } } break; default: throw new Exception("Invalid automation state!"); } } //删除需要删除的自动化作业单元 if (_toBeDelList.Count > 0) { foreach (AutomationUnit automationUnit in _toBeDelList) { _workingList.Remove(automationUnit); } _toBeDelList.Clear(); } //删除等待完成的自动化作业单元 if (_toBeWaitList.Count > 0) { foreach (AutomationUnit automationUnit in _toBeWaitList) { _workingList.Remove(automationUnit); _waitForCompleteList.Add(automationUnit); } _toBeWaitList.Clear(); } //添加需要添加的自动化作业单元 if (_toBeAddList.Count > 0) { foreach (AutomationUnit automationUnit in _toBeAddList) { _workingList.Add(automationUnit); } _toBeAddList.Clear(); } } Thread.Sleep(1); } }
public override void Do(AutomationContext context) { try { if (_state == AutomationState.Init) { File.Delete(SystemConfig.Current.AdminServerUploadFileRootPath + _fileName); Finish(AutomationResult.Success); } } catch (Exception) { Finish(AutomationResult.Failure); } }
/// <summary> /// 已连接 /// </summary> public void OnConnected(long connectionId, byte[] communicationKey, int port) { try { lock (_syncRoot) { _connected = true; _port = port; _connectionId = connectionId; if (communicationKey != null) { _communicationKey = new byte[communicationKey.Length]; Array.Copy(communicationKey, _communicationKey, communicationKey.Length); } _serverState = ServerState.Running; ContinueTasks(); AppendMessage("Connected", GameServer.MessageInfo.Type.Success); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} Connected", this.ToString()); context.Server = this; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.ServerConnected, context); if (Connected != null) { Connected(this); } } } catch (Exception ex) { Util.DebugLog(string.Format("Exception in Server[{0}] OnConnected : {1}", this.Name, ex.Message)); } }
public override void Do(AutomationContext context) { switch (_state) { case AutomationState.Init: { BatchTask task = AdminServer.TheInstance.BatchTaskManager.GetBatchTask(_taskId); if (task != null) { try { task.Reset(); task.Start(new BatchTask.BatchTaskComplete(BatchTaskComplete), task); } catch (Exception) { _state = AutomationState.Done; _result = AutomationResult.Failure; } _state = AutomationState.Doing; } else { _state = AutomationState.Done; _result = AutomationResult.Failure; } } break; } }
/// <summary> /// 断开连接 /// </summary> public void OnDisconnected() { try { lock (_syncRoot) { _connected = false; _port = 0; _serverState = ServerState.Unknown; PauseTasks(); ClearHistoryInfo(); AppendMessage("Disconnected", GameServer.MessageInfo.Type.Failure); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} Disconnected", this.ToString()); context.Server = this; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.ServerDisconnected, context); if (Disconnected != null) { Disconnected(this); } } } catch (Exception ex) { Util.DebugLog(string.Format("Exception in Server[{0}] OnDisconnected : {1}", this.Name, ex.Message)); } }
//public override string Parameter //{ // get // { // StringBuilder text = new StringBuilder(); // if (_selectType == SelectType.All) // { // text.Append(ParameterAll); // } // else if (_selectType == SelectType.None) // { // text.Append(ParameterNone); // } // else if (_selectType == SelectType.Custom) // { // if (_serverId > 0) // { // text.Append(ParameterServer); // text.Append(_serverId); // text.Append(ParameterDelimiter); // } // else // { // foreach (int serverId in _serverIdList) // { // text.Append(ParameterServer); // text.Append(serverId); // text.Append(ParameterDelimiter); // } // foreach (int groupId in _groupIdList) // { // text.Append(ParameterGroup); // text.Append(groupId); // text.Append(ParameterDelimiter); // } // } // if (text.Length > 0) // { // text.Remove(text.Length - ParameterDelimiter.Length, ParameterDelimiter.Length); // } // } // return text.ToString(); // } // set // { // try // { // _serverIdList.Clear(); // _groupIdList.Clear(); // if (value == null || value == ParameterAll) // { // _selectType = SelectType.All; // } // else if (value == ParameterNone) // { // _selectType = SelectType.None; // } // else // { // _selectType = SelectType.Custom; // string[] parameterArray = value.Split(new string[] { ParameterDelimiter }, StringSplitOptions.None); // if (parameterArray.Length == 1 && parameterArray[0].StartsWith(ParameterServer)) // { // _serverId = int.Parse(parameterArray[0].Substring(ParameterServer.Length)); // } // else // { // foreach (string parameter in parameterArray) // { // if (parameter.StartsWith(ParameterServer)) // { // int serverId = int.Parse(parameter.Substring(ParameterServer.Length)); // _serverIdList.Add(serverId); // } // else if (parameter.StartsWith(ParameterGroup)) // { // int groupId = int.Parse(parameter.Substring(ParameterGroup.Length)); // _groupIdList.Add(groupId); // } // } // } // } // } // catch (Exception e) // { // throw new BadParameterException("The currect format of parameter should be: s# s# g# g#", e); // } // } //} public override void Do(AutomationContext context) { GameServerManager gsm = AdminServer.TheInstance.GameServerManager; if (_serverIdList != null && _serverIdList.Count != 0) { foreach (int serverId in _serverIdList) { GameServer server = gsm.GetGameServer(serverId); if (server != null) { context.ServerList.Add(server); } } } if (_groupIdList != null && _groupIdList.Count != 0) { foreach (int groupId in _groupIdList) { ServerGroup group = gsm.GetGameServerGroup(groupId); if (group != null) { context.ServerGroupList.Add(group); } } } //switch (_selectType) //{ // case SelectType.Custom: // { // if (_serverId > 0) // { // GameServer server = gsm.GetGameServer(_serverId); // if (server != null) // { // context.Server = server; // } // } // foreach (int serverId in _serverIdList) // { // GameServer server = gsm.GetGameServer(serverId); // if (server != null) // { // context.ServerList.Add(server); // } // } // foreach (int groupId in _groupIdList) // { // ServerGroup group = gsm.GetGameServerGroup(groupId); // if (group != null) // { // context.ServerGroupList.Add(group); // } // } // } // break; // case SelectType.All: // { // foreach (GameServer server in gsm.Servers) // { // context.ServerList.Add(server); // } // } // break; // case SelectType.None: // { // context.ClearAllServers(); // } // break; //} _state = AutomationState.Done; _result = AutomationResult.Success; }
/// <summary> /// 执行任务 /// </summary> /// <remarks>耗时的操作</remarks> void DoTask() { while (!_needAbort && _state != State.Done) { lock (_lock) { if (_state == State.Doing) { if (_needPause) { _state = State.Paused; _needPause = false; } else { if (_workingUnitCount < _step) { if (_nextUnitIndex < _taskUnitList.Count) { BatchTaskUnit unit = _taskUnitList[_nextUnitIndex]; if (unit.UnitState == BatchTaskUnit.State.Querying) { GameServer server = AdminServer.TheInstance.GameServerManager.GetGameServer(unit.ServerId); if (server != null) { unit.UnitState = BatchTaskUnit.State.Doing; _workingUnitCount++; AutomationContext context = new AutomationContext(); context.ServerList.Add(server); AdminServer.TheInstance.AutomationManager.Do(Automation, context, new DelegateAutomationDone(AutomationDone), unit); } else { unit.UnitState = BatchTaskUnit.State.Done; } } _nextUnitIndex++; } else if (_workingUnitCount == 0) { _state = State.Done; } } } } else if (_state == State.Paused) { if (_needContinue) { _state = State.Doing; _needContinue = false; } else { Thread.Sleep(1000); } } } Thread.Sleep(1); } if (_needAbort) { _state = State.Aborted; _needAbort = false; } _endTime = DateTime.Now; }
public override void Do(AutomationContext context) { _state = AutomationState.Done; _result = AutomationResult.Success; }
public override void Do(AutomationContext context) { switch (_state) { case AutomationState.Init: { _waitFinishTime = DateTime.Now.AddSeconds(_waitSeconds); _state = AutomationState.Doing; } break; case AutomationState.Doing: { if (DateTime.Now >= _waitFinishTime) { _state = AutomationState.Done; _result = AutomationResult.Success; } } break; } }
public override void Do(AutomationContext context) { //switch (_state) //{ // case AutomationState.Init: // if (_receiverMailList != null && _receiverMailList.Count != 0) // { // SmtpClient mailClient = new SmtpClient(MailServerName); // mailClient.Credentials = new NetworkCredential(User, Password); // //先设置为成功,如果有异常则设置为失败,但并不影响向其它Mail的发送。 // _result = AutomationResult.Success; // foreach (string receiverMail in _receiverMailList) // { // try // { // MailMessage message = new MailMessage(SenderMail, receiverMail, _subject, context.Message); // message.SubjectEncoding = SystemConfig.Current.DefaultEncoding; // message.BodyEncoding = SystemConfig.Current.DefaultEncoding; // mailClient.Send(message); // } // catch (Exception) // { // _result = AutomationResult.Failure; // } // } // } // _state = AutomationState.Done; // break; //} try { switch (_state) { case AutomationState.Init: if (_receiverMailList != null && _receiverMailList.Count != 0) { SmtpClient mailClient = new SmtpClient(MailServerName); mailClient.Credentials = new NetworkCredential(User, Password); if (_mailContentTypeList.Count == 0) { //先设置为成功,如果有异常则设置为失败,但并不影响向其它Mail的发送。 _result = AutomationResult.Success; foreach (string receiverMail in _receiverMailList) { try { MailMessage message = new MailMessage(SenderMail, receiverMail, _subject, context.Message); message.SubjectEncoding = SystemConfig.Current.DefaultEncoding; message.BodyEncoding = SystemConfig.Current.DefaultEncoding; mailClient.Send(message); } catch (Exception ex) { _result = AutomationResult.Failure; throw ex; } } } else { string tableStyle = "<style type='text/css'> table, td { border-color: black; border-style: solid; border-width: 1px; border-spacing: 0; border-collapse: collapse; padding: 4px; } </style>"; string contentString = tableStyle; ArrayList attachmentLocations = new ArrayList(); foreach (string str in _mailContentTypeList) { switch (str) { case "PlayerCountOneDayStyleText": { contentString += "<div style=\"font-family:Arial\">各区服24小时内在线人数统计(文字)<br /><br /></div>"; contentString += GetPlayerCountTextOneDay(); break; } case "PlayerCountOneDayStylePic": { contentString += "<div style=\"font-family:Arial\">各区服24小时内在线人数统计(图表)<br /><br /></div>"; foreach (GameServer server in AdminServer.TheInstance.GameServerManager.Servers) { if (server.Type == GameServer.ServerType.gamecenter) { string fileName = string.Empty; MemoryStream imageMemoryStream = CreatePlayerCountImageOneDay(server, out fileName); if (imageMemoryStream != null) { contentString += "<div style=\"font-family:Arial\">" + server.Group.Name + "<br /><img src=\"cid:" + fileName + "\" alt=\"IMAGE HERE\" width=\"840\" height=\"450\"><br /><br /></div>"; Attachment attachment = new Attachment(imageMemoryStream, fileName, System.Net.Mime.MediaTypeNames.Image.Jpeg); attachmentLocations.Add(attachment); } } } break; } case "PlayerCountOneMonthStyleText": { contentString += "<div style=\"font-family:Arial\">各区服一月内在线人数统计(文字)<br /><br /></div>"; contentString += GetPlayerCountTextOneMonth(); break; } case "PlayerCountOneMonthStylePic": { contentString += "<div style=\"font-family:Arial\">各区服一月内在线人数统计(图表)<br /><br /></div>"; foreach (GameServer server in AdminServer.TheInstance.GameServerManager.Servers) { if (server.Type == GameServer.ServerType.gamecenter) { string fileName = string.Empty; MemoryStream imageMemoryStream = CreatePlayerCountImageOneMonth(server, out fileName); if (imageMemoryStream != null) { contentString += "<div style=\"font-family:Arial\">" + server.Group.Name + "<br /><img src=\"cid:" + fileName + "\" alt=\"IMAGE HERE\" width=\"840\" height=\"450\"><br /><br /></div>"; Attachment attachment = new Attachment(imageMemoryStream, fileName, System.Net.Mime.MediaTypeNames.Image.Jpeg); attachmentLocations.Add(attachment); } } } break; } case "ServerEventOneDay": { string summaryContent = GetServerEventSummaryOneDay(); contentString += summaryContent; break; } } } //先设置为成功,如果有异常则设置为失败,但并不影响向其它Mail的发送。 _result = AutomationResult.Success; foreach (string receiverMail in _receiverMailList) { try { MailMessage message = new MailMessage(SenderMail, receiverMail, _subject, contentString); message.SubjectEncoding = SystemConfig.Current.DefaultEncoding; message.BodyEncoding = SystemConfig.Current.DefaultEncoding; message.IsBodyHtml = true; if (attachmentLocations.Count > 0) { foreach (Attachment attachment in attachmentLocations) { message.Attachments.Add(attachment); } } mailClient.Send(message); } catch (Exception ex) { _result = AutomationResult.Failure; throw ex; } } } } _result = AutomationResult.Success; _state = AutomationState.Done; break; } } catch (Exception ex) { Util.DebugLog(ex.ToString()); _state = AutomationState.Done; _result = AutomationResult.Failure; } }
public override void Do(AutomationContext context) { IList<GameServer> serverList = context.GetAllServers(); foreach (GameServer server in serverList) { } _state = AutomationState.Done; _result = AutomationResult.Success; }
public void GameStateChanged(GameServer server, GameServer.ServiceState originalState, GameServer.ServiceState newState) { GameServer.ServerEventType eventType = GameServer.ServerEventType.UnknownEvent; switch (originalState) { case GameServer.ServiceState.Starting: { if (newState == GameServer.ServiceState.Running) { //游戏正常启动 server.AppendMessage("Start", GameServer.MessageInfo.Type.Success); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} Start", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStart, context); eventType = GameServer.ServerEventType.GameStart; } else if (newState == GameServer.ServiceState.ErrorStopped) { //游戏启动失败 server.AppendMessage("StartFail", GameServer.MessageInfo.Type.Failure); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} StartFail", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.StartGameFail, context); eventType = GameServer.ServerEventType.GameStartFail; } } break; case GameServer.ServiceState.Stopping: { if (newState == GameServer.ServiceState.OKStopped || newState == GameServer.ServiceState.ErrorStopped) { //停止,指web主动关闭服务器程序 //游戏正常关闭 server.AppendMessage("Stop", GameServer.MessageInfo.Type.Alert); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} Stop", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStop, context); eventType = GameServer.ServerEventType.GameStop; } } break; case GameServer.ServiceState.ErrorStopped: case GameServer.ServiceState.OKStopped : { if (newState == GameServer.ServiceState.Running) { //游戏意外启动 server.AppendMessage("StartByAccident", GameServer.MessageInfo.Type.Failure); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} StartByAccident", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStartByAccident, context); eventType = GameServer.ServerEventType.GameStartByAccident; } } break; case GameServer.ServiceState.Running: { if (newState == GameServer.ServiceState.ErrorStopped) { //游戏崩溃 server.AppendMessage("StopByAccident", GameServer.MessageInfo.Type.Failure); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} StopByAccident", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStopByAccident, context); eventType = GameServer.ServerEventType.GameStopByAccident; } } break; } if (eventType != GameServer.ServerEventType.UnknownEvent) { DateTime eventTime = DateTime.Now; using (IBlazeDatabase db = DbFactory.GetDatabase()) { IBlazeTable table = db.GetTable(TableString.ServerEventTableName); string[] fieldNames = { TableString.ServerEventFieldServerId, TableString.ServerEventFieldEventTime, TableString.ServerEventFieldEventType }; object[] fieldValues = { server.Id, eventTime, (Int16)eventType }; table.Add(fieldNames, fieldValues); } } }