33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using AS1024.GeoFeed.Models;
|
|
using System.Text;
|
|
|
|
namespace AS1024.GeoFeed.Core.Tools
|
|
{
|
|
public static class GeoFeedTools
|
|
{
|
|
/// <summary>
|
|
/// Returns a CSV string for a given GeoFeed retreived from various sources
|
|
/// </summary>
|
|
/// <param name="geoFeeds">GeoFeed returned from the source of truth</param>
|
|
/// <param name="timeStamp">If a timestamp should be appended at the header</param>
|
|
/// <param name="isCached">If the result is cached</param>
|
|
/// <returns></returns>
|
|
public static string ToGeoFeedCsv(this List<IPGeoFeed> geoFeeds, bool timeStamp = false, bool isCached = false)
|
|
{
|
|
StringBuilder csvContent = new();
|
|
|
|
if (timeStamp)
|
|
csvContent.AppendLine($"# GeoFeed generated on {DateTime.UtcNow:R}");
|
|
|
|
if (isCached)
|
|
csvContent.AppendLine($"# Geofeed data is returned from local in memory cache");
|
|
|
|
foreach (IPGeoFeed feed in geoFeeds)
|
|
{
|
|
csvContent.AppendLine($"{feed.Prefix},{feed.GeolocCountry},{feed.GeolocRegion},{feed.GeolocCity},{feed.GeolocPostalCode}");
|
|
}
|
|
|
|
return csvContent.ToString();
|
|
}
|
|
}
|
|
} |