Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApi api)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Initialize Piranha
            App.Init(api);

            // Build content types
            new ContentTypeBuilder(api)
            .AddAssembly(typeof(Startup).Assembly)
            .Build()
            .DeleteOrphans();

            // Configure Tiny MCE
            EditorConfig.FromFile("editorconfig.json");

            // Middleware setup
            app.UsePiranha(options => {
                options.UseManager();
                options.UseTinyMCE();
                options.UseIdentity();
            });

            // Seed test data
            Seed.RunAsync(api).GetAwaiter().GetResult();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApi api)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            App.Init(api);

            // Configure cache level
            App.CacheLevel = Piranha.Cache.CacheLevel.Full;

            // Custom components
            App.Blocks.Register <Models.Blocks.ColumnBlock>();

            // Build content types
            var pageTypeBuilder = new Piranha.AttributeBuilder.PageTypeBuilder(api)
                                  .AddType(typeof(Models.BlogArchive))
                                  .AddType(typeof(Models.StandardPage))
                                  .AddType(typeof(Models.TeaserPage))
                                  .Build()
                                  .DeleteOrphans();
            var postTypeBuilder = new Piranha.AttributeBuilder.PostTypeBuilder(api)
                                  .AddType(typeof(Models.BlogPost))
                                  .Build()
                                  .DeleteOrphans();
            var siteTypeBuilder = new Piranha.AttributeBuilder.SiteTypeBuilder(api)
                                  .AddType(typeof(Models.StandardSite))
                                  .Build()
                                  .DeleteOrphans();

            /**
             *
             * Test another culture in the UI
             *
             * var cultureInfo = new System.Globalization.CultureInfo("en-US");
             * System.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
             * System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
             */

            // Register middleware
            app.UseStaticFiles();
            app.UseAuthentication();
            app.UsePiranha();
            app.UsePiranhaManager();
            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "areaRoute",
                                template: "{area:exists}/{controller}/{action}/{id?}",
                                defaults: new { controller = "Home", action = "Index" });

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

            Seed.RunAsync(api).GetAwaiter().GetResult();
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApi api)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            App.Init(api);

            // Configure cache level
            App.CacheLevel = Piranha.Cache.CacheLevel.Full;

            // Build content types
            var pageTypeBuilder = new Piranha.AttributeBuilder.PageTypeBuilder(api)
                                  .AddType(typeof(Models.BlogArchive))
                                  .AddType(typeof(Models.StandardPage))
                                  .AddType(typeof(Models.TeaserPage))
                                  .Build()
                                  .DeleteOrphans();
            var postTypeBuilder = new Piranha.AttributeBuilder.PostTypeBuilder(api)
                                  .AddType(typeof(Models.BlogPost))
                                  .Build()
                                  .DeleteOrphans();
            var siteTypeBuilder = new Piranha.AttributeBuilder.SiteTypeBuilder(api)
                                  .AddType(typeof(Models.StandardSite))
                                  .Build()
                                  .DeleteOrphans();

            /**
             *
             * Test another culture in the UI
             *
             * var cultureInfo = new System.Globalization.CultureInfo("en-US");
             * System.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
             * System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
             */

            // Register middleware
            app.UseStaticFiles();
            app.UsePiranha();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UsePiranhaIdentity();
            app.UsePiranhaManager();
            app.UsePiranhaTinyMCE();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapPiranhaManager();
            });

            Seed.RunAsync(api).GetAwaiter().GetResult();
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApi api)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();

                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(options =>
                {
                    options.SwaggerEndpoint("/swagger/v1/swagger.json", "PiranhaCMS API V1");
                });
            }

            App.Init(api);

            // Configure cache level
            App.CacheLevel = Piranha.Cache.CacheLevel.Full;

            // Build content types
            new ContentTypeBuilder(api)
            .AddAssembly(typeof(Startup).Assembly)
            .Build()
            .DeleteOrphans();

            // Configure editor
            Piranha.Manager.Editor.EditorConfig.FromFile("editorconfig.json");

            /**
             *
             * Test another culture in the UI
             *
             * var cultureInfo = new System.Globalization.CultureInfo("en-US");
             * System.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
             * System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
             */

            app.UsePiranha(options =>
            {
                options.UseManager();
                options.UseTinyMCE();
                options.UseIdentity();
            });

            Seed.RunAsync(api).GetAwaiter().GetResult();
        }
Exemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApi api)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            App.Init(api);

            // Configure cache level
            App.CacheLevel = Piranha.Cache.CacheLevel.Full;

            // Build content types
            new ContentTypeBuilder(api)
            .AddAssembly(typeof(Startup).Assembly)
            .Build()
            .DeleteOrphans();

            // Configure editor
            Piranha.Manager.Editor.EditorConfig.FromFile("editorconfig.json");

            /**
             *
             * Test another culture in the UI
             *
             * var cultureInfo = new System.Globalization.CultureInfo("en-US");
             * System.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
             * System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
             */

            app.UsePiranha(options =>
            {
                options.UseManager();
                options.UseTinyMCE();
                options.UseIdentity();
            });

            Seed.RunAsync(api).GetAwaiter().GetResult();
        }
Exemplo n.º 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var defaultServices = services.Clone();

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddMultiTenancy <Tenant>((builder) =>
            {
                builder.IdentifyTenantsWithRequestAuthorityUri()
                .InitialiseTenant <TenantShellFactory>()
                .AddAspNetCore()
                .ConfigureTenantContainers((containerOptions) =>
                {
                    var x = 0;
                    containerOptions
                    .SetDefaultServices(defaultServices)
                    .Autofac((tenant, services) =>
                    {
                        if (tenant != null)
                        {
                            services.AddControllersWithViews();
                            services.AddRazorPages()
                            .AddPiranhaManagerOptions();

                            services.AddPiranha();
                            services.AddPiranhaApplication();
                            services.AddPiranhaFileStorage();
                            services.AddPiranhaImageSharp();
                            services.AddPiranhaManager();
                            services.AddPiranhaTinyMCE();
                            // services.AddPiranhaApi();

                            services.AddPiranhaEF(options =>
                                                  options.UseSqlite(tenant.ConnectionString));
                            //services.AddPiranhaIdentityWithSeed<IdentitySQLiteDb>(options =>
                            //    options.UseSqlite(tenant.ConnectionString));

                            services.AddMemoryCache();
                            services.AddPiranhaMemoryCache();
                            //tenantServices.AddRazorPages((o) =>
                            //{
                            //    o.RootDirectory = $"/Pages/{tenant.Name}";
                            //}).AddNewtonsoftJson();
                        }
                    });
                })
                .ConfigureTenantMiddleware((tenantOptions) =>
                {
                    var x = tenantOptions;

                    tenantOptions.AspNetCorePipeline((context, app) =>
                    {
                        app.Use(async(c, next) =>
                        {
                            Console.WriteLine("Entering tenant pipeline: " + context.Tenant?.Name);
                            await next.Invoke();
                        });

                        app.UseRouting();

                        if (context.Tenant != null)
                        {
                            var api = app.ApplicationServices.GetService <IApi>();

                            var type = typeof(App);
                            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);

                            App.Init(api);

                            // Configure cache level
                            App.CacheLevel = Piranha.Cache.CacheLevel.Full;

                            var builder = new ContentTypeBuilder(api)
                                          .AddAssembly(typeof(Startup).Assembly)
                                          .Build()
                                          .DeleteOrphans();

                            //// Build content types
                            //var pageTypeBuilder = new Piranha.AttributeBuilder.PageTypeBuilder(api)
                            //    .AddType(typeof(Models.BlogArchive))
                            //    .AddType(typeof(Models.StandardPage))
                            //    .AddType(typeof(Models.TeaserPage))
                            //    .Build()
                            //    .DeleteOrphans();
                            //var postTypeBuilder = new Piranha.AttributeBuilder.PostTypeBuilder(api)
                            //    .AddType(typeof(Models.BlogPost))
                            //    .Build()
                            //    .DeleteOrphans();
                            //var siteTypeBuilder = new Piranha.AttributeBuilder.SiteTypeBuilder(api)
                            //    .AddType(typeof(Models.StandardSite))
                            //    .Build()
                            //    .DeleteOrphans();

                            // Register middleware
                            app.UseStaticFiles();
                            app.UsePiranha();
                            app.UseRouting();
                            app.UseAuthentication();
                            app.UseAuthorization();
                            app.UsePiranhaIdentity();
                            app.UsePiranhaManager();
                            app.UsePiranhaTinyMCE();
                            app.UseEndpoints(endpoints =>
                            {
                                endpoints.MapControllerRoute(
                                    name: "default",
                                    pattern: "{controller=Home}/{action=Index}/{id?}");

                                endpoints.MapPiranhaManager();
                            });

                            Seed.RunAsync(api, context.Tenant).GetAwaiter().GetResult();

                            //tenantAppBuilder.UseAuthorization();

                            //tenantAppBuilder.Use(async (c, next) =>
                            //{
                            //     // Demonstrates per tenant files.
                            //     // /foo.txt exists for one tenant but not another.
                            //     var webHostEnvironment = c.RequestServices.GetRequiredService<IWebHostEnvironment>();
                            //    var contentFileProvider = webHostEnvironment.ContentRootFileProvider;
                            //    var webFileProvider = webHostEnvironment.WebRootFileProvider;

                            //    var fooTextFile = webFileProvider.GetFileInfo("/foo.txt");

                            //    Console.WriteLine($"/Foo.txt file exists? {fooTextFile.Exists}");
                            //    await next.Invoke();
                            //});

                            //tenantAppBuilder.UseEndpoints(endpoints =>
                            //{
                            //    endpoints.MapRazorPages();
                            //});
                        }
                    });
                })
                ;
            });
        }
Exemplo n.º 7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApi api)
        {
            app.UseResponseCompression();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();

                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(options =>
                {
                    options.SwaggerEndpoint("/swagger/v1/swagger.json", "PiranhaCMS API V1");
                });
            }

            App.Init(api);

            // Configure cache level
            App.CacheLevel = Piranha.Cache.CacheLevel.Full;


            // Build content types
            var pageTypeBuilder = new Piranha.AttributeBuilder.PageTypeBuilder(api)
                                  .AddType(typeof(Models.TeaserPage))
                                  .AddType(typeof(Models.RelationPage))
                                  .AddType(typeof(Models.ContactPage))
                                  .AddType(typeof(Models.IntroPage))
                                  .AddType(typeof(Models.ServicesPage))
                                  .AddType(typeof(Models.InvestbankPage))
                                  .AddType(typeof(Models.AgencyPage))
                                  .AddType(typeof(Models.NewsPage))
                                  .AddType(typeof(Models.RequestOpenAccPage))
                                  .AddType(typeof(Models.RecruitPage))
                                  .AddType(typeof(Models.LoginPage))
                                  .AddType(typeof(Models.RegisterPage))
                                  .AddType(typeof(Models.SearchPage))
                                  .AddType(typeof(Models.ForgotPassword))
                                  .AddType(typeof(Models.AnalyzePage))
                                  .AddType(typeof(Models.OtherServicesPage))
                                  .Build()
                                  .DeleteOrphans();
            var postTypeBuilder = new Piranha.AttributeBuilder.PostTypeBuilder(api)
                                  .AddType(typeof(Models.NewsPost))
                                  .Build()
                                  .DeleteOrphans();
            var siteTypeBuilder = new Piranha.AttributeBuilder.SiteTypeBuilder(api)
                                  .AddType(typeof(Models.StandardSite))
                                  .Build()
                                  .DeleteOrphans();

            /**
             *
             * Test another culture in the UI
             *
             * var cultureInfo = new System.Globalization.CultureInfo("en-US");
             * System.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
             * System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
             */

            // Register middleware
            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    var headers          = ctx.Context.Response.GetTypedHeaders();
                    headers.CacheControl = new CacheControlHeaderValue
                    {
                        Public = true,
                        MaxAge = TimeSpan.FromDays(3)
                    };
                }
            });
            app.UsePiranha();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UsePiranhaIdentity();
            app.UsePiranhaManager();
            app.UsePiranhaSummernote();
            app.UsePiranhaTinyMCE();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapPiranhaManager();
            });

            app.UseRewriter(new RewriteOptions()
                            .AddIISUrlRewrite(env.ContentRootFileProvider, "RedirectToWwwRule.xml")
                            .AddRedirectToHttps()
                            );
            Seed.RunAsync(api).GetAwaiter().GetResult();
        }