BudgetAnalyser.Engine.Widgets.SurprisePaymentWidget.Update C# (CSharp) Метод

Update() приватный Метод

private Update ( ) : void
Результат void
        public override void Update(params object[] input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (!ValidateUpdateInput(input))
            {
                Enabled = false;
                return;
            }

            this.bucketRepository = (IBudgetBucketRepository) input[0];
            this.filter = (GlobalFilterCriteria) input[1];

            if (this.filter == null || this.filter.Cleared || this.filter.BeginDate == null || this.filter.BeginDate == DateTime.MinValue ||
                this.filter.EndDate == null || this.filter.EndDate.Value == DateTime.MinValue || this.bucketRepository == null)
            {
                Enabled = false;
                return;
            }

            if (!this.bucketRepository.IsValidCode(BucketCode))
            {
                Enabled = false;
                LargeNumber = string.Empty;
                ToolTip = string.Empty;
                DetailedText = string.Empty;
                return;
            }

            this.diagLogger.LogInfo(l => l.Format("{0} Calculating Payment Plan for {1}. From {2} to {3}", WidgetType.Name, Id, this.filter.BeginDate, this.filter.EndDate));
            var currentDate = CalculateStartDate(StartPaymentDate, this.filter.BeginDate.Value);
            var content = new StringBuilder();
            // Ignore start date in filter and force it to be one month prior to end date in filter.
            var currentMonthTally = new NextOccurance
            {
                StartDate = this.filter.EndDate.Value.AddDays(1).AddMonths(-1),
                EndDate = this.filter.EndDate.Value
            };
            var alert = false;
            NextOccurance firstOccurance = null;
            do
            {
                if (currentDate.Date <= currentMonthTally.EndDate)
                {
                    currentMonthTally.Tally(currentDate.Date.Day);
                }
                else
                {
                    this.diagLogger.LogInfo(
                        l =>
                            l.Format("    {0} {1}", currentMonthTally.StartDate.ToString("MMMM"),
                                currentMonthTally.ConcatDates()));
                    if (AbnormalNumberOfPayments(currentMonthTally.Dates.Count))
                    {
                        if (firstOccurance == null)
                        {
                            firstOccurance = currentMonthTally;
                        }
                        content.AppendFormat(CultureInfo.CurrentCulture, "{0}, ",
                            currentMonthTally.StartDate.ToString("MMMM"));
                        if (currentMonthTally.EndDate == this.filter.EndDate.Value ||
                            currentMonthTally.EndDate == this.filter.EndDate.Value.AddMonths(1))
                        {
                            // Is current or next month, so signal alert status
                            alert = true;
                            this.diagLogger.LogInfo(l => l.Format("    ***** ALERT *****"));
                        }
                    }
                    currentMonthTally = currentMonthTally.NextMonth(currentDate.Date.Day);
                }

                currentDate = CalculateNextPaymentDate(currentDate);
            } while (currentDate.Date <= this.filter.EndDate.Value.AddYears(1));

            ColourStyleName = alert ? WidgetWarningStyle : WidgetStandardStyle;
            DetailedText = string.Format(CultureInfo.CurrentCulture, "Monitoring {0} {1} bucket. {2}", Frequency,
                BucketCode, content);
            if (firstOccurance == null)
            {
                LargeNumber = string.Empty;
                ToolTip = ToolTipPrefix;
            }
            else
            {
                LargeNumber = firstOccurance.StartDate.ToString("MMMM");
                ToolTip = ToolTipPrefix +
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "{0} to the {1} has payments on {2}",
                              firstOccurance.StartDate.ToString("d-MMM"),
                              firstOccurance.EndDate.ToString("d-MMM"),
                              firstOccurance.ConcatDates());
            }
        }