Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            Serenity.Extensibility.ExtensibilityHelper.SelfAssemblies = new System.Reflection.Assembly[]
            {
                typeof(LocalTextRegistry).GetAssembly(),
                typeof(SqlConnections).GetAssembly(),
                typeof(Row).GetAssembly(),
                typeof(SaveRequestHandler <>).GetAssembly(),
                typeof(WebSecurityHelper).GetAssembly(),
                typeof(Startup).GetAssembly()
            };

            SqlSettings.AutoQuotedIdentifiers = true;
            RegisterDataProviders();

            Dependency.SetResolver(new AppServices.DependencyResolver(app.ApplicationServices));

            var textRegistry = app.ApplicationServices.GetRequiredService <ILocalTextRegistry>();

            textRegistry.AddNestedTexts();
            textRegistry.AddNestedPermissions();
            textRegistry.AddEnumTexts();
            textRegistry.AddRowTexts();
            var contentRoot = env.ContentRootPath;

            textRegistry.AddJsonTexts(System.IO.Path.Combine(env.WebRootPath, "Scripts/serenity/texts".Replace('/', Path.DirectorySeparatorChar)));
            textRegistry.AddJsonTexts(System.IO.Path.Combine(env.WebRootPath, "Scripts/site/texts".Replace('/', Path.DirectorySeparatorChar)));
            textRegistry.AddJsonTexts(System.IO.Path.Combine(env.ContentRootPath, "App_Data/texts".Replace('/', Path.DirectorySeparatorChar)));

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            var reqLocOpt = new RequestLocalizationOptions();

            reqLocOpt.SupportedUICultures = UserCultureProvider.SupportedCultures;
            reqLocOpt.SupportedCultures   = UserCultureProvider.SupportedCultures;
            reqLocOpt.RequestCultureProviders.Clear();
            reqLocOpt.RequestCultureProviders.Add(new UserCultureProvider());
            app.UseRequestLocalization(reqLocOpt);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme  = "CookieAuthenticationScheme",
                CookieName            = ".AspNetAuth",
                LoginPath             = new PathString("/Account/Login/"),
                AccessDeniedPath      = new PathString("/Account/AccessDenied"),
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true
            });

            app.UseDynamicScripts();
            app.UseMvc(routes =>
            {
            });

            DataMigrations.Initialize();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes the value to cache with specified key and
 /// expiration date.
 /// </summary>
 /// <typeparam name="TValue">Value type.</typeparam>
 /// <param name="key">Key</param>
 /// <param name="value">Value</param>
 /// <param name="expiresAt">The time the cached item will be expired on.</param>
 public static void Set <TValue>(string key, TValue value, TimeSpan expiration)
 {
     Dependency.Resolve <IDistributedCache>().Set(key, value, expiration);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Reads the value with given key. If value didn't exist in cache,
 /// return the default(T) value.
 /// </summary>
 /// <typeparam name="TValue">Value type</typeparam>
 /// <param name="key">Key</param>
 /// <remarks>It may raise an exception if the value is not of type TValue.</remarks>
 public static TValue Get <TValue>(string key)
 {
     return(Dependency.Resolve <IDistributedCache>().Get <TValue>(key));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Writes the value to cache with specified key.
 /// </summary>
 /// <typeparam name="TValue">Value type.</typeparam>
 /// <param name="key">Key</param>
 /// <param name="value">Value</param>
 public static void Set <TValue>(string key, TValue value)
 {
     Dependency.Resolve <IDistributedCache>().Set(key, value);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Increments value with specified key and returns the new value.
 /// If value doesn't exist, its new value will be 1.
 /// </summary>
 /// <param name="key">Key.</param>
 /// <param name="amount">Increase amount.</param>
 /// <returns>Increased amount, or 1 if it didn't exist before</returns>
 public static long Increment(string key, int amount = 1)
 {
     return(Dependency.Resolve <IDistributedCache>().Increment(key, amount));
 }