aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-12-24 14:46:55 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-12-24 14:46:55 +0200
commit0fb83fb3abb456ee6707b7f3cabc6b0c1ab2281b (patch)
tree6b0076b6c1daacd51c2aab18aaaf15e6edb19d9e /Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs
parent2f77ad3cebf771bdf02188174c9712027b004d41 (diff)
downloadTango-0fb83fb3abb456ee6707b7f3cabc6b0c1ab2281b.tar.gz
Tango-0fb83fb3abb456ee6707b7f3cabc6b0c1ab2281b.zip
Moved all common web components to Tango.Web
Changed app keys names. Fixed issue with machine studio and the initialization of observables static collections.
Diffstat (limited to 'Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs')
-rw-r--r--Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs b/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs
new file mode 100644
index 000000000..a581d9ec7
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs
@@ -0,0 +1,72 @@
+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 JsonController : ApiController
+ {
+ protected LogManager LogManager { get; private set; }
+
+ public JsonController()
+ {
+ 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
+ {
+ String request = String.Empty;
+
+ try
+ {
+ request = context.Request.Content.ReadAsStringAsync().Result;
+ }
+ catch {}
+
+ LogManager.Log($"Request Received on {controllerName + "/" + actionName}: \n{request}");
+
+ 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