本文整理汇总了C#中CsvReader.ReadRow方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ReadRow方法的具体用法?C# CsvReader.ReadRow怎么用?C# CsvReader.ReadRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.ReadRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCsvColumns
public string[] GetCsvColumns(string csvFileName, char columnDelimiter)
{
using (var data = GetCsvContent(csvFileName))
{
CsvReader csvReader = new CsvReader(data, columnDelimiter);
return csvReader.ReadRow();
}
}
示例2: GetCsvNamesAndIndexes
private static Dictionary<string, int> GetCsvNamesAndIndexes(CsvReader reader)
{
string[] csvNames = reader.ReadRow();
Dictionary<string, int> csvNamesAndIndexes = new Dictionary<string, int>();
for (int i = 0; i < csvNames.Length; i++)
csvNamesAndIndexes.Add(csvNames[i], i);
return csvNamesAndIndexes;
}
示例3: Import
private void Import(ImportJob job, CsvReader reader, ImportResult result)
{
Dictionary<string, int> csvNames = GetCsvNamesAndIndexes(reader);
ColumnMapping columnMapping = ColumnMappings.First(x => x.ColumnMappingId == job.ColumnMappingId);
IEntityImporter importer = _entityImporters.FirstOrDefault(i => i.Name == job.EntityImporter);
while (true)
{
try
{
string[] csvValues = reader.ReadRow();
if (csvValues == null)
break;
var systemValues = MapColumns(columnMapping.SystemPropertiesMap, csvNames, csvValues);
var customValues = MapColumns(columnMapping.CustomPropertiesMap, csvNames, csvValues);
importer.Import(job.ContainerId, columnMapping.PropertySetId, systemValues, customValues, _catalogRepository);
result.CurrentProgress = reader.CurrentPosition;
result.ProcessedRecordsCount++;
}
catch(Exception e)
{
result.ErrorsCount++;
if (result.Errors == null)
result.Errors = new List<string>();
result.Errors.Add(e.Message);
//check if errors amount reached the allowed errors limit if yes do not save made changes.
if (result.ErrorsCount >= job.MaxErrorsCount)
{
_catalogRepository.UnitOfWork.RollbackChanges();
break;
}
}
}
if (result.ErrorsCount < job.MaxErrorsCount)
{
_catalogRepository.UnitOfWork.Commit();
}
}