本文整理汇总了C#中CsvReader.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ToList方法的具体用法?C# CsvReader.ToList怎么用?C# CsvReader.ToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.ToList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginImport
public static DeviceImportContext BeginImport(DiscoDataContext Database, string Filename, bool HasHeader, Stream FileContent)
{
if (FileContent == null)
throw new ArgumentNullException("FileContent");
if (string.IsNullOrWhiteSpace(Filename))
Filename = "<None Specified>";
DeviceImportContext context;
List<Tuple<string, DeviceImportFieldTypes>> header;
List<string[]> rawData;
using (TextReader csvTextReader = new StreamReader(FileContent))
{
using (CsvReader csvReader = new CsvReader(csvTextReader, HasHeader))
{
csvReader.DefaultParseErrorAction = ParseErrorAction.ThrowException;
csvReader.MissingFieldAction = MissingFieldAction.ReplaceByNull;
rawData = csvReader.ToList();
header = csvReader.GetFieldHeaders().Select(h => Tuple.Create(h, DeviceImportFieldTypes.IgnoreColumn)).ToList();
}
}
context = new DeviceImportContext(Filename, header, rawData);
context.GuessHeaderTypes(Database);
return context;
}
示例2: UploadScores
public ActionResult UploadScores(string data, int orgID)
{
var csv = new CsvReader(new StringReader(data), false, '\t');
var list = csv.ToList();
foreach (var score in list)
{
var peopleID = score[0].ToInt();
var player = (from e in DbUtil.Db.OrganizationMembers
where e.OrganizationId == orgID
where e.PeopleId == peopleID
select e).SingleOrDefault();
if (player != null)
player.Score = score[1].ToInt();
DbUtil.Db.SubmitChanges();
}
return Content("OK");
}
示例3: DoUpload
public bool DoUpload(string text, bool testing = false)
{
var rt = Db2.UploadPeopleRuns.OrderByDescending(mm => mm.Id).First();
var csv = new CsvReader(new StringReader(text), false, '\t');
var list = csv.ToList();
var list0 = list.First().Select(kk => kk).ToList();
names = list0.ToDictionary(i => i.TrimEnd(),
i => list0.FindIndex(s => s == i), StringComparer.OrdinalIgnoreCase);
if (names.ContainsKey("campus"))
{
var campuslist = (from li in list.Skip(1)
where li.Length == names.Count
group li by li[names["campus"]]
into campus
where campus.Key.HasValue()
select campus.Key).ToList();
var dbc = from c in campuslist
join cp in Db.Campus on c equals cp.Description into j
from cp in j.DefaultIfEmpty()
select new {cp, c};
var clist = dbc.ToList();
if (clist.Count > 0)
{
var maxcampusid = 0;
if (Db.Campus.Any())
maxcampusid = Db.Campus.Max(c => c.Id);
foreach (var i in clist)
if (i.cp == null)
{
var cp = new Campu {Description = i.c, Id = ++maxcampusid};
if (!testing)
Db.Campus.InsertOnSubmit(cp);
}
}
}
var now = DateTime.Now;
if (!testing)
Db.SubmitChanges();
Campuses = Db.Campus.ToDictionary(cp => cp.Description, cp => cp.Id);
var q = (from li in list.Skip(1)
where li.Length == names.Count
group li by li[names["familyid"]]
into fam
select fam).ToList();
rt.Count = q.Sum(ff => ff.Count());
Db2.SubmitChanges();
var standardnames = new List<string>
{
"familyid", "title", "first", "last", "goesby", "altname", "gender", "marital", "maidenName",
"address", "address2", "city", "state", "zip", "position", "birthday", "cellphone", "homephone",
"workphone", "email", "email2", "suffix", "middle", "joindate", "dropdate", "baptismdate", "weddingdate",
"memberstatus", "employer", "occupation"
};
var orgs = new Dictionary<string, int>();
var membertypes = new Dictionary<string, int>();
foreach (var fam in q)
{
Family f = null;
FindPerson3 pid;
Person p = null;
foreach (var a in fam)
{
var potentialdup = false;
var first = a[names["first"]];
var last = a[names["last"]];
DateTime dt;
DateTime? dob = null;
if (names.ContainsKey("birthday"))
if (DateTime.TryParse(a[names["birthday"]], out dt))
{
dob = dt;
if (dob.Value < SqlDateTime.MinValue)
dob = null;
}
string email = null;
string cell = null;
string homephone = null;
if (names.ContainsKey("email"))
email = a[names["email"]].Trim();
if (names.ContainsKey("cellphone"))
cell = a[names["cellphone"]].GetDigits();
if (names.ContainsKey("homephone"))
homephone = a[names["homephone"]].GetDigits();
pid = Db.FindPerson3(first, last, dob, email, cell, homephone, null).FirstOrDefault();
if (noupdate && pid != null)
{
if (!testing)
{
var pd = Db.LoadPersonById(pid.PeopleId.Value);
pd.AddEditExtraBool("FoundDup", true);
}
potentialdup = true;
pid = null;
//.........这里部分代码省略.........
示例4: DoUpload
public bool DoUpload(string text)
{
var rt = Db2.UploadPeopleRuns.OrderByDescending(mm => mm.Id).First();
var sep = text.First(vv => new char[] {'\t', ','}.Contains(vv));
var csv = new CsvReader(new StringReader(text), false, sep);
csv.SupportsMultiline = true;
var list = csv.ToList();
var list0 = list.First().Select(kk => kk).ToList();
names = list0.ToDictionary(i => i.TrimEnd(),
i => list0.FindIndex(s => s == i), StringComparer.OrdinalIgnoreCase);
extravaluenames = (from name in names.Keys
where !standardnames.Contains(name, StringComparer.OrdinalIgnoreCase)
where !standardrecregnames.Contains(name)
select name).ToList();
recregnames = (from name in names.Keys
where standardrecregnames.Contains(name)
select name).ToList();
var db = DbUtil.Create(host);
if (names.ContainsKey("campus"))
{
var campuslist = (from li in list.Skip(1)
where li.Length == names.Count
group li by li[names["campus"]]
into campus
where campus.Key.HasValue()
select campus.Key).ToList();
var dbc = from c in campuslist
join cp in db.Campus on c equals cp.Description into j
from cp in j.DefaultIfEmpty()
select new {cp, c};
var clist = dbc.ToList();
if (clist.Count > 0)
{
var maxcampusid = 0;
if (db.Campus.Any())
maxcampusid = db.Campus.Max(c => c.Id);
foreach (var i in clist)
if (i.cp == null)
{
var cp = new Campu {Description = i.c, Id = ++maxcampusid};
if (!testing)
db.Campus.InsertOnSubmit(cp);
}
}
}
var now = DateTime.Now;
if (!testing)
db.SubmitChanges();
Campuses = db.Campus.ToDictionary(cp => cp.Description, cp => cp.Id);
var q = (from li in list.Skip(1)
where li.Length == names.Count
group li by li[names["familyid"]]
into fam
select fam).ToList();
rt.Count = q.Sum(ff => ff.Count());
Db2.SubmitChanges();
foreach (var fam in q)
{
Family f = null;
var prevpid = 0;
FindPerson3 pid;
Person p = null;
foreach (var a in fam)
{
if (!testing)
{
db.SubmitChanges();
db.Dispose();
db = DbUtil.Create(host);
}
var potentialdup = false;
var first = a[names["first"]];
var last = a[names["last"]];
DateTime dt;
DateTime? dob = null;
if (names.ContainsKey("birthday"))
if (DateTime.TryParse(a[names["birthday"]], out dt))
{
dob = dt;
if (dob.Value < SqlDateTime.MinValue)
dob = null;
}
string email = null;
string cell = null;
string homephone = null;
if (names.ContainsKey("email"))
email = a[names["email"]].Trim();
if (names.ContainsKey("cellphone"))
cell = a[names["cellphone"]].GetDigits();
if (names.ContainsKey("homephone"))
homephone = a[names["homephone"]].GetDigits();
pid = db.FindPerson3(first, last, dob, email, cell, homephone, null).FirstOrDefault();
//.........这里部分代码省略.........