/// <summary>
 /// Create a SpeciesFactCondition instance.
 /// </summary>
 public SpeciesFactCondition()
     : base(DataQueryType.SpeciesFactCondition)
 {
     Factors = new FactorList();
     Periods = new PeriodList();
     IndividualCategories       = new IndividualCategoryList();
     SpeciesFactFieldConditions = new List <SpeciesFactFieldCondition>();
 }
 /// <summary>
 /// Create a user parameter selection instance.
 /// </summary>
 public UserParameterSelection()
 {
     _factors = new FactorList(true);
     _hosts   = new TaxonList(true);
     _individualCategories = new IndividualCategoryList(true);
     _periods    = new PeriodList(true);
     _references = new ReferenceList(true);
     _taxa       = new TaxonList(true);
 }
 /// <summary>
 /// Add individual categories to the data identifier list.
 /// </summary>
 /// <param name='individualCategories'>Individual categories.</param>
 public void AddRange(IndividualCategoryList individualCategories)
 {
     if (individualCategories.IsNotEmpty())
     {
         foreach (IndividualCategory individualCategory in individualCategories)
         {
             Add(individualCategory);
         }
     }
 }
        /// <summary>
        /// Get all individual category objects.
        /// </summary>
        /// <returns>All individual categories.</returns>
        public static IndividualCategoryList GetIndividualCategories()
        {
            IndividualCategoryList individualCategories = null;

            for (Int32 getAttempts = 0; (individualCategories.IsNull()) && (getAttempts < 3); getAttempts++)
            {
                LoadIndividualCategories();
                individualCategories = IndividualCategories;
            }
            return(individualCategories);
        }
 /// <summary>
 /// Private constructor. Makes a clone of a UserParameterSelection.
 /// </summary>
 /// <param name="userParameterSelection">UserParameterSelection to clone</param>
 private UserParameterSelection(UserParameterSelection userParameterSelection)
 {
     _factors = new FactorList(true);
     _factors.AddRange(userParameterSelection.Factors);
     _hosts = new TaxonList(true);
     _hosts.AddRange(userParameterSelection.Hosts);
     _individualCategories = new IndividualCategoryList(true);
     _individualCategories.AddRange(userParameterSelection.IndividualCategories);
     _periods = new PeriodList(true);
     _periods.AddRange(userParameterSelection.Periods);
     _references = new ReferenceList(true);
     _references.AddRange(userParameterSelection.References);
     _taxa = new TaxonList(true);
     _taxa.AddRange(userParameterSelection.Taxa);
 }
        /// <summary>
        /// Get individual categories from web service.
        /// </summary>
        private static void LoadIndividualCategories()
        {
            IndividualCategoryList individualCategories;

            if (IndividualCategories.IsNull())
            {
                // Get data from web service.
                individualCategories = new IndividualCategoryList(true);
                foreach (WebIndividualCategory webIndividualCategory in WebServiceClient.GetIndividualCategories())
                {
                    individualCategories.Add(new IndividualCategory(webIndividualCategory.Id,
                                                                    webIndividualCategory.Name,
                                                                    webIndividualCategory.Definition,
                                                                    webIndividualCategory.SortOrder));
                }
                IndividualCategories = individualCategories;
            }
        }
        /// <summary>
        /// Method that returns a filtered version of this species fact list. The filtering is done on Individual Categories
        /// </summary>
        /// <param name="individualCategories"></param>
        /// <returns>A filtered SpeciesFactList</returns>
        public SpeciesFactList FilterSpeciesFacts(IndividualCategoryList individualCategories)
        {
            if (individualCategories == null)
            {
                throw new ArgumentException("CategoryList is null", "individualCategories");
            }

            SpeciesFactList filteredList = new SpeciesFactList();

            {
                foreach (SpeciesFact fact in this)
                {
                    foreach (IndividualCategory category in individualCategories)
                    {
                        if (fact.IndividualCategory.Id == category.Id)
                        {
                            filteredList.Add(fact);
                            break;
                        }
                    }
                }
            }
            return(filteredList);
        }
        /// <summary>
        /// Method that returns a filtered version of this species fact list. The filtering is done on several parameters.
        /// </summary>
        /// <param name="individualCategories"></param>
        /// <param name="periods"></param>
        /// <param name="hosts"></param>
        /// <param name="taxa"></param>
        /// <param name="factors"></param>
        /// <returns>A filtered SpeciesFactList</returns>
        public SpeciesFactList FilterSpeciesFacts(
            IndividualCategoryList individualCategories,
            PeriodList periods,
            TaxonList hosts,
            TaxonList taxa,
            FactorList factors)
        {
            SpeciesFactList filteredList = new SpeciesFactList();

            foreach (SpeciesFact fact in this)
            {
                bool go = true;

                if (fact.IndividualCategory != null)
                {
                    if ((individualCategories != null) && (individualCategories.Count > 0))
                    {
                        if (!individualCategories.Exists(fact.IndividualCategory))
                        {
                            go = false;
                        }
                    }
                }

                if (go)
                {
                    if (fact.Period != null)
                    {
                        if ((periods != null) && (periods.Count > 0))
                        {
                            if (!periods.Exists(fact.Period))
                            {
                                go = false;
                            }
                        }
                    }
                }
                if (go)
                {
                    if (fact.Host != null)
                    {
                        // For the time being we only accept species facts that dont have a host.

                        go = false;

                        //if ((hosts != null) && (hosts.Count > 0))
                        //{
                        //    if (!hosts.Exists(fact.Host))
                        //        go = false;
                        //}
                    }
                }
                if (go)
                {
                    if (fact.Taxon != null)
                    {
                        if ((taxa != null) && (taxa.Count > 0))
                        {
                            if (!taxa.Exists(fact.Taxon))
                            {
                                go = false;
                            }
                        }
                    }
                }
                if (go)
                {
                    if (fact.Factor != null)
                    {
                        if ((factors != null) && (factors.Count > 0))
                        {
                            if (!factors.Exists(fact.Factor))
                            {
                                go = false;
                            }
                        }
                    }
                }

                if (go)
                {
                    filteredList.Add(fact);
                }
            }

            return(filteredList);
        }
 /// <summary>
 /// Refresh cached data.
 /// </summary>
 private static void RefreshCache()
 {
     IndividualCategories = null;
 }