Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// 支持直接跳转到指定的节点
        /// </summary>
        /// <param name="targetNodeID">指定的节点</param>
        /// <returns></returns>
        public IResponseMessage JumpToTargetnode(string openId, string targetNodeID)
        {
            if (FirstLoaded == false)
            {
                //初始化
                FirstLoaded = true;
                this.Loaded();
            }

            //##创建节点
            NodeInstanceService newNode = this.CreateServicInstance(targetNodeID);

            if (newNode == null)
            {
                return(null);
            }
            else
            {
                //替换当前节点
                CurrentNode = newNode;

                //处理附加的行为
                if (CurrentNode.DealingHandler != null)
                {
                    DealingHandlerAdditionalBehaviorAttribute attribute = Attribute.GetCustomAttribute(CurrentNode.DealingHandler.GetType(),
                                                                                                       typeof(DealingHandlerAdditionalBehaviorAttribute))
                                                                          as DealingHandlerAdditionalBehaviorAttribute;
                    if (attribute != null)
                    {
                        //忽略 呈现ReadyMessage流程
                        if (attribute.AdditionalBehavior.HasFlag(DealingHandlerAdditionalBehaviorType.IgnoreReadyMessage))
                        {
                            CurrentNode.NodeStatus = NodeStatusTypes.Dealing;
                        }
                    }
                }

                //执行
                IResponseMessage ret = ProcessData(openId, DataTypes.InputAll, null);
                return(ret);
            }
        }
Esempio n. 3
0
        //---------Control---------

        #region 处理数据

        /// <summary>
        /// 处理数据
        /// </summary>
        /// <param name="openId">OpenID</param>
        /// <param name="inputType">输入的类型</param>
        /// <param name="rawData">Raw格式的数据</param>
        /// <returns>响应结果</returns>
        public IResponseMessage HanderData(string openId, DataTypes inputType, object rawData)
        {
            if (FirstLoaded == false)
            {
                //初始化
                FirstLoaded = true;
                this.Loaded();

                //##创建初始节点
                CurrentNode = this.CreateServicInstance(ConstString.ROOT_NODE_ID);
            }

            //##任意时刻都采纳的指令
            if (rawData != null && rawData.ToString() == "0")
            {
                CurrentNode = this.CreateServicInstance(ConstString.ROOT_NODE_ID);
            }

            //处理数据,如果响应结果为“跳转节点”,则继续进行处理;否则,返回结果到外部。
            IResponseMessage ret = ProcessData(openId, inputType, rawData);

            if (ret is ResponseJumpNode)
            {
                ResponseJumpNode jumpResult = ret as ResponseJumpNode;

                if (NodeIdValidator.IsValid(jumpResult.NodeId) == false)
                {
                    throw new ArgumentException("节点ID格式不正确", "nodeId");
                }
                CurrentNode = this.CreateServicInstance(jumpResult.NodeId);

                //如果无法创建
                if (CurrentNode == null)
                {
                    return(null);
                }

                //处理附加的行为

                #region 流程特性 DealingHandlerAdditionalBehaviorAttribute

                if (CurrentNode.NodeStatus == NodeStatusTypes.Created &&
                    CurrentNode.DealingHandler != null)
                {
                    DealingHandlerAdditionalBehaviorAttribute attribute = Attribute.GetCustomAttribute(CurrentNode.DealingHandler.GetType(),
                                                                                                       typeof(DealingHandlerAdditionalBehaviorAttribute))
                                                                          as DealingHandlerAdditionalBehaviorAttribute;
                    if (attribute != null)
                    {
                        //忽略 呈现ReadyMessage流程
                        if (attribute.AdditionalBehavior.HasFlag(DealingHandlerAdditionalBehaviorType.IgnoreReadyMessage))
                        {
                            CurrentNode.NodeStatus = NodeStatusTypes.Dealing;
                        }
                    }
                }

                #endregion

                return(ProcessData(openId, inputType, rawData));
            }
            else
            {
                return(ret);
            }
        }