Ejemplo n.º 1
0
        private InjectionRequest GetInjectionRequest(HttpContext context, InjectionOptions options)
        {
#if NET45
            NameValueCollection form    = context.Request.Form;
            string formConnectionString = form["connectionstring"];
            string sqlCommand           = form["sqlcommand"];
            bool   isQuery = form["querytype"].Equals("isquery");
#elif (NETCOREAPP2_1 || NETCOREAPP3_0)
            IFormCollection form = context.Request.ReadFormAsync().Result;
            string          formConnectionString = form["connectionstring"];
            string          sqlCommand           = form["sqlcommand"];
            bool            isQuery = form["querytype"].ToString().Equals("isquery");
#endif

            //Choose the connection string source (options overrides form, if available)
            string connectionString = string.IsNullOrEmpty(options.ConnectionString) ? formConnectionString : options.ConnectionString;

            //Create the injection
            InjectionRequest injection = new InjectionRequest {
                IsQuery          = isQuery,
                ConnectionString = connectionString,
                SqlCommand       = sqlCommand
            };
            Trace.WriteLine($"Injection is query: '{injection.IsQuery}', with command: '{injection.SqlCommand}'");
            return(injection);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Accepts the options or throws and Exception if not valid.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <exception cref="System.ArgumentNullException">
        ///     options - The Syringe options are mandatory. or options - The Syringe FromIp option is mandatory.
        /// </exception>
        private void AcceptOptions(InjectionOptions options)
        {
            Trace.WriteLine($"Accepting the following options: source IP: {options.FromIp}, URL slug: {options.UrlSlug}, has connection string: {options.HasConnectionString}");
            _options = options ?? throw new ArgumentNullException(nameof(options), "The Syringe options are mandatory.");

            if (options.FromIp == null)
            {
                throw new ArgumentNullException(nameof(options), "The Syringe FromIp option is mandatory.");
            }
        }
Ejemplo n.º 3
0
 public Syringe(InjectionOptions options)
 {
     AcceptOptions(options);
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Syringe" /> class.
 /// </summary>
 /// <param name="next">The next.</param>
 /// <param name="options">The options.</param>
 public Syringe(RequestDelegate next, InjectionOptions options)
 {
     _next = next;
     AcceptOptions(options);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Uses the SqlSyringe Middleware with the given options.
 /// </summary>
 /// <param name="app">The app to use SqlSyringe on.</param>
 /// <param name="options">The options to use.</param>
 /// <returns>The app with SqlSyringe applied.</returns>
 public static IApplicationBuilder UseSqlSyringe(this IApplicationBuilder app, InjectionOptions options)
 {
     app.UseMiddleware <Syringe>(options);
     return(app);
 }