예제 #1
0
        /// <summary>
        /// Handles the resulted context.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public HttpResult Handle(MessagingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            HttpStatusCode statusCode   = DetermineStatusCode(context.Exception);
            const string   errorMessage = "something went wrong while processing the request";

            Logger.Error($"Respond with {(int) statusCode} {statusCode} {errorMessage}");
            return(HttpResult.FromBytes(
                       statusCode,
                       Encoding.UTF8.GetBytes(errorMessage),
                       "text/plain"));
        }
예제 #2
0
        /// <summary>
        /// Handle the incoming request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public HttpResult Handle(HttpListenerRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            string file = request.Url.ToString().Replace(request.UrlReferrer.ToString(), "./");

            if (File.Exists(file) == false)
            {
                return(HttpResult.Empty(HttpStatusCode.NotFound));
            }

            return(HttpResult.FromBytes(HttpStatusCode.OK, File.ReadAllBytes(file), "image/jpeg"));
        }
예제 #3
0
        /// <summary>
        /// Handle the incoming request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public HttpResult Handle(HttpListenerRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            string logoLocation = request.RawUrl.TrimEnd('/') + "/assets/as4logo.png";
            string html         =
                $@"<html>
                    <head>
                        <meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"">
                        <title>AS4.NET</title>       
                    </head>
                    <body>
                        <img src=""{logoLocation}"" alt=""AS4.NET logo"" Style=""width:100%; height:auto; display:block, margin:auto""></img>
                        <div Style=""text-align:center""><p>This AS4.NET MessageHandler is online</p></div>
                    </body>";

            return(HttpResult.FromBytes(HttpStatusCode.OK, Encoding.UTF8.GetBytes(html), "text/html"));
        }