diff options
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService.Gateway')
11 files changed, 314 insertions, 13 deletions
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 + }); + } + + /// <summary> + /// Gets or sets the environments. + /// </summary> + public DbSet<Environment> 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<EnvironmentConfiguration> Environments { get; set; } + + public EnvironmentsResponse() + { + Environments = new List<EnvironmentConfiguration>(); + } + } +}
\ 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 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> + <HintPath>..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath> + </Reference> + <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> + <HintPath>..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath> + </Reference> <Reference Include="JWT, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\..\packages\JWT.5.0.0\lib\net46\JWT.dll</HintPath> <Private>True</Private> @@ -161,6 +167,7 @@ <Reference Include="System.IdentityModel" /> <Reference Include="System.Net" /> <Reference Include="System.Runtime" /> + <Reference Include="System.Security" /> <Reference Include="System.Web.Entity" /> <Reference Include="System.Web.ApplicationServices" /> <Reference Include="System.ComponentModel.DataAnnotations" /> @@ -244,18 +251,25 @@ <Compile Include="Controllers\GatewayController.cs" /> <Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\ValuesController.cs" /> + <Compile Include="DB\Environment.cs" /> + <Compile Include="DB\GatewayDbContext.cs" /> + <Compile Include="DTO\EnvironmentConfiguration.cs" /> <Compile Include="Filters\JwtTokenFilter.cs" /> <Compile Include="Global.asax.cs"> <DependentUpon>Global.asax</DependentUpon> </Compile> <Compile Include="GatewayConfig.cs" /> + <Compile Include="Messages\EnvironmentsRequest.cs" /> + <Compile Include="Messages\EnvironmentsResponse.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="TangoController.cs" /> <Compile Include="WebToken.cs" /> </ItemGroup> <ItemGroup> <Content Include="Global.asax" /> - <Content Include="Web.config" /> + <Content Include="Web.config"> + <SubType>Designer</SubType> + </Content> <Content Include="Web.Debug.config"> <DependentUpon>Web.config</DependentUpon> </Content> @@ -270,7 +284,10 @@ <Folder Include="Models\" /> </ItemGroup> <ItemGroup> - <None Include="packages.config" /> + <Content Include="Nswag\GatewayClient.nswag" /> + <None Include="packages.config"> + <SubType>Designer</SubType> + </None> <None Include="Properties\PublishProfiles\machineservice-gateway - Web Deploy.pubxml" /> </ItemGroup> <ItemGroup> @@ -287,6 +304,9 @@ <Name>Tango.Logging</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> + </ItemGroup> <PropertyGroup> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> 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 --> <configuration> + <configSections> + <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> + <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> + </configSections> <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> - <add key="DB_ADDRESS" value="twine.database.windows.net" /> <add key="DB_USER_NAME" value="Roy" /> <add key="DB_PASSWORD" value="Aa123456" /> - <add key="DB_CATALOG" value="Tango_Gateway" /> - + <add key="DB_CATALOG" value="Gateway" /> <add key="TENANT_ID" value="2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4" /> <add key="CLIENT_ID" value="be33437c-5052-449f-ab9d-a88d008eae24" /> <add key="CLIENT_SECRET" value="bf67fb6f-4d06-4893-988c-6b347aff23d6" /> <add key="SUBSCRIPTION_ID" value="10c8aa60-3b15-4e0d-b412-6aeef90e5e91" /> - <add key="AZURE_UTILS_GROUP" value="Azure Utils" /> - <add key="STORAGE_ACCOUNT" value="DefaultEndpointsProtocol=https;AccountName=tangostorage;AccountKey=S4z/D+Yg6mwMis+bs/VpcDLA9yE1iZaYq23shQlRIi2KmM9E7JY8zdZjeAPOPdG3gONHoNDEpsgH6D4cqQ/bsA==;EndpointSuffix=core.windows.net" /> <add key="TANGO_VERSIONS_CONTAINER" value="tango-versions-dev" /> <add key="MACHINE_STUDIO_VERSIONS_CONTAINER" value="machine-studio-versions-dev" /> - <add key="JWT_TOKEN_SECRET" value="GQDstcKsx0NHjLOuXOYg5MbeJ1yT0u1iwDVTwine" /> - <add key="CDN_ENDPOINT" value="https://tango.azureedge.net" /> </appSettings> <system.web> @@ -104,4 +102,13 @@ <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom> -</configuration> + <entityFramework> + <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> + <providers> + <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> + </providers> + </entityFramework> + <connectionStrings> + <add name="GatewayDbContext" connectionString="metadata=res://*/DB.GatewayDatabaseModel.csdl|res://*/DB.GatewayDatabaseModel.ssdl|res://*/DB.GatewayDatabaseModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost\SQLEXPRESS;initial catalog=Gateway;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> + </connectionStrings> +</configuration>
\ 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 @@ <packages> <package id="Antlr" version="3.5.0.2" targetFramework="net461" /> <package id="bootstrap" version="3.3.7" targetFramework="net461" /> + <package id="EntityFramework" version="6.2.0" targetFramework="net461" /> <package id="jQuery" version="3.3.1" targetFramework="net461" /> <package id="JWT" version="5.0.0" targetFramework="net461" /> <package id="Microsoft.AspNet.Mvc" version="5.2.4" targetFramework="net461" /> |
