Esempio n. 1
0
        /// <summary>
        /// Get all species activity categories.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <returns>All species activity categories.</returns>
        public static List <WebSpeciesActivityCategory> GetSpeciesActivityCategories(WebServiceContext context)
        {
            String cacheKey;
            List <WebSpeciesActivityCategory> speciesActivityCategories;
            WebSpeciesActivityCategory        speciesActivityCategory;

            // Get cached information.
            cacheKey = Settings.Default.SpeciesActivityCategoriesCacheKey + ":" + context.Locale.ISOCode;
            speciesActivityCategories = (List <WebSpeciesActivityCategory>)(context.GetCachedObject(cacheKey));

            if (speciesActivityCategories.IsEmpty())
            {
                // Data not in cache. Get information from database.
                speciesActivityCategories = new List <WebSpeciesActivityCategory>();

                using (DataReader dataReader = context.GetSpeciesObservationDatabase().GetSpeciesActivityCategories(context.Locale.Id))
                {
                    while (dataReader.Read())
                    {
                        speciesActivityCategory = new WebSpeciesActivityCategory();
                        speciesActivityCategory.LoadData(dataReader);
                        speciesActivityCategories.Add(speciesActivityCategory);
                    }
                }

                // Add information to cache.
                context.AddCachedObject(cacheKey,
                                        speciesActivityCategories,
                                        DateTime.Now + new TimeSpan(1, 0, 0, 0),
                                        CacheItemPriority.High);
            }

            return(speciesActivityCategories);
        }
        public void LoadData()
        {
            WebSpeciesActivityCategory speciesActivityCategory;

            using (SpeciesObservationServer database = new SpeciesObservationServer())
            {
                using (DataReader dataReader = database.GetSpeciesActivityCategories((Int32)(LocaleId.sv_SE)))
                {
                    while (dataReader.Read())
                    {
                        speciesActivityCategory = new WebSpeciesActivityCategory();
                        speciesActivityCategory.LoadData(dataReader);
                        Assert.IsNotNull(speciesActivityCategory);
                        Assert.IsTrue(speciesActivityCategory.Guid.IsNotEmpty());
                        Assert.IsTrue(0 <= speciesActivityCategory.Id);
                        Assert.IsTrue(speciesActivityCategory.Identifier.IsNotEmpty());
                        Assert.IsTrue(speciesActivityCategory.Name.IsNotEmpty());
                    }
                }
            }
        }