Exemplo n.º 1
0
        /// <summary>
        /// Get all factor trees.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <returns>All factor trees.</returns>
        public static List <WebFactorTreeNode> GetFactorTrees(WebServiceContext context)
        {
            FactorInformation        factorInformation;
            List <WebFactorTreeNode> factorTrees;
            Boolean getOnlyPublicFactors = !IsUserAuthorizedToReadNonPublicFactors(context);

            // Get cached information.
            factorTrees = null;
            if (!context.IsInTransaction())
            {
                factorTrees = GetFactorInformation(context, getOnlyPublicFactors).FactorTrees;
            }

            if (factorTrees.IsNull())
            {
                // Get information from database.
                using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetFactorTrees(getOnlyPublicFactors))
                {
                    factorInformation = new FactorInformation(context, dataReader);
                }

                factorTrees = factorInformation.FactorTrees;
            }

            return(factorTrees);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get information about factor trees that matches the search criteria.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="searchCriteria">Factor tree information.</param>
        /// <returns>Filtered factor trees.</returns>
        /// <exception cref="ArgumentException">Thrown if factorSearchCriteria is null.</exception>
        public static List <WebFactorTreeNode> GetFactorTreesBySearchCriteria(WebServiceContext context,
                                                                              WebFactorTreeSearchCriteria searchCriteria)
        {
            FactorInformation        factorInformation;
            List <WebFactorTreeNode> factorTrees;
            WebFactorTreeNodeList    factorTreeNodes;
            Boolean getOnlyPublicFactors = !IsUserAuthorizedToReadNonPublicFactors(context);

            // Check arguments.
            searchCriteria.CheckNotNull("searchCriteria");
            searchCriteria.CheckData();

            if (searchCriteria.FactorIds.IsEmpty())
            {
                // Get all factor trees.
                factorTrees = GetFactorTrees(context);
            }
            else
            {
                // Get all factor tree nodes.
                if (context.IsInTransaction())
                {
                    // Get information from database.
                    using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetFactorTrees(getOnlyPublicFactors))
                    {
                        factorInformation = new FactorInformation(context, dataReader);
                    }

                    factorTreeNodes = factorInformation.FactorTreeNodes;
                }
                else
                {
                    factorTreeNodes = GetFactorInformation(context, getOnlyPublicFactors).FactorTreeNodes;
                }

                // Get all factor trees that are requested.
                factorTrees = new List <WebFactorTreeNode>();
                foreach (Int32 factorId in searchCriteria.FactorIds)
                {
                    if (factorTreeNodes.Contains(factorId))
                    {
                        factorTrees.Add(factorTreeNodes.Get(factorId));
                    }
                }
            }

            return(factorTrees);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get information about factor trees and factors.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <returns>Factor information.</returns>
        private static FactorInformation GetFactorInformation(WebServiceContext context)
        {
            FactorInformation factorInformation;
            String            cacheKey;

            // Get cached information.
            cacheKey          = "FactorInformation";
            factorInformation = (FactorInformation)context.GetCachedObject(cacheKey);

            if (factorInformation.IsNull())
            {
                // Get information from database.
                using (DataReader dataReader = DataServer.GetFactorTrees(context))
                {
                    factorInformation = new FactorInformation(dataReader);

                    // Add information to cache.
                    context.AddCachedObject(cacheKey, factorInformation, DateTime.Now + new TimeSpan(12, 0, 0), CacheItemPriority.AboveNormal);
                }
            }
            return(factorInformation);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get information about factor trees and factors.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="getOnlyPublicFactors">If true: Get only public factor trees. If false: get all factor trees. Default is true.</param>
        /// <returns>Factor information.</returns>
        private static FactorInformation GetFactorInformation(WebServiceContext context, Boolean getOnlyPublicFactors = true)
        {
            FactorInformation factorInformation;
            String            cacheKey;
            Boolean           cacheAllFactors = !getOnlyPublicFactors;

            // Get cached information.
            cacheKey = GetFactorInformationCacheKeyByUserRole(cacheAllFactors);

            factorInformation = (FactorInformation)context.GetCachedObject(cacheKey);
            if (factorInformation.IsNull())
            {
                // Get information from database.
                using (DataReader dataReader = context.GetTaxonAttributeDatabase().GetFactorTrees(getOnlyPublicFactors))
                {
                    factorInformation = new FactorInformation(context, dataReader);

                    // Add information to the cache.
                    context.AddCachedObject(cacheKey, factorInformation, DateTime.Now + new TimeSpan(12, 0, 0), CacheItemPriority.AboveNormal);
                }
            }

            return(factorInformation);
        }