Beispiel #1
0
            public async Task Handle(ImportFromCsvCommand message)
            {
                if (!_database.IsOpen)
                {
                    throw new DatabaseClosedException();
                }

                var fileContents = await _file.ReadTextFile(message.FilePath);

                for (var index = message.HasHeaderRow ? 1 : 0; index < fileContents.Count; index++)
                {
                    var line   = fileContents[index];
                    var fields = line.Split(message.Delimiter);

                    var entry = _database.CreateEntry(message.DestinationGroupId);
                    for (var i = 0; i < fields.Length; i++)
                    {
                        var fieldMapping = message.FieldMappings[i];
                        await _database.UpdateEntry(entry.Id, fieldMapping, fields[i], fieldMapping == EntryFieldName.Password);
                    }
                }
            }