From cbc80e71fac7d2896ac496b0fbf22051c0cdcff7 Mon Sep 17 00:00:00 2001 From: Avi Levkovich Date: Mon, 17 Feb 2020 17:00:29 +0200 Subject: merge --- .../Controllers/GatewayController.cs | 28 ++++- .../Tango.MachineService.Gateway/DB/ENVIRONMENT.cs | 24 ++++ .../DB/GatewayDbContext.cs | 38 ++++++ .../DTO/EnvironmentConfiguration.cs | 15 +++ .../Tango.MachineService.Gateway/GatewayConfig.cs | 5 + .../Messages/EnvironmentsRequest.cs | 12 ++ .../Messages/EnvironmentsResponse.cs | 17 +++ .../Nswag/GatewayClient.nswag | 140 +++++++++++++++++++++ .../Tango.MachineService.Gateway.csproj | 24 +++- .../Web/Tango.MachineService.Gateway/Web.config | 23 ++-- .../Tango.MachineService.Gateway/packages.config | 1 + 11 files changed, 314 insertions(+), 13 deletions(-) create mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag (limited to 'Software/Visual_Studio/Web/Tango.MachineService.Gateway') diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs index 52036e46b..e3391cd5d 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs @@ -4,15 +4,37 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; +using Tango.MachineService.Gateway.DB; +using Tango.MachineService.Gateway.DTO; +using Tango.MachineService.Gateway.Messages; +using Tango.Web.Controllers; namespace Tango.MachineService.Gateway.Controllers { - public class GatewayController : ApiController + public class GatewayController : TangoController { [HttpPost] - public String GetUrl() + public EnvironmentsResponse GetEnvironments(EnvironmentsRequest request) { - return "URL"; + EnvironmentsResponse response = new EnvironmentsResponse(); + + using (GatewayDbContext db = GatewayDbContext.CreateDefault()) + { + var envs = db.Environments.ToList(); + + foreach (var env in envs) + { + response.Environments.Add(new EnvironmentConfiguration() + { + ID = env.ID.ToString(), + Name = env.Name, + Description = env.Description, + MachineServiceAddress = env.MachineServiceAddress + }); + } + } + + return response; } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs new file mode 100644 index 000000000..66cd2ff0c --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Gateway.DB +{ + [Table("ENVIRONMENTS")] + public class Environment + { + [Column("ID")] + public int ID { get; set; } + + [Column("NAME")] + public String Name { get; set; } + + [Column("DESCRIPTION")] + public String Description { get; set; } + + [Column("MACHINE_SERVICE_ADDRESS")] + public String MachineServiceAddress { get; set; } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs new file mode 100644 index 000000000..9f4a9f0f9 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Web; +using Tango.Core; + +namespace Tango.MachineService.Gateway.DB +{ + public class GatewayDbContext : DbContext + { + public GatewayDbContext(DataSource dataSource) : base(dataSource.ToConnection(), true) + { + + } + + public static GatewayDbContext CreateDefault() + { + return new GatewayDbContext(new DataSource() + { + Address = GatewayConfig.DB_ADDRESS, + IntegratedSecurity = false, + Catalog = GatewayConfig.DB_CATALOG, + Type = DataSourceType.SQLServer, + UserName = GatewayConfig.DB_USER_NAME, + Password = GatewayConfig.DB_PASSWORD + }); + } + + /// + /// Gets or sets the environments. + /// + public DbSet Environments + { + get; set; + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs new file mode 100644 index 000000000..0da9de5e5 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Gateway.DTO +{ + public class EnvironmentConfiguration + { + public String ID { get; set; } + public String Name { get; set; } + public String Description { get; set; } + public String MachineServiceAddress { get; set; } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs index e7ad241ed..dbbb10709 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs @@ -9,6 +9,11 @@ namespace Tango.MachineService.Gateway { public class GatewayConfig { + 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 JWT_TOKEN_SECRET => ConfigurationManager.AppSettings[nameof(JWT_TOKEN_SECRET)].ToString(); public static String AZURE_UTILS_GROUP => ConfigurationManager.AppSettings[nameof(AZURE_UTILS_GROUP)].ToString(); public static String TENANT_ID => ConfigurationManager.AppSettings[nameof(TENANT_ID)].ToString(); diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs new file mode 100644 index 000000000..6d2ab0f8d --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Gateway.Messages +{ + public class EnvironmentsRequest + { + public String AppSecret { get; set; } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs new file mode 100644 index 000000000..2063d5e59 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Tango.MachineService.Gateway.DTO; + +namespace Tango.MachineService.Gateway.Messages +{ + public class EnvironmentsResponse + { + public List Environments { get; set; } + + public EnvironmentsResponse() + { + Environments = new List(); + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag new file mode 100644 index 000000000..d3db33524 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag @@ -0,0 +1,140 @@ +{ + "runtime": "Default", + "defaultVariables": "", + "documentGenerator": { + "webApiToOpenApi": { + "controllerNames": [ + "Tango.MachineService.Gateway.Controllers.GatewayController" + ], + "isAspNetCore": false, + "resolveJsonOptions": false, + "defaultUrlTemplate": "api/{controller}/{action}", + "addMissingPathParameters": false, + "includedVersions": null, + "defaultPropertyNameHandling": "Default", + "defaultReferenceTypeNullHandling": "Null", + "defaultDictionaryValueReferenceTypeNullHandling": "NotNull", + "defaultResponseReferenceTypeNullHandling": "NotNull", + "defaultEnumHandling": "Integer", + "flattenInheritanceHierarchy": false, + "generateKnownTypes": true, + "generateEnumMappingDescription": false, + "generateXmlObjects": false, + "generateAbstractProperties": false, + "generateAbstractSchemas": true, + "ignoreObsoleteProperties": false, + "allowReferencesWithProperties": false, + "excludedTypeNames": [], + "serviceHost": null, + "serviceBasePath": null, + "serviceSchemes": [], + "infoTitle": "My Title", + "infoDescription": null, + "infoVersion": "1.0.0", + "documentTemplate": null, + "documentProcessorTypes": [], + "operationProcessorTypes": [], + "typeNameGeneratorType": null, + "schemaNameGeneratorType": null, + "contractResolverType": null, + "serializerSettingsType": null, + "useDocumentProvider": true, + "documentName": "v1", + "aspNetCoreEnvironment": null, + "createWebHostBuilderMethod": null, + "startupType": null, + "allowNullableBodyParameters": true, + "output": null, + "outputType": "Swagger2", + "assemblyPaths": [ + "$(assembly)" + ], + "assemblyConfig": null, + "referencePaths": [], + "useNuGetCache": false + } + }, + "codeGenerators": { + "openApiToCSharpClient": { + "clientBaseClass": null, + "configurationClass": null, + "generateClientClasses": true, + "generateClientInterfaces": false, + "injectHttpClient": true, + "disposeHttpClient": true, + "protectedMethods": [], + "generateExceptionClasses": true, + "exceptionClass": "ApiException", + "wrapDtoExceptions": true, + "useHttpClientCreationMethod": false, + "httpClientType": "System.Net.Http.HttpClient", + "useHttpRequestMessageCreationMethod": false, + "useBaseUrl": true, + "generateBaseUrlProperty": true, + "generateSyncMethods": true, + "exposeJsonSerializerSettings": false, + "clientClassAccessModifier": "public", + "typeAccessModifier": "public", + "generateContractsOutput": false, + "contractsNamespace": null, + "contractsOutputFilePath": null, + "parameterDateTimeFormat": "s", + "parameterDateFormat": "yyyy-MM-dd", + "generateUpdateJsonSerializerSettingsMethod": true, + "useRequestAndResponseSerializationSettings": false, + "serializeTypeInformation": false, + "queryNullValue": "", + "className": "GatewayClient", + "operationGenerationMode": "MultipleClientsFromOperationId", + "additionalNamespaceUsages": [], + "additionalContractNamespaceUsages": [], + "generateOptionalParameters": false, + "generateJsonMethods": false, + "enforceFlagEnums": false, + "parameterArrayType": "System.Collections.Generic.IEnumerable", + "parameterDictionaryType": "System.Collections.Generic.IDictionary", + "responseArrayType": "System.Collections.Generic.ICollection", + "responseDictionaryType": "System.Collections.Generic.IDictionary", + "wrapResponses": false, + "wrapResponseMethods": [], + "generateResponseClasses": true, + "responseClass": "SwaggerResponse", + "namespace": "Tango.MachineService.Gateway", + "requiredPropertiesMustBeDefined": true, + "dateType": "System.DateTimeOffset", + "jsonConverters": null, + "anyType": "object", + "dateTimeType": "System.DateTimeOffset", + "timeType": "System.TimeSpan", + "timeSpanType": "System.TimeSpan", + "arrayType": "System.Collections.Generic.ICollection", + "arrayInstanceType": "System.Collections.ObjectModel.Collection", + "dictionaryType": "System.Collections.Generic.IDictionary", + "dictionaryInstanceType": "System.Collections.Generic.Dictionary", + "arrayBaseType": "System.Collections.ObjectModel.Collection", + "dictionaryBaseType": "System.Collections.Generic.Dictionary", + "classStyle": "Poco", + "generateDefaultValues": true, + "generateDataAnnotations": true, + "excludedTypeNames": [], + "excludedParameterNames": [], + "handleReferences": false, + "generateImmutableArrayProperties": false, + "generateImmutableDictionaryProperties": false, + "jsonSerializerSettingsTransformationMethod": null, + "inlineNamedArrays": false, + "inlineNamedDictionaries": false, + "inlineNamedTuples": true, + "inlineNamedAny": false, + "generateDtoTypes": true, + "generateOptionalPropertiesAsNullable": false, + "templateDirectory": null, + "typeNameGeneratorType": null, + "propertyNameGeneratorType": null, + "enumNameGeneratorType": null, + "serviceHost": null, + "serviceSchemes": null, + "output": "$(output)" + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj index c1f3b59bd..f749f7f57 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj @@ -45,6 +45,12 @@ 4 + + ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll + + + ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + ..\..\packages\JWT.5.0.0\lib\net46\JWT.dll True @@ -161,6 +167,7 @@ + @@ -244,18 +251,25 @@ + + + Global.asax + + - + + Designer + Web.config @@ -270,7 +284,10 @@ - + + + Designer + @@ -287,6 +304,9 @@ Tango.Logging + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config index f53e9c92e..6dd29d57d 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config @@ -4,30 +4,28 @@ https://go.microsoft.com/fwlink/?LinkId=301879 --> + + +
+ - - - + - - - - @@ -104,4 +102,13 @@ - + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config index 8f284e11d..72f15dbf6 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config +++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config @@ -2,6 +2,7 @@ + -- cgit v1.3.1