You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
2.3 KiB

using System.Collections.Generic;
using System.Linq;
using Sog;
using Google.Protobuf.WellKnownTypes;
namespace SMCenter
{
public class BaseCmdProc
{
public CmdInfo m_nowCmd;
public string m_explainCmd;
public bool m_needCheckValidServerId;
public void InitCmd(CmdInfo cmd)
{
m_nowCmd = cmd;
}
public virtual void ClearData()
{
m_nowCmd = null;
}
public virtual int DoCmd(out string msg)
{
msg = "invalid cmd...";
TraceLog.Error("BaseCmdProc.DoCmd should not call this func, cmd {0}", m_nowCmd.CMD);
return 0;
}
// 返回值:-1 出错(cmd结束) 0 cmd结束 1 继续update
public virtual int UpdateCmd(long tMs)
{
TraceLog.Error("BaseCmdProc.UpdateCmd should not call this func, cmd {0}", m_nowCmd.CMD);
return 0;
}
public virtual void OnAgentDoCommandRes(ClientInfo client, SMAgentDoCommandRes res)
{
TraceLog.Error("BaseCmdProc.OnAgentDoCommandRes should not call this func, cmd {0}", m_nowCmd.CMD);
}
// m_procs去重, 同时只加载已经注册连接的agent数据
// todo 这个函数写的有点问题, m_procs是符合命令条件的所有app信息, 去重后获得这些app部署的host
// 最好不要Distinct去重后直接覆盖原来的m_procs, 代码调用太广, 暂不修改吧
public void CmdProcInfoDistinct(string hostName = "")
{
if (m_nowCmd == null)
{
return;
}
//排除非指定的hostName
if(string.IsNullOrEmpty(hostName) == false && hostName != "*")
{
m_nowCmd.m_procs = m_nowCmd.m_procs.Where(p => p.Value.SMApp.HostName == hostName).ToDictionary(p => p.Key, p => p.Value);
}
var hostList = new List<string>();
var tempProcs = new Dictionary<uint, CmdProcInfo>();
var regAgents = SMCenterNet.Instance.GetAllAgent(); //所有的已经启动的agent
foreach (var info in m_nowCmd.m_procs)
{
if (string.IsNullOrEmpty(hostList.Find(x => x == info.Value.SMApp.HostName)))
{
hostList.Add(info.Value.SMApp.HostName);
if (regAgents.Find(p => p.HostName == info.Value.SMApp.HostName) != null)
{
tempProcs.Add(info.Key, info.Value);
}
}
}
m_nowCmd.m_procs = tempProcs;
}
}
}