Example #1
0
        /// <summary>
        /// Adds optional Responsive File Manager services and configuration callback.
        /// </summary>
        public static IServiceCollection AddResponsiveFileManager(this IServiceCollection services, Action <ResponsiveFileManagerOptions> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.Configure(configure);

            services.AddPhp(options =>
            {
                options.RequestStart += (Context ctx) =>
                {
                    // construct the options
                    var options = new ResponsiveFileManagerOptions();
                    ctx.GetService <IConfiguration>().GetSection("ResponsiveFileManagerOptions").Bind(options);
                    ctx.GetService <IConfigureOptions <ResponsiveFileManagerOptions> >()?.Configure(options);

                    // pass the options object to PHP globals
                    ctx.Globals["rfm_options"] = PhpValue.FromClass(options);
                };
            });

            //
            return(services);
        }
Example #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)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/error");
            }

            app.UseSession();

            var rfmOptions = new ResponsiveFileManagerOptions();

            Configuration.GetSection("ResponsiveFileManagerOptions").Bind(rfmOptions);

            string root = Path.Combine(new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName, "wwwroot");

            app.UsePhp(new PhpRequestOptions(scriptAssemblyName: "ResponsiveFileManager")
            {
                //RootPath = Path.GetDirectoryName(Directory.GetCurrentDirectory()) + "\\Website",
                BeforeRequest = (Context ctx) =>
                {
                    // Since the config.php file is compiled, we cannot modify it once deployed... everything is hard coded there.
                    //  TODO: Place these values in appsettings.json and pass them in here to override the ones from config.php

                    ctx.Globals["appsettings"] = (PhpValue) new PhpArray()
                    {
                        { "upload_dir", rfmOptions.UploadDirectory },
                        { "current_path", rfmOptions.CurrentPath },
                        { "thumbs_base_path", rfmOptions.ThumbsBasePath }
                    };
                }
            });

            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(root)
            });

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        /// <summary>
        /// Installs ResponsiveFileManager middleware.
        /// </summary>
        /// <param name="app">The application builder.</param>
        public static IApplicationBuilder UseResponsiveFileManager(this IApplicationBuilder app)
        {
            const string filemanagerPath = "/filemanager";

            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath  = filemanagerPath,
                FileProvider = new PhysicalFileProvider(Path.GetFullPath(Path.Combine(Assembly.GetEntryAssembly().Location, ".." + filemanagerPath))),
            });

            app.UsePhp(filemanagerPath, (Context ctx) =>
            {
                // construct the options
                var options = new ResponsiveFileManagerOptions();
                ctx.GetService <IConfiguration>().GetSection("ResponsiveFileManagerOptions").Bind(options);
                ctx.GetService <IConfigureOptions <ResponsiveFileManagerOptions> >()?.Configure(options);

                // pass the options object to PHP globals
                ctx.Globals["rfm_options"] = PhpValue.FromClass(options);
            });

            return(app);
        }