예제 #1
0
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            AjaxResult <string> result = new AjaxResult <string>();

            try
            {
                System.Collections.Generic.List <System.Collections.Generic.Dictionary <string, object> > ls = null;
                ls = CoreCMS.Rest.Insert.Json2List(context.Request.Body);

                CoreDb.WriteDAL writeDAL = (CoreDb.WriteDAL)context.RequestServices.GetService(
                    typeof(CoreDb.WriteDAL)
                    );

                string sql = AnyList.GetContentOfEmbeddedFile(AnyList.GetParam(context, "sql"));

                using (System.Data.IDbCommand cmd = writeDAL.CreateCommand(sql))
                {
                    writeDAL.InsertList <System.Collections.Generic.Dictionary <string, object> >(cmd, ls,
                                                                                                  delegate(System.Collections.Generic.Dictionary <string, object> item)
                    {
                        foreach (System.Collections.Generic.KeyValuePair <string, object> kvp in item)
                        {
                            writeDAL.AddParameter(cmd, kvp.Key, kvp.Value);
                        }     // Next k
                    }
                                                                                                  );
                } // End Using cmd


                ls.Clear();
                ls = null;
            } // End Try
            catch (System.Exception ex)
            {
                result.Error = ex;
            } // End Catch

            context.Response.StatusCode  = StatusCodes.Status200OK;
            context.Response.ContentType = "application/json; charset=utf-8";

            result.WriteAsJson(context);
        } // End IHttpHandler.ProcessRequest
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(AuthTest.JwtAuthentication.SetCookieSchemes)
            .AddCookie(AuthTest.JwtAuthentication.SetupCookie)
            // .AddJwtBearer(AuthTest.JwtAuthentication.SetupBearer)
            ;

            /*
             * services.AddAntiforgery(
             *  delegate (Microsoft.AspNetCore.Antiforgery.AntiforgeryOptions options)
             *  {
             *       // https://damienbod.com/2017/05/09/anti-forgery-validation-with-asp-net-core-mvc-and-angular/
             *       options.HeaderName = "X-XSRF-TOKEN";
             *       //options.CookieDomain = "localhost";
             *       options.Cookie.Name = "XSRF";
             *  }
             * );
             */
            // services.AddMvc();

            // https://geeks.ms/clanderas/2016/10/18/asp-net-core-node-services-to-execute-your-nodejs-scripts/
            // https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/
            services.AddNodeServices(options => {
                // options.DebuggingPort
            });

            services.AddRouting(delegate(Microsoft.AspNetCore.Routing.RouteOptions options)
                                { });


            services.AddMvc(

                /*
                 * delegate (Microsoft.AspNetCore.Mvc.MvcOptions config)
                 * {
                 *  Microsoft.AspNetCore.Authorization.AuthorizationPolicy policy =
                 *      new Microsoft.AspNetCore.Authorization.AuthorizationPolicyBuilder()
                 *                   .RequireAuthenticatedUser()
                 *                   // .AddRequirements( new NoBannedIPsRequirement(new HashSet<string>() { "127.0.0.1", "0.0.0.1" } ))
                 *                   .Build();
                 *
                 *  config.Filters.Add(new Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter(policy));
                 * }
                 */
                )
            .AddJsonOptions(options =>
            {
#if DEBUG
                options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
#else
                options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.None;
#endif
            });


            services.Configure <Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new CoreCMS.Routing.SubdomainViewLocationExpander());
            });



            Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions
            .Configure <ConfigData.SmtpConfig>(services, Configuration.GetSection("Smtp"));


            /*
             * Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions
             *  .Configure<Dictionary<string, ConfigData.cConnectionString>>(services
             *  , Configuration.GetSection("ConnectionStrings")
             * );
             *
             * Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions
             *  .Configure<ConfigData.cConnectionStrings>(services
             *      , Configuration.GetSection("DataBase"));
             *
             * string foo = Configuration.GetValue<string>("data:userID");
             * System.Console.WriteLine(foo);
             * // https://msdn.microsoft.com/en-us/magazine/mt632279.aspx
             */

            ConfigData.Databases dbs = Configuration.Get <ConfigData.Databases>();

            // System.Console.WriteLine(cs);
            // services.AddSingleton<ConfigData.Database>(cs);

            DbConfig dbConfig = null;

            if (dbs.ConnectionStrings.ContainsKey(System.Environment.MachineName))
            {
                dbConfig = dbs.ConnectionStrings[System.Environment.MachineName];
            }


            if (dbConfig == null)
            {
                if (dbs.ConnectionStrings.ContainsKey("server"))
                {
                    dbConfig = dbs.ConnectionStrings["server"];
                }
            }


            if (dbConfig == null)
            {
                throw new System.IO.InvalidDataException("Connection string not configured...");
            }


            CoreDb.DalConfig dalConfig =
                new CoreDb.DalConfig(dbConfig.ProviderName, dbConfig.ConnectionString);

            CoreDb.ReadDAL  readData  = new CoreDb.ReadDAL(dalConfig);
            CoreDb.WriteDAL writeData = new CoreDb.WriteDAL(dalConfig);

            services.AddSingleton <CoreDb.ReadDAL>(readData);
            services.AddSingleton <CoreDb.WriteDAL>(writeData);
        }