use app settings for worker, use http request for getting data
This commit is contained in:
parent
2d7a7c1f61
commit
7d8177688f
@ -1,19 +1,41 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.Production.json" />
|
||||
<None Remove="appsettings.Development.json" />
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BinaryDad.AacpsBusAlert.Services\BinaryDad.AacpsBusAlert.Services.csproj" />
|
||||
<ProjectReference Include="..\BinaryDad.AacpsBusAlert\BinaryDad.AacpsBusAlert.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Production.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<DependentUpon>appsettings.json</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="appsettings.Development.json">
|
||||
<DependentUpon>appsettings.json</DependentUpon>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BinaryDad.AacpsBusAlert.Services\BinaryDad.AacpsBusAlert.Services.csproj" />
|
||||
<ProjectReference Include="..\BinaryDad.AacpsBusAlert\BinaryDad.AacpsBusAlert.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,8 +1,21 @@
|
||||
using BinaryDad.AacpsBusAlert.Services;
|
||||
using BinaryDad.AacpsBusAlert;
|
||||
using BinaryDad.AacpsBusAlert.Services;
|
||||
using BinaryDad.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((context, builder) =>
|
||||
{
|
||||
builder.AddEnvironmentVariables();
|
||||
|
||||
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");// context.HostingEnvironment.EnvironmentName;
|
||||
|
||||
builder.AddJsonFile("appsettings.json");
|
||||
builder.AddJsonFile($"appsettings.{env}.json", true);
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddTransient<BusRouteService>();
|
||||
@ -10,6 +23,18 @@ var host = Host.CreateDefaultBuilder(args)
|
||||
})
|
||||
.Build();
|
||||
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
|
||||
var configuration = host.Services.GetService<IConfiguration>();
|
||||
var httpClientFactory = host.Services.GetService<IHttpClientFactory>();
|
||||
var httpClient = httpClientFactory.CreateClient();
|
||||
|
||||
var apiBaseUrl = configuration["Urls:Api"];
|
||||
var apiBusRouteUrl = UrlUtility.Combine(apiBaseUrl, "api/routes");
|
||||
var busRoutesRaw = await httpClient.GetStringAsync(apiBusRouteUrl);
|
||||
|
||||
var busRoutes = JsonConvert.DeserializeObject<ICollection<BusRoute>>(busRoutesRaw);
|
||||
|
||||
var busRouteService = host.Services.GetService<BusRouteService>();
|
||||
|
||||
var routes = await busRouteService.GetBusRoutesAsync();
|
||||
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"profiles": {
|
||||
"BinaryDad.AacpsBusAlert.Worker": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"Urls": {
|
||||
"Api": "http://localhost:5299/"
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"Urls": {
|
||||
"Api": "https://buses.binarydad.com/"
|
||||
}
|
||||
}
|
3
BinaryDad.AacpsBusAlert.Worker/appsettings.json
Normal file
3
BinaryDad.AacpsBusAlert.Worker/appsettings.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user