aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Web/Controllers/ProtoController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Web/Controllers/ProtoController.cs')
-rw-r--r--Software/Visual_Studio/Tango.Web/Controllers/ProtoController.cs64
1 files changed, 64 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Web/Controllers/ProtoController.cs b/Software/Visual_Studio/Tango.Web/Controllers/ProtoController.cs
new file mode 100644
index 000000000..090638f3a
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Web/Controllers/ProtoController.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Security.Authentication;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Web;
+using System.Web.Http;
+using System.Web.Http.Controllers;
+using Tango.Logging;
+
+namespace Tango.Web.Controllers
+{
+ public class ProtoController : ApiController
+ {
+ protected LogManager LogManager { get; private set; }
+
+ public ProtoController()
+ {
+ LogManager = LogManager.Default;
+ }
+
+ public override async Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext context, CancellationToken cancellationToken)
+ {
+ string controllerName = String.Empty;
+ string actionName = String.Empty;
+
+ try
+ {
+ var routeData = HttpContext.Current.Request.RequestContext.RouteData;
+ actionName = routeData.Values["action"].ToString();
+ controllerName = routeData.Values["controller"].ToString();
+ }
+ catch { }
+
+ try
+ {
+ LogManager.Log($"Request Received on {controllerName + "/" + actionName}.");
+
+ var result = await base.ExecuteAsync(context, cancellationToken);
+ return result;
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"An error occurred while processing the request message on {controllerName + "/" + actionName}.");
+
+ HttpStatusCode code = HttpStatusCode.InternalServerError;
+
+ if (ex is ArgumentException)
+ {
+ code = HttpStatusCode.BadRequest;
+ }
+ else if (ex is AuthenticationException)
+ {
+ code = HttpStatusCode.Unauthorized;
+ }
+
+ throw new HttpResponseException(Request.CreateErrorResponse(code, ex.Message));
+ }
+ }
+ }
+} \ No newline at end of file