Exemple #1
0
        /// <summary>
        /// 执行系统命令
        /// </summary>
        /// <param name="cmd">命令</param>
        /// <param name="input">输入</param>
        /// <param name="newTask">任务</param>
        /// <param name="needLog">是否需要记录日志</param>
        /// <param name="bNeedResult">是否需要反馈结果</param>
        bool ExecuteSystemCommand(int userId, string cmd, string input, GuardTask newTask, ExeSysCmdComplete exeSysCmdComplete, bool needLog, bool bNeedResult)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            if (input == null)
            {
                input = string.Empty;
            }

            bool result = false;

            //TODO: if (_server.IsConnected && _guardTask == GuardTask.Idle)
            if (_server.IsConnected)
            {
                IProtocol realProtocol = null;
                if (cmd.Length >= 1024)
                {
                    e2g_exesyscmd_large protocol = new e2g_exesyscmd_large();
                    protocol.Command     = cmd;
                    protocol.InputBuff   = input;
                    protocol.bNeedOutput = Convert.ToUInt16(bNeedResult);

                    realProtocol = protocol;
                }
                else
                {
                    e2g_exesyscmd protocol = new e2g_exesyscmd();
                    protocol.Command     = cmd;
                    protocol.InputBuff   = input;
                    protocol.bNeedOutput = Convert.ToUInt16(bNeedResult);

                    realProtocol = protocol;
                }

                if (_server.SendMessage(realProtocol))
                {
                    _lastSystemCommand      = cmd;
                    _lastSystemCommandInput = input;
                    _sysCmdOutput.Length    = 0;
                    _exeSysCmdComplete      = exeSysCmdComplete;

                    _guardTask = newTask;

                    result = true;
                }
            }

            if (needLog)
            {
                User user = AdminServer.TheInstance.SecurityManager.GetUser(userId);
                Security.LogSystem.TheInstance.WriteLog(
                    userId,
                    Security.OpType.EXECUTE,
                    _server.Id,
                    string.Format(StringDef.LogMessageExecuteSystemCommand,
                                  user == null ? userId.ToString() : user.UserName,
                                  _server.Name,
                                  cmd,
                                  result ? StringDef.Success : StringDef.Fail)
                    );
            }
            return(result);
        }
Exemple #2
0
		/// <summary>
		/// 执行系统命令
		/// </summary>
		/// <param name="cmd">命令</param>
		/// <param name="input">输入</param>
		/// <param name="newTask">任务</param>
		/// <param name="needLog">是否需要记录日志</param>
        /// <param name="bNeedResult">是否需要反馈结果</param>
        bool ExecuteSystemCommand(int userId,string cmd, string input, GuardTask newTask, ExeSysCmdComplete exeSysCmdComplete, bool needLog, bool bNeedResult)
		{
			if (cmd == null)
				throw new ArgumentNullException("cmd");
			if (input == null)
				input = string.Empty;

            bool result = false;

            //TODO: if (_server.IsConnected && _guardTask == GuardTask.Idle)
			if (_server.IsConnected)
			{
				IProtocol realProtocol = null;
				if (cmd.Length >= 1024)
				{
					e2g_exesyscmd_large protocol = new e2g_exesyscmd_large();
					protocol.Command = cmd;
					protocol.InputBuff = input;
                    protocol.bNeedOutput = Convert.ToUInt16(bNeedResult);

					realProtocol = protocol;
				}
				else
				{
					e2g_exesyscmd protocol = new e2g_exesyscmd();
					protocol.Command = cmd;
					protocol.InputBuff = input;
                    protocol.bNeedOutput = Convert.ToUInt16(bNeedResult);

					realProtocol = protocol;
				}

				if (_server.SendMessage(realProtocol))
				{
					_lastSystemCommand = cmd;
					_lastSystemCommandInput = input;
					_sysCmdOutput.Length = 0;
					_exeSysCmdComplete = exeSysCmdComplete;

					_guardTask = newTask;
                    					
                    result = true;
				}
			}

			if (needLog)
			{
                User user = AdminServer.TheInstance.SecurityManager.GetUser(userId);
                Security.LogSystem.TheInstance.WriteLog(
                    userId,
                    Security.OpType.EXECUTE,
                    _server.Id,
                    string.Format(StringDef.LogMessageExecuteSystemCommand,
                        user == null ? userId.ToString() : user.UserName,
                        _server.Name,
                        cmd,
                        result ? StringDef.Success : StringDef.Fail)
                );
			}
			return result;
		}