Exemplo n.º 1
0
        /// <summary>
        /// Model Validation
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            // ensure at least one conception model is associated
            int conceptionModelCount = this.FindAllChildren <Model>().Where(a => typeof(IConceptionModel).IsAssignableFrom(a.GetType())).Count();

            if (conceptionModelCount > 1)
            {
                string[] memberNames = new string[] { "RuminantType.IConceptionModel" };
                results.Add(new ValidationResult(String.Format("Only one Conception component is permitted below the Ruminant Type [r={0}]", Name), memberNames));
            }

            if (this.FindAllChildren <AnimalPricing>().Count() > 1)
            {
                string[] memberNames = new string[] { "RuminantType.Pricing" };
                results.Add(new ValidationResult(String.Format("Only one Animal pricing schedule is permitted within a Ruminant Type [{0}]", this.Name), memberNames));
            }
            else if (this.FindAllChildren <AnimalPricing>().Count() == 1)
            {
                AnimalPricing price = this.FindAllChildren <AnimalPricing>().FirstOrDefault() as AnimalPricing;

                if (price.FindAllChildren <AnimalPriceGroup>().Count() == 0)
                {
                    string[] memberNames = new string[] { "RuminantType.Pricing.RuminantPriceGroup" };
                    results.Add(new ValidationResult(String.Format("At least one Ruminant Price Group is required under an animal pricing within Ruminant Type [{0}]", this.Name), memberNames));
                }
            }
            return(results);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a copy of the current instance
        /// </summary>
        /// <returns></returns>
        public AnimalPricing Clone()
        {
            AnimalPricing clone = new AnimalPricing();

            foreach (AnimalPriceGroup item in this.Children.OfType <AnimalPriceGroup>())
            {
                clone.Children.Add(item.Clone());
            }
            return(clone);
        }
Exemplo n.º 3
0
        private void OnCLEMInitialiseResource(object sender, EventArgs e)
        {
            // clone pricelist so model can modify if needed and not affect initial parameterisation
            if (Apsim.Children(this, typeof(AnimalPricing)).Count() > 0)
            {
                PriceList = (Apsim.Children(this, typeof(AnimalPricing)).FirstOrDefault() as AnimalPricing).Clone();
            }

            // get conception parameters and rate calculation method
            ConceptionModel = Apsim.Children(this, typeof(Model)).Where(a => typeof(IConceptionModel).IsAssignableFrom(a.GetType())).Cast <IConceptionModel>().FirstOrDefault();
        }
Exemplo n.º 4
0
        private void OnCLEMInitialiseResource(object sender, EventArgs e)
        {
            parentHerd = this.Parent as RuminantHerd;

            // clone pricelist so model can modify if needed and not affect initial parameterisation
            if (this.FindAllChildren <AnimalPricing>().Count() > 0)
            {
                PriceList = this.FindAllChildren <AnimalPricing>().FirstOrDefault();
                // Components are not permanently modifed during simulation so no need for clone: PriceList = Apsim.Clone(this.FindAllChildren<AnimalPricing>().FirstOrDefault()) as AnimalPricing;

                priceGroups = PriceList.FindAllChildren <AnimalPriceGroup>().Cast <AnimalPriceGroup>().ToList();
            }

            // get conception parameters and rate calculation method
            ConceptionModel = this.FindAllChildren <Model>().Where(a => typeof(IConceptionModel).IsAssignableFrom(a.GetType())).Cast <IConceptionModel>().FirstOrDefault();
        }