From 4e496467dcc8549605917a44263d78cef40f71bb Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 23 Dec 2018 12:44:08 +0200 Subject: Implemented machine studio active directory secure login. --- .../Controllers/MachineStudioController.cs | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs') diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 8225d75e1..8485cd67d 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -14,6 +14,7 @@ using Tango.Core.Cryptography; using Tango.MachineService.Helpers; using Tango.MachineService.Models; using Tango.MachineStudio.Common.Authentication; +using System.Data.Entity; using Tango.MachineStudio.Common.Update; namespace Tango.MachineService.Controllers @@ -191,40 +192,45 @@ namespace Tango.MachineService.Controllers #endregion + [HttpPost] public LoginResponse Login(LoginRequest request) { - var authContext = new AuthenticationContext("https://login.microsoftonline.com/2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4"); - UserCredential userCredential = new UserCredential(request.Email, request.Password); - AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", "ec612854-7abc-457b-808a-5d0c5ba80c57", userCredential); + AuthenticationResult authResult = AzureDirectoryHelper.AuthenticateUser(request.Email, request.Password); using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - db.Roles.ToList(); db.Permissions.ToList(); db.UsersRoles.ToList(); db.RolesPermissions.ToList(); - var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower()); + + IHashGenerator g = new BasicHashGenerator(); if (user == null) { //Than add the user !! - - IHashGenerator g = new BasicHashGenerator(); - - BL.Entities.User new_user = new User(); + User new_user = new User(); new_user.Email = request.Email; - new_user.Password = g.Encrypt("Aa123456"); - new_user.Organization = db.Organizations.Single(x => x.Name == "Twine"); - new_user.Address = new Address() { }; + new_user.Password = g.Encrypt(request.Password); + new_user.Organization = db.Organizations.Include(x => x.Address).Single(x => x.Name == "Twine"); + new_user.Address = new_user.Organization.Address.Clone(); new_user.Contact = new Contact() { FirstName = authResult.UserInfo.GivenName, LastName = authResult.UserInfo.FamilyName, + FullName = authResult.UserInfo.GivenName + " " + authResult.UserInfo.FamilyName, + Email = request.Email, }; new_user.Roles.Add(db.Roles.Single(x => (Roles)x.Code == Roles.User)); } + else + { + user.Password = g.Encrypt(request.Password); + } + + db.SaveChanges(); } return new LoginResponse() @@ -234,6 +240,7 @@ namespace Tango.MachineService.Controllers Address = Config.DB_ADDRESS, Catalog = Config.DB_CATALOG, Type = Core.DataSourceType.Azure, + IntegratedSecurity = false, UserName = request.Email, Password = request.Password, } -- cgit v1.3.1 From 0fb83fb3abb456ee6707b7f3cabc6b0c1ab2281b Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 24 Dec 2018 14:46:55 +0200 Subject: Moved all common web components to Tango.Web Changed app keys names. Fixed issue with machine studio and the initialization of observables static collections. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 20578304 -> 20578304 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1581 -> 1516 bytes .../DefaultAuthenticationProvider.cs | 2 + .../ViewModels/LoginViewVM.cs | 1 - .../Tango.Web/ApplicationInsights.config | 2 + .../Tango.Web/Controllers/JsonController.cs | 72 ++++++ .../Tango.Web/Controllers/ProtoController.cs | 64 +++++ .../Tango.Web/Formatters/JsonNetFormatter.cs | 89 +++++++ .../Tango.Web/Formatters/ProtoBufFormatter.cs | 143 +++++++++++ .../Tango.Web/Helpers/AzureDirectoryHelper.cs | 19 ++ .../Tango.Web/Helpers/ObservablesContextHelper.cs | 26 ++ .../Tango.Web/Properties/AssemblyInfo.cs | 7 + Software/Visual_Studio/Tango.Web/SMO/SmoManager.cs | 73 ++++++ .../Tango.Web/Storage/ExtensionMethods.cs | 48 ++++ .../Tango.Web/Storage/StorageManager.cs | 27 ++ Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 276 +++++++++++++++++++++ .../Visual_Studio/Tango.Web/WebApiException.cs | 18 ++ Software/Visual_Studio/Tango.Web/WebConfig.cs | 24 ++ Software/Visual_Studio/Tango.Web/packages.config | 31 +++ Software/Visual_Studio/Tango.sln | 54 +++- .../Tango.MachineService/App_Start/WebApiConfig.cs | 1 + .../Web/Tango.MachineService/Config.cs | 16 -- .../Controllers/MachineStudioController.cs | 22 +- .../Controllers/PPCController.cs | 46 ++-- .../Helpers/AzureDirectoryHelper.cs | 19 -- .../Helpers/ObservablesContextHelper.cs | 26 -- .../Tango.MachineService/Helpers/StorageHelper.cs | 68 ----- .../Web/Tango.MachineService/JsonController.cs | 72 ------ .../Web/Tango.MachineService/JsonNetFormatter.cs | 89 ------- .../Tango.MachineService/MachineServiceConfig.cs | 15 ++ .../Web/Tango.MachineService/ProtoBufFormatter.cs | 143 ----------- .../Web/Tango.MachineService/ProtoController.cs | 64 ----- .../Web/Tango.MachineService/SMO/SmoManager.cs | 73 ------ .../Tango.MachineService.csproj | 17 +- .../Web/Tango.MachineService/Web.config | 23 +- .../Web/Tango.MachineService/WebApiException.cs | 18 -- 37 files changed, 1041 insertions(+), 647 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Web/ApplicationInsights.config create mode 100644 Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs create mode 100644 Software/Visual_Studio/Tango.Web/Controllers/ProtoController.cs create mode 100644 Software/Visual_Studio/Tango.Web/Formatters/JsonNetFormatter.cs create mode 100644 Software/Visual_Studio/Tango.Web/Formatters/ProtoBufFormatter.cs create mode 100644 Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs create mode 100644 Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs create mode 100644 Software/Visual_Studio/Tango.Web/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Tango.Web/SMO/SmoManager.cs create mode 100644 Software/Visual_Studio/Tango.Web/Storage/ExtensionMethods.cs create mode 100644 Software/Visual_Studio/Tango.Web/Storage/StorageManager.cs create mode 100644 Software/Visual_Studio/Tango.Web/Tango.Web.csproj create mode 100644 Software/Visual_Studio/Tango.Web/WebApiException.cs create mode 100644 Software/Visual_Studio/Tango.Web/WebConfig.cs create mode 100644 Software/Visual_Studio/Tango.Web/packages.config delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Config.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 810f4b5c0..978deab2f 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 9281ede10..30de45e33 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 9c594a6b0..16360627d 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index 3293dab3f..450756705 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -65,6 +65,8 @@ namespace Tango.MachineStudio.UI.Authentication ObservablesContext.OverrideSettingsDataSource(response.DataSource); + ObservablesStaticCollections.Instance.Initialize(); + using (ObservablesContext db = ObservablesContext.CreateDefault()) { db.Roles.Load(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index 4e659d46a..59cc69a57 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -124,7 +124,6 @@ namespace Tango.MachineStudio.UI.ViewModels { _authenticationProvider.Login(Email, Password); - ObservablesStaticCollections.Instance.Initialize(); _eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); _navigationManager.NavigateTo(NavigationView.MainView); diff --git a/Software/Visual_Studio/Tango.Web/ApplicationInsights.config b/Software/Visual_Studio/Tango.Web/ApplicationInsights.config new file mode 100644 index 000000000..75e12df9d --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/ApplicationInsights.config @@ -0,0 +1,2 @@ + + \ No newline at end of file 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 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 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 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 diff --git a/Software/Visual_Studio/Tango.Web/Formatters/JsonNetFormatter.cs b/Software/Visual_Studio/Tango.Web/Formatters/JsonNetFormatter.cs new file mode 100644 index 000000000..7912f810f --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Formatters/JsonNetFormatter.cs @@ -0,0 +1,89 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Formatting; +using System.Net.Http.Headers; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using Tango.BL; + +namespace Tango.Web.Formatters +{ + public class JsonNetFormatter : MediaTypeFormatter + { + private class JsonIgnoreAttributeIgnorerContractResolver : DefaultContractResolver + { + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + var property = base.CreateProperty(member, memberSerialization); + + if (typeof(IObservableEntity).IsAssignableFrom(property.PropertyType)) + { + property.Ignored = false; + } + return property; + } + } + + private JsonSerializerSettings _jsonSerializerSettings; + + public JsonNetFormatter(JsonSerializerSettings jsonSerializerSettings) + { + _jsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings(); + _jsonSerializerSettings.ContractResolver = new JsonIgnoreAttributeIgnorerContractResolver(); + + SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json")); + } + + public override bool CanReadType(Type type) + { + return true; + } + + public override bool CanWriteType(Type type) + { + return true; + } + + public override Task ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) + { + // Create a serializer + JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings); + + // Create task reading the content + return Task.Factory.StartNew(() => + { + using (StreamReader streamReader = new StreamReader(readStream)) + { + using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader)) + { + return serializer.Deserialize(jsonTextReader, type); + } + } + }); + } + + public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) + { + // Create a serializer + JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings); + + // Create task writing the serialized content + return Task.Factory.StartNew(() => + { + using (JsonTextWriter jsonTextWriter = new JsonTextWriter(new StreamWriter(writeStream)) { CloseOutput = false }) + { + serializer.Serialize(jsonTextWriter, value); + jsonTextWriter.Flush(); + } + }); + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Formatters/ProtoBufFormatter.cs b/Software/Visual_Studio/Tango.Web/Formatters/ProtoBufFormatter.cs new file mode 100644 index 000000000..eee35ec6b --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Formatters/ProtoBufFormatter.cs @@ -0,0 +1,143 @@ +using Google.Protobuf; +using System; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Http.Formatting; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Web.Http; +using Tango.PMR.Stubs; +using Tango.PMR.Synchronization; + +namespace Tango.Web.Formatters +{ + /// + /// Represents a protobuf web request/response formatter capable of formatting messages using protobuf. + /// + /// + public class ProtoBufFormatter : MediaTypeFormatter + { + private static readonly MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/x-protobuf"); + + /// + /// Initializes a new instance of the class. + /// + public ProtoBufFormatter() + { + SupportedMediaTypes.Add(mediaType); + } + + /// + /// Gets the default type of the media. + /// + /// + /// The default type of the media. + /// + public static MediaTypeHeaderValue DefaultMediaType + { + get { return mediaType; } + } + + /// + /// Queries whether this can deserializean object of the specified type. + /// + /// The type to deserialize. + /// + /// true if the can deserialize the type; otherwise, false. + /// + public override bool CanReadType(Type type) + { + return true; + } + + /// + /// Queries whether this can serializean object of the specified type. + /// + /// The type to serialize. + /// + /// true if the can serialize the type; otherwise, false. + /// + public override bool CanWriteType(Type type) + { + return true; + } + + /// + /// Reads from stream asynchronous. + /// + /// The type. + /// The stream. + /// The content. + /// The formatter logger. + /// + public override Task ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger) + { + var tcs = new TaskCompletionSource(); + + try + { + MessageParser parser = type.GetProperty("Parser").GetValue(null, null) as MessageParser; + IMessage req = parser.ParseFrom(stream); + tcs.SetResult(req); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + + return tcs.Task; + } + + /// + /// Writes to stream asynchronous. + /// + /// The type. + /// The value. + /// The stream. + /// The content. + /// The transport context. + /// + public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext) + { + var tcs = new TaskCompletionSource(); + + if (value is IMessage) + { + try + { + (value as IMessage).WriteTo(stream); + tcs.SetResult(null); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + + return tcs.Task; + } + else if (value is HttpError) + { + var httpError = value as HttpError; + + try + { + HttpProtoException msg = new HttpProtoException(); + msg.Message = httpError["Message"].ToString(); + msg.StatusCode = (int)HttpStatusCode.InternalServerError; + + msg.WriteTo(stream); + tcs.SetResult(null); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + + return tcs.Task; + } + + return base.WriteToStreamAsync(type, value, stream, content, transportContext); + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs b/Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs new file mode 100644 index 000000000..27b5e7cf5 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs @@ -0,0 +1,19 @@ +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.Web.Helpers +{ + public static class AzureDirectoryHelper + { + public static AuthenticationResult AuthenticateUser(String email, String password) + { + var authContext = new AuthenticationContext("https://login.microsoftonline.com/2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4"); + UserCredential userCredential = new UserCredential(email, password); + AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", "ec612854-7abc-457b-808a-5d0c5ba80c57", userCredential); + return authResult; + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs b/Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs new file mode 100644 index 000000000..fcf6eb599 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Web; +using Tango.BL; +using Tango.Core; + +namespace Tango.Web.Helpers +{ + public static class ObservablesContextHelper + { + public static ObservablesContext CreateContext() + { + return new ObservablesContext(new DataSource() + { + Address = WebConfig.DB_ADDRESS, + Catalog = WebConfig.DB_CATALOG, + IntegratedSecurity = false, + Type = DataSourceType.SQLServer, + UserName = WebConfig.DB_USER_NAME, + Password = WebConfig.DB_PASSWORD + }); + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.Web/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1471db897 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Properties/AssemblyInfo.cs @@ -0,0 +1,7 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tango - Web Components")] +[assembly: AssemblyVersion("2.0.11.1608")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/SMO/SmoManager.cs b/Software/Visual_Studio/Tango.Web/SMO/SmoManager.cs new file mode 100644 index 000000000..86953d233 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/SMO/SmoManager.cs @@ -0,0 +1,73 @@ +using Microsoft.SqlServer.Management.Common; +using Microsoft.SqlServer.Management.Smo; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Tango.Core.DB; + +namespace Tango.Web.SMO +{ + public class SmoManager : IDisposable + { + private ServerConnection _connection; + private Server _server; + private static Random random = new Random(); + + public SmoManager() + { + _connection = new ServerConnection(WebConfig.DB_ADDRESS, WebConfig.DB_USER_NAME, WebConfig.DB_PASSWORD); + _server = new Server(_connection); + } + + public DbCredentials CreateRandomLoginAndUser() + { + var database = _server.Databases.OfType().SingleOrDefault(x => x.Name == WebConfig.DB_CATALOG); + + String userName = GetRandomString(36); + String password = System.Web.Security.Membership.GeneratePassword(16, 2); + + Login login = new Login(_server, userName); + login.LoginType = LoginType.SqlLogin; + login.DefaultDatabase = WebConfig.DB_CATALOG; + login.PasswordPolicyEnforced = false; + login.Create(password); + + User user = new User(database, userName); + user.Login = userName; + user.Create(); + user.AddToRole("db_datareader"); + + return new DbCredentials() { UserName = userName, Password = password }; + } + + public void DeleteLoginAndUser(String userName) + { + var database = _server.Databases.OfType().SingleOrDefault(x => x.Name == WebConfig.DB_CATALOG); + + var user = database.Users.OfType().SingleOrDefault(x => x.Name == userName); + + if (user != null) + { + user.Drop(); + } + + Login login = _server.Logins.OfType().SingleOrDefault(x => x.Name == userName); + if (login != null) + { + login.Drop(); + } + } + + public string GetRandomString(int length) + { + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + return "TEMP_" + new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); + } + + public void Dispose() + { + _connection.Disconnect(); + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Storage/ExtensionMethods.cs b/Software/Visual_Studio/Tango.Web/Storage/ExtensionMethods.cs new file mode 100644 index 000000000..4acd10082 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Storage/ExtensionMethods.cs @@ -0,0 +1,48 @@ +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Web.Storage +{ + public static class ExtensionMethods + { + public static CloudBlockBlob CreateEmptyBlob(this CloudBlobContainer container, String name) + { + CloudBlockBlob emptyBlob = container.GetBlockBlobReference(name); + using (MemoryStream ms = new MemoryStream()) + { + emptyBlob.UploadFromStream(ms);//Empty memory stream. Will create an empty blob. + } + + return emptyBlob; + } + + public static String GenerateReadSignature(this CloudBlockBlob blob, TimeSpan duration) + { + String signature = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() + { + SharedAccessStartTime = DateTime.UtcNow, + SharedAccessExpiryTime = DateTime.UtcNow.Add(duration), + Permissions = SharedAccessBlobPermissions.Read + }); + + return new Uri(blob.Uri + signature).ToString(); + } + + public static String GenerateWriteSignature(this CloudBlockBlob blob, TimeSpan duration) + { + String signature = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() + { + SharedAccessStartTime = DateTime.UtcNow, + SharedAccessExpiryTime = DateTime.UtcNow.Add(duration), + Permissions = SharedAccessBlobPermissions.Write + }); + + return new Uri(blob.Uri + signature).ToString(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Web/Storage/StorageManager.cs b/Software/Visual_Studio/Tango.Web/Storage/StorageManager.cs new file mode 100644 index 000000000..17b01d1e2 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Storage/StorageManager.cs @@ -0,0 +1,27 @@ +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Web.Storage +{ + public class StorageManager + { + private CloudBlobClient _client; + + public StorageManager() + { + CloudStorageAccount storageAccount = CloudStorageAccount.Parse(WebConfig.STORAGE_ACCOUNT); + _client = storageAccount.CreateCloudBlobClient(); + } + + public CloudBlobContainer GetContainer(String name) + { + var container = _client.GetContainerReference(name); + return container; + } + } +} diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj new file mode 100644 index 000000000..9d199a409 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -0,0 +1,276 @@ + + + + + + + Debug + AnyCPU + {5001990F-977B-48FF-B217-0236A5022AD8} + Library + Properties + Tango.Web + Tango.Web + v4.6.1 + 512 + true + + + ..\packages\WebGrease.1.5.2\lib + + + true + full + false + ..\Build\Core\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\Build\Core\Release\ + TRACE + prompt + 4 + + + + ..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll + + + ..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll + + + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + + ..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.0.6\lib\net45\Microsoft.AI.Agent.Intercept.dll + + + ..\packages\Microsoft.ApplicationInsights.DependencyCollector.2.2.0\lib\net45\Microsoft.AI.DependencyCollector.dll + + + ..\packages\Microsoft.ApplicationInsights.PerfCounterCollector.2.2.0\lib\net45\Microsoft.AI.PerfCounterCollector.dll + + + ..\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0\lib\net45\Microsoft.AI.ServerTelemetryChannel.dll + + + ..\packages\Microsoft.ApplicationInsights.Web.2.2.0\lib\net45\Microsoft.AI.Web.dll + + + ..\packages\Microsoft.ApplicationInsights.WindowsServer.2.2.0\lib\net45\Microsoft.AI.WindowsServer.dll + + + ..\packages\Microsoft.ApplicationInsights.2.2.0\lib\net46\Microsoft.ApplicationInsights.dll + + + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.7.10707.1513-rc\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.7.10707.1513-rc\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.AzureStorageEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.BatchParserClient.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.ConnectionInfo.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.ConnectionInfoExtended.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Diagnostics.Strace.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Dmf.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Dmf.Common.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.Collector.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.CollectorEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.RegisteredServers.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.Sdk.Sfc.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.SqlParser.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.Utility.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.UtilityEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEvent.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEventDbScoped.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEventDbScopedEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEventEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.PolicyEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.RegSvrEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.ServiceBrokerEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Smo.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SmoExtended.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlClrProvider.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlEnum.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlTDiagm.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlWmiManagement.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SString.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Types.dll + + + ..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.WmiEnum.dll + + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + + + + + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll + + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll + + + ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll + + + ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll + + + ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + + + + + + + + + ..\packages\WebGrease.1.5.2\lib\WebGrease.dll + + + + + GlobalVersionInfo.cs + + + + + + + + + + + + + + + + + + + + {f441feee-322a-4943-b566-110e12fd3b72} + Tango.BL + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} + Tango.Logging + + + {e4927038-348d-4295-aaf4-861c58cb3943} + Tango.PMR + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/WebApiException.cs b/Software/Visual_Studio/Tango.Web/WebApiException.cs new file mode 100644 index 000000000..c9b464c6f --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/WebApiException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Web; + +namespace Tango.Web +{ + public class WebApiException : Exception + { + public HttpStatusCode StatusCode { get; set; } + + public WebApiException(HttpStatusCode statusCode, String message) : base(message) + { + StatusCode = statusCode; + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/WebConfig.cs b/Software/Visual_Studio/Tango.Web/WebConfig.cs new file mode 100644 index 000000000..a10da3321 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/WebConfig.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Web; + +namespace Tango.Web +{ + public class WebConfig + { + public static String DB_ADDRESS => ConfigurationManager.AppSettings[nameof(DB_ADDRESS)].ToString(); + public static String DB_USER_NAME => ConfigurationManager.AppSettings[nameof(DB_USER_NAME)].ToString(); + public static String DB_PASSWORD => ConfigurationManager.AppSettings[nameof(DB_PASSWORD)].ToString(); + public static String DB_CATALOG => ConfigurationManager.AppSettings[nameof(DB_CATALOG)].ToString(); + + public static String STORAGE_ACCOUNT => ConfigurationManager.AppSettings[nameof(STORAGE_ACCOUNT)].ToString(); + + public static String TENANT_ID => ConfigurationManager.AppSettings[nameof(TENANT_ID)].ToString(); + public static String CLIENT_ID => ConfigurationManager.AppSettings[nameof(CLIENT_ID)].ToString(); + public static String APP_SECRET => ConfigurationManager.AppSettings[nameof(APP_SECRET)].ToString(); + + } +} + diff --git a/Software/Visual_Studio/Tango.Web/packages.config b/Software/Visual_Studio/Tango.Web/packages.config new file mode 100644 index 000000000..6266503ba --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/packages.config @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index 387a9e1bf..01be05c3e 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -246,6 +246,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PPC.BootScreen", "PPC EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PPC.Logging", "PPC\Modules\Tango.PPC.Logging\Tango.PPC.Logging.csproj", "{D2EE865B-B006-487A-9487-60A663636AC3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.Web", "Tango.Web\Tango.Web.csproj", "{5001990F-977B-48FF-B217-0236A5022AD8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution AppVeyor|Any CPU = AppVeyor|Any CPU @@ -4409,6 +4411,46 @@ Global {D2EE865B-B006-487A-9487-60A663636AC3}.Release|x64.Build.0 = Release|Any CPU {D2EE865B-B006-487A-9487-60A663636AC3}.Release|x86.ActiveCfg = Release|Any CPU {D2EE865B-B006-487A-9487-60A663636AC3}.Release|x86.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|Any CPU.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|Any CPU.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|ARM.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|ARM.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|ARM64.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|ARM64.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|x64.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|x64.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|x86.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.AppVeyor|x86.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|ARM.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|ARM.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|ARM64.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|x64.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|x64.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|x86.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Debug|x86.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|Any CPU.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|Any CPU.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|ARM.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|ARM.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|ARM64.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|ARM64.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|x64.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|x64.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|x86.ActiveCfg = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.DefaultBuild|x86.Build.0 = Debug|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|Any CPU.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|ARM.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|ARM.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|ARM64.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|ARM64.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|x64.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|x64.Build.0 = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|x86.ActiveCfg = Release|Any CPU + {5001990F-977B-48FF-B217-0236A5022AD8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4488,12 +4530,12 @@ Global {D2EE865B-B006-487A-9487-60A663636AC3} = {0048447D-1D94-4E60-9DAD-7349C777CB4E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - BuildVersion_UseGlobalSettings = False - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs - BuildVersion_StartDate = 2000/1/1 - BuildVersion_UpdateFileVersion = False - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_UpdateFileVersion = False + BuildVersion_StartDate = 2000/1/1 + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_UseGlobalSettings = False EndGlobalSection EndGlobal diff --git a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs index 3129482cb..0a63e9acb 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Web.Http; +using Tango.Web.Formatters; namespace Tango.MachineService { diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Config.cs b/Software/Visual_Studio/Web/Tango.MachineService/Config.cs deleted file mode 100644 index b1d2dafca..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Config.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Web; - -namespace Tango.MachineService -{ - public class Config - { - public static String DB_ADDRESS => ConfigurationManager.AppSettings["DbAddress"].ToString(); - public static String DB_USER_NAME => ConfigurationManager.AppSettings["DbUserName"].ToString(); - public static String DB_PASSWORD => ConfigurationManager.AppSettings["DbPassword"].ToString(); - public static String DB_CATALOG => ConfigurationManager.AppSettings["DbCatalog"].ToString(); - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 8485cd67d..8d46ed7d9 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -11,11 +11,13 @@ using Tango.BL.Builders; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core.Cryptography; -using Tango.MachineService.Helpers; using Tango.MachineService.Models; using Tango.MachineStudio.Common.Authentication; using System.Data.Entity; using Tango.MachineStudio.Common.Update; +using Tango.Web.Controllers; +using Tango.Web.Helpers; +using Tango.Web.Storage; namespace Tango.MachineService.Controllers { @@ -70,11 +72,11 @@ namespace Tango.MachineService.Controllers if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion) { - var client = StorageHelper.GetStorageBlobClient(); - var container = StorageHelper.GetMachineStudioVersionsContainer(client); + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); var blob = container.GetBlockBlobReference(latestVersion.BlobName); - response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); response.IsUpdateAvailable = true; response.Version = latestVersion.Version; @@ -116,12 +118,12 @@ namespace Tango.MachineService.Controllers { String newVersionFileName = "Machine Studio Version" + " " + currentVersion.ToString() + ".zip"; - var client = StorageHelper.GetStorageBlobClient(); - var container = StorageHelper.GetMachineStudioVersionsContainer(client); - var blob = StorageHelper.CreateEmptyBlob(container, newVersionFileName); + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); + var blob = container.CreateEmptyBlob(newVersionFileName); response.Token = Guid.NewGuid().ToString(); - response.BlobAddress = StorageHelper.GenerateBlobWriteSignature(blob, TimeSpan.FromMinutes(30)); + response.BlobAddress = blob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); _pendingUploads.Add(new MachineStudioPendingUpload() { @@ -237,8 +239,8 @@ namespace Tango.MachineService.Controllers { DataSource = new Core.DataSource() { - Address = Config.DB_ADDRESS, - Catalog = Config.DB_CATALOG, + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, Type = Core.DataSourceType.Azure, IntegratedSecurity = false, UserName = request.Email, diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 68f597fcc..6b4190313 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -23,9 +23,7 @@ using Tango.Core.DB; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.Logging; -using Tango.MachineService.Helpers; using Tango.MachineService.Models; -using Tango.MachineService.SMO; using Tango.PMR.Stubs; using Tango.PMR.Synchronization; using Tango.PPC.Common.MachineSetup; @@ -33,6 +31,10 @@ using Tango.PPC.Common.MachineUpdate; using Tango.PPC.Common.Update; using Tango.Synchronization.Local; using Tango.Synchronization.Remote; +using Tango.Web.Controllers; +using Tango.Web.Helpers; +using Tango.Web.SMO; +using Tango.Web.Storage; namespace Tango.MachineService.Controllers { @@ -81,17 +83,17 @@ namespace Tango.MachineService.Controllers response.Version = latest_machine_version.Version; - var client = StorageHelper.GetStorageBlobClient(); - var container = StorageHelper.GetTangoVersionsContainer(client); + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); - response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); DbCredentials credentials = new DbCredentials(); - using (SmoManager manager = new SmoManager()) + using (SmoManager smo = new SmoManager()) { - credentials = manager.CreateRandomLoginAndUser(); + credentials = smo.CreateRandomLoginAndUser(); Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => { @@ -104,8 +106,8 @@ namespace Tango.MachineService.Controllers response.DataSource = new DataSource() { - Address = Config.DB_ADDRESS, - Catalog = Config.DB_CATALOG, + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, IntegratedSecurity = false, @@ -147,17 +149,17 @@ namespace Tango.MachineService.Controllers response.Version = latest_machine_version.Version; - var client = StorageHelper.GetStorageBlobClient(); - var container = StorageHelper.GetTangoVersionsContainer(client); + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); - response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); DbCredentials credentials = new DbCredentials(); - using (SmoManager manager = new SmoManager()) + using (SmoManager smo = new SmoManager()) { - credentials = manager.CreateRandomLoginAndUser(); + credentials = smo.CreateRandomLoginAndUser(); Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => { @@ -170,8 +172,8 @@ namespace Tango.MachineService.Controllers response.DataSource = new DataSource() { - Address = Config.DB_ADDRESS, - Catalog = Config.DB_CATALOG, + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, IntegratedSecurity = false, @@ -247,8 +249,8 @@ namespace Tango.MachineService.Controllers response.DataSource = new DataSource() { - Address = Config.DB_ADDRESS, - Catalog = Config.DB_CATALOG, + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, IntegratedSecurity = false, @@ -328,12 +330,12 @@ namespace Tango.MachineService.Controllers { String newVersionFileName = "Tango Version" + " " + currentVersion.ToString() + ".zip"; - var client = StorageHelper.GetStorageBlobClient(); - var container = StorageHelper.GetTangoVersionsContainer(client); - var blob = StorageHelper.CreateEmptyBlob(container, newVersionFileName); + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); + var blob = container.CreateEmptyBlob(newVersionFileName); response.Token = Guid.NewGuid().ToString(); - response.BlobAddress = StorageHelper.GenerateBlobWriteSignature(blob, TimeSpan.FromMinutes(30)); + response.BlobAddress = blob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); _pendingUploads.Add(new PPCPendingUpload() { diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs deleted file mode 100644 index fe7733323..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace Tango.MachineService.Helpers -{ - public static class AzureDirectoryHelper - { - public static AuthenticationResult AuthenticateUser(String email, String password) - { - var authContext = new AuthenticationContext("https://login.microsoftonline.com/2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4"); - UserCredential userCredential = new UserCredential(email, password); - AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", "ec612854-7abc-457b-808a-5d0c5ba80c57", userCredential); - return authResult; - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs deleted file mode 100644 index fff0eebea..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Web; -using Tango.BL; -using Tango.Core; - -namespace Tango.MachineService.Helpers -{ - public static class ObservablesContextHelper - { - public static ObservablesContext CreateContext() - { - return new ObservablesContext(new DataSource() - { - Address = Config.DB_ADDRESS, - Catalog = Config.DB_CATALOG, - IntegratedSecurity = false, - Type = DataSourceType.SQLServer, - UserName = Config.DB_USER_NAME, - Password = Config.DB_PASSWORD - }); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs deleted file mode 100644 index a2cc2a0dc..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Microsoft.WindowsAzure.Storage; -using Microsoft.WindowsAzure.Storage.Blob; -using System; -using System.Collections.Generic; -using System.Configuration; -using System.IO; -using System.Linq; -using System.Web; - -namespace Tango.MachineService.Helpers -{ - public static class StorageHelper - { - public static CloudBlobClient GetStorageBlobClient() - { - String storageAddress = ConfigurationManager.AppSettings["Storage"].ToString(); - CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAddress); - return storageAccount.CreateCloudBlobClient(); - } - - public static CloudBlobContainer GetTangoVersionsContainer(CloudBlobClient client) - { - var container = client.GetContainerReference("tango-versions"); - return container; - } - - public static CloudBlobContainer GetMachineStudioVersionsContainer(CloudBlobClient client) - { - var container = client.GetContainerReference("machine-studio-versions"); - return container; - } - - public static CloudBlockBlob CreateEmptyBlob(CloudBlobContainer container, String name) - { - CloudBlockBlob emptyBlob = container.GetBlockBlobReference(name); - using (MemoryStream ms = new MemoryStream()) - { - emptyBlob.UploadFromStream(ms);//Empty memory stream. Will create an empty blob. - } - - return emptyBlob; - } - - public static String GenerateBlobReadSignature(CloudBlockBlob blob, TimeSpan duration) - { - String signature = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() - { - SharedAccessStartTime = DateTime.UtcNow, - SharedAccessExpiryTime = DateTime.UtcNow.Add(duration), - Permissions = SharedAccessBlobPermissions.Read - }); - - return new Uri(blob.Uri + signature).ToString(); - } - - public static String GenerateBlobWriteSignature(CloudBlockBlob blob, TimeSpan duration) - { - String signature = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() - { - SharedAccessStartTime = DateTime.UtcNow, - SharedAccessExpiryTime = DateTime.UtcNow.Add(duration), - Permissions = SharedAccessBlobPermissions.Write - }); - - return new Uri(blob.Uri + signature).ToString(); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs b/Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs deleted file mode 100644 index 163a89589..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs +++ /dev/null @@ -1,72 +0,0 @@ -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.MachineService -{ - public class JsonController : ApiController - { - protected LogManager LogManager { get; private set; } - - public JsonController() - { - LogManager = LogManager.Default; - } - - public override async Task 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 diff --git a/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs b/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs deleted file mode 100644 index 7cadceb0b..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Formatting; -using System.Net.Http.Headers; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Web; -using Tango.BL; - -namespace Tango.MachineService -{ - public class JsonNetFormatter : MediaTypeFormatter - { - private class JsonIgnoreAttributeIgnorerContractResolver : DefaultContractResolver - { - protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) - { - var property = base.CreateProperty(member, memberSerialization); - - if (typeof(IObservableEntity).IsAssignableFrom(property.PropertyType)) - { - property.Ignored = false; - } - return property; - } - } - - private JsonSerializerSettings _jsonSerializerSettings; - - public JsonNetFormatter(JsonSerializerSettings jsonSerializerSettings) - { - _jsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings(); - _jsonSerializerSettings.ContractResolver = new JsonIgnoreAttributeIgnorerContractResolver(); - - SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json")); - } - - public override bool CanReadType(Type type) - { - return true; - } - - public override bool CanWriteType(Type type) - { - return true; - } - - public override Task ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) - { - // Create a serializer - JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings); - - // Create task reading the content - return Task.Factory.StartNew(() => - { - using (StreamReader streamReader = new StreamReader(readStream)) - { - using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader)) - { - return serializer.Deserialize(jsonTextReader, type); - } - } - }); - } - - public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) - { - // Create a serializer - JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings); - - // Create task writing the serialized content - return Task.Factory.StartNew(() => - { - using (JsonTextWriter jsonTextWriter = new JsonTextWriter(new StreamWriter(writeStream)) { CloseOutput = false }) - { - serializer.Serialize(jsonTextWriter, value); - jsonTextWriter.Flush(); - } - }); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs new file mode 100644 index 000000000..6039f55ac --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Web; +using Tango.Web; + +namespace Tango.MachineService +{ + public class MachineServiceConfig : WebConfig + { + public static String TANGO_VERSIONS_CONTAINER => ConfigurationManager.AppSettings[nameof(TANGO_VERSIONS_CONTAINER)].ToString(); + public static String MACHINE_STUDIO_VERSIONS_CONTAINER => ConfigurationManager.AppSettings[nameof(MACHINE_STUDIO_VERSIONS_CONTAINER)].ToString(); + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs b/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs deleted file mode 100644 index b82f1adef..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs +++ /dev/null @@ -1,143 +0,0 @@ -using Google.Protobuf; -using System; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Net.Http.Formatting; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using System.Web.Http; -using Tango.PMR.Stubs; -using Tango.PMR.Synchronization; - -namespace Tango.MachineService -{ - /// - /// Represents a protobuf web request/response formatter capable of formatting messages using protobuf. - /// - /// - public class ProtoBufFormatter : MediaTypeFormatter - { - private static readonly MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/x-protobuf"); - - /// - /// Initializes a new instance of the class. - /// - public ProtoBufFormatter() - { - SupportedMediaTypes.Add(mediaType); - } - - /// - /// Gets the default type of the media. - /// - /// - /// The default type of the media. - /// - public static MediaTypeHeaderValue DefaultMediaType - { - get { return mediaType; } - } - - /// - /// Queries whether this can deserializean object of the specified type. - /// - /// The type to deserialize. - /// - /// true if the can deserialize the type; otherwise, false. - /// - public override bool CanReadType(Type type) - { - return true; - } - - /// - /// Queries whether this can serializean object of the specified type. - /// - /// The type to serialize. - /// - /// true if the can serialize the type; otherwise, false. - /// - public override bool CanWriteType(Type type) - { - return true; - } - - /// - /// Reads from stream asynchronous. - /// - /// The type. - /// The stream. - /// The content. - /// The formatter logger. - /// - public override Task ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger) - { - var tcs = new TaskCompletionSource(); - - try - { - MessageParser parser = type.GetProperty("Parser").GetValue(null, null) as MessageParser; - IMessage req = parser.ParseFrom(stream); - tcs.SetResult(req); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - - return tcs.Task; - } - - /// - /// Writes to stream asynchronous. - /// - /// The type. - /// The value. - /// The stream. - /// The content. - /// The transport context. - /// - public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext) - { - var tcs = new TaskCompletionSource(); - - if (value is IMessage) - { - try - { - (value as IMessage).WriteTo(stream); - tcs.SetResult(null); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - - return tcs.Task; - } - else if (value is HttpError) - { - var httpError = value as HttpError; - - try - { - HttpProtoException msg = new HttpProtoException(); - msg.Message = httpError["Message"].ToString(); - msg.StatusCode = (int)HttpStatusCode.InternalServerError; - - msg.WriteTo(stream); - tcs.SetResult(null); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - - return tcs.Task; - } - - return base.WriteToStreamAsync(type, value, stream, content, transportContext); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs b/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs deleted file mode 100644 index 572604d3c..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs +++ /dev/null @@ -1,64 +0,0 @@ -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.MachineService -{ - public class ProtoController : ApiController - { - protected LogManager LogManager { get; private set; } - - public ProtoController() - { - LogManager = LogManager.Default; - } - - public override async Task 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 diff --git a/Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs b/Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs deleted file mode 100644 index d2ee0ed5f..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Microsoft.SqlServer.Management.Common; -using Microsoft.SqlServer.Management.Smo; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Tango.Core.DB; - -namespace Tango.MachineService.SMO -{ - public class SmoManager : IDisposable - { - private ServerConnection _connection; - private Server _server; - private static Random random = new Random(); - - public SmoManager() - { - _connection = new ServerConnection(Config.DB_ADDRESS, Config.DB_USER_NAME, Config.DB_PASSWORD); - _server = new Server(_connection); - } - - public DbCredentials CreateRandomLoginAndUser() - { - var database = _server.Databases.OfType().SingleOrDefault(x => x.Name == Config.DB_CATALOG); - - String userName = GetRandomString(36); - String password = System.Web.Security.Membership.GeneratePassword(16, 2); - - Login login = new Login(_server, userName); - login.LoginType = LoginType.SqlLogin; - login.DefaultDatabase = Config.DB_CATALOG; - login.PasswordPolicyEnforced = false; - login.Create(password); - - User user = new User(database, userName); - user.Login = userName; - user.Create(); - user.AddToRole("db_datareader"); - - return new DbCredentials() { UserName = userName, Password = password }; - } - - public void DeleteLoginAndUser(String userName) - { - var database = _server.Databases.OfType().SingleOrDefault(x => x.Name == Config.DB_CATALOG); - - var user = database.Users.OfType().SingleOrDefault(x => x.Name == userName); - - if (user != null) - { - user.Drop(); - } - - Login login = _server.Logins.OfType().SingleOrDefault(x => x.Name == userName); - if (login != null) - { - login.Drop(); - } - } - - public string GetRandomString(int length) - { - const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - return "TEMP_" + new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); - } - - public void Dispose() - { - _connection.Disconnect(); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index c05cb5fe7..ca1376ff7 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -275,16 +275,10 @@ - + - - - - - - @@ -293,9 +287,6 @@ - - - @@ -346,6 +337,10 @@ {74e700b0-1156-4126-be40-ee450d3c3026} Tango.Transport + + {5001990f-977b-48ff-b217-0236a5022ad8} + Tango.Web + @@ -380,7 +375,7 @@ False - + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index ef2420349..77d9a1bb3 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -13,15 +13,20 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + MSDeploy + /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/machineservice/slots/MachineService-DEV + Tango + AzureWebSite + Debug + Any CPU + http://machineservice-machineservice-dev.azurewebsites.net + True + False + machineservice-machineservice-dev.scm.azurewebsites.net:443 + machineservice__MachineService-DEV + + True + False + WMSVC + True + $machineservice__MachineService-DEV + <_SavePWD>True + <_DestinationType>AzureWebSite + + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml deleted file mode 100644 index 612e38bfb..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - MSDeploy - /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/MachineService - Tango - AzureWebSite - Debug - Any CPU - http://machineservice.azurewebsites.net - True - False - machineservice.scm.azurewebsites.net:443 - MachineService - - True - False - WMSVC - True - $MachineService - <_SavePWD>True - <_DestinationType>AzureWebSite - - \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml new file mode 100644 index 000000000..a611d5ffd --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml @@ -0,0 +1,28 @@ + + + + + MSDeploy + /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/MachineService + Tango + AzureWebSite + Release + Any CPU + https://machineservice.twine-srv.com + True + False + machineservice.scm.azurewebsites.net:443 + MachineService + + True + False + WMSVC + True + $MachineService + <_SavePWD>True + <_DestinationType>AzureWebSite + + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml new file mode 100644 index 000000000..12e2de377 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml @@ -0,0 +1,28 @@ + + + + + MSDeploy + /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/machineservice/slots/MachineService-TEST + Tango + AzureWebSite + Release + Any CPU + http://machineservice-machineservice-test.azurewebsites.net + True + False + machineservice-machineservice-test.scm.azurewebsites.net:443 + machineservice__MachineService-TEST + + True + False + WMSVC + True + $machineservice__MachineService-TEST + <_SavePWD>True + <_DestinationType>AzureWebSite + + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index ca1376ff7..63c8521da 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -346,7 +346,9 @@ - + + + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 097943016..2d700244b 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -27,6 +27,9 @@ + + +