/// <summary>
        /// Get application user context.
        /// </summary>
        /// <param name="userManager">A user manager instance.</param>
        /// <param name="localeIsoCode">The locale ISO code.</param>
        /// <returns>Application user context.</returns>
        public static IUserContext GetApplicationContext(this IUserManager userManager, string localeIsoCode)
        {
            IUserContext applicationUserContext;
            String       cacheKey;

            if (HttpContextSessionHelper.IsInTestMode)
            {
                applicationUserContext = HttpContextSessionHelper.TestHelper.GetFromSession <IUserContext>("applicationUserContext");
                return(applicationUserContext);
            }

            cacheKey = GetApplicationContextCacheKey(localeIsoCode);
            applicationUserContext = (IUserContext)HttpRuntime.Cache.Get(cacheKey);
            if (applicationUserContext == null)
            {
                lock (ThisLock)
                {
                    applicationUserContext = (IUserContext)HttpRuntime.Cache.Get(cacheKey);
                    if (applicationUserContext == null)
                    {
                        CoreData.UserManager.LoginApplicationUser();
                        applicationUserContext = (IUserContext)HttpRuntime.Cache.Get(cacheKey);
                        DyntaxaLogger.WriteException(new Exception(string.Format("GetApplicationContext() didn't find application user. Tried to login. Successfull: {0}", (applicationUserContext != null).ToString())));
                    }
                }
            }
            return(applicationUserContext);
        }
Пример #2
0
        /// <summary>
        /// Reads species fact.
        /// </summary>
        private void InitSpeciesFact()
        {
            Stopwatch sp = new Stopwatch();

            sp.Start();
            try
            {
                ISpeciesFactSearchCriteria speciesFactSearchCriteria = new SpeciesFactSearchCriteria();
                speciesFactSearchCriteria.EnsureNoListsAreNull();
                speciesFactSearchCriteria.IncludeNotValidHosts = true;
                speciesFactSearchCriteria.IncludeNotValidTaxa  = true;
                speciesFactSearchCriteria.Taxa = new TaxonList();
                speciesFactSearchCriteria.Taxa.Add(_taxon);

                var factorIds = new List <Int32> {
                    (int)FactorId.SwedishOccurrence, (int)FactorId.SwedishHistory
                };
                FactorList factors = CoreData.FactorManager.GetFactors(_user, factorIds);
                speciesFactSearchCriteria.Factors = new FactorList();
                foreach (IFactor factor in factors)
                {
                    speciesFactSearchCriteria.Factors.Add(factor);
                }

                SpeciesFactList speciesFacts = CoreData.SpeciesFactManager.GetDyntaxaSpeciesFacts(_user, speciesFactSearchCriteria);
                foreach (SpeciesFact speciesFact in speciesFacts)
                {
                    if (speciesFact.Factor.Id == (int)FactorId.SwedishOccurrence)
                    {
                        _swedishOccourrenceFact = speciesFact;
                    }

                    if (speciesFact.Factor.Id == (int)FactorId.SwedishHistory)
                    {
                        _swedishHistoryFact = speciesFact;
                    }
                }
            }
            catch (Exception ex)
            {
                DyntaxaLogger.WriteMessage("Dyntaxa - InitSpeciesFact: " + ex.Message);
            }

            sp.Stop();
            Debug.WriteLine("Retrieving species fact: {0:N0} milliseconds", sp.ElapsedMilliseconds);
        }