aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Web
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.Web
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.Web')
-rw-r--r--Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs5
-rw-r--r--Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs20
-rw-r--r--Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs1
-rw-r--r--Software/Visual_Studio/Tango.Web/Tango.Web.csproj1
-rw-r--r--Software/Visual_Studio/Tango.Web/TangoWebApplication.cs14
-rw-r--r--Software/Visual_Studio/Tango.Web/TangoWebClient.cs28
-rw-r--r--Software/Visual_Studio/Tango.Web/TangoWebClientv2.cs125
7 files changed, 15 insertions, 179 deletions
diff --git a/Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs b/Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs
index 0a0a1d476..a1eede7ef 100644
--- a/Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs
+++ b/Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs
@@ -58,11 +58,6 @@ namespace Tango.Web.ActiveDirectory
return groups;
}
- public bool IsUserMemberOf(String group, String email)
- {
- return GetUserGroups(email).Exists(x => x.DisplayName == group);
- }
-
public bool CanUserAccessCurrentEnvironment(String email)
{
var groups = GetUserGroups(email);
diff --git a/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs b/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs
index deaa7cf48..28637d97c 100644
--- a/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs
+++ b/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
@@ -61,7 +60,7 @@ namespace Tango.Web.Controllers
HttpStatusCode code = HttpStatusCode.InternalServerError;
- if (ex is ArgumentException || ex is InvalidDataException)
+ if (ex is ArgumentException)
{
code = HttpStatusCode.BadRequest;
}
@@ -69,21 +68,8 @@ namespace Tango.Web.Controllers
{
code = HttpStatusCode.Unauthorized;
}
- else if (ex is KeyNotFoundException)
- {
- code = HttpStatusCode.NotFound;
- }
- HttpResponseException httpException = null;
-
- if (ex is HttpResponseException httpResponseException)
- {
- httpException = httpResponseException;
- }
- else
- {
- httpException = new HttpResponseException(Request.CreateErrorResponse(code, ex.FlattenMessage(), ex));
- }
+ var httpException = new HttpResponseException(Request.CreateErrorResponse(code, ex.FlattenMessage()));
#if DEBUG
throw httpException;
@@ -97,7 +83,7 @@ namespace Tango.Web.Controllers
if (expandedExceptionValues != null)
{
- expandedExceptionValues["StackTrace"] = "";
+ expandedExceptionValues["StackTrace"] = "StackTrace not provided.";
}
}
#endif
diff --git a/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs b/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
index 8bc84f7b5..ce83d387c 100644
--- a/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
+++ b/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
@@ -15,7 +15,6 @@ namespace Tango.Web.SQLServer
public AuthenticationResult GetAccessToken()
{
var authContext = new AuthenticationContext(_service_root);
- authContext.TokenCache.Clear();
ClientCredential clientCredentials = new ClientCredential(WebConfig.CLIENT_ID, WebConfig.APP_SECRET);
AuthenticationResult authResult = authContext.AcquireTokenAsync("https://database.windows.net/", clientCredentials).Result;
return authResult;
diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj
index ce62ac4b4..426aa87ed 100644
--- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj
+++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj
@@ -263,7 +263,6 @@
<Compile Include="Storage\BlobStorageManager.cs" />
<Compile Include="Storage\TableStorageManager.cs" />
<Compile Include="TangoWebApplication.cs" />
- <Compile Include="TangoWebClientV2.cs" />
<Compile Include="TangoWebClient.cs" />
<Compile Include="WebConfig.cs" />
<Compile Include="Controllers\TangoController.cs" />
diff --git a/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs b/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs
index 1f98d0a39..a8acc419c 100644
--- a/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs
+++ b/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs
@@ -19,17 +19,14 @@ namespace Tango.Web
{
public override void OnException(HttpActionExecutedContext context)
{
- LogManager.Default.Log(context.Exception);
+ ErrorLogService.LogError(context.Exception);
}
}
protected virtual void Application_Start()
{
- LogManager.Default.Categories.Add(LogCategory.Debug);
LogManager.Default.RegisterLogger(new AzureCloudLogger());
GlobalConfiguration.Configuration.Filters.Add(new LogExceptionFilterAttribute());
-
- LogManager.Default.Log("Application Started!");
}
protected void Application_Error(object sender, EventArgs e)
@@ -40,5 +37,14 @@ namespace Tango.Web
LogManager.Default.Log(exception, "Global Exception!");
}
}
+
+ //common service to be used for logging errors
+ public static class ErrorLogService
+ {
+ public static void LogError(Exception ex)
+ {
+ LogManager.Default.Log(ex, "Global Exception!");
+ }
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs
index 7c3c6ad2a..1d2f9fc8e 100644
--- a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs
+++ b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs
@@ -37,12 +37,6 @@ namespace Tango.Web
public WebToken WebToken { get; private set; }
public bool IsAuthenticated { get; private set; }
- public TimeSpan RequestTimeout
- {
- get { return _client.RequestTimeout; }
- set { _client.RequestTimeout = value; }
- }
-
public TangoWebClient(DeploymentSlot environment, String controller)
{
_client = new WebTransportClient();
@@ -63,24 +57,6 @@ namespace Tango.Web
Token = token;
}
- public TangoWebClient(TangoWebClient<TLoginRequest, TLoginResponse> cloned)
- {
- _client = new WebTransportClient();
- Environment = cloned.Environment;
- Address = cloned.Address;
- Controller = cloned.Controller;
- IsAuthenticated = cloned.IsAuthenticated;
- RequestTimeout = cloned.RequestTimeout;
- WebToken = cloned.WebToken;
- _lastLoginRequest = cloned._lastLoginRequest;
- Token = cloned.Token;
- }
-
- public T Clone<T>() where T : TangoWebClient<TLoginRequest, TLoginResponse>
- {
- return Activator.CreateInstance(typeof(T), new object[] { this }) as T;
- }
-
public async Task<TLoginResponse> Login(TLoginRequest request)
{
var response = await _client.PostJson<TLoginRequest, TLoginResponse>(GetActionAddress("Login"), request);
@@ -109,7 +85,7 @@ namespace Tango.Web
var response = await _client.PostJson<TRequest, TResponse>(GetActionAddress(action), request);
return response;
}
- catch (TokenExpiredException ex)
+ catch (TokenExpiredException)
{
try
{
@@ -122,7 +98,7 @@ namespace Tango.Web
throw;
}
}
- catch (Exception ex)
+ catch
{
throw;
}
diff --git a/Software/Visual_Studio/Tango.Web/TangoWebClientv2.cs b/Software/Visual_Studio/Tango.Web/TangoWebClientv2.cs
deleted file mode 100644
index 3a4ff7756..000000000
--- a/Software/Visual_Studio/Tango.Web/TangoWebClientv2.cs
+++ /dev/null
@@ -1,125 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Authentication;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Transport.Web;
-using Tango.Web.Security;
-
-namespace Tango.Web
-{
- public abstract class TangoWebClientV2<TLoginRequest, TLoginResponse> : IDisposable where TLoginRequest : WebRequestMessage where TLoginResponse : WebTokenResponse
- {
- private WebTransportClient _client;
- private bool _disposed;
- private TLoginRequest _lastLoginRequest;
-
- public String Address { get; set; }
- public String Controller { get; private set; }
- public String Token { get; private set; }
- public WebToken WebToken { get; private set; }
- public bool IsAuthenticated { get; private set; }
-
- public TimeSpan RequestTimeout
- {
- get { return _client.RequestTimeout; }
- set { _client.RequestTimeout = value; }
- }
-
- public TangoWebClientV2(String address, String controller)
- {
- _client = new WebTransportClient();
- Controller = controller;
- Address = address;
- }
-
- public TangoWebClientV2(String address, String controller, String token) : this(address, controller)
- {
- Token = token;
- }
-
- public TangoWebClientV2(TangoWebClientV2<TLoginRequest, TLoginResponse> cloned)
- {
- _client = new WebTransportClient();
- Address = cloned.Address;
- Controller = cloned.Controller;
- IsAuthenticated = cloned.IsAuthenticated;
- RequestTimeout = cloned.RequestTimeout;
- WebToken = cloned.WebToken;
- _lastLoginRequest = cloned._lastLoginRequest;
- Token = cloned.Token;
- }
-
- public T Clone<T>() where T : TangoWebClientV2<TLoginRequest, TLoginResponse>
- {
- return Activator.CreateInstance(typeof(T), new object[] { this }) as T;
- }
-
- public async Task<TLoginResponse> Login(TLoginRequest request)
- {
- var response = await _client.PostJson<TLoginRequest, TLoginResponse>(GetActionAddress("Login"), request);
- Token = response.AccessToken;
- _client.AuthenticationToken = Token;
-
- WebToken = WebToken.FromToken(Token);
-
- _lastLoginRequest = request;
- IsAuthenticated = true;
- return response;
- }
-
- protected virtual async Task<TResponse> Post<TRequest, TResponse>(String action, TRequest request) where TRequest : class, IWebRequestMessage where TResponse : class, IWebResponseMessage
- {
- if (IsAuthenticated)
- {
- if (DateTime.UtcNow >= WebToken.Expiration)
- {
- await Login(_lastLoginRequest);
- }
- }
-
- try
- {
- var response = await _client.PostJson<TRequest, TResponse>(GetActionAddress(action), request);
- return response;
- }
- catch (TokenExpiredException ex)
- {
- try
- {
- await Login(_lastLoginRequest);
- var response = await _client.PostJson<TRequest, TResponse>(GetActionAddress(action), request);
- return response;
- }
- catch
- {
- throw;
- }
- }
- catch (Exception ex)
- {
- throw;
- }
- }
-
- private String GetActionAddress(String action)
- {
- return GetServiceAddress() + action;
- }
-
- protected virtual String GetServiceAddress()
- {
- return Address + $"/api/{Controller}/";
- }
-
- public virtual void Dispose()
- {
- if (!_disposed)
- {
- _disposed = true;
- _client.Dispose();
- }
- }
- }
-}