Пример #1
0
        public TestScript Parse(string scriptString)
        {
            TestScript result    = new TestScript();
            var        matchHead = regHead.Match(scriptString);

            if (matchHead.Success)
            {
                var matchLinkStartUrl = regLinkStartUrl.Match(matchHead.Value);
                if (matchLinkStartUrl.Success)
                {
                    var matchHrefStartUrl = regHrefStartUrl.Match(matchLinkStartUrl.Value);
                    if (matchHrefStartUrl.Success)
                    {
                        var matchStartUrl = regAttrValue.Match(matchHrefStartUrl.Value);
                        if (matchStartUrl.Success)
                        {
                            result.StartUrl = System.Web.HttpUtility.HtmlDecode(matchStartUrl.Value.Replace("\"", "")).Trim();
                        }
                    }
                }
                var matchTitle = regTitle.Match(matchHead.Value);
                if (matchTitle.Success)
                {
                    result.Title = System.Web.HttpUtility.HtmlDecode(regTag.Replace(matchTitle.Value, "")).Trim();
                }
            }

            var matchTBody = regTBody.Match(scriptString);

            if (matchTBody.Success)
            {
                var matchTrColl = regTr.Matches(matchTBody.Value);
                foreach (Match matchTr in matchTrColl)
                {
                    var matchTdColl = regTd.Matches(matchTr.Value);
                    if (matchTdColl.Count == 3)
                    {
                        string command = System.Web.HttpUtility.HtmlDecode(regTag.Replace(matchTdColl[0].Value, "")).Trim();
                        string target  = System.Web.HttpUtility.HtmlDecode(regTag.Replace(matchTdColl[1].Value, "")).Trim();
                        string value   = System.Web.HttpUtility.HtmlDecode(regTag.Replace(matchTdColl[2].Value, "")).Trim();
                        result.AddCommand(command, target, value);
                    }
                }
            }
            return(result);
        }