예제 #1
0
        private void GetView(MyBlogCore.SqlFactory factory, string viewPath)
        {
            string query = @"
SELECT Content, LastModified FROM Views WHERE Location = @Path; 
UPDATE Views SET LastRequested = GetUtcDate() WHERE Location = @Path; 
";

            try
            {
                using (System.Data.Common.DbConnection cnn = factory.Connection)
                {
                    using (System.Data.Common.DbCommand cmd = cnn.CreateCommand())
                    {
                        cmd.CommandText = query;
                        cmd.AddWithValue("@Path", viewPath);

                        if (cnn.State != System.Data.ConnectionState.Open)
                        {
                            cnn.Open();
                        }

                        using (System.Data.Common.DbDataReader reader = cmd.ExecuteReader())
                        {
                            _exists = reader.HasRows;
                            if (_exists)
                            {
                                reader.Read();
                                _viewContent  = System.Text.Encoding.UTF8.GetBytes(reader["Content"].ToString());
                                _lastModified = System.Convert.ToDateTime(reader["LastModified"]);
                            } // End if (_exists)
                        }     // End Using reader
                    }         // End Using cmd

                    if (cnn.State != System.Data.ConnectionState.Closed)
                    {
                        cnn.Close();
                    }
                } // End Using cnn
            }
            catch (System.Exception ex)
            {
                // if something went wrong, Exists will be false
            }
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();

            services.AddSingleton <SearchValueTransformer>();

            MyBlogCore.SqlFactory fac = CreateAppropriateFactory();
            services.AddSingleton <MyBlogCore.SqlFactory>(fac);


            // This method configures the MVC services for the commonly used features with controllers with views.
            // This combines the effects of Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(Microsoft.Extensions.DependencyInjection.IServiceCollection),
            // Microsoft.Extensions.DependencyInjection.MvcApiExplorerMvcCoreBuilderExtensions.AddApiExplorer(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
            // Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddAuthorization(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
            // Microsoft.Extensions.DependencyInjection.MvcCorsMvcCoreBuilderExtensions.AddCors(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
            // Microsoft.Extensions.DependencyInjection.MvcDataAnnotationsMvcCoreBuilderExtensions.AddDataAnnotations(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
            // Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddFormatterMappings(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
            // Microsoft.Extensions.DependencyInjection.TagHelperServicesExtensions.AddCacheTagHelper(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
            // Microsoft.Extensions.DependencyInjection.MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
            // and Microsoft.Extensions.DependencyInjection.MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder).
            // To add services for pages call Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddRazorPages(Microsoft.Extensions.DependencyInjection.IServiceCollection)
            // services.AddControllersWithViews();
            /// string cs = Configuration.GetConnectionString("DefaultConnection");



            services.AddControllersWithViews(
                delegate(Microsoft.AspNetCore.Mvc.MvcOptions opts)
            {
                // opts.default
            }
                ).AddRazorRuntimeCompilation(
                delegate(Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions options)
            {
                // options.FileProviders.Clear();
                options.FileProviders.Add(new DatabaseFileProvider(fac));
                // https://github.com/aspnet/FileSystem/blob/master/src/FS.Embedded/EmbeddedFileProvider.cs
                // options.FileProviders.Add( new Microsoft.Extensions.FileProviders.EmbeddedFileProvider(typeof(Startup).Assembly) );
            }
                )
            ;



            // https://www.mikesdotnetting.com/article/301/loading-asp-net-core-mvc-views-from-a-database-or-other-location
            // https://stackoverflow.com/questions/38247080/using-razor-outside-of-mvc-in-net-core
            // https://github.com/dotnet/AspNetCore.Docs/issues/14593
            //services.Configure<Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions>(
            //    delegate(Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions options)
            //    {
            //        // Requires adding nuget Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
            //        // options.FileProviders.Clear();
            //        options.FileProviders.Add(new DatabaseFileProvider("cs"));
            //    }
            //);



            services.AddOptions <Microsoft.AspNetCore.Builder.StaticFileOptions>()
            .Configure <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Hosting.IWebHostEnvironment>(
                delegate(Microsoft.AspNetCore.Builder.StaticFileOptions options, Microsoft.AspNetCore.Http.IHttpContextAccessor httpContext, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env)
            {
                options.FileProvider = new DomainSpecificFileProvider(httpContext, env);
            }
                );
        } // End Sub ConfigureServices
예제 #3
0
 public DatabaseChangeToken(MyBlogCore.SqlFactory factory, string viewPath)
 {
     this.m_factory = factory;
     _viewPath      = viewPath;
 }
예제 #4
0
 public DatabaseFileProvider(MyBlogCore.SqlFactory factory)
 {
     this.m_factory = factory;
 }
예제 #5
0
 public DatabaseFileInfo(MyBlogCore.SqlFactory factory, string viewPath)
 {
     _viewPath = viewPath;
     GetView(factory, viewPath);
 }