Пример #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);
        }
Пример #2
0
 /// <summary>
 /// Populate species activity category with content from data reader.
 /// </summary>
 /// <param name="speciesActivityCategory">Species activity category that will be populated.</param>
 /// <param name="dataReader">Data source that will populate the species activity.</param>
 public static void LoadData(this WebSpeciesActivityCategory speciesActivityCategory,
                             DataReader dataReader)
 {
     speciesActivityCategory.Guid       = dataReader.GetString(SpeciesActivityCategoryData.GUID);
     speciesActivityCategory.Id         = dataReader.GetInt32(SpeciesActivityCategoryData.ID);
     speciesActivityCategory.Identifier = dataReader.GetString(SpeciesActivityCategoryData.IDENTIFIER);
     speciesActivityCategory.Name       = dataReader.GetString(SpeciesActivityCategoryData.NAME);
 }
        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());
                    }
                }
            }
        }