コード例 #1
0
        public static bool SetCurrentLanguage(Language language)
        {
            bool wasSet = ContextHelper.Set(SelectedLanguageKey, language, ContextType.Session);

            if (!wasSet)
            {
                ContextHelper.Set(SelectedLanguageKey, language, ContextType.RequestContext);
            }

            return(wasSet);
        }
コード例 #2
0
        public static Entities GetDataModel(bool forceNew = false, bool generateProxies = true, ConnectionStringSettings connectionStringSettings = null)
        {
            Entities context;

            var cachedContext = (Entities)ContextHelper.Get(DataModelKey, dataContextStorageContext);

            if ((cachedContext == null) || (forceNew))
            {
                if (connectionStringSettings == null)
                {
                    connectionStringSettings = FrameworkBaseMedia.ConnectionSettings;
                }

                context = new Entities(connectionStringSettings.ConnectionString);

                if (!CanConnectToDBUsingEntities(context))
                {
                    return(null);
                }

                if (generateProxies)
                {
                    context.Configuration.LazyLoadingEnabled   = true;
                    context.Configuration.ProxyCreationEnabled = true;
                }
                else
                {
                    context.Configuration.LazyLoadingEnabled   = false;
                    context.Configuration.ProxyCreationEnabled = false;
                }

                if (!forceNew)
                {
                    if (FrameworkBaseMedia.ConnectionSettings.ConnectionString.Contains(context.Database.Connection.ConnectionString))
                    {
                        ContextHelper.Set(DataModelKey, context, dataContextStorageContext);
                    }
                }

                return(context);
            }

            if (cachedContext.Database.Connection.State == ConnectionState.Broken)
            {
                cachedContext.Database.Connection.Close();
                cachedContext.Database.Connection.Open();
            }

            return(cachedContext);
        }
コード例 #3
0
        public static Language GetCurrentLanguage()
        {
            Language language = (Language)ContextHelper.Get(SelectedLanguageKey, ContextType.Session);

            if (language == null)
            {
                language = (Language)ContextHelper.Get(SelectedLanguageKey, ContextType.RequestContext);

                if (language == null)
                {
                    language = LanguagesMapper.GetDefaultLanguage();
                    ContextHelper.Set(SelectedLanguageKey, language, ContextType.RequestContext);
                }
            }

            if ((language != null) && (Thread.CurrentThread.CurrentCulture.Name != language.CultureCode))
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(language.CultureCode);
            }

            return(language);
        }