Ejemplo n.º 1
0
        /// <summary>
        /// Get a subset of this factor list by search string.
        /// </summary>
        /// <param name="searchString">Search string.</param>
        /// <param name="comparisonType">Type of string comparison.</param>
        /// <returns>A factor list.</returns>
        public FactorList GetFactorsBySearchString(String searchString,
                                                   StringComparison comparisonType)
        {
            FactorList factors = new FactorList();
            var        subset  = from IFactor factor in this
                                 where factor.Label.StartsWith(searchString, comparisonType)
                                 orderby factor.Label ascending
                                 select factor;

            factors.AddRange(subset.ToArray());
            return(factors);
        }
        /// <summary>
        /// Get factors with specified datatype.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="factorDataType">Factor datatype.</param>
        /// <returns>Factors with specified datatype.</returns>
        public virtual FactorList GetFactors(IUserContext userContext, IFactorDataType factorDataType)
        {
            FactorList allFactors, factors;

            // Check arguments.
            factorDataType.CheckNotNull("factorDataType");

            allFactors = GetFactors(userContext);
            factors    = new FactorList();
            factors.AddRange(allFactors.FindAll(factor => factor.DataType.IsNotNull() && factor.DataType.Id == factorDataType.Id));
            return(factors);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get all child factors that belongs to this factor tree node.
        /// The factor for this tree node is also included in the result.
        /// </summary>
        /// <returns>All child factors that belongs to this factor tree node.</returns>
        public FactorList GetAllChildFactors()
        {
            FactorList factors = new FactorList {
                Factor
            };

            if (Children.IsNotEmpty())
            {
                foreach (IFactorTreeNode child in Children)
                {
                    factors.AddRange(child.GetAllChildFactors());
                }
            }

            return(factors);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get all child factors that belongs to this factor tree node.
        /// The factor for this tree node may also
        /// be included in the result.
        /// </summary>
        /// <returns>All leaf factors that belongs to this factor tree node.</returns>
        public FactorList GetAllLeafFactors()
        {
            FactorList leaves = new FactorList();

            if (Children.IsEmpty())
            {
                leaves.Add(Factor);
            }
            else
            {
                foreach (IFactorTreeNode child in Children)
                {
                    leaves.AddRange(child.GetAllLeafFactors());
                }
            }

            return(leaves);
        }
        /// <summary>
        /// Update information about which factors, hosts,
        /// individual categories, periods, references and taxa
        /// that are used in the species facts.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="selection">
        /// Scope of the data set is defined by this
        /// species fact data set selection.
        /// </param>
        /// <param name="speciesFacts">Species facts.</param>
        private void UpdateScope(IUserContext userContext,
                                 ISpeciesFactDataSetSelection selection,
                                 SpeciesFactList speciesFacts)
        {
            Factors = new FactorList(true);
            Factors.AddRange(selection.Factors);
            Hosts = new TaxonList(true);
            Hosts.AddRange(selection.Hosts);
            IndividualCategories = new IndividualCategoryList(true);
            IndividualCategories.AddRange(selection.IndividualCategories);
            Periods = new PeriodList(true);
            Periods.AddRange(selection.Periods);
            References = new ReferenceList(true);
            Taxa       = new TaxonList(true);
            Taxa.AddRange(selection.Taxa);

            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    Factors.Merge(speciesFact.Factor);
                    if (speciesFact.HasHost)
                    {
                        Hosts.Merge(speciesFact.Host);
                    }

                    IndividualCategories.Merge(speciesFact.IndividualCategory);
                    if (speciesFact.HasPeriod)
                    {
                        Periods.Merge(speciesFact.Period);
                    }

                    if (speciesFact.HasReference)
                    {
                        References.Merge(speciesFact.Reference);
                    }

                    Taxa.Merge(speciesFact.Taxon);
                }
            }

            // Set default values if no values are entered.
            if (Hosts.IsEmpty())
            {
                Hosts.Add(CoreData.TaxonManager.GetTaxon(userContext, TaxonId.Life));
            }

            if (IndividualCategories.IsEmpty())
            {
                IndividualCategories.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext));
            }

            if (Periods.IsEmpty())
            {
                Periods.AddRange(CoreData.FactorManager.GetPeriods(userContext));
            }

            // Sort all lists.
            Factors.Sort();
            Hosts.Sort();
            IndividualCategories.Sort();
            Periods.Sort();
            References.Sort();
            Taxa.Sort();
        }