/// <summary>
        /// Get taxa that belongs to specified organism groups.
        /// </summary>
        /// <param name="userContext">User context.</param>
        /// <param name="organismGroups">Organism groups.</param>
        /// <returns>Taxa that belongs to specified organism groups.</returns>
        public virtual TaxonList GetTaxa(IUserContext userContext,
                                         OrganismGroupList organismGroups)
        {
            IFactor factor;
            ISpeciesFactFieldSearchCriteria fieldSearchCriteria;
            ISpeciesFactSearchCriteria      searchCriteria;
            TaxonList taxa;

            taxa = null;
            if (organismGroups.IsNotEmpty())
            {
                searchCriteria = new SpeciesFactSearchCriteria();
                factor         = CoreData.FactorManager.GetFactor(userContext,
                                                                  FactorId.Redlist_OrganismLabel1);
                searchCriteria.Add(factor);
                searchCriteria.IncludeNotValidHosts = false;
                searchCriteria.IncludeNotValidTaxa  = false;
                searchCriteria.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext));
                searchCriteria.FieldLogicalOperator = LogicalOperator.Or;
                foreach (IOrganismGroup organismGroup in organismGroups)
                {
                    fieldSearchCriteria             = new SpeciesFactFieldSearchCriteria();
                    fieldSearchCriteria.FactorField = factor.DataType.Field1;
                    fieldSearchCriteria.Operator    = CompareOperator.Equal;
                    fieldSearchCriteria.AddValue(organismGroup.Id);
                    searchCriteria.Add(fieldSearchCriteria);
                }

                taxa = DataSource.GetTaxa(userContext, searchCriteria);
            }

            return(taxa);
        }
        /// <summary>
        /// The data set is initiated or redefined by
        /// using this method.
        /// Scope of the data set is defined by this
        /// species fact data set selection.
        /// At least one factor and one taxon must be specified
        /// in the species fact data set selection.
        /// </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>
        public virtual void UpdateSelection(IUserContext userContext,
                                            ISpeciesFactDataSetSelection selection)
        {
            IFactor factor;
            Int32   factorIndex;
            ISpeciesFactDataSetSelection workingSelection;
            ISpeciesFactSearchCriteria   searchCriteria;
            SpeciesFactList speciesFacts;

            // Check arguments.
            selection.CheckNotNull("selection");
            if (selection.Factors.IsEmpty() || selection.Taxa.IsEmpty())
            {
                // Reset species fact data set and end method.
                // Conditions to retrieve species facts are not fulfilled.
                Reset(selection);
                return;
            }

            // Add dependent factors to selection if necessary.
            workingSelection = (ISpeciesFactDataSetSelection)(selection.Clone());
            for (factorIndex = 0; factorIndex < workingSelection.Factors.Count; factorIndex++)
            {
                factor = workingSelection.Factors[factorIndex];
                workingSelection.Factors.Merge(factor.GetDependentFactors(userContext));
            }

            // Get species facts.
            searchCriteria         = new SpeciesFactSearchCriteria();
            searchCriteria.Factors = workingSelection.Factors;
            searchCriteria.Hosts   = workingSelection.Hosts;
            searchCriteria.IncludeNotValidHosts = true;
            searchCriteria.IncludeNotValidTaxa  = true;
            searchCriteria.IndividualCategories = workingSelection.IndividualCategories;
            searchCriteria.Periods    = workingSelection.Periods;
            searchCriteria.References = workingSelection.References;
            searchCriteria.Taxa       = workingSelection.Taxa;
            speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, searchCriteria);

            // Update species fact scope with new information.
            UpdateScope(userContext, workingSelection, speciesFacts);

            // Remove old species facts that are no longer
            // included in the species fact scope.
            RemoveSpeciesFactsNotInScope();

            // Merge old and new species facts to same list.
            MergeSpeciesFacts(speciesFacts);

            // Get missing species facts according to expanded
            // combinations of species fact data set selection.
            UpdateWithEmptySpeciesFacts(userContext);

            // Init automated calculation.
            InitAutomatedCalculations(userContext);

            // Save selection information.
            _selection     = (ISpeciesFactDataSetSelection)(selection.Clone());
            _selectionCopy = (ISpeciesFactDataSetSelection)(selection.Clone());
        }