Пример #1
0
        public static List <SingleRule> CreateSingleRules(IEnumerable <Rule> basicRules)
        {
            var newRules = new List <SingleRule>();
            var iters    = new Dictionary <string, int>();

            foreach (var rule in basicRules)
            {
                var symbols = rule.Symbols.ToList();
                if (symbols.Count <= 1)
                {
                    newRules.Add(new SingleRule(rule.Key, rule.Symbols[0], rule.LastSymbol));
                    continue;
                }

                if (!iters.ContainsKey(rule.Key))
                {
                    iters[rule.Key] = 0;
                }

                var first = true;
                while (symbols.Count > 1)
                {
                    var newSymbol = rule.Key + (iters[rule.Key] + 1).ToLowerUnicode();
                    var newRule   = new SingleRule(first ? rule.Key : rule.Key + iters[rule.Key].ToLowerUnicode(), symbols[0], newSymbol);
                    newRules.Add(newRule);
                    symbols.RemoveAt(0);
                    iters[rule.Key]++;
                    first = false;
                }
                var lastRule = new SingleRule(rule.Key + iters[rule.Key].ToLowerUnicode(), symbols[0], rule.LastSymbol);
                newRules.Add(lastRule);
            }

            return(newRules);
        }
Пример #2
0
        private void CheckBox_Checked(object sender, RoutedEventArgs e, SpawnOrSurviveRule rule, bool Checked)
        {
            CheckBox checkbox = (CheckBox)sender;
            int      value    = Int32.Parse(checkbox.Content.ToString());

            SingleRule newRule = new SingleRule(value, rule);

            associatedGrid.ProcessRuleChange(newRule, Checked);
        }
Пример #3
0
 internal void ProcessRuleChange(SingleRule newRule, bool added)
 {
     if (added && !rules.Contains(newRule))
     {
         rules.Add(newRule);
     }
     else if (!added && rules.Contains(newRule))
     {
         rules.Remove(newRule);
     }
     gridController.ActiveRules = rules;
 }
Пример #4
0
        public void ThereCanOnlybeOneInstanceOfARuleInACollection()
        {
            RuleCollection ruleList = new RuleCollection();

            SingleRule testRule = new SingleRule(7, SpawnOrSurviveRule.SpawnRule);

            SingleRule testRule2 = new SingleRule(7, SpawnOrSurviveRule.SpawnRule);

            ruleList.Add(testRule);
            ruleList.Add(testRule2);

            Assert.AreEqual(1, ruleList.Count);
        }
Пример #5
0
        public void ThereCanBeMultipleRulesInACollection()
        {
            RuleCollection ruleList = new RuleCollection();

            SingleRule testRule = new SingleRule(7, SpawnOrSurviveRule.SpawnRule);

            SingleRule testRule2 = new SingleRule(8, SpawnOrSurviveRule.SpawnRule);

            SingleRule testRule3 = new SingleRule(8, SpawnOrSurviveRule.SurviveRule);

            SingleRule testRule4 = new SingleRule(7, SpawnOrSurviveRule.SpawnRule);

            ruleList.Add(testRule);
            ruleList.Add(testRule2);
            ruleList.Add(testRule3);
            ruleList.Add(testRule4);

            Assert.AreEqual(3, ruleList.Count);
        }
Пример #6
0
 protected override bool LoadNode(XmlNode node)
 {
     if (node.Name == "ProgSetId")
     {
         ProgSetId = Guid.Parse(node.InnerText);
     }
     else if (node.Name == "OnState")
     {
         Enum.TryParse(node.InnerText, out OnState);
     }
     else if (node.Name == "OffState")
     {
         Enum.TryParse(node.InnerText, out OffState);
     }
     else if (node.Name == "Rule")
     {
         SingleRule Rule = new SingleRule();
         foreach (XmlNode subNode in node.ChildNodes)
         {
             if (subNode.Name == "RuleId")
             {
                 Rule.RuleId = subNode.InnerText;
             }
             else if (subNode.Name == "OnState")
             {
                 Rule.OnState = bool.Parse(subNode.InnerText);
             }
             else if (subNode.Name == "OffState")
             {
                 Rule.OffState = bool.Parse(subNode.InnerText);
             }
         }
         if (Rule.RuleId != null)
         {
             Rules.Add(Rule.RuleId, Rule);
         }
     }
     else if (!base.LoadNode(node))
     {
         return(false);
     }
     return(true);
 }
Пример #7
0
        /// <summary>
        /// 父节点,拆单规则
        /// </summary>
        /// <param name="rule"></param>
        public ProductSingleRuleEntity(SingleRule singleRule, RuleEntity rule)
        {
            this.Rule = rule;
            this.Key  = string.Format("{0}${1}", rule.Key, this.PTId);

            this.PTId        = singleRule.PTId;
            this.BlackBrands = singleRule.BlackBrands;
            //this.ClassId = Int32.Parse(singleRule.ClassId);
            //this.ClassName = singleRule.ClassName;
            this.Levels       = singleRule.Levels;
            this.MaxPrice     = (decimal)singleRule.MaxPrice;
            this.MaxQuantity  = singleRule.MaxQuantity;
            this.MaxWeight    = (int)singleRule.MaxWeight;
            this.MinUnitPrice = singleRule.MinUnitPrice;
            //this.SingleOnly = singleRule.SingleOnly;
            //this.Specs = productType.Specs;
            //this.TaxRate = (int)singleRule.TaxRate;
            this.TaxThreshold = (decimal)singleRule.TaxThreshold;
            this.TypeName     = singleRule.TypeName;
            this.WhiteBrands  = singleRule.WhiteBrands;
        }
Пример #8
0
 public RulesList(BasicObject targetObject, SingleRule rule)
 {
     this.targetObject = targetObject;
     rules             = new List <SingleRule>();
     rules.Add(rule);
 }