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.
127 lines
3.6 KiB
127 lines
3.6 KiB
using System.Linq;
|
|
using Sog;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
|
namespace SMCenter
|
|
{
|
|
// 传输文件
|
|
public class FileTransCmdProc : BaseCmdProc
|
|
{
|
|
public override void ClearData()
|
|
{
|
|
m_nowCmd = null;
|
|
}
|
|
|
|
// cmdParams[0] is serverId
|
|
public override int DoCmd(out string msg)
|
|
{
|
|
if (m_nowCmd.CMD == "cancelpush")
|
|
{
|
|
CancelPush();
|
|
msg = "";
|
|
return 0;
|
|
}
|
|
|
|
if (m_nowCmd.CmdParams.Count < 1)
|
|
{
|
|
msg = "invalid cmd param";
|
|
return -1;
|
|
}
|
|
|
|
if (m_nowCmd.CMD != "pushagent")
|
|
{
|
|
if (CmdUtils.CheckValidServerId(m_nowCmd.CmdParams[0], out string fixSvrId) == false)
|
|
{
|
|
msg = "invalid server id";
|
|
return -1;
|
|
}
|
|
|
|
if (fixSvrId != null)
|
|
{
|
|
m_nowCmd.CmdParams[0] = fixSvrId;
|
|
}
|
|
|
|
SMProcAppMgr.Instance.GetAllMatchingProc(m_nowCmd.CmdParams[0], m_nowCmd.m_procs);
|
|
}
|
|
|
|
if (CenterFileTransMng.Instance.DoTransCmd(m_nowCmd) != 0)
|
|
{
|
|
msg = CenterFileTransMng.Instance.errorMsg;
|
|
return -1;
|
|
}
|
|
|
|
msg = "";
|
|
TraceLog.Trace("FileTransCmdProc.DoCmd {0}", m_nowCmd.CMD);
|
|
return 0;
|
|
}
|
|
|
|
|
|
public override int UpdateCmd(long tMs)
|
|
{
|
|
if (CenterFileTransMng.Instance.isFinish)
|
|
{
|
|
AckConsoleCmdResult();
|
|
CenterFileTransMng.Instance.Clear();
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
private void AckConsoleCmdResult()
|
|
{
|
|
SMConsoleCommandRes res = new SMConsoleCommandRes();
|
|
res.Command = m_nowCmd.ConsoleInput;
|
|
res.Message = "";
|
|
|
|
var transMgr = CenterFileTransMng.Instance.transMgr;
|
|
|
|
string procResult = "";
|
|
|
|
string pushFile = "";
|
|
for (int i = 0; i < transMgr.fileList.Count; i++)
|
|
{
|
|
pushFile += transMgr.fileList[i].fileName;
|
|
// 每行3个文件
|
|
pushFile += i % 3 == 2 ? "\n\t" : "\t";
|
|
}
|
|
|
|
foreach (var transNode in transMgr.transHosts.Values)
|
|
{
|
|
// 接收节点在网络正常的情况下一定会上报接收结果, 没有收到上报基本上是因为网络问题
|
|
if (transNode.fileState.Count == 0)
|
|
{
|
|
procResult += string.Format("\n{0} : NoRes", transNode.receiverHost);
|
|
}
|
|
else
|
|
{
|
|
procResult += string.Format("\n{0} : ", transNode.receiverHost);
|
|
|
|
// 1表示成功
|
|
string str = string.Join(' ', transNode.fileState.Where(r => r.RecvState != 1).Select(r => r.FileName));
|
|
if (str.Length == 0)
|
|
{
|
|
procResult += "Succ";
|
|
}
|
|
else
|
|
{
|
|
procResult += "Fail (" + str + ")";
|
|
}
|
|
}
|
|
|
|
res.Message += "Files: " + pushFile;
|
|
res.Message += procResult;
|
|
}
|
|
|
|
SMCenterNet.Instance.SendMsg(m_nowCmd.SessionId, SMMsgID.ConsoleCommandRes, res);
|
|
}
|
|
|
|
public void CancelPush()
|
|
{
|
|
TraceLog.Trace("FileTransCmdProc.CancelPush");
|
|
|
|
CenterFileTransMng.Instance.CancelPush();
|
|
}
|
|
}
|
|
}
|
|
|