예제 #1
0
        public virtual void Compute()
        {
            this.Schedule = new List <PointInTimeAmount>();

            var hasPayments  = Payments.Count() > 0;
            var currentMonth = new DateTime(Mortgage.StartDate.Year, Mortgage.StartDate.Month, 1);
            var finalMonth   = currentMonth.AddMonths(Mortgage.TermInMonths);
            var balanceLeft  = Mortgage.Principal;

            while (balanceLeft > 0 && currentMonth < finalMonth)
            {
                var monthlyInterest  = balanceLeft * Mortgage.MonthlyRate;
                var monthlyPrincipal = Mortgage.MonthlyAmount - monthlyInterest;

                var supplement = 0.0;
                if (hasPayments)
                {
                    supplement = Payments.Where(p => Rules.All(r => r.CanApply()))
                                 .Select(p => p.Amount)
                                 .Sum();
                }

                var adjustedBalance = balanceLeft - (monthlyPrincipal + supplement);
                balanceLeft = Math.Max(0, adjustedBalance);

                this.Schedule.Add(new PointInTimeAmount
                {
                    ScheduledFor = currentMonth,
                    Amount       = balanceLeft
                });
                currentMonth = currentMonth.AddMonths(1);
            }
        }
예제 #2
0
 /// <summary>
 /// 添加规则
 /// </summary>
 public virtual void AddRule(IReqRule rule)
 {
     if (Rules.All(m => !m.Equals(rule)))
     {
         Rules.Add(rule);
     }
 }
예제 #3
0
        public bool IsValidFor(IEnumerable <FieldWithValue> allCollectedFieldValues, IPublishedContent content)
        {
            // swap the rule fields for the actual fields collected by the form model
            foreach (var rule in Rules)
            {
                if (rule.Field == null)
                {
                    // should not happen!
                    continue;
                }
                var collectedField = allCollectedFieldValues.FirstOrDefault(f => f.Name == rule.Field.Name);
                if (collectedField != null)
                {
                    rule.Field = collectedField;
                }
            }

            Invalid = Rules.Any(r => r.IsApplicable == false)
                      // it's impossible to validate the rule if we have frontend only conditions in play
                                ? false
                      // the validation fails if all rules are fulfilled
                                : Rules.All(r => r.IsFulfilledBy(allCollectedFieldValues, content));

            return(Invalid == false);
        }
예제 #4
0
 /// <summary>
 /// 添加规则
 /// </summary>
 public void AddRule(FilterRule rule)
 {
     if (Rules.All(m => !m.Equals(rule)))
     {
         Rules.Add(rule);
     }
 }
예제 #5
0
        public bool RulesMatch(Error instance)
        {
            if (Rules != null && Rules.All(r => r.IsMatch(instance)))
            {
                return(true);
            }

            return(false);
        }
예제 #6
0
        /// <summary>
        /// 添加规则
        /// </summary>
        public FilterGroup AddRule(FilterRule rule)
        {
            if (Rules.All(m => !m.Equals(rule)))
            {
                Rules.Add(rule);
            }

            return(this);
        }
예제 #7
0
 public bool Handle(Move move, Board board)
 {
     if (move.PieceType == Type)
     {
         return(Rules.All(rule => rule.IsMoveValid(move, board)));
     }
     if (Next != null)
     {
         return(Next.Handle(move, board));
     }
     throw new Exception("NOBODY TREATS THIS PIECE !!! " + move.PieceType);
 }
예제 #8
0
        protected override object SolvePartTwo()
        {
            int count = 0;

            foreach (var passport in _passports)
            {
                if (Rules.All(rule => passport.ContainsKey(rule.Key) && rule.Validate(passport[rule.Key])))
                {
                    count++;
                }
            }
            return(count.ToString());
        }
예제 #9
0
파일: LItem.cs 프로젝트: ysj1995/Trinity
        public void AddRule(string propertyName, RuleType ruleType)
        {
            var propertiesWithDuplicatesAllowed = new HashSet <ItemProperty>
            {
                ItemProperty.ElementalDamage,
                ItemProperty.SkillDamage
            };

            Func <ItemProperty, bool> allowedToAdd = p => Rules.All(r => r.ItemProperty != p) || propertiesWithDuplicatesAllowed.Contains(p);

            ItemProperty property;

            Core.Logger.Log("Attempting to Add {0} Type={1}", propertyName, ruleType);

            if (!Enum.TryParse(propertyName, out property))
            {
                return;
            }

            var allowed = allowedToAdd(property);

            if (property != ItemProperty.Unknown && allowed)
            {
                var id        = (int)property;
                var statRange = GetItemStatRange(property);
                if (statRange != null)
                {
                    Core.Logger.Verbose($"Stats Min = {statRange.AbsMin} Max = {statRange.AbsMax} Step = {statRange.AbsStep}");
                }

                Rules.Add(new LRule
                {
                    Id              = id,
                    ItemStatRange   = statRange,
                    ItemReference   = ItemReference,
                    TrinityItemType = TrinityItemType,
                    RuleType        = ruleType,
                    Value           = LRule.GetDefaultValue(property)
                });

                OnPropertyChanged(nameof(Rules));
                OnPropertyChanged(ruleType + "Rules");
            }
            else
            {
                if (!allowed)
                {
                    Core.Logger.Log("{0} has already been added and duplicates are not allowed", propertyName);
                }
            }
        }
예제 #10
0
        public bool IsMatch(IResourceInfo resource)
        {
            if ((Rules?.Length ?? 0) <= 0)
            {
                return(false);
            }

            var target = Source == FilterSource.Name ? resource.Title : resource.Hash;

            if (IsRegex)
            {
                return(CompiledRegex?.All(s => s.IsMatch(target)) == true);
            }

            return(Rules.All(s => target.IndexOf(s, StringComparison.OrdinalIgnoreCase) != -1));
        }
예제 #11
0
 /// <summary>
 /// Tries to match all rules against a collection of argument values
 /// </summary>
 /// <param name="argsCollection">collection of argument values</param>
 /// <returns></returns>
 public bool Match(IEnumerable <CommandArgValue> argsCollection)
 {
     if (argsCollection == null)
     {
         return(false);
     }
     //must match first
     if (!Command.Match(argsCollection.FirstOrDefault()))
     {
         return(false);
     }
     //match other arguments in any position
     foreach (var arg in argsCollection.Skip(1))
     {
         //try to match any no-matched rule with any argument in any position after first command
         if (!Rules.Where(rule => !rule.Matched).Any(rule => rule.Match(arg)))
         {
             return(false);
         }
     }
     //here we must have all rules matched
     return(Rules.All(rule => rule.Matched));
 }
예제 #12
0
        public void AddRule(string propertyName, RuleType ruleType)
        {
            var propertiesWithDuplicatesAllowed = new HashSet <ItemProperty>
            {
                ItemProperty.ElementalDamage,
                ItemProperty.SkillDamage
            };

            Func <ItemProperty, bool> allowedToAdd = p => Rules.All(r => r.ItemProperty != p) || propertiesWithDuplicatesAllowed.Contains(p);

            ItemProperty property;

            Logger.Log("Attempting to Add {0} Type={1}", propertyName, ruleType);

            if (Enum.TryParse(propertyName, out property) && property != ItemProperty.Unknown && allowedToAdd(property))
            {
                var statRange = GetItemStatRange(property);
                if (statRange != null)
                {
                    Logger.LogVerbose(string.Format("Stats Min = {0} Max = {1} Step = {2}",
                                                    statRange.AbsMin.ToString(), statRange.AbsMax.ToString(), statRange.AbsStep.ToString()));
                }

                Rules.Add(new LRule
                {
                    Id              = (int)property,
                    ItemStatRange   = statRange,
                    TrinityItemType = TrinityItemType,
                    RuleType        = ruleType,
                    Value           = LRule.GetDefaultValue(property)
                });

                OnPropertyChanged("Rules");
                OnPropertyChanged(ruleType + "Rules");
            }
        }
예제 #13
0
 internal bool IsValid()
 {
     return(!string.IsNullOrWhiteSpace(Title) && !string.IsNullOrWhiteSpace(TitleTranslated) &&
            EnumerableValidator.IsNotEmpty(Rules) && Rules.All(e => e.IsValid()));
 }
예제 #14
0
 public override bool IsMatch(DateTime day)
 {
     return(Rules.All(r => r.IsMatch(day)));
 }
예제 #15
0
 public bool IsValid(int input)
 {
     return(Rules.All(i => !i.IsValid(input)));
 }
예제 #16
0
 public override bool ShouldImport(LogEntry logEntry) =>
 Rules.All(rule => rule.ShouldImport(logEntry));
예제 #17
0
 public override bool IsValid()
 {
     return(Rules.All(rule => rule.Passed(this)));
 }
예제 #18
0
 public bool IsSatisfiedBy(ClaimsPrincipal principal)
 {
     return(Operator == RuleSetOperator.Or
         ? Rules.Any(r => r.IsSatisfiedBy(principal))
         : Rules.All(r => r.IsSatisfiedBy(principal)));
 }
예제 #19
0
 protected override bool InternalMatch(ParserState p)
 {
     return(Rules.All(r => r.Match(p)));
 }
예제 #20
0
        public void Solve1()
        {
            var sum = NearbyTickets.SelectMany(t => t.Numbers.Where(n => Rules.All(r => !r.IsValid(n)))).Sum();

            Console.WriteLine(sum);
        }
예제 #21
0
 public bool Eval(T t)
 {
     return(IsTrue = Rules.All(x => x.Eval(t)));
 }
예제 #22
0
 private bool CheckDirectRules(string stringToCheck)
 {
     return(Rules.All(x => x.ConformsToRule(stringToCheck)));
 }
 private bool IsMatchRules(BaseItem item, User user)
 {
     return(Rules.All(x => x.IsMatch(new UserItem(user, item))));
 }