From 59827c1a5646e2599e2bb97f83ebea2a591d0d83 Mon Sep 17 00:00:00 2001 From: Michael Stephenson Date: Sat, 2 Oct 2021 22:50:51 +0200 Subject: [PATCH] Add project files. --- .dockerignore | 25 ++++ Common/Common.csproj | 7 ++ Common/WeatherForecast.cs | 20 ++++ .../WeatherForecastsPersistorController.cs | 108 ++++++++++++++++++ DataPersistor/Data/DataPersistorContext.cs | 19 +++ DataPersistor/DataPersistor.csproj | 26 +++++ DataPersistor/Dockerfile | 22 ++++ DataPersistor/Program.cs | 26 +++++ .../local/appInsights1.arm.json | 67 +++++++++++ DataPersistor/Properties/launchSettings.json | 38 ++++++ .../Properties/serviceDependencies.json | 15 +++ .../Properties/serviceDependencies.local.json | 17 +++ DataPersistor/Startup.cs | 65 +++++++++++ DataPersistor/appsettings.Development.json | 9 ++ DataPersistor/appsettings.json | 16 +++ .../Controllers/WeatherForecastController.cs | 40 +++++++ DataProvider/DataProvider.csproj | 20 ++++ DataProvider/Dockerfile | 22 ++++ DataProvider/Program.cs | 26 +++++ .../local/appInsights1.arm.json | 67 +++++++++++ DataProvider/Properties/launchSettings.json | 38 ++++++ .../Properties/serviceDependencies.json | 11 ++ .../Properties/serviceDependencies.local.json | 13 +++ DataProvider/Startup.cs | 60 ++++++++++ DataProvider/appsettings.Development.json | 9 ++ DataProvider/appsettings.json | 13 +++ TestPersistence.sln | 37 ++++++ 27 files changed, 836 insertions(+) create mode 100644 .dockerignore create mode 100644 Common/Common.csproj create mode 100644 Common/WeatherForecast.cs create mode 100644 DataPersistor/Controllers/WeatherForecastsPersistorController.cs create mode 100644 DataPersistor/Data/DataPersistorContext.cs create mode 100644 DataPersistor/DataPersistor.csproj create mode 100644 DataPersistor/Dockerfile create mode 100644 DataPersistor/Program.cs create mode 100644 DataPersistor/Properties/ServiceDependencies/local/appInsights1.arm.json create mode 100644 DataPersistor/Properties/launchSettings.json create mode 100644 DataPersistor/Properties/serviceDependencies.json create mode 100644 DataPersistor/Properties/serviceDependencies.local.json create mode 100644 DataPersistor/Startup.cs create mode 100644 DataPersistor/appsettings.Development.json create mode 100644 DataPersistor/appsettings.json create mode 100644 DataProvider/Controllers/WeatherForecastController.cs create mode 100644 DataProvider/DataProvider.csproj create mode 100644 DataProvider/Dockerfile create mode 100644 DataProvider/Program.cs create mode 100644 DataProvider/Properties/ServiceDependencies/local/appInsights1.arm.json create mode 100644 DataProvider/Properties/launchSettings.json create mode 100644 DataProvider/Properties/serviceDependencies.json create mode 100644 DataProvider/Properties/serviceDependencies.local.json create mode 100644 DataProvider/Startup.cs create mode 100644 DataProvider/appsettings.Development.json create mode 100644 DataProvider/appsettings.json create mode 100644 TestPersistence.sln diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/Common/Common.csproj b/Common/Common.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/Common/Common.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/Common/WeatherForecast.cs b/Common/WeatherForecast.cs new file mode 100644 index 0000000..f87820d --- /dev/null +++ b/Common/WeatherForecast.cs @@ -0,0 +1,20 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; + +namespace Common +{ + public class WeatherForecast + { + [JsonIgnore] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public string Summary { get; set; } + + public string Location { get; set; } + } +} diff --git a/DataPersistor/Controllers/WeatherForecastsPersistorController.cs b/DataPersistor/Controllers/WeatherForecastsPersistorController.cs new file mode 100644 index 0000000..7e8b664 --- /dev/null +++ b/DataPersistor/Controllers/WeatherForecastsPersistorController.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Common; +using DataPersistor.Data; + +namespace DataPersistor.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class WeatherForecastsPersistorController : ControllerBase + { + private readonly DataPersistorContext _context; + + public WeatherForecastsPersistorController(DataPersistorContext context) + { + _context = context; + } + + // GET: api/WeatherForecastsPersistor + [HttpGet] + public async Task>> GetWeatherForecast() + { + return await _context.WeatherForecast.ToListAsync(); + } + + // GET: api/WeatherForecastsPersistor/5 + [HttpGet("{id}")] + public async Task> GetWeatherForecast(int id) + { + var weatherForecast = await _context.WeatherForecast.FindAsync(id); + + if (weatherForecast == null) + { + return NotFound(); + } + + return weatherForecast; + } + + // PUT: api/WeatherForecastsPersistor/5 + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPut("{id}")] + public async Task PutWeatherForecast(int id, WeatherForecast weatherForecast) + { + if (id != weatherForecast.Id) + { + return BadRequest(); + } + + _context.Entry(weatherForecast).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!WeatherForecastExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/WeatherForecastsPersistor + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPost] + public async Task> PostWeatherForecast(WeatherForecast weatherForecast) + { + _context.WeatherForecast.Add(weatherForecast); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetWeatherForecast", new { id = weatherForecast.Id }, weatherForecast); + } + + // DELETE: api/WeatherForecastsPersistor/5 + [HttpDelete("{id}")] + public async Task DeleteWeatherForecast(int id) + { + var weatherForecast = await _context.WeatherForecast.FindAsync(id); + if (weatherForecast == null) + { + return NotFound(); + } + + _context.WeatherForecast.Remove(weatherForecast); + await _context.SaveChangesAsync(); + + return NoContent(); + } + + private bool WeatherForecastExists(int id) + { + return _context.WeatherForecast.Any(e => e.Id == id); + } + } +} diff --git a/DataPersistor/Data/DataPersistorContext.cs b/DataPersistor/Data/DataPersistorContext.cs new file mode 100644 index 0000000..5617bb8 --- /dev/null +++ b/DataPersistor/Data/DataPersistorContext.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Common; + +namespace DataPersistor.Data +{ + public class DataPersistorContext : DbContext + { + public DataPersistorContext (DbContextOptions options) + : base(options) + { + } + + public DbSet WeatherForecast { get; set; } + } +} diff --git a/DataPersistor/DataPersistor.csproj b/DataPersistor/DataPersistor.csproj new file mode 100644 index 0000000..ff3cd4b --- /dev/null +++ b/DataPersistor/DataPersistor.csproj @@ -0,0 +1,26 @@ + + + + net5.0 + 3b3dafd7-1a43-4d83-bc53-1350d82f9fe7 + Linux + /subscriptions/206ee0c3-cbc6-403d-9e80-39628698ac8d/resourceGroups/app-insights/providers/microsoft.insights/components/DataProvider + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/DataPersistor/Dockerfile b/DataPersistor/Dockerfile new file mode 100644 index 0000000..e7eda5b --- /dev/null +++ b/DataPersistor/Dockerfile @@ -0,0 +1,22 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build +WORKDIR /src +COPY ["DataPersistor/DataPersistor.csproj", "DataPersistor/"] +RUN dotnet restore "DataPersistor/DataPersistor.csproj" +COPY . . +WORKDIR "/src/DataPersistor" +RUN dotnet build "DataPersistor.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "DataPersistor.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "DataPersistor.dll"] \ No newline at end of file diff --git a/DataPersistor/Program.cs b/DataPersistor/Program.cs new file mode 100644 index 0000000..14e95e8 --- /dev/null +++ b/DataPersistor/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace DataPersistor +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/DataPersistor/Properties/ServiceDependencies/local/appInsights1.arm.json b/DataPersistor/Properties/ServiceDependencies/local/appInsights1.arm.json new file mode 100644 index 0000000..305ae83 --- /dev/null +++ b/DataPersistor/Properties/ServiceDependencies/local/appInsights1.arm.json @@ -0,0 +1,67 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "app-insights", + "metadata": { + "_parameterType": "resourceGroup", + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "westeurope", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource group. Resource groups could have different location than resources." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('DataProvider', subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "name": "DataProvider", + "type": "microsoft.insights/components", + "location": "[parameters('resourceLocation')]", + "kind": "web", + "properties": {}, + "apiVersion": "2015-05-01" + } + ] + } + } + } + ], + "metadata": { + "_dependencyType": "appInsights.azure" + } +} \ No newline at end of file diff --git a/DataPersistor/Properties/launchSettings.json b/DataPersistor/Properties/launchSettings.json new file mode 100644 index 0000000..95bb3d0 --- /dev/null +++ b/DataPersistor/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:45496", + "sslPort": 44368 + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "DataPersistor": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": "true", + "applicationUrl": "https://localhost:5001;http://localhost:5000" + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true + } + } +} \ No newline at end of file diff --git a/DataPersistor/Properties/serviceDependencies.json b/DataPersistor/Properties/serviceDependencies.json new file mode 100644 index 0000000..79cd5a9 --- /dev/null +++ b/DataPersistor/Properties/serviceDependencies.json @@ -0,0 +1,15 @@ +{ + "dependencies": { + "mssql1": { + "type": "mssql", + "connectionId": "ConnectionStrings:DataPersistorContext" + }, + "secrets1": { + "type": "secrets" + }, + "appInsights1": { + "type": "appInsights", + "connectionId": "APPINSIGHTS_CONNECTIONSTRING" + } + } +} \ No newline at end of file diff --git a/DataPersistor/Properties/serviceDependencies.local.json b/DataPersistor/Properties/serviceDependencies.local.json new file mode 100644 index 0000000..b2159a4 --- /dev/null +++ b/DataPersistor/Properties/serviceDependencies.local.json @@ -0,0 +1,17 @@ +{ + "dependencies": { + "mssql1": { + "type": "mssql.local", + "connectionId": "ConnectionStrings:DataPersistorContext" + }, + "secrets1": { + "type": "secrets.user" + }, + "appInsights1": { + "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/microsoft.insights/components/DataProvider", + "type": "appInsights.azure", + "connectionId": "APPINSIGHTS_CONNECTIONSTRING", + "secretStore": "LocalSecretsFile" + } + } +} \ No newline at end of file diff --git a/DataPersistor/Startup.cs b/DataPersistor/Startup.cs new file mode 100644 index 0000000..249205e --- /dev/null +++ b/DataPersistor/Startup.cs @@ -0,0 +1,65 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using DataPersistor.Data; + +namespace DataPersistor +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "DataPersistor", Version = "v1" }); + }); + + services.AddDbContext(options => + options.UseSqlServer(Configuration.GetConnectionString("DataPersistorContext"))); + services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DataPersistor v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/DataPersistor/appsettings.Development.json b/DataPersistor/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/DataPersistor/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/DataPersistor/appsettings.json b/DataPersistor/appsettings.json new file mode 100644 index 0000000..e7795dd --- /dev/null +++ b/DataPersistor/appsettings.json @@ -0,0 +1,16 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "DataPersistorContext": "Server=(localdb)\\mssqllocaldb;Database=DataPersistorContext-edba02bc-fa40-457a-97df-371c2ccdb2f9;Trusted_Connection=True;MultipleActiveResultSets=true" + }, + "ApplicationInsights": { + "ConnectionString": "InstrumentationKey=e6fc80dc-b84b-4f87-b919-4244915d7fed;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/" + } +} \ No newline at end of file diff --git a/DataProvider/Controllers/WeatherForecastController.cs b/DataProvider/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..f25c7b9 --- /dev/null +++ b/DataProvider/Controllers/WeatherForecastController.cs @@ -0,0 +1,40 @@ +using Common; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace DataProvider.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get(DateTime start, int numberDays) + { + var rng = new Random(); + return Enumerable.Range(0, numberDays).Select(index => new WeatherForecast + { + Date = start.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/DataProvider/DataProvider.csproj b/DataProvider/DataProvider.csproj new file mode 100644 index 0000000..b6d938a --- /dev/null +++ b/DataProvider/DataProvider.csproj @@ -0,0 +1,20 @@ + + + + net5.0 + a2311eb1-c3ec-4e26-8434-d15e82985f00 + Linux + /subscriptions/206ee0c3-cbc6-403d-9e80-39628698ac8d/resourcegroups/app-insights/providers/Microsoft.Insights/components/DataProvider + + + + + + + + + + + + + diff --git a/DataProvider/Dockerfile b/DataProvider/Dockerfile new file mode 100644 index 0000000..10bd62c --- /dev/null +++ b/DataProvider/Dockerfile @@ -0,0 +1,22 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build +WORKDIR /src +COPY ["DataProvider/DataProvider.csproj", "DataProvider/"] +RUN dotnet restore "DataProvider/DataProvider.csproj" +COPY . . +WORKDIR "/src/DataProvider" +RUN dotnet build "DataProvider.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "DataProvider.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "DataProvider.dll"] \ No newline at end of file diff --git a/DataProvider/Program.cs b/DataProvider/Program.cs new file mode 100644 index 0000000..00118d1 --- /dev/null +++ b/DataProvider/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace DataProvider +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/DataProvider/Properties/ServiceDependencies/local/appInsights1.arm.json b/DataProvider/Properties/ServiceDependencies/local/appInsights1.arm.json new file mode 100644 index 0000000..305ae83 --- /dev/null +++ b/DataProvider/Properties/ServiceDependencies/local/appInsights1.arm.json @@ -0,0 +1,67 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "app-insights", + "metadata": { + "_parameterType": "resourceGroup", + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "westeurope", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource group. Resource groups could have different location than resources." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('DataProvider', subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "name": "DataProvider", + "type": "microsoft.insights/components", + "location": "[parameters('resourceLocation')]", + "kind": "web", + "properties": {}, + "apiVersion": "2015-05-01" + } + ] + } + } + } + ], + "metadata": { + "_dependencyType": "appInsights.azure" + } +} \ No newline at end of file diff --git a/DataProvider/Properties/launchSettings.json b/DataProvider/Properties/launchSettings.json new file mode 100644 index 0000000..524f52b --- /dev/null +++ b/DataProvider/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:56707", + "sslPort": 44385 + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "DataProvider": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": "true", + "applicationUrl": "https://localhost:5001;http://localhost:5000" + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true + } + } +} \ No newline at end of file diff --git a/DataProvider/Properties/serviceDependencies.json b/DataProvider/Properties/serviceDependencies.json new file mode 100644 index 0000000..fa44c13 --- /dev/null +++ b/DataProvider/Properties/serviceDependencies.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "secrets1": { + "type": "secrets" + }, + "appInsights1": { + "type": "appInsights", + "connectionId": "APPINSIGHTS_CONNECTIONSTRING" + } + } +} \ No newline at end of file diff --git a/DataProvider/Properties/serviceDependencies.local.json b/DataProvider/Properties/serviceDependencies.local.json new file mode 100644 index 0000000..f7edc16 --- /dev/null +++ b/DataProvider/Properties/serviceDependencies.local.json @@ -0,0 +1,13 @@ +{ + "dependencies": { + "secrets1": { + "type": "secrets.user" + }, + "appInsights1": { + "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourcegroups/[parameters('resourceGroupName')]/providers/Microsoft.Insights/components/DataProvider", + "type": "appInsights.azure", + "connectionId": "APPINSIGHTS_CONNECTIONSTRING", + "secretStore": "LocalSecretsFile" + } + } +} \ No newline at end of file diff --git a/DataProvider/Startup.cs b/DataProvider/Startup.cs new file mode 100644 index 0000000..3ee57f8 --- /dev/null +++ b/DataProvider/Startup.cs @@ -0,0 +1,60 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace DataProvider +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "DataProvider", Version = "v1" }); + }); + services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DataProvider v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/DataProvider/appsettings.Development.json b/DataProvider/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/DataProvider/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/DataProvider/appsettings.json b/DataProvider/appsettings.json new file mode 100644 index 0000000..9cb012d --- /dev/null +++ b/DataProvider/appsettings.json @@ -0,0 +1,13 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "ApplicationInsights": { + "ConnectionString": "InstrumentationKey=e6fc80dc-b84b-4f87-b919-4244915d7fed;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/" + } +} \ No newline at end of file diff --git a/TestPersistence.sln b/TestPersistence.sln new file mode 100644 index 0000000..a52e227 --- /dev/null +++ b/TestPersistence.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31702.278 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataProvider", "DataProvider\DataProvider.csproj", "{2B16E89A-4AAB-41EB-BF0D-F980BBC76328}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataPersistor", "DataPersistor\DataPersistor.csproj", "{295AD1BD-AA3E-4B46-A3BB-599BFE46B199}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{07CE3B0C-E99F-4658-9BB1-37CB630542B2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2B16E89A-4AAB-41EB-BF0D-F980BBC76328}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B16E89A-4AAB-41EB-BF0D-F980BBC76328}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B16E89A-4AAB-41EB-BF0D-F980BBC76328}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B16E89A-4AAB-41EB-BF0D-F980BBC76328}.Release|Any CPU.Build.0 = Release|Any CPU + {295AD1BD-AA3E-4B46-A3BB-599BFE46B199}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {295AD1BD-AA3E-4B46-A3BB-599BFE46B199}.Debug|Any CPU.Build.0 = Debug|Any CPU + {295AD1BD-AA3E-4B46-A3BB-599BFE46B199}.Release|Any CPU.ActiveCfg = Release|Any CPU + {295AD1BD-AA3E-4B46-A3BB-599BFE46B199}.Release|Any CPU.Build.0 = Release|Any CPU + {07CE3B0C-E99F-4658-9BB1-37CB630542B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07CE3B0C-E99F-4658-9BB1-37CB630542B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07CE3B0C-E99F-4658-9BB1-37CB630542B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07CE3B0C-E99F-4658-9BB1-37CB630542B2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E29ABDD4-F9E8-4E77-A73C-E2EBA28575DC} + EndGlobalSection +EndGlobal