using System; using Sog; using Google.Protobuf.WellKnownTypes; namespace SMCenter { // 更新agent public class UpdateAgentCmdProc : BaseCmdProc { public override void ClearData() { m_nowCmd = null; } public override int DoCmd(out string msg) { try { var req = new SMAgentDoCommandReq(); req.Command = m_nowCmd.CMD; req.SeqNum = m_nowCmd.SeqNum; req.ExeFileName = GetExeFileName(); // 先简单处理,立刻广播,有问题再挪到UpdateCmd SMCenterNet.Instance.BroadcastToAllAgent(SMMsgID.AgentDoCommandReq, req); } catch (Exception e) { TraceLog.Exception(e); msg = "update agent throw a exception ..."; return -1; } msg = "update agent begin ..."; return 0; } public override int UpdateCmd(long tMs) { // 消息发送后强制等待5s if (tMs / 1000 - m_nowCmd.CreateTime >= 5) { var res = new SMConsoleCommandRes(); res.Command = m_nowCmd.CMD; res.Message = "\tuse [checkagent] to see if update succ"; SMCenterNet.Instance.SendMsg(m_nowCmd.SessionId, SMMsgID.ConsoleCommandRes, res); return 0; } return 1; } public override void OnAgentDoCommandRes(ClientInfo client, SMAgentDoCommandRes res) { TraceLog.Error("UpdateAgentCmdProc.OnAgentDoCommandRes cmd {0} invalid res from {1}", m_nowCmd.CMD, client.HostName); } private string GetExeFileName() { string exename = "SMAgentUpdater"; if (OSUtils.IsWindows()) { exename += ".exe"; } return exename; } } }