private void OnCLEMInitialiseResource(object sender, EventArgs e) { Details = this.FindAllChildren <RuminantTypeCohort>().FirstOrDefault(); ruminantType = resources.FindResourceType <RuminantHerd, RuminantType>(this.Parent as Model, RuminantTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop); // create example ruminant Details.Number = 1; ExampleIndividual = Details.CreateIndividuals(null, BreedParams).FirstOrDefault(); }
/// <inheritdoc/> public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var results = new List <ValidationResult>(); if (this.FindAllChildren <Transmutation>().Count() > 0) { string[] memberNames = new string[] { "Transmutations" }; results.Add(new ValidationResult("Transmutations are not available for the CommonLandFoodStoreType (" + this.Name + ")", memberNames)); } pasture = new object(); // check that either a AnimalFoodStoreType or a GrazeFoodStoreType can be found if link required. if (PastureLink != null && !PastureLink.StartsWith("Not specified")) { // check animalFoodStoreType pasture = resources.FindResourceType <ResourceBaseWithTransactions, IResourceType>(this, PastureLink, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop); if (pasture == null) { string[] memberNames = new string[] { "Pasture link" }; results.Add(new ValidationResult("A link to an animal food store or graze food store type must be supplied to link to common land (" + this.Name + ")", memberNames)); } } if (PastureLink != null && PastureLink.StartsWith("Not specified")) { // no link so need to ensure values are all supplied. List <string> missing = new List <string>(); if (NToDMDCoefficient == 0) { missing.Add("NToDMDCoefficient"); } if (NToDMDIntercept == 0) { missing.Add("NToDMDIntercept"); } if (missing.Count() > 0) { foreach (var item in missing) { string[] memberNames = new string[] { item }; results.Add(new ValidationResult("The common land [r=" + this.Name + "] requires [o=" + item + "] as it is not linked to an on-farm pasture", memberNames)); } } } return(results); }
/// <summary> /// Validate model /// </summary> /// <param name="validationContext"></param> /// <returns></returns> public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { RuminantTypeCohort ruminantCohort = Parent as RuminantTypeCohort; var results = new List <ValidationResult>(); if ((Parent as RuminantTypeCohort).Sex == Sex.Female) { // get the breed to check gestation RuminantType ruminantType = this.FindAncestor <RuminantType>(); if (ruminantType is null) { // find type from a specify ruminant component var specifyRuminant = this.FindAncestor <SpecifyRuminant>(); if (specifyRuminant != null) { ruminantType = resources.FindResourceType <RuminantHerd, RuminantType>(this as Model, specifyRuminant.RuminantTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop); } if (ruminantType != null) { if (NumberMonthsPregnant < ruminantType.GestationLength) { string[] memberNames = new string[] { "Ruminant cohort details" }; results.Add(new ValidationResult($"The number of months pregant [{NumberMonthsPregnant}] for [r=SetPreviousConception] must be less than the gestation length of the breed [{ruminantType.GestationLength}]", memberNames)); } // get the individual to check female and suitable age for conception supplied. if (ruminantCohort.Age - NumberMonthsPregnant >= ruminantType.MinimumAge1stMating) { string[] memberNames = new string[] { "Ruminant cohort details" }; results.Add(new ValidationResult($"The individual specified must be at least [{ruminantType.MinimumAge1stMating}] month old at the time of conception [r=SetPreviousConception]", memberNames)); } } else { string[] memberNames = new string[] { "Ruminant cohort details" }; results.Add(new ValidationResult($"Cannot locate a [r=RuminantType] in tree structure above [r=SetPreviousConception]", memberNames)); } } } else { string[] memberNames = new string[] { "ActivityHolder" }; results.Add(new ValidationResult("Previous conception status can only be calculated for female ruminants", memberNames)); } return(results); }