コード例 #1
0
        //-----------Static------------

        #region 创建实例

        private static DefaultDealingHandler InternalCreateInstance(IResponseMessage DealingMessage)
        {
            DefaultDealingHandler result = new DefaultDealingHandler
            {
                DealingMessage = DealingMessage,
            };

            return(result);
        }
コード例 #2
0
ファイル: ResponseService.cs プロジェクト: zero1036/TGNet
        /// <summary>
        /// 根据节点ID,获取服务实例
        /// </summary>
        /// <param name="nodeID">节点ID</param>
        internal override NodeInstanceService CreateServicInstance(string nodeID)
        {
            //查找 节点ID对应 的配置信息
            ResponseNodeConfig configNodeInfo = ConfigTree.GetConfigByNodeID(nodeID);

            if (configNodeInfo == null)
            {
                return(null);
            }

            //找不到配置节点时的处理
            if (configNodeInfo == null)
            {
                NodeInstanceService node_unknown = new NodeInstanceService(ConstString.UNKNOWN_NODE_ID);
                node_unknown.DealingHandler = DefaultDealingHandler.CreateInstance_Text("抱歉,當前指令現在無法為您提供服務。");
                return(node_unknown);
            }

            //根据配置文件处理
            NodeInstanceService result = new NodeInstanceService(configNodeInfo.NodeID);

            if (configNodeInfo.DealingHandlerConfig != null)
            {
                dynamic dealingHandlerConfig = configNodeInfo.DealingHandlerConfig;
                result.DealingHandler = dealingHandlerConfig.CreateInstanceFromConfig();

                #region 如果是自定义处理器,再注入参数配置的内容
                try
                {
                    if (result.DealingHandler is ICustomHandler && result.DealingHandler is ICustomHandlerConfigable)
                    {
                        Type configClassType = ConfigClassOfCustomHandlerHelper.GetConfigClassType(result.DealingHandler.GetType());
                        if (configClassType != null)
                        {
                            dynamic configData = ConfigClassOfCustomHandlerHelper.GetConfigClassInstance(configClassType, configNodeInfo.NodeID);
                            dynamic dh         = result.DealingHandler;
                            dh.ConfigData = configData;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log4Net.Error("自定义处理器的参数配置,注入失败。", ex);
                }

                #endregion
            }
            if (configNodeInfo.DoneHandlerConfig != null)
            {
                dynamic doneHandlerConfig = configNodeInfo.DoneHandlerConfig;
                result.DonedHandler = doneHandlerConfig.CreateInstanceFromConfig();
            }

            return(result);
        }