示例#1
0
 /// <summary>
 /// 添加要记录的命令
 /// </summary>
 /// <param name="data"></param>
 public static void AppendRecCommand(RecCommand data)
 {
     if (commandRecorder == null || !commandRecorder.IsRuning)
     {
         return;
     }
     commandRecorder.Append(data);
 }
示例#2
0
        /// <summary>
        /// 完成命令
        /// </summary>
        /// <param name="command"></param>
        public static void CompleteCommand(RequestCommand command)
        {
            command.endTime       = DateTime.Now;
            command.timeConsuming = RecCommand.GetTimeSpanStr(command.beginTime, command.endTime);
            // 命令记录
            CommandManager.AppendRecCommand(RecCommand.ToRecCommand(command));
            // 命令回执
            ResponseCommand responseCommand;

            switch (command.state)
            {
            case CommandState.Succeed:
            {
                responseCommand = new ResponseCommand()
                {
                    info       = "命令执行成功",
                    errMsg     = "",
                    statusCode = "200"
                };
            }
            break;

            case CommandState.Timeout:
            {
                responseCommand = new ResponseCommand()
                {
                    info       = "",
                    errMsg     = "命令执行超时",
                    statusCode = "490"
                };
            }
            break;

            default:
            {
                responseCommand = new ResponseCommand()
                {
                    info       = "",
                    errMsg     = "命令执行失败:" + command.message,
                    statusCode = "491"
                };
            }
            break;
            }
            string data = ByteUtil.ToSerializeObject(responseCommand);
            string err  = command.FinshCallBack(command.sessionID, data, true);

            if (!string.IsNullOrWhiteSpace(err))
            {
                TraceManagerForCommand.AppendErrMsg("命令ID:" + command.ID + "发送回执命令失败");
            }
        }
示例#3
0
        private void Excute(RecCommand command)
        {
            command.UpdateDateTime = DataUtil.ToDateString(DateTime.Now);
            string sql = string.Format(@"INSERT INTO IoTCommand (会话ID,服务类型, 操作类型,SensorID,PumpJZID,数据业务地址,预设值,最后更新时间,用户ID,状态,开始时间,结束时间,耗时,消息) 
                                                            VALUES ('{0}','{1}','{2}','{3}',{4},'{5}',{6},'{7}',{8},'{9}','{10}','{11}','{12}','{13}');",
                                       DataUtil.ToString(command.SessionID), DataUtil.ToString(command.ServerType), DataUtil.ToString(command.OperType), DataUtil.ToString(command.SensorID),
                                       DataUtil.ToInt(command.PumpJZID), DataUtil.ToString(command.FDBAddress), DataUtil.ToDouble(command.SetValue), DataUtil.ToDateString(command.UpdateDateTime),
                                       DataUtil.ToInt(command.UserID), DataUtil.ToString(command.State), DataUtil.ToDateString(command.BeginTime), DataUtil.ToDateString(command.EndTime), DataUtil.ToString(command.TimeConsuming), DataUtil.ToString(command.Message));

            DBUtil.ExecuteNonQuery(sql, out string errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForCommand.AppendErrMsg("命令记录器记录数据库失败" + errMsg);
            }
        }
示例#4
0
 public void Append(RecCommand data)
 {
     if (!IsRuning)
     {
         return;
     }
     if (queue.IsAddingCompleted)
     {
         return;
     }
     if (queue.Count > 4096)
     {
         TraceManagerForCommand.AppendErrMsg("命令记录器队列到达上限无法插入");
         return;
     }
     queue.Add(data);
 }
示例#5
0
        // 将命令转换成可存储的命令
        public static RecCommand ToRecCommand(RequestCommand command)
        {
            RecCommand recCommand = new RecCommand();

            recCommand.SessionID      = command.sessionID;
            recCommand.ServerType     = ToCommandServerTypeStr(command.sonServerType);
            recCommand.OperType       = ToCommandOperType(command.operType);
            recCommand.SensorID       = command.sensorID;
            recCommand.PumpJZID       = command.jzID;
            recCommand.FDBAddress     = command.fDBAddress;
            recCommand.SetValue       = command.value;
            recCommand.UpdateDateTime = DataUtil.ToDateString(command.updateTime);
            recCommand.UserID         = command.userID;
            recCommand.State          = ToStateStr(command.state);
            recCommand.BeginTime      = DataUtil.ToDateString(command.beginTime);
            recCommand.EndTime        = DataUtil.ToDateString(command.endTime);
            recCommand.TimeConsuming  = command.timeConsuming;
            recCommand.Message        = command.message;
            return(recCommand);
        }