private ValidationResult CheckForPotentiallyMisconfiguredComponents(IWindsorContainer container)
        {
            var host = (IDiagnosticsHost)container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);
            var diagnostics = host.GetDiagnostic<IPotentiallyMisconfiguredComponentsDiagnostic>();

            var handlers = diagnostics.Inspect();

            ValidationResult result = new ValidationResult();

            if (handlers.Any())
            {
                var message = new StringBuilder();
                var inspector = new DependencyInspector(message);

                foreach (IExposeDependencyInfo handler in handlers)
                {
                    handler.ObtainDependencyDetails(inspector);
                }

                result.AddMessage(Severity.Error, message.ToString());
                Console.Write(message.ToString());
            }

            return result;
        }
Example #2
0
        public ValidationResult CanPayFines(int number)
        {
            var canPayFines = new ValidationResult();

            if (!this.Fines.Any(x => x.Outstanding))
            {
                canPayFines.AddMessage(Severity.Error, "This user doesn't have any fines to pay!");
                return canPayFines;
            }

            if(this.Fines.Count(x => x.Outstanding) < number)
            {
                canPayFines.AddMessage(Severity.Warning, "This user doesn't have that many fines!");
            }

            return canPayFines;
        }
Example #3
0
        public ValidationResult Second(Guid seconderId)
        {
            ValidationResult result = new ValidationResult();

            if(seconderId == IssuerId)
            {
                result.AddMessage(Severity.Error, "You may not second a fine you awarded!");
            }

            if(result.HasErrors) return result;

            this.SeconderId = seconderId;

            return result;
        }
        private ValidationResult ValidateFine(Fine fine)
        {
            ValidationResult validationResult = new ValidationResult();

            if (fine.Reason.IsNullOrEmpty())
            {
                validationResult.AddMessage(Severity.Error, "A fine requires a reason");
            }

            if (!this.userApi.IsValidFineIssuer(fine.IssuerId))
            {
                validationResult.AddMessage(Severity.Error, string.Format("Only {0} fines per user per day can be awarded", int.Parse(ConfigurationManager.AppSettings["MaxFinesPerUserPerDay"])));
            }

            return validationResult;
        }
Example #5
0
        public ValidationResult PayFines(Payment payment, int number)
        {
            var validationResult = new ValidationResult();

            validationResult.Append(this.CanPayFines(number));

            if(payment.PayerId == this.Id)
            {
                validationResult.AddMessage(Severity.Error, "You cannot pay a fine for yourself!");
            }

            if(validationResult.HasErrors) return validationResult;

            var orderedFines = this.Fines.Where(x => x.Outstanding).OrderBy(x => x.AwardedDate).ToList();

            bool hasPending = orderedFines.All(x => x.Pending);

            if (hasPending)
            {
                return validationResult.AddMessage(Severity.Error, "Payable fines need to be seconded first");
            }

            int limit = number;

            if(orderedFines.Count < number)
            {
                limit = orderedFines.Count;
            }

            for(int i = 0; i < limit; i++)
            {
                orderedFines[i].Pay(payment.Id);
            }

            return validationResult;
        }