Ejemplo n.º 1
0
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            try
            {
                System.Collections.Generic.Dictionary <string, object> pars = SqlServiceHelper.GetParameters(context);

                if (!pars.ContainsKey("sql"))
                {
                    throw new System.Exception("Parameter sql not provided....");
                }


                string sql = System.Convert.ToString(pars["sql"]);
                sql = System.IO.Path.Combine("SQL", sql);
                sql = System.IO.File.ReadAllText(sql, System.Text.Encoding.UTF8);


                RenderType_t format = RenderType_t.Array;

                if (pars.ContainsKey("format"))
                {
                    string form       = System.Convert.ToString(pars["format"]);
                    int    renderType = 1;
                    int.TryParse(form, out renderType);

                    format = (RenderType_t)renderType;
                } // End if (pars.ContainsKey("format"))

                SqlServiceJsonHelper.AnyDataReaderToAnyJson(sql, new MS_SQL_Service(), pars, context, format);

                // throw new Exception("SQL error");
                // await context.Response.WriteAsync("Howdy");
                // context.Response.StatusCode = 500;
            } // End Try
            catch (System.Exception ex)
            {
                // header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
                // header("HTTP/1.0 500 Internal Server Error");
                // header('HTTP/1.1 200 OK');

                // context.Response.Headers["HTTP/1.0 500 Internal Server Error"] = "";
                context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                context.Response.Headers["X-Error-Message"] = "Incorrect username or password";

                context.Response.ContentType = "text/plain";

                context.Response.Write(ex.Message);
                context.Response.Write(System.Environment.NewLine);
                context.Response.Write(System.Environment.NewLine);
                context.Response.Write(ex.StackTrace);
                System.Console.WriteLine();
            } // End Catch
        }
Ejemplo n.º 2
0
        public async System.Threading.Tasks.Task Invoke(Microsoft.AspNetCore.Http.HttpContext context)
        {
            // Do some request logic here.
            // await this._next.Invoke(context).ConfigureAwait(false);


            // Do some response logic here.
            // context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
            // throw new Exception("YaY");
            string sql = null;

            System.Collections.Generic.Dictionary <string, object> pars = null;

            try
            {
                pars               = SqlServiceHelper.GetParameters(context);
                pars["BE_Hash"]    = 12435;
                pars["__stichtag"] = System.DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);

                if (!pars.ContainsKey("sql"))
                {
                    throw new System.Exception("Parameter sql not provided....");
                }

                sql = System.Convert.ToString(pars["sql"]);
                sql = System.IO.Path.Combine("SQL", sql);
                sql = System.IO.File.ReadAllText(sql, System.Text.Encoding.UTF8);


                RenderType_t format = RenderType_t.Array;

                if (pars.ContainsKey("format"))
                {
                    string form       = System.Convert.ToString(pars["format"]);
                    int    renderType = 1;
                    int.TryParse(form, out renderType);

                    format = (RenderType_t)renderType;
                } // End if (pars.ContainsKey("format"))


                using (System.Data.Common.DbConnection cnn = this.m_service.Connection)
                {
                    System.Exception hasErrors = await cnn.AsJSON(context.Response.Body, sql, (Dapper.RenderType_t) format, pars);

                    // TOOD: Log if not NULL
                }


                // await SqlServiceJsonHelper.AnyDataReaderToJson(sql, pars, context, format);

                // throw new Exception("SQL error");
                // await context.Response.WriteAsync("Howdy");
                // context.Response.StatusCode = 500;
            } // End Try
            catch (System.Exception ex)
            {
                // header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
                // header("HTTP/1.0 500 Internal Server Error");
                // header('HTTP/1.1 200 OK');

                // context.Response.Headers["HTTP/1.0 500 Internal Server Error"] = "";
                context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                context.Response.Headers["X-Error-Message"] = "Incorrect username or password";

                context.Response.ContentType = "text/plain";

                SqlException se = new SqlException(ex.Message, sql, pars, context, ex);
                se.ToJSON(context.Response.Body);

                //await context.Response.WriteAsync(ex.Message);
                //await context.Response.WriteAsync(System.Environment.NewLine);
                //await context.Response.WriteAsync(System.Environment.NewLine);
                //await context.Response.WriteAsync(ex.StackTrace);
                //await context.Response.WriteAsync(System.Environment.NewLine);
                //await context.Response.WriteAsync(System.Environment.NewLine);
                //await context.Response.WriteAsync(sql);
                //await context.Response.WriteAsync(System.Environment.NewLine);
                //await context.Response.WriteAsync(System.Environment.NewLine);
                //await context.Response.WriteAsync(System.Convert.ToString(pars));
                System.Console.WriteLine();
            } // End Catch
        }     // End Async Invoke