mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add csvHelper
This commit is contained in:
parent
2ea93c77a4
commit
b150184985
2 changed files with 11 additions and 7 deletions
|
|
@ -6,6 +6,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CsvHelper" Version="4.0.2" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using CsvHelper;
|
||||
using FilterLists.Data.Models.Implementations;
|
||||
using FilterLists.Data.Repositories.Contracts;
|
||||
using FilterLists.Services.Contracts;
|
||||
|
||||
|
|
@ -20,18 +22,19 @@ public TableService(ITableCsvRepository tableCsvRepository)
|
|||
/// </summary>
|
||||
public void UpdateTables()
|
||||
{
|
||||
//TODO: loop through all CSVs
|
||||
UpdateTable("List");
|
||||
UpdateListTable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// update table via .CSV from GitHub
|
||||
/// update table via List.csv from GitHub
|
||||
/// </summary>
|
||||
/// <param name="tableName">name of database table</param>
|
||||
public void UpdateTable(string tableName)
|
||||
public void UpdateListTable()
|
||||
{
|
||||
var file = FetchFile(_tableCsvRepository.GetUrlByName(tableName), tableName).Result;
|
||||
//TODO: exec stored procedure to merge/upsert csv into corresponding db table
|
||||
var localCsvFilePath = FetchFile(_tableCsvRepository.GetUrlByName("List"), "List").Result;
|
||||
TextReader textReader = File.OpenText(localCsvFilePath);
|
||||
var csv = new CsvReader(textReader);
|
||||
csv.Configuration.MissingFieldFound = null;
|
||||
var records = csv.GetRecords<List>();
|
||||
//TODO: delete file when finished
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue