diff --git a/AS1024.GeoFeed.Core.GeoFeedLocalCache/AS1024.GeoFeed.Core.GeoFeedLocalCache.csproj b/AS1024.GeoFeed.Core.GeoFeedLocalCache/AS1024.GeoFeed.Core.GeoFeedLocalCache.csproj deleted file mode 100644 index b4b33b9..0000000 --- a/AS1024.GeoFeed.Core.GeoFeedLocalCache/AS1024.GeoFeed.Core.GeoFeedLocalCache.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - - - - - - - - - diff --git a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheDbContext.cs b/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheDbContext.cs deleted file mode 100644 index ff17f44..0000000 --- a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheDbContext.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.EntityFrameworkCore; - -namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache -{ - public class GeoFeedCacheDbContext : DbContext - { - public GeoFeedCacheDbContext(DbContextOptions options) - : base(options) - { - } - - public virtual DbSet GeoFeedCacheEntries { get; set; } - } - -} \ No newline at end of file diff --git a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheEntry.cs b/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheEntry.cs deleted file mode 100644 index 142e6b0..0000000 --- a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheEntry.cs +++ /dev/null @@ -1,12 +0,0 @@ -using AS1024.GeoFeed.Models; -using System.ComponentModel.DataAnnotations; - -namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache -{ - public class GeoFeedCacheEntry : IPGeoFeed - { - [Key] - public int Id { get; set; } - } - -} \ No newline at end of file diff --git a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheService.cs b/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheService.cs deleted file mode 100644 index f516ea0..0000000 --- a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedCacheService.cs +++ /dev/null @@ -1,58 +0,0 @@ -using AS1024.GeoFeed.Core.Interfaces; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System.Runtime.CompilerServices; - -namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache -{ - public class GeoFeedCacheService : IHostedService - { - private readonly ILogger logger; - private readonly IGeoFeedProvider feedProvider; - private readonly IHost host; - private readonly IGeoFeedPersistentCacheProvider persistentCacheProvider; - - public GeoFeedCacheService(ILogger logger, - IGeoFeedProvider feedProvider, - IHost host, - IGeoFeedPersistentCacheProvider persistentCacheProvider) - { - this.logger = logger; - this.feedProvider = feedProvider; - this.host = host; - this.persistentCacheProvider = persistentCacheProvider; - } - - public Task StartAsync(CancellationToken cancellationToken) - { - _ = StartPerioidicSync(cancellationToken); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - - public async Task StartPerioidicSync(CancellationToken Token) - { - while (!Token.IsCancellationRequested) - { - try - { - var results = await feedProvider.GetGeoFeedData(); - await persistentCacheProvider.CacheGeoFeed(results); - } - catch (Exception) - { - logger.LogWarning("On disk cache failed to run. Waiting on 30 minutes before retry..."); - } - await Task.Delay(TimeSpan.FromMinutes(30)); - } - - return false; - } - } -} \ No newline at end of file diff --git a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedDesignTimeMigration.cs b/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedDesignTimeMigration.cs deleted file mode 100644 index 90d896e..0000000 --- a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedDesignTimeMigration.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Design; - -namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache - -{ - public class GeoFeedDesignTimeMigration : IDesignTimeDbContextFactory - { - public GeoFeedCacheDbContext CreateDbContext(string[] args) - { - var builder = new DbContextOptionsBuilder(); - builder.UseSqlite("Data Source=migratedb.db"); - return new GeoFeedCacheDbContext(builder.Options); - } - } - -} \ No newline at end of file diff --git a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedSqliteCache.cs b/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedSqliteCache.cs deleted file mode 100644 index c625536..0000000 --- a/AS1024.GeoFeed.Core.GeoFeedLocalCache/GeoFeedSqliteLocalCache/GeoFeedSqliteCache.cs +++ /dev/null @@ -1,72 +0,0 @@ -using AS1024.GeoFeed.Core.Interfaces; -using AS1024.GeoFeed.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Hosting; -using AS1024.GeoFeed.Core.Tools; - -namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache -{ - public class GeoFeedSqliteCache : IGeoFeedPersistentCacheProvider - { - protected readonly GeoFeedCacheDbContext dbContext; - private readonly IGeoFeedProvider feedProvider; - - public GeoFeedSqliteCache(GeoFeedCacheDbContext geoFeedCacheDb, - IHost host, - IGeoFeedProvider provider) - { - dbContext = geoFeedCacheDb; - feedProvider = provider; - } - - public string ProviderName => "sqlite"; - - public async Task CacheGeoFeed(IList pGeoFeeds) - { - await DBContextMigrate(); - List geoFeedCacheEntry = []; - - var results = pGeoFeeds.ToList(); - - results.ForEach(x => - { - geoFeedCacheEntry.Add(new() - { - Prefix = x.Prefix, - GeolocCity = x.GeolocCity, - GeolocCountry = x.GeolocCountry, - GeolocHasLocation = x.GeolocHasLocation, - GeolocPostalCode = x.GeolocPostalCode, - GeolocRegion = x.GeolocRegion - }); - }); - - if (dbContext.GeoFeedCacheEntries.Any()) - { - dbContext.GeoFeedCacheEntries.RemoveRange(dbContext.GeoFeedCacheEntries.ToArray()); - } - await dbContext.AddRangeAsync(geoFeedCacheEntry); - await dbContext.SaveChangesAsync(); - - return true; - } - - public string GetGeoFeed() - { - var results = - dbContext.GeoFeedCacheEntries.ToList(); - List cachedData = []; - results.ForEach(cachedData.Add); - - return cachedData.ToGeoFeedCsv(); - } - - private async Task DBContextMigrate() - { - if (dbContext.Database.GetPendingMigrations().Any()) - { - await dbContext.Database.MigrateAsync(); - } - } - } -}