Initial work on getting minimal API to work
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core.GeoFeedLocalCache\AS1024.GeoFeed.Core.GeoFeedLocalCache.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core.SqliteGeoFeedCache\AS1024.GeoFeed.Core.SqliteGeoFeedCache.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core\AS1024.GeoFeed.Core.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Models\AS1024.GeoFeed.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -3,7 +3,6 @@ using AS1024.GeoFeed.Core.Interfaces;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using System.Text;
|
||||
using AS1024.GeoFeed.Core.GeoFeedLocalCache;
|
||||
using AS1024.GeoFeed.Core.Tools;
|
||||
|
||||
namespace AS1024.GeoFeed.Controllers
|
||||
@@ -18,16 +17,16 @@ namespace AS1024.GeoFeed.Controllers
|
||||
private readonly IMemoryCache memoryCache;
|
||||
private readonly IWebHostEnvironment environment;
|
||||
private readonly ILogger<GeofeedController> logger;
|
||||
private readonly GeoFeedCacheDbContext dbContext;
|
||||
private readonly IGeoFeedPersistentCacheProvider geoFeedPersistentCache;
|
||||
private const string GeoFeedCacheKey = "GeoFeedData";
|
||||
|
||||
public GeofeedController(IGeoFeedProvider builder,
|
||||
IMemoryCache memoryCache,
|
||||
IWebHostEnvironment environment,
|
||||
ILogger<GeofeedController> logger,
|
||||
GeoFeedCacheDbContext dbContext) {
|
||||
IGeoFeedPersistentCacheProvider geoFeedPersistentCache) {
|
||||
this.logger = logger;
|
||||
this.dbContext = dbContext;
|
||||
this.geoFeedPersistentCache = geoFeedPersistentCache;
|
||||
this.builder = builder;
|
||||
this.memoryCache = memoryCache;
|
||||
this.environment = environment;
|
||||
@@ -54,10 +53,7 @@ namespace AS1024.GeoFeed.Controllers
|
||||
} catch (HttpRequestException ex)
|
||||
{
|
||||
logger.LogWarning($"Temporary failure of retrieving GeoData from upstream. {ex}");
|
||||
var results =
|
||||
dbContext.GeoFeedCacheEntries.ToList();
|
||||
List<IPGeoFeed> cachedData = [];
|
||||
results.ForEach(cachedData.Add);
|
||||
var cachedData = geoFeedPersistentCache.GetGeoFeed();
|
||||
return ReturnFile(cachedData);
|
||||
}
|
||||
|
||||
@@ -73,6 +69,12 @@ namespace AS1024.GeoFeed.Controllers
|
||||
private IActionResult ReturnFile(List<IPGeoFeed>? feed)
|
||||
{
|
||||
string csvContent = feed.ToGeoFeedCsv(); // Assuming ToGeoFeedCsv() returns a string in CSV format.
|
||||
return ReturnFile(csvContent);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
private IActionResult ReturnFile(string csvContent)
|
||||
{
|
||||
byte[] contentBytes = Encoding.UTF8.GetBytes(csvContent);
|
||||
string contentType = "text/csv";
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.GeoFeedPreloader;
|
||||
using AS1024.GeoFeed.Core.GeoFeedLocalCache;
|
||||
using AS1024.GeoFeed.Core.GeoFeedProviders;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache;
|
||||
using AS1024.GeoFeed.Core.CacheService;
|
||||
|
||||
namespace AS1024.GeoFeed
|
||||
{
|
||||
@@ -14,11 +15,13 @@ namespace AS1024.GeoFeed
|
||||
|
||||
builder.Services.AddHostedService<PreLoadGeoFeed>();
|
||||
builder.Services.AddTransient<IGeoFeedProvider, NetBoxGeoFeedProvider>();
|
||||
builder.Services.AddDbContext<GeoFeedCacheDbContext>(
|
||||
options =>
|
||||
{
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("LocalFeedCache"));
|
||||
});
|
||||
builder.Services.AddScoped<IGeoFeedPersistentCacheProvider, GeoFeedSqliteCache>();
|
||||
builder.Services.AddHostedService<GeoFeedCacheService>();
|
||||
builder.Services.AddDbContext<GeoFeedCacheDbContext>(options =>
|
||||
{
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("LocalFeedCache"));
|
||||
});
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddMemoryCache();
|
||||
// Add services to the container.
|
||||
|
||||
Reference in New Issue
Block a user