mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 16:10:16 -04:00
WIP Clean Architecture
Windows 8.1 App Uses keepasslib v2.44 (temporarily)
This commit is contained in:
39
ModernKeePass.Infrastucture.12/File/CsvImportFormat.cs
Normal file
39
ModernKeePass.Infrastucture.12/File/CsvImportFormat.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.File
|
||||
{
|
||||
public class CsvImportFormat: IImportFormat
|
||||
{
|
||||
private readonly IFileProxy _fileService;
|
||||
private const bool HasHeaderRow = true;
|
||||
private const char Delimiter = ';';
|
||||
private const char LineDelimiter = '\n';
|
||||
|
||||
public CsvImportFormat(IFileProxy fileService)
|
||||
{
|
||||
_fileService = fileService;
|
||||
}
|
||||
|
||||
public async Task<List<Dictionary<string, string>>> Import(string path)
|
||||
{
|
||||
var parsedResult = new List<Dictionary<string, string>>();
|
||||
var content = await _fileService.OpenTextFile(path);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user