Compare commits

14 Commits

Author SHA1 Message Date
Roland Fieger
3abaf417a9 merge commit 2021-11-26 10:02:35 +01:00
Roland Fieger
31540dbfe6 SearchLogic extended 2021-11-26 10:00:58 +01:00
Roland Fieger
380dd7d577 net 6 fixes 2021-10-19 12:41:53 +02:00
Roland Fieger
b2c0c7517a some mysql fixes - not working 2021-10-15 09:54:05 +02:00
Roland Fieger
505487a345 net 6 migration 2021-10-15 09:14:09 +02:00
Roland Fieger
f8c6316d4e Migration to net 6 - not working for now 2021-10-14 16:53:06 +02:00
Roland Fieger
e9d30aad16 OP and Logging to Elasticsearch 2021-10-12 16:42:24 +02:00
Roland Fieger
66f8d19f67 OP changes 2021-10-12 11:22:16 +02:00
Roland Fieger
fdc816624e some OP 2021-10-12 10:55:47 +02:00
Roland Fieger
c384e3bdca swagger, lauch, tasks 2021-10-08 12:17:50 +02:00
Roland Fieger
a28799273b Merge branch 'master' into develop 2021-09-22 12:38:13 +02:00
Roland Fieger
b7f04522ce cred test 2021-08-28 15:45:37 +02:00
Roland Fieger
3b5ae86ce5 First idea of ResultModel 2021-08-28 15:40:03 +02:00
Roland Fieger
2de05c3856 Initial 2021-08-28 13:11:33 +02:00
23 changed files with 472 additions and 134 deletions

36
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/SearchWebApi/bin/Debug/net6.0/SearchWebApi.dll",
"args": [],
"cwd": "${workspaceFolder}/SearchWebApi",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

44
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,44 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
"${workspaceFolder}/SearchWebApi/SearchWebApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/SearchWebApi/SearchWebApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/SearchWebApi/SearchWebApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -27,6 +27,7 @@ namespace BusinessLogic.LookupLogic
public async Task<DataResult<List<LookupCategory>>> GetAllLookups() public async Task<DataResult<List<LookupCategory>>> GetAllLookups()
{ {
var result = await _lookupRepo.GetAllLookups(); var result = await _lookupRepo.GetAllLookups();
_logger.LogInformation($"Call to GetAllLookups ended with {result.GeneralResult.ToString()}");
return result; return result;
} }

View File

@@ -1,17 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ItemGroup> <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.16" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.16" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ItemGroup> <ProjectReference Include="..\..\Datamodels\Datamodels.csproj" />
<ProjectReference Include="..\..\Datamodels\Datamodels.csproj" /> <ProjectReference Include="..\..\Repositories\Repositories.csproj" />
<ProjectReference Include="..\..\Repositories\Repositories.csproj" /> </ItemGroup>
</ItemGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PropertyGroup> </PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> </Project>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
using System;
namespace SearchApi.Exceptions
{
public class FieldAliasMissingException : Exception
{
public FieldAliasMissingException(string message) : base(message: message) {}
}
}

View File

@@ -0,0 +1,9 @@
using System;
namespace SearchApi.Exceptions
{
public class TableAliasMissingException : Exception
{
public TableAliasMissingException(string message) : base(message: message) {}
}
}

View File

@@ -6,7 +6,7 @@ using Datamodels.BusinessModels;
using Datamodels.DatabaseModels; using Datamodels.DatabaseModels;
using Datamodels.SearchModels; using Datamodels.SearchModels;
namespace SearchLogic namespace SearchApi.SearchLogic
{ {
public interface ISearchLogic public interface ISearchLogic
{ {

View File

@@ -9,14 +9,22 @@ using Datamodels.SearchModels;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using SearchApi.Exceptions;
using Datamodels.Enums;
namespace SearchLogic namespace SearchApi.SearchLogic
{ {
public class SearchLogic : ISearchLogic public class SearchLogic : ISearchLogic
{ {
private readonly ILogger<SearchLogic> _logger; private readonly ILogger<SearchLogic> _logger;
private readonly IFwMariaSearchRepo _searchRepo; private readonly IFwMariaSearchRepo _searchRepo;
private List<string> _tableNames = new List<string>();
private List<string> _joinConditions = new List<string>();
private List<string> _fieldNames = new List<string>();
private List<string> _whereConditions = new List<string>();
private List<string> _sortFields = new List<string>();
public SearchLogic(ILogger<SearchLogic> logger, IFwMariaSearchRepo searchRepo) public SearchLogic(ILogger<SearchLogic> logger, IFwMariaSearchRepo searchRepo)
{ {
_logger = logger; _logger = logger;
@@ -34,8 +42,143 @@ namespace SearchLogic
var result = new DataResult<ResultModel>(); var result = new DataResult<ResultModel>();
result.Data = new ResultModel(); result.Data = new ResultModel();
result.Data.SearchModel = filter; result.Data.SearchModel = filter;
var sql = await Task.Run(() => { return AssembleSqlQuery(filter); } );
return result; return result;
} }
// Extract Table
private void GetTables(FilterModel filter)
{
bool hasTableList = filter.TableDescriptions.Count > 0;
_tableNames = new List<string>();
foreach(var table in filter.TableDescriptions)
{
if (hasTableList && string.IsNullOrEmpty(table.TableAlias))
{
throw new TableAliasMissingException($"No Alias defined for Table {table.TableName}");
}
_tableNames.Add($"{table.TableName} {(string.IsNullOrEmpty(table.TableAlias) ? string.Empty : table.TableAlias)}");
}
}
// Extract Fieldlist
private void GetFields(FilterModel filter)
{
var tables = filter.TableDescriptions;
foreach (var table in tables)
{
bool hasMultipleFields = table.Fields.Count > 0;
foreach (var field in table.Fields) {
if (hasMultipleFields && string.IsNullOrEmpty(field.FieldAlias))
{
throw new FieldAliasMissingException($"No Alias defined for Field {field.FieldName} in Table {table.TableName}");
}
_fieldNames.Add($"{table.TableAlias}.{field.FieldName} {field.FieldAlias}");
}
}
}
// Extract Join Path if more than one table
private void GetTableJoinConditions(FilterModel filter)
{
}
// Extract Where Conditions
// ToDo: wenn es mehrere Values gibt, werden die generell mit OR verknüpft? Oder nehmen wir lieber AND?
private void GetWhereConditions(string tableName, FieldModel field)
{
if (field.SearchDescriptions.Count > 0)
{
foreach (var condition in field.SearchDescriptions)
{
var op = Operator(condition.SearchData.PhraseOperator);
if (op != "NOTHING")
{
var usedField = $"{tableName}.{field.FieldName}{op}{condition.SearchData.Values[0]}";
_whereConditions.Add(usedField);
}
else
{
if (condition.SearchData.PhraseOperator == PhraseOperators.Contains)
{
var usedField = $"{tableName}.{field.FieldName} like '%{condition.SearchData.Values[0]}%'";
_whereConditions.Add(usedField);
}
if (condition.SearchData.PhraseOperator == PhraseOperators.StartsWith)
{
var usedField = $"{tableName}.{field.FieldName} like '%{condition.SearchData.Values[0]}'";
_whereConditions.Add(usedField);
}
if (condition.SearchData.PhraseOperator == PhraseOperators.EndsWith)
{
var usedField = $"{tableName}.{field.FieldName} like '{condition.SearchData.Values[0]} + %'";
_whereConditions.Add(usedField);
}
}
}
}
}
public string Operator(PhraseOperators ops)
{
switch (ops)
{
case PhraseOperators.Equal:
return "=";
case PhraseOperators.NotEqual:
return "!=";
case PhraseOperators.GreaterThan:
return ">";
case PhraseOperators.GreaterThanOrEqual:
return ">=";
case PhraseOperators.LowerThan:
return "<";
case PhraseOperators.LowerThanOrEqual:
return "<=";
default:
return "NOTHING";
}
}
// Extract Sort Items
private void GetSortFields(FilterModel filter)
{
}
// Assemble SQL Query
private string AssembleSqlQuery(FilterModel filter)
{
GetTables(filter);
GetFields(filter);
var result = BuildSql();
return result;
}
//Build SQL String itself
private string BuildSql()
{
var sql = "SELECT ";
foreach (var field in _fieldNames)
{
sql += field.ToUpper();
if (_fieldNames.IndexOf(field) < _fieldNames.Count - 1) sql += ",";
}
sql += " FROM ";
foreach (var table in _tableNames)
{
sql += table.ToUpper();
if (_tableNames.IndexOf(table) < _tableNames.Count - 1)
{
sql += ",";
}
}
return sql;
}
} }
} }

View File

@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>net6.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup> </ItemGroup>

View File

@@ -13,8 +13,8 @@ namespace Repositories
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
var version = new MariaDbServerVersion(new Version(10,5));
optionsBuilder.UseMySql(_connectionString); optionsBuilder.UseMySql(_connectionString, version);
} }
public DbSet<LookupCategory> LookupCategories { get; set; } public DbSet<LookupCategory> LookupCategories { get; set; }

View File

@@ -8,6 +8,7 @@ using Repositories.Interfaces;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using System.Configuration;
namespace Repositories namespace Repositories
{ {
@@ -26,11 +27,11 @@ namespace Repositories
{ {
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{ {
_dbContext._connectionString = "SERVER=127.0.0.1;DATABASE=testdb;PORT=3306;USER=root;PASSWORD=example"; _dbContext._connectionString = "SERVER=192.168.178.44;DATABASE=fwTest;PORT=3330;USER=root;PASSWORD=$64,Rf1209";
} }
else else
{ {
string usedDb = configuration.GetSection("GeneralSettings").GetSection("DbToUse").Get<string>(); string usedDb = configuration.GetSection("GeneralSettings").GetSection("DbToUse").Value;
string connectionString = configuration.GetConnectionString(usedDb); string connectionString = configuration.GetConnectionString(usedDb);
_dbContext._connectionString = connectionString; _dbContext._connectionString = connectionString;
} }
@@ -55,7 +56,7 @@ namespace Repositories
_logger.LogError(ex, "Error reading Lookup Data"); _logger.LogError(ex, "Error reading Lookup Data");
return new DataResult<List<LookupCategory>> return new DataResult<List<LookupCategory>>
{ {
UserMessage = "Daten f<>r Lookups konnten nicht gelesen werden.", UserMessage = "Daten f<>r Lookups konnten nicht gelesen werden.",
ServerMessage = ex.Message, ServerMessage = ex.Message,
GeneralResult = GeneralResults.DatabaseError, GeneralResult = GeneralResults.DatabaseError,
StackTrace = ex.StackTrace StackTrace = ex.StackTrace
@@ -79,7 +80,7 @@ namespace Repositories
_logger.LogError(ex, $"Error reading Lookup Category with Id: {id}"); _logger.LogError(ex, $"Error reading Lookup Category with Id: {id}");
return new DataResult<LookupCategory> return new DataResult<LookupCategory>
{ {
UserMessage = $"Daten f<>r Lookup Kategorie mit Id {id} konnten nicht gelesen werden.", UserMessage = $"Daten f<>r Lookup Kategorie mit Id {id} konnten nicht gelesen werden.",
ServerMessage = ex.Message, ServerMessage = ex.Message,
GeneralResult = GeneralResults.DatabaseError, GeneralResult = GeneralResults.DatabaseError,
StackTrace = ex.StackTrace StackTrace = ex.StackTrace
@@ -103,7 +104,7 @@ namespace Repositories
_logger.LogError(ex, $"Error reading Lookup Category with Name: {categoryName}"); _logger.LogError(ex, $"Error reading Lookup Category with Name: {categoryName}");
return new DataResult<List<LookupCategory>> return new DataResult<List<LookupCategory>>
{ {
UserMessage = $"Daten f<>r Lookup Kategorie mit Namen {categoryName} konnten nicht gelesen werden.", UserMessage = $"Daten f<>r Lookup Kategorie mit Namen {categoryName} konnten nicht gelesen werden.",
ServerMessage = ex.Message, ServerMessage = ex.Message,
GeneralResult = GeneralResults.DatabaseError, GeneralResult = GeneralResults.DatabaseError,
StackTrace = ex.StackTrace StackTrace = ex.StackTrace
@@ -127,7 +128,7 @@ namespace Repositories
_logger.LogError(ex, "Error reading active Lookup Data"); _logger.LogError(ex, "Error reading active Lookup Data");
return new DataResult<List<LookupCategory>> return new DataResult<List<LookupCategory>>
{ {
UserMessage = "Daten f<>r aktive Lookups konnten nicht gelesen werden.", UserMessage = "Daten f<>r aktive Lookups konnten nicht gelesen werden.",
ServerMessage = ex.Message, ServerMessage = ex.Message,
GeneralResult = GeneralResults.DatabaseError, GeneralResult = GeneralResults.DatabaseError,
StackTrace = ex.StackTrace StackTrace = ex.StackTrace

View File

@@ -33,7 +33,7 @@ namespace Repositories
} }
else else
{ {
string usedDb = configuration.GetSection("GeneralSettings").GetSection("DbToUse").Get<string>(); string usedDb = configuration.GetSection("GeneralSettings").GetSection("DbToUse").Value;
string connectionString = configuration.GetConnectionString(usedDb); string connectionString = configuration.GetConnectionString(usedDb);
_dbContext._connectionString = connectionString; _dbContext._connectionString = connectionString;
} }

View File

@@ -1,22 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ItemGroup> <ProjectReference Include="..\Datamodels\Datamodels.csproj" />
<ProjectReference Include="..\Datamodels\Datamodels.csproj" /> </ItemGroup>
</ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.16" /> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.16"> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference>
<PrivateAssets>all</PrivateAssets> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
</PackageReference> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.6" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.16" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.16" /> </ItemGroup>
</ItemGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PropertyGroup> </PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> </Project>
</PropertyGroup>
</Project>

View File

@@ -26,7 +26,10 @@ namespace FwSearchApi.Controllers
public async Task<JsonResult> GetAllLookups() public async Task<JsonResult> GetAllLookups()
{ {
var result = await _lookupLogic.GetAllLookups(); var result = await _lookupLogic.GetAllLookups();
_logger.LogInformation($"Lookups zur Verf<72>gung gestellt von {nameof(GetAllLookups)}"); if (result.GeneralResult != Datamodels.BusinessModels.GeneralResults.Success) {
throw new System.Exception("das war wohl nix");
}
_logger.LogInformation($"Lookups zur Verfügung gestellt von {nameof(GetAllLookups)}");
return new JsonResult(result); return new JsonResult(result);
} }

View File

@@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Threading.Tasks; using System.Threading.Tasks;
using SearchLogic; using SearchApi.SearchLogic;
using Datamodels.SearchModels; using Datamodels.SearchModels;
using System.Collections.Generic; using System.Collections.Generic;
using Datamodels.DatabaseModels; using Datamodels.DatabaseModels;

17
SearchWebApi/NuGet.Config Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSourceCredentials>
<Gtue.Framework>
<add key="Username" value="not_needed" />
<add key="ClearTextPassword" value="%NUGET_PAT%" />
</Gtue.Framework>
<Gtue.Welt>
<add key="Username" value="not_needed" />
<add key="ClearTextPassword" value="%NUGET_PAT%" />
</Gtue.Welt>
</packageSourceCredentials>
</configuration>

View File

@@ -1,3 +1,5 @@
using System.Collections.Immutable;
using System.Buffers;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -7,6 +9,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;
using Serilog; using Serilog;
namespace FwSearchApi namespace FwSearchApi
@@ -24,19 +27,41 @@ namespace FwSearchApi
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration) .ReadFrom.Configuration(Configuration)
.CreateLogger(); .CreateLogger();
try { try {
CreateWebHostBuilder(args).Build().Run(); CreateHostBuilder(args).Build().Run();
} }
finally{ finally
{
Log.CloseAndFlush(); Log.CloseAndFlush();
} }
} }
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.UseConfiguration(Configuration) .ConfigureWebHostDefaults(webBuilder =>
.UseStartup<Startup>() {
.UseSerilog() webBuilder.UseStartup<Startup>();
.SuppressStatusMessages(true); webBuilder.UseSerilog();
webBuilder.UseConfiguration(Configuration);
webBuilder.SuppressStatusMessages(true);
})
.ConfigureLogging((context, builder) =>
{
builder.ClearProviders();
builder.AddConsole();
builder.AddSerilog();
builder.AddOpenTelemetry(options =>
{
options.IncludeScopes = true;
options.ParseStateValues = true;
options.IncludeFormattedMessage = true;
options.AddConsoleExporter();
});
});
} }
} }

View File

@@ -1,25 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<PropertyGroup> <TargetFramework>net6.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework> <LangVersion>10</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ItemGroup> <PackageReference Include="Elastic.Apm.EntityFrameworkCore" Version="1.11.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.16" /> <PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.11.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.1.4" /> <PackageReference Include="OpenTelemetry.Contrib.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.1.4" /> <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.1.4" /> <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.1.0" />
</ItemGroup> <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc8" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc8" />
<ItemGroup> <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc8" />
<ProjectReference Include="..\BusinessLogic\LookupLogic\LookupLogic.csproj" /> <PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<ProjectReference Include="..\BusinessLogic\SearchLogic\SearchLogic.csproj" /> <PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<ProjectReference Include="..\Datamodels\Datamodels.csproj" /> <PackageReference Include="Serilog.Enrichers.ExceptionStackTraceHash" Version="1.3.0" />
<ProjectReference Include="..\Repositories\Repositories.csproj" /> <PackageReference Include="Serilog.Exceptions" Version="7.1.0" />
</ItemGroup> <PackageReference Include="Serilog.Formatting.Elasticsearch" Version="8.4.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="serilog.sinks.console" Version="4.0.0" />
</Project> <PackageReference Include="Serilog.Sinks.ElasticSearch" Version="8.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessLogic\LookupLogic\LookupLogic.csproj" />
<ProjectReference Include="..\BusinessLogic\SearchLogic\SearchLogic.csproj" />
<ProjectReference Include="..\Datamodels\Datamodels.csproj" />
<ProjectReference Include="..\Repositories\Repositories.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,20 +1,22 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Repositories;
using Repositories.Interfaces;
using BusinessLogic.LookupLogic; using BusinessLogic.LookupLogic;
using BusinessLogic.LookupLogic.Interfaces; using BusinessLogic.LookupLogic.Interfaces;
using SearchLogic;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Repositories;
using Repositories.Interfaces;
using SearchApi.SearchLogic;
namespace FwSearchApi namespace FwSearchApi
{ {
@@ -24,11 +26,10 @@ namespace FwSearchApi
readonly ILogger<Startup> _logger; readonly ILogger<Startup> _logger;
public IConfiguration _configuration { get; } public IConfiguration _configuration { get; }
public Startup(IConfiguration configuration, ILogger<Startup> logger) public Startup(IConfiguration configuration)
{ {
_configuration = configuration; _configuration = configuration;
_logger = logger;
_logger.LogInformation("Starting up FeatureWerk Search API");
} }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
@@ -42,10 +43,20 @@ namespace FwSearchApi
services.AddTransient<ILookupLogic, FwLookupLogic>(); services.AddTransient<ILookupLogic, FwLookupLogic>();
services.AddTransient<IFwMariaLookupRepo, FwMariaLookupRepo>(); services.AddTransient<IFwMariaLookupRepo, FwMariaLookupRepo>();
services.AddTransient<IFwMariaSearchRepo, FwMariaSearchRepo>(); services.AddTransient<IFwMariaSearchRepo, FwMariaSearchRepo>();
services.AddTransient<ISearchLogic, SearchLogic.SearchLogic>(); services.AddTransient<ISearchLogic, SearchLogic>();
services.AddSwaggerGen(); services.AddSwaggerGen();
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); //needed if no Security is used when calling APM Server
services.AddOpenTelemetryTracing((builder) => builder
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("TxSearchApi"))
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddEntityFrameworkCoreInstrumentation(o => o.SetDbStatementForText = true) //logging of Statement as Span
.AddOtlpExporter(otlpOptions => {
otlpOptions.Endpoint = new Uri("http://192.168.178.44:8200");
}));
_logger.LogInformation("Services for FeatureWerkAPIs configured");
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@@ -1,8 +1,8 @@
{ {
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning", "Default": "Information",
"Microsoft": "Warning", "Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Information"
} }
}, },
@@ -17,24 +17,28 @@
}, },
"Serilog": { "Serilog": {
"MinimumLevel": { "MinimumLevel": {
"Default": "Information", "Default": "Information",
"Override": { "Override": {
"System": "Information", "System": "Information",
"Microsoft": "Warning" "Microsoft": "Information"
} }
}, },
"WriteTo": [ "WriteTo": [
{ "Name": "File", {
"Args": { "Name": "Elasticsearch",
"path": "/tmp/FwSearchApi.log", "Args": {
"rollingInterval": "Day" "nodeUris": "http://192.168.178.44:9200",
} "indexFormat": "TextorSearchLoggingIndex-{0:yyyy.MM}",
} "autoRegisterTemplate": true,
"autoRegisterTemplateVersion": "ESv7",
"registerTemplateFailure": "IndexAnyway"
}
}
], ],
"Enrich": ["FromLogContext", "WithMachineName"], "Enrich": ["FromLogContext", "WithMachineName", "WithProcessId", "WithProcessName"],
"Properties": { "Properties": {
"Appname": "FeatureWerkSearchAPI", "Appname": "TxSearchApi",
"Environment": "Development" "Environment": "Development"
} }
} }
} }

View File

@@ -1,10 +1,42 @@
{ {
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information"
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
} }
}, },
"AllowedHosts": "*" "ElasticApm":
{
"ServerUrl": "http://192.168.178.44:8200",
"SecretToken": "",
"ServiceName": "TxSearchApi",
"Environment": "Development",
"CaptureBody": "all"
},
"AllowedHosts": "*",
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"System": "Information",
"Microsoft": "Information"
}
},
"WriteTo": [
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://192.168.178.44:9200",
"indexFormat": "TextorSearchLoggingIndex-{0:yyyy.MM}",
"autoRegisterTemplate": true,
"autoRegisterTemplateVersion": "ESv7",
"registerTemplateFailure": "IndexAnyway"
}
}
],
"Enrich": ["FromLogContext", "WithMachineName", "WithProcessId", "WithProcessName"],
"Properties": {
"Appname": "TxSearchApi",
"Environment": "Production"
}
}
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

@@ -1,19 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ItemGroup> <ProjectReference Include="..\..\..\Repositories\Repositories.csproj"/>
<ProjectReference Include="..\..\..\Repositories\Repositories.csproj" /> </ItemGroup>
</ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-rc.2.21480.5">
<ItemGroup> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.16"> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference>
<PrivateAssets>all</PrivateAssets> </ItemGroup>
</PackageReference> <PropertyGroup>
</ItemGroup> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PropertyGroup> </PropertyGroup>
<OutputType>Exe</OutputType> </Project>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>