Exemple #1
0
        public void RegexWildcard_Core()
        {
            // Arrange
            var testString               = "ate Ape are";
            var fullWildcard             = new Wildcard("* are*");
            var partialWildcard          = new Wildcard("a?e", RegexOptions.IgnoreCase, false, false);
            var expected_full_IsMatch    = true;
            var expected_full_NumMatches = 1;
            var expected_part_IsMatch    = true;
            var expected_part_NumMatches = 3;
            var expected_part_2ndMatch   = "Ape";

            Console.WriteLine(fullWildcard.ToString());
            Console.WriteLine(partialWildcard.ToString());

            // Act
            var fullMatches            = fullWildcard.Matches(testString);
            var actual_full_IsMatch    = fullWildcard.IsMatch(testString);
            var actual_full_NumMatches = fullMatches.Count;

            var partialMatches         = partialWildcard.Matches(testString);
            var actual_part_IsMatch    = partialWildcard.IsMatch(testString);
            var actual_part_NumMatches = partialMatches.Count;
            var actual_part_2ndMatch   = partialMatches[1].ToString();

            // Assert
            Assert.AreEqual(expected_full_IsMatch, actual_full_IsMatch);
            Assert.AreEqual(expected_full_NumMatches, actual_full_NumMatches);
            Assert.AreEqual(expected_part_IsMatch, actual_part_IsMatch);
            Assert.AreEqual(expected_part_NumMatches, actual_part_NumMatches);
            Assert.AreEqual(expected_part_2ndMatch, actual_part_2ndMatch);
        }
Exemple #2
0
        public JObject ToJson()
        {
            var json = new JObject();

            json["verb"]        = Verb.ToString();
            json["wildcard"]    = Wildcard.ToString();
            json["containerID"] = ContainerId.ToJson();
            return(json);
        }
Exemple #3
0
        /// <summary>
        /// 分析一个投注号码,计算此号码所包含的注数。
        /// 投注号码格式错误时抛出异常AntecodeFormatException。
        /// </summary>
        /// <param name="antecode">投注号码</param>
        /// <returns>号码所包含的注数</returns>
        public int AnalyzeAnteCode(string antecode)
        {
            string msg;

            if (!CheckAntecode(antecode, out msg))
            {
                throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg);
            }
            var totalCount = 0;
            var danList    = new List <string>();
            var tmp        = new List <string>();

            for (int i = 0; i < TotalNumber; i++)
            {
                if (DanNumbers.Contains(i))
                {
                    danList.Add(AnteCodeNumbers[i]);
                }
                else
                {
                    if (AnteCodeNumbers[i] != Wildcard.ToString())
                    {
                        tmp.Add(AnteCodeNumbers[i]);
                    }
                }
            }
            var c = new Combination();

            c.Calculate(tmp.ToArray(), BallNumber - DanNumbers.Length, (item) =>
            {
                var count = 1;
                foreach (var t in item)
                {
                    count *= t.Length;
                }
                totalCount += count;
            });
            foreach (var dan in danList)
            {
                totalCount *= dan.Length;
            }
            return(totalCount);
        }
        /// <summary>
        /// Creates regular expressions from the scope string
        /// </summary>
        /// <param name="scopeString">The scope string provided from the user</param>
        /// <param name="scopeRegex">OUT: The positive scope regex to apply</param>
        /// <param name="negativeScopeRegex">OUT: The negative scope regex to apply</param>
        private void getScopeRegex(String scopeString, out Regex scopeRegex, out Regex negativeScopeRegex)
        {
            scopeRegex         = null;
            negativeScopeRegex = null;
            StringBuilder combinedRegexString = new StringBuilder();
            StringBuilder negativeRegexString = new StringBuilder();

            if (!String.IsNullOrEmpty(scopeString))
            {
                foreach (String scope in scopeString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    try
                    {
                        if (scope.Trim()[0] != '-')
                        {
                            Wildcard wildcard = new Wildcard(scope.Trim());
                            combinedRegexString.AppendFormat("({0})|", wildcard.ToString());
                        }
                        else
                        {
                            Wildcard wildcard = new Wildcard(scope.Trim().Substring(1).Trim());
                            negativeRegexString.AppendFormat("({0})|", wildcard.ToString().Substring(1).Trim());
                        }
                    }
                    catch { }
                }
                try
                {
                    if (combinedRegexString.Length > 0)
                    {
                        scopeRegex = new Regex(combinedRegexString.ToString(0, combinedRegexString.Length - 1), RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    }
                    if (negativeRegexString.Length > 0)
                    {
                        negativeScopeRegex = new Regex(negativeRegexString.ToString(0, negativeRegexString.Length - 1), RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    }
                }
                catch { }
            }
        }
Exemple #5
0
        /// <summary>
        /// 检查投注号码格式是否正确
        /// </summary>
        /// <param name="antecode">投注号码</param>
        /// <param name="errMsg">错误消息</param>
        /// <returns>格式是否正确</returns>
        public bool CheckAntecode(string antecode, out string errMsg)
        {
            // 前置验证 - 彩种、玩法、投注号码
            PreconditionAssert.IsNotEmptyString(GameCode, "检查投注号码格式前,必须设置彩种");
            PreconditionAssert.IsNotEmptyString(GameType, "检查投注号码格式前,必须设置玩法");
            PreconditionAssert.IsNotEmptyString(antecode, "必须传入非空的投注号码");

            var list = antecode.Split('|');

            if (list.Length > 1)
            {
                var dans = list[1].Split(new char[] { Spliter }, StringSplitOptions.RemoveEmptyEntries);
                DanNumbers = new int[dans.Length];
                for (int i = 0; i < dans.Length; i++)
                {
                    DanNumbers[i] = int.Parse(dans[i]);
                }
                if (DanNumbers.GroupBy(i => i).Count() != DanNumbers.Length)
                {
                    errMsg = "胆码重复";
                    return(false);
                }
            }
            else
            {
                DanNumbers = new int[0];
            }
            AnteCodeNumbers = list[0].Split(Spliter);
            if (AnteCodeNumbers.Length != TotalNumber)
            {
                errMsg = string.Format("投注号码必须是被\"{0}\"切分成 {1}个部分的字符串", Spliter, TotalNumber);
                return(false);
            }
            var orderAnalyzer = AnalyzerFactory.GetOrderAnalyzer(GameCode, GameType);
            var tmp           = AnteCodeNumbers.Clone() as string[];

            if (IsEnableWildcard)
            {
                tmp = AnteCodeNumbers.Where(a =>
                {
                    return(!a.Equals(Wildcard.ToString()));
                }).ToArray();
                if (tmp.Length < BallNumber || tmp.Length > TotalNumber)
                {
                    errMsg = string.Format("有效投注号码必须是\"{0} - {1}\"个号码", BallNumber, TotalNumber);
                    return(false);
                }
            }
            if (tmp.Length == BallNumber && DanNumbers.Length > 0)
            {
                errMsg = "胆码设置错误 - " + antecode;
                return(false);
            }
            if (DanNumbers.Length >= BallNumber)
            {
                errMsg = "胆码设置错误,胆码必须小于 " + BallNumber + "个 - " + antecode;
                return(false);
            }
            foreach (var danIndex in DanNumbers)
            {
                var dan = AnteCodeNumbers[danIndex];
                if (dan == Wildcard.ToString())
                {
                    errMsg = "胆码设置错误,对应胆码为通配符 - " + antecode;
                    return(false);
                }
            }
            foreach (var item in tmp)
            {
                if (!orderAnalyzer.CheckOneAntecodeNumber(item, out errMsg))
                {
                    return(false);
                }
            }
            errMsg = "";
            return(true);
        }