/// <summary> /// 执行一个KAE系统命令 /// </summary> /// <param name="msg">执行命令的请求消息</param> /// <param name="stateLogger">KAE宿主状态记录器实例</param> /// <returns>返回操作的结果</returns> public IExecuteResult Execute(MetadataContainer msg, IKAEStateLogger stateLogger) { Guid kppUniqueId = msg.GetAttributeAsType <Guid>(0x03); if (kppUniqueId == Guid.Empty) { return(ExecuteResult.Fail((byte)KAEErrorCodes.IllegalArgument, string.Empty)); } //stateLogger.Log(string.Format("#[Retrieving KPP Info] #KAE application: {0}, Internal un-rsp count: {1}", kppUniqueId, APPExecuter.Application.UnRspCount)); //return ExecuteResult.Succeed(APPExecuter.Application.UnRspCount.ToString()); throw new NotImplementedException(); }
static void MetadataNewTransaction(object sender, LightSingleArgEventArgs <IMessageTransaction <MetadataContainer> > e) { MetadataConnectionAgent agent = (MetadataConnectionAgent)sender; IMessageTransaction <MetadataContainer> transaction = e.Target; MetadataContainer reqMsg = transaction.Request; Tuple <KAENetworkResource, ApplicationLevel> tag = new Tuple <KAENetworkResource, ApplicationLevel>((KAENetworkResource)agent.Tag, (reqMsg.IsAttibuteExsits(0x05) ? (ApplicationLevel)reqMsg.GetAttributeAsType <byte>(0x05) : ApplicationLevel.Stable)); MessageIdentity reqMsgIdentity = reqMsg.GetAttributeAsType <MessageIdentity>(0x00); TransactionIdentity transactionIdentity = reqMsg.GetAttributeAsType <TransactionIdentity>(0x01); Guid uniqueId = reqMsg.GetAttributeAsType <Guid>(0x03); /* * We always makes a checking on the Metadata protocol network communication. * Because all of ours internal system communications are constructed by this kind of MSG protocol. */ if (reqMsgIdentity.ProtocolId >= 0xFC) { HandleSystemCommand(transaction); } //sends it to the appropriate application. else { HandleBusiness(tag, (MetadataMessageTransaction)transaction, reqMsgIdentity, reqMsg, uniqueId, transactionIdentity); } }
/// <summary> /// 执行相应的KAE系统命令 /// </summary> /// <param name="msg">系统请求消息</param> /// <param name="logger">状态记录器实例</param> /// <returns>返回执行后的结果</returns> public static IExecuteResult Execute(MetadataContainer msg, IKAEStateLogger logger) { MessageIdentity messageIdentity = msg.GetAttributeAsType <MessageIdentity>(0x00); IKAESystemCommand command; if (!_commands.TryGetValue(messageIdentity, out command)) { return(ExecuteResult.Fail((byte)KAEErrorCodes.NotSupportedCommand, string.Format("#Not supported system command protocol: {0}", messageIdentity))); } try { return(command.Execute(msg, logger)); } catch (Exception ex) { logger.Log(string.Format("#Occured an unhandled exception while executing a system level KAE command. #Command msg struct: {0}. \r\n#Error: {1}", msg, ex.Message)); _tracing.Error(ex, null); return(ExecuteResult.Fail((byte)KAEErrorCodes.Unknown, ex.Message)); } }