Example #1
0
 private void CheckIfDeafultSiteHasBeenInstalled()
 {
     if (SiteRepository.GetByName("Default") == null)
     {
         _siteInstallationService.InstallDefaultSite();
     }
 }
Example #2
0
        public void Should_return_site_by_name()
        {
            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var site       = repository.GetByName("Name 1");

                Assert.NotNull(site);
            }
        }
Example #3
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)
        {
            // ===== Temporary ===== //
            CheckIfDeafultAppsHaveBeenInstalled();
            CheckIfDeafultSiteHasBeenInstalled();
            CheckIfAdminUserHasBeenCreated();
            // ==================== //

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

            app.UseApplicationInsightsRequestTelemetry();

            app.UseStatusCodePagesWithRedirects("~/error/{0}");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/error/500");
            }

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseIdentity();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

            var site            = SiteRepository.GetByName("Default");
            var activeLanguages = LanguageFacade.GetAllActive(site.Id);

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "area",
                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

                if (site != null)
                {
                    foreach (var page in PageFacade.GetAllForAdminAsync(site.Id).Result)
                    {
                        var defaults    = new RouteValueDictionary();
                        var constraints = new RouteValueDictionary();
                        var tokens      = new RouteValueDictionary();

                        defaults.Add("controller", "Home");
                        defaults.Add("action", "Index");
                        defaults.Add("data", string.Empty);

                        constraints.Add("data", @"[a-zA-Z0-9\-]*");

                        tokens.Add("namespaces", new[] { "Weapsy.Controllers" });
                        tokens.Add(ContextKeys.PageKey, page.Id);
                        //tokens.Add("languageId", default language id);

                        routes.MapRoute(
                            name: page.Name,
                            template: page.Url,
                            defaults: defaults,
                            constraints: constraints,
                            dataTokens: tokens);

                        foreach (var language in activeLanguages)
                        {
                            if (tokens.ContainsKey(ContextKeys.LanguageKey))
                            {
                                tokens.Remove(ContextKeys.LanguageKey);
                            }

                            tokens.Add(ContextKeys.LanguageKey, language.Id);

                            var pageLocalisation = page.PageLocalisations.FirstOrDefault(x => x.LanguageId == language.Id);

                            var url = (pageLocalisation != null && !string.IsNullOrWhiteSpace(pageLocalisation.Url))
                                ? pageLocalisation.Url
                                : page.Url;

                            routes.MapRoute(
                                name: $"{page.Name} - {language.Name}",
                                template: $"{language.Url}/{url}",
                                defaults: defaults,
                                constraints: constraints,
                                dataTokens: tokens);
                        }
                    }
                }

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            var            supportedCultures = new List <CultureInfo>();
            RequestCulture defaultRequestCulture;

            try
            {
                foreach (var language in activeLanguages)
                {
                    supportedCultures.Add(new CultureInfo(language.CultureName));
                }

                defaultRequestCulture = new RequestCulture(supportedCultures[0].Name);
            }
            catch (Exception)
            {
                supportedCultures.Add(new CultureInfo("en"));
                defaultRequestCulture = new RequestCulture("en");
            }

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = defaultRequestCulture,
                SupportedCultures     = supportedCultures,
                SupportedUICultures   = supportedCultures
            });
        }