Beispiel #1
0
        Dictionary <string, ActionDefine> getActionDictionary()
        {
            Dictionary <string, ActionDefine> ret = new Dictionary <string, ActionDefine>();
            string xml = TextFileComm.getFileText("MsgActionDic.xml", "xml");

            if (xml == null)
            {
                return(ret);
            }
            XmlDocument xmldoc = new XmlDocument();

            try
            {
                xmldoc.LoadXml(xml);
                XmlNode     root  = xmldoc.SelectSingleNode("root");
                XmlNodeList nlist = root.SelectNodes("action");
                foreach (XmlNode node in nlist)
                {
                    ActionDefine ad = new ActionDefine();

                    string type = XmlUtil.GetSubNodeText(node, "@type");
                    ad.actionName = type;
                    List <string> slist  = new List <string>();
                    XmlNodeList   snodes = node.SelectNodes("item");
                    foreach (XmlNode snode in snodes)
                    {
                        slist.Add(XmlUtil.GetSubNodeText(snode, "."));
                    }
                    ad.regConditions = slist;
                    snodes           = node.SelectNodes("response/case");
                    foreach (XmlNode snode in snodes)
                    {
                        ResponseProcessItem rpi = new ResponseProcessItem();
                        rpi.condition = XmlUtil.GetSubNodeText(snode, "condition");
                        rpi.isUrl     = XmlUtil.GetSubNodeText(snode, "isUrl");
                        rpi.type      = XmlUtil.GetSubNodeText(snode, "type");
                        rpi.msg       = XmlUtil.GetSubNodeText(snode, "msg");
                        rpi.paramList = XmlUtil.GetSubNodeText(snode, "paramList");
                        if (!ad.responseGroup.ContainsKey(rpi.condition))
                        {
                            ad.responseGroup.Add(rpi.condition, rpi);
                        }
                    }
                    if (!ret.ContainsKey(type))
                    {
                        ret.Add(type, ad);
                    }
                }
            }
            catch (Exception ce)
            {
                return(ret);
            }
            return(ret);
        }
Beispiel #2
0
        bool ProcessOneMsg(wxMessageClass wxmsg, ref ShareLotteryPlanClass optPlan)
        {
            ActionDefine define     = null;
            ActionType   curraction = checkTheAction(wxmsg, ref define);

            if (waitingAsk != null)
            {
                if (waitingAsk.ContainsKey(wxmsg.FromUserNam) && waitingAsk[wxmsg.FromUserNam].ContainsKey(wxmsg.FromMemberUserName))
                {
                    //如果回复的人就是等待回答清单中的人,首先判断是否是回复,如果不是回复,宣布首先回答我的问题,其他问题无效,等下再问
                    if (curraction != ActionType.ValidateInfo)
                    {
                        TheAskWaitingUserAnswer askObj = waitingAsk[wxmsg.FromUserNam][wxmsg.FromMemberUserName];
                        string msg = string.Format(@"@{0} 请您先回答我刚才提出的问题!在回答之前我不会接受你其他任何请求.
{1}", wxmsg.FromMemberNikeName, askObj.askMsg);
                        SendMsg(msg, wxmsg.FromUserNam);
                        return(false);
                    }
                }
            }


            ResponseActionClass rac = ResponseActionClass.CreateAction(curraction, this, wxmsg);

            rac.actionDefine = define;
            if (rac == null)
            {
                optPlan = null;
                return(false);
            }
            if (curraction == ActionType.Undefined)
            {
                rac.currPlan = null;
            }
            else
            {
                rac.currPlan = AllPlan.getCurrRoomPlan(wxmsg.FromUserNam);
            }
            return(rac.Response(ref optPlan));

            if (curraction == ActionType.Undefined)
            {
                return(false);
            }
        }
Beispiel #3
0
        public ActionType checkTheAction(wxMessageClass wxmsg, ref ActionDefine define)
        {
            define = new ActionDefine();
            string myname = string.Format("@{0}", wxmsg.AtMemberNikeName[0]);
            string msg    = wxmsg.Msg.Replace(myname, "").Trim().Replace(" ", "");

            ////string strtest = @"\[[\s\S]*?]";
            ////Regex regtest = new Regex(strtest);

            ////MatchCollection tmcs = regtest.Matches(msg);

            if (ActionDic == null)
            {
                ActionDic = getActionDictionary();
            }
            Type  t   = typeof(ActionType);
            Array arr = Enum.GetValues(t);

            foreach (int myCode in arr)
            {
                string strName = Enum.GetName(t, myCode);//获取名称
                if (!ActionDic.ContainsKey(strName))
                {
                    continue;
                }
                ActionDefine dic = ActionDic[strName];
                if (dic == null)
                {
                    continue;
                }
                for (int i = 0; i < dic.regConditions.Count; i++)
                {
                    Regex           regTr = new Regex(dic.regConditions[i]);
                    MatchCollection mcs   = regTr.Matches(msg);
                    if (mcs.Count > 0)
                    {
                        return((ActionType)myCode);
                    }
                }
            }
            return(ActionType.Undefined);
        }