Move towards explicit types
This commit is contained in:
parent
db05b0b815
commit
5b367121c4
|
|
@ -34,7 +34,7 @@ namespace AS1024.GeoFeed.Controllers
|
|||
&& environment.IsProduction())
|
||||
{
|
||||
feed = await builder.GetGeoFeedData();
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
MemoryCacheEntryOptions cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
.SetSlidingExpiration(TimeSpan.FromMinutes(15));
|
||||
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
||||
} else
|
||||
|
|
@ -42,9 +42,9 @@ namespace AS1024.GeoFeed.Controllers
|
|||
feed = await builder.GetGeoFeedData();
|
||||
}
|
||||
|
||||
var csvContent = feed.ToGeoFeedCsv(); // Assuming ToGeoFeedCsv() returns a string in CSV format.
|
||||
var contentBytes = Encoding.UTF8.GetBytes(csvContent);
|
||||
var contentType = "text/csv";
|
||||
string csvContent = feed.ToGeoFeedCsv(); // Assuming ToGeoFeedCsv() returns a string in CSV format.
|
||||
byte[] contentBytes = Encoding.UTF8.GetBytes(csvContent);
|
||||
string contentType = "text/csv";
|
||||
|
||||
return new FileContentResult(contentBytes, contentType)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
{
|
||||
StringBuilder csvContent = new();
|
||||
|
||||
foreach (var feed in geoFeeds)
|
||||
foreach (IPGeoFeed feed in geoFeeds)
|
||||
{
|
||||
csvContent.AppendLine($"{feed.Prefix},{feed.GeolocCountry},{feed.GeolocRegion},{feed.GeolocCity},");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
|
||||
public async Task<List<IPGeoFeed>> GetGeoFeedData()
|
||||
{
|
||||
var geoFeed = new List<IPGeoFeed>();
|
||||
using var client = httpClientFactory.CreateClient();
|
||||
List<IPGeoFeed> geoFeed = new List<IPGeoFeed>();
|
||||
using HttpClient client = httpClientFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
foreach (var family in addressFamilies)
|
||||
foreach (AddressFamily family in addressFamilies)
|
||||
{
|
||||
Uri uri = BuildNetBoxURI(family);
|
||||
NetboxData? jsonData = null;
|
||||
|
|
@ -45,10 +45,10 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
{
|
||||
logger.LogDebug($"Making request to {uri}...");
|
||||
|
||||
using var result = await client.GetAsync(uri);
|
||||
using HttpResponseMessage result = await client.GetAsync(uri);
|
||||
if (result.IsSuccessStatusCode)
|
||||
{
|
||||
var stringResult = await result.Content.ReadAsStringAsync();
|
||||
string stringResult = await result.Content.ReadAsStringAsync();
|
||||
jsonData = JsonConvert.DeserializeObject<NetboxData>(stringResult);
|
||||
|
||||
if (jsonData?.Results == null || jsonData.Results.Count == 0)
|
||||
|
|
@ -56,7 +56,7 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
break;
|
||||
}
|
||||
|
||||
foreach (var data in jsonData.Results)
|
||||
foreach (Result data in jsonData.Results)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -92,7 +92,7 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
|
||||
protected Uri BuildNetBoxURI(AddressFamily family)
|
||||
{
|
||||
var queryParameters = HttpUtility.ParseQueryString(string.Empty);
|
||||
System.Collections.Specialized.NameValueCollection queryParameters = HttpUtility.ParseQueryString(string.Empty);
|
||||
queryParameters["cf_geoloc_has_location"] = "true";
|
||||
queryParameters["limit"] = "50";
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
break;
|
||||
}
|
||||
|
||||
var endUrl = new UriBuilder
|
||||
UriBuilder endUrl = new UriBuilder
|
||||
{
|
||||
Path = "api/ipam/prefixes/",
|
||||
Query = queryParameters.ToString(),
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
async Task IHostedService.StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
logger.LogInformation("Preloading GeoFeed data in memory...");
|
||||
var feed = await provider.GetGeoFeedData();
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(45));
|
||||
List<Models.IPGeoFeed> feed = await provider.GetGeoFeedData();
|
||||
MemoryCacheEntryOptions cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(45));
|
||||
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue