Пример #1
0
        /// <summary>
        /// 创建实例 状态成员
        /// </summary>
        /// <typeparam name="T_IHandler">IHandler类型</typeparam>
        /// <param name="hanlderConfig">IHandlerConfig</param>
        public static void CreateInstanceStatusMember <T_IHandler>(this IHandlerConfig <T_IHandler> hanlderConfig,
                                                                   out IResponseMessage readyMessage, out IResponseMessage successResult, out IResponseMessage failResult)
            where T_IHandler : IHandler
        {
            //初始化
            readyMessage  = null;
            successResult = null;
            failResult    = null;

            //根据赋值情况进行创建
            if (hanlderConfig.ReadyMessageConfig != null)
            {
                dynamic config = hanlderConfig.ReadyMessageConfig;
                readyMessage = config.CreateInstanceFromConfig();
            }
            if (hanlderConfig.SuccessResultConfig != null)
            {
                dynamic config = hanlderConfig.SuccessResultConfig;
                readyMessage = config.CreateInstanceFromConfig();
            }
            if (hanlderConfig.FailResultConfig != null)
            {
                dynamic config = hanlderConfig.FailResultConfig;
                readyMessage = config.CreateInstanceFromConfig();
            }
        }
Пример #2
0
        /// <summary>
        /// 序列化 状态成员
        /// </summary>
        /// <typeparam name="T_IHandler">IHandler类型</typeparam>
        /// <param name="hanlderConfig">IHandlerConfig</param>
        /// <param name="readyConfig">ReadyMessage结果</param>
        /// <param name="successConfig">SuccessMessage结果</param>
        /// <param name="failConfig">FailMessage结果</param>
        public static void SerializeStatusMember <T_IHandler>(this IHandlerConfig <T_IHandler> hanlderConfig,
                                                              out XElement readyConfig, out XElement successConfig, out XElement failConfig)
            where T_IHandler : IHandler
        {
            //初始化
            readyConfig   = null;
            successConfig = null;
            failConfig    = null;

            //根据赋值情况进行处理
            if (hanlderConfig.ReadyMessageConfig != null)
            {
                readyConfig = new XElement("ReadyMessageConfig");
                hanlderConfig.ReadyMessageConfig.SerializeConfigToXmlNode(readyConfig);
                readyConfig.SetAttributeValue("Type", hanlderConfig.ReadyMessageConfig.GetType().FullName);
            }
            if (hanlderConfig.SuccessResultConfig != null)
            {
                successConfig = new XElement("SuccessResultConfig");
                hanlderConfig.SuccessResultConfig.SerializeConfigToXmlNode(successConfig);
                successConfig.SetAttributeValue("Type", hanlderConfig.SuccessResultConfig.GetType().FullName);
            }
            if (hanlderConfig.FailResultConfig != null)
            {
                failConfig = new XElement("FailResultConfig");
                hanlderConfig.FailResultConfig.SerializeConfigToXmlNode(failConfig);
                failConfig.SetAttributeValue("Type", hanlderConfig.FailResultConfig.GetType().FullName);
            }
        }
Пример #3
0
        /// <summary>
        /// Handler配置类,辅助获取当前配置信息的概要描述
        /// </summary>
        /// <typeparam name="T_IHandler"></typeparam>
        /// <param name="config"></param>
        /// <returns></returns>
        public static string GetSummary(this IHandlerConfig config)
        {
            if (config is DefaultDealingHandlerConfig)
            {
                var realConfig = config as DefaultDealingHandlerConfig;

                switch (realConfig.DataType)
                {
                case DataTypes.Text:
                    return(String.Format("呈現指定的文本({0})", GetShortString(realConfig.RawData.ToString())));

                case DataTypes.News:
                    return(String.Format("呈現指定的文章({0})", GetShortString(((ArticleCan)realConfig.RawData).Title)));

                default:
                    return(DescriptionAttribute.GetDescription(config.GetType().GetMethod("CreateInstanceFromConfig").ReturnType));
                }
            }
            else if (config is DefaultDoneHandlerConfig)
            {
                var realConfig = config as DefaultDoneHandlerConfig;

                if (realConfig.NodeId == ConstString.ROOT_NODE_ID)
                {
                    return("輸入任意文字,返回主功能表");
                }
                else
                {
                    return(String.Format("輸入#時,{0}(節點:{1})", realConfig.TipText, realConfig.NodeId));
                }
            }
            else if (config is TextMenuHandlerConfig)
            {
                var    realConfig = config as TextMenuHandlerConfig;
                string nodes      = String.Join(" | ", realConfig.Menus.Select(keyvalue => keyvalue.Value));

                return(String.Format("跳轉菜單({0}個功能表項目,節點:{1})", realConfig.Menus.Count, nodes));
            }
            else if (config is CustomHandlerConfig)
            {
                Type targetType = CustomHandlerConfig.GetICustomHandlerTypeFromCurrentDomain(((CustomHandlerConfig)config).HandlerTypeName);
                return(DescriptionAttribute.GetDescription(targetType));
            }
            else
            {
                return(DescriptionAttribute.GetDescription(config.GetType().GetMethod("CreateInstanceFromConfig").ReturnType));
            }
        }
Пример #4
0
        //---------Control---------

        #region 读取配置文件
        /// <summary>
        /// 从配置文件,读取 配置信息 。(非线程安全,请外部自己处理。)
        /// </summary>
        /// <param name="ConfigNodeDic">结果集合</param>
        public static void LoadConfig_ResponseChain(Dictionary <string, ResponseNodeConfig> ConfigNodeDic)
        {
            //初始化
            if (ConfigNodeDic == null)
            {
                ConfigNodeDic = new Dictionary <string, ResponseNodeConfig>();
            }
            else
            {
                ConfigNodeDic.Clear();
            }

            //读取配置文件
            string fullPath = System.Web.Hosting.HostingEnvironment.MapPath(CONFIG_FILEPATH);

            if (System.IO.File.Exists(fullPath) == false)
            {
                return;
            }

            //开始解析
            XDocument xdoc     = XDocument.Load(fullPath);
            var       nodeList = xdoc.Root.Elements("Node");

            foreach (XElement item in nodeList)
            {
                try
                {
                    string         nodeID = item.Element("NodeID").Value;
                    IHandlerConfig DealingHandlerConfig = ConfigHelper.GetIConfigFromXElement(item.Element("DealingHandler")) as IHandlerConfig;
                    IHandlerConfig DoneHandlerConfig    = ConfigHelper.GetIConfigFromXElement(item.Element("DoneHandler")) as IHandlerConfig;

                    //##生成Node节点
                    ResponseNodeConfig node = new ResponseNodeConfig(nodeID, DealingHandlerConfig, DoneHandlerConfig);

                    //##添加到静态集合
                    lock (((ICollection)ConfigNodeDic).SyncRoot)
                        ConfigNodeDic[nodeID] = node;
                }
                catch (Exception ex)
                {
                    Logger.Log4Net.Error("LoadConfig_ResponseChain 过程发生异常。", ex);
                    continue;
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 反序列化 状态成员
 /// </summary>
 /// <typeparam name="T_IHandler">IHandler类型</typeparam>
 /// <param name="hanlderConfig">IHandlerConfig</param>
 /// <param name="currentNode">当前节点元素</param>
 public static void DeserializeStatusMember <T_IHandler>(this IHandlerConfig <T_IHandler> hanlderConfig,
                                                         XElement currentNode)
     where T_IHandler : IHandler
 {
     //根据变量情况进行赋值
     if (currentNode.Element("ReadyMessageConfig") != null)
     {
         hanlderConfig.ReadyMessageConfig = ConfigHelper.GetIConfigFromXElement(currentNode.Element("ReadyMessageConfig")) as IResponseMessageConfig;
         hanlderConfig.ReadyMessageConfig.DeserializeConfigFromXmlNode(currentNode.Element("ReadyMessageConfig"));
     }
     if (currentNode.Element("SuccessResultConfig") != null)
     {
         hanlderConfig.SuccessResultConfig = ConfigHelper.GetIConfigFromXElement(currentNode.Element("SuccessResultConfig")) as IResponseMessageConfig;
         hanlderConfig.SuccessResultConfig.DeserializeConfigFromXmlNode(currentNode.Element("SuccessResultConfig"));
     }
     if (currentNode.Element("FailResultConfig") != null)
     {
         hanlderConfig.FailResultConfig = ConfigHelper.GetIConfigFromXElement(currentNode.Element("FailResultConfig")) as IResponseMessageConfig;
         hanlderConfig.FailResultConfig.DeserializeConfigFromXmlNode(currentNode.Element("FailResultConfig"));
     }
 }
Пример #6
0
 public FillerConfig(IRequestMatcher matcher, IHandlerConfig parent, AppContext context)
 {
     _matcher = matcher;
     _parent  = parent;
     _context = context;
 }
Пример #7
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="ID"></param>
 public ResponseNodeConfig(string ID, IHandlerConfig dealingHandlerConfig, IHandlerConfig doneHandlerConfig)
 {
     this.NodeID = ID;
     this.DealingHandlerConfig = dealingHandlerConfig;
     this.DoneHandlerConfig    = doneHandlerConfig;
 }
Пример #8
0
 public ConsHandlerConfig(IHandlerConfig tail, IRequestHandler handler, AppContext javaScriptSerializer) : base(javaScriptSerializer)
 {
     _tail    = tail;
     _handler = handler;
 }
Пример #9
0
 public ConsHandlerConfig(IHandlerConfig tail, IRequestHandler handler, AppContext appContext) : base(appContext)
 {
     _tail    = tail;
     _handler = handler;
 }
Пример #10
0
 public ConsHandlerConfig(IHandlerConfig tail, IRequestHandler handler, AppContext javaScriptSerializer) : base(javaScriptSerializer)
 {
     _tail = tail;
     _handler = handler;
 }
Пример #11
0
 public ConsHandlerConfig(IHandlerConfig tail, IRequestHandler handler, AppContext appContext)
     : base(appContext)
 {
     _tail = tail;
     _handler = handler;
 }