2018-09-10 17:29:52 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Windows.Storage;
|
2018-09-10 11:13:44 +02:00
|
|
|
|
using ModernKeePass.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ImportFormats
|
|
|
|
|
{
|
|
|
|
|
public class CsvImportFormat: IFormat
|
|
|
|
|
{
|
2018-09-10 17:29:52 +02:00
|
|
|
|
public bool HasHeaderRow { get; set; } = true;
|
|
|
|
|
public char Delimiter { get; set; } = ';';
|
|
|
|
|
public char LineDelimiter { get; set; } = '\n';
|
|
|
|
|
|
|
|
|
|
public async Task<List<Dictionary<string, string>>> Import(IStorageFile source)
|
2018-09-10 11:13:44 +02:00
|
|
|
|
{
|
2018-09-10 17:29:52 +02:00
|
|
|
|
var parsedResult = new List<Dictionary<string, string>>();
|
|
|
|
|
var content = await FileIO.ReadLinesAsync(source);
|
|
|
|
|
foreach (var line in content)
|
|
|
|
|
{
|
|
|
|
|
var fields = line.Split(Delimiter);
|
|
|
|
|
var recordItem = new Dictionary<string, string>();
|
|
|
|
|
var i = 0;
|
|
|
|
|
foreach (var field in fields)
|
|
|
|
|
{
|
|
|
|
|
recordItem.Add(i.ToString(), field);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
parsedResult.Add(recordItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parsedResult;
|
2018-09-10 11:13:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|