async public Task FinishParsing(ILogEnd log, MyDbContext data) { /* * text use cases: * Commander-in-Chief - DOC, GEN5 * Commanding Officer - Constance, CPT * Executive Officer - Deceded, LTC * BetaHook, PFC - On Leave * Guthrie, PFC - On Leave * Constance, CPT * Juvenis, COL */ var person = await GetPersonFromName(data, name, rank); if (onLeave) { person.Status = "on leave"; } var personToUnit = data.PersonUnits.FirstOrDefault(p => p.Person.PersonId == person.PersonId && p.Unit.UnitId == unitId); if (personToUnit == null) { personToUnit = new PersonUnit(); personToUnit.Person = person; personToUnit.Unit = data.Units.Find(unitId); personToUnit.Joined = DateTime.UtcNow; personToUnit = data.PersonUnits.Add(personToUnit); } personToUnit.PositionNameShort = positionNameShort; personToUnit.Removed = new DateTime(9999, 1, 1); // (DateTime)SqlDateTime.MaxValue; PersonToUnitId = personToUnit.PersonUnitId; try { await data.SaveChangesAsync(); } catch (Exception e) { log.Fatal(e); } }
public UnitRoasterPersonLine(ILogEnd log, string text, long unitId) { this.unitId = unitId; var dashIndex = text.LastIndexOf("-"); if (dashIndex != -1) { var part1 = text.Substring(0, dashIndex - 1).Trim(); var part2 = text.Substring(dashIndex + 1).Trim(); if (part2.ToLower().Contains("on leave")) { onLeave = true; var parts = part1.Split(','); name = parts[0].Trim(); rank = parts[1].Trim(); } else { positionNameLong = part1; var parts = part2.Split(','); name = parts[0].Trim(); rank = parts[1].Trim(); } } else { var parts = text.Split(','); name = parts[0].Trim(); rank = parts[1].Trim(); } if (positionNameLong != "") { positionNameShort = PersonUnit.PositionNameLongToPositionNameShort(positionNameLong); if (positionNameShort.IsNullOrWhiteSpace()) { log.Warn("cannot find positionNameShortToPositionNameLong.Reverse[" + positionNameLong + "]"); } } }
public void TestMethod1() { PersonUnit person = new PersonUnit(20, 80.00); }