Пример #1
0
        /// <summary>
        /// Creates an iterator that traverses the tree breadth first.
        /// </summary>
        /// <param name="taxonTreeNodeList">The Taxon tree node list.</param>
        public static IEnumerable <ITaxonTreeNode> AsBreadthFirstIterator(this TaxonTreeNodeList taxonTreeNodeList)
        {
            Queue <ITaxonTreeNode> q = new Queue <ITaxonTreeNode>();

            foreach (ITaxonTreeNode taxonTreeNode in taxonTreeNodeList)
            {
                q.Enqueue(taxonTreeNode);
            }

            while (q.Any())
            {
                ITaxonTreeNode current = q.Dequeue();
                if (current != null)
                {
                    if (current.Children != null)
                    {
                        foreach (ITaxonTreeNode childNode in current.Children)
                        {
                            q.Enqueue(childNode);
                        }
                    }

                    yield return(current);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Creates an iterator that traverses the tree depth first.
        /// </summary>
        /// <param name="taxonTreeNodeList">The Taxon tree node list.</param>
        public static IEnumerable <ITaxonTreeNode> AsDepthFirstIterator(this TaxonTreeNodeList taxonTreeNodeList)
        {
            Stack <ITaxonTreeNode> q = new Stack <ITaxonTreeNode>();

            foreach (ITaxonTreeNode taxonTreeNode in taxonTreeNodeList)
            {
                q.Push(taxonTreeNode);
            }

            while (q.Any())
            {
                ITaxonTreeNode current = q.Pop();
                if (current != null)
                {
                    if (current.Children != null)
                    {
                        for (int i = current.Children.Count - 1; i >= 0; i--)
                        {
                            q.Push(current.Children[i]);
                        }
                    }

                    yield return(current);
                }
            }
        }
Пример #3
0
        public TaxonTreeNodeList GetTaxonTrees(IUserContext userContext, ITaxonTreeSearchCriteria searchCriteria)
        {
            TaxonTreeNodeList list     = new TaxonTreeNodeList();
            TaxonTreeNode     treeNode = new TaxonTreeNode();

            treeNode.Id    = 22;
            treeNode.Taxon = this.GetReferenceTaxon(userContext, testTaxonId);
            TaxonTreeNodeList parentList = new TaxonTreeNodeList();

            TaxonTreeNode parentTreeNode = new TaxonTreeNode();

            parentTreeNode.Id    = 21;
            parentTreeNode.Taxon = GetReferenceTaxon(userContext, 100067);
            parentList.Add(parentTreeNode);
            treeNode.Parents = parentList;

            TaxonTreeNodeList childList = new TaxonTreeNodeList();

            TaxonTreeNode childTreeNode = new TaxonTreeNode();

            childTreeNode.Id = 21;
            ITaxon taxon = GetReferenceTaxon(userContext, 100068);

            taxon.Category.IsTaxonomic = false;
            childTreeNode.Taxon        = taxon;
            childList.Add(childTreeNode);
            treeNode.Children = childList;

            list.Add(treeNode);
            return(list);
        }
Пример #4
0
        /// <summary>
        /// Get all protected taxa
        /// </summary>
        /// <returns>A list of all protected taxa</returns>
        private TaxonList GetProtectedTaxa()
        {
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.Factors = new FactorList();
            searchCriteria.IndividualCategories = new IndividualCategoryList
            {
                CoreData.FactorManager.GetDefaultIndividualCategory(mContext)
            };
            searchCriteria.Factors.Add(CoreData.FactorManager.GetFactor(mContext, FactorId.ProtectionLevel));

            var speciesFactList = CoreData.SpeciesFactManager.GetSpeciesFacts(mContext, searchCriteria);

            var taxonList = new TaxonList(true);

            foreach (var speciesFact in speciesFactList)
            {
                if (speciesFact.MainField != null && speciesFact.MainField.HasValue &&
                    speciesFact.MainField.EnumValue != null && speciesFact.MainField.EnumValue.Enum != null)
                {
                    const int RedListProtectionLevel = 1;
                    if (speciesFact.MainField.EnumValue.KeyInt > RedListProtectionLevel)
                    {
                        taxonList.Add(speciesFact.Taxon);
                    }
                }
            }

            ITaxonTreeSearchCriteria taxonTreeSearchCriteria = new TaxonTreeSearchCriteria();

            taxonTreeSearchCriteria.TaxonIds        = taxonList.GetIds();
            taxonTreeSearchCriteria.Scope           = TaxonTreeSearchScope.AllChildTaxa;
            taxonTreeSearchCriteria.IsValidRequired = true;
            TaxonTreeNodeList taxonTreeNodeList = CoreData.TaxonManager.GetTaxonTrees(mContext, taxonTreeSearchCriteria);

            foreach (var taxonTreeNode in taxonTreeNodeList)
            {
                taxonList.Merge(taxonTreeNode.GetChildTaxa());
            }

            return(taxonList);
        }