protected static BO.Taxonomy.BOTaxon[] GetTaxonDescendants(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant, CustomConditionTaxaDelegate CustomCondition) { System.Collections.ArrayList BadParents = new System.Collections.ArrayList(); BO.Taxonomy.BOTaxon[] Descendants = new BO.Taxonomy.BOTaxon [0]; BO.Taxonomy.BOTaxon Descendant = GetTaxonDescendant(Taxon, RequiredDescendant); //Get the parent of the found required type. BO.Taxonomy.BOTaxon DescendantParent = Descendant.GetParentTaxon(); bool DescendantsFound = false; while (DescendantParent != null & !DescendantsFound) { //Get the children of the parent. Descendants = DescendantParent.GetLowerTaxa(); if ((CustomCondition != null && CustomCondition(Descendants).Length == 0) & Descendants.Length == 0) { //This parent is no good so get another. BadParents.Add(DescendantParent); BO.Taxonomy.BOTaxon [] BadParentsArray = new BO.Taxonomy.BOTaxon [BadParents.Count]; BadParents.CopyTo(BadParentsArray); DescendantParent = GetTaxonDescendant(Taxon, DescendantParent.TaxonType, new CustomConditionDelegate(CustomConditionGetTaxonNotIn), BadParentsArray); } else { DescendantsFound = true; } } return(Descendants); }
protected static BO.Taxonomy.BOTaxon GetTaxonDescendant(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant, CustomConditionDelegate CustomCondition) { return(GetTaxonDescendant(Taxon, RequiredDescendant, CustomCondition, null)); }
protected static BO.Taxonomy.BOTaxon GetTaxonDescendant(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant, CustomConditionDelegate CustomCondition, object[] CustomConditionArgs) { if (RequiredDescendant != BO.Taxonomy.TaxonTypeEnum.Stock) { //Check if the supplied Taxon is the one required. if (Taxon.TaxonType == RequiredDescendant) { //Check if there are any custom tests to run. if (CustomCondition != null) { return(CustomCondition(Taxon, CustomConditionArgs)); } else { return(Taxon); } } else //The supplied taxon is not the one required. { BO.Taxonomy.BOTaxon[] LowerTaxa = Taxon.GetLowerTaxa(); BO.Taxonomy.BOTaxon GotTaxon = null; //Check that there are children. if (LowerTaxa.Length > 0) { System.Int32 x = 0; //Loop all the child taxon until one is returned. while (GotTaxon == null & x < LowerTaxa.Length) { GotTaxon = GetTaxonDescendant(LowerTaxa[x], RequiredDescendant, CustomCondition, CustomConditionArgs); x++; } return(GotTaxon); } else //The supplied taxon does not have any children. { return(null); } } } else { throw new ApplicationException("Cannot search for Stock name as these do not form part of the hierarchy"); } }
/// <summary> /// This gets a taxon of the type specified that is a descendant of the supplied Taxon For example, supply a Kingdom Taxon and specify you want a species - if one exists a species from within the Kingdom will be returned. /// </summary> /// <param name="Taxon"></param> /// <param name="RequiredDescendant"></param> /// <returns>A Taxon or null</returns> protected static BO.Taxonomy.BOTaxon GetTaxonDescendant(BO.Taxonomy.BOTaxon Taxon, BO.Taxonomy.TaxonTypeEnum RequiredDescendant) { return(GetTaxonDescendant(Taxon, RequiredDescendant, null)); }