async Task <ParseEventResult> ParseEventData_1(ILogEnd log, MyDbContext data, MyHttpWebResponse response, long eventTawId) { var uriPath = response.ResponseUri.AbsolutePath; if (uriPath.Contains("event") == false) { log.Warn("the event you are trying to parse has invalid uri:" + uriPath + " should contain taw event id:" + eventTawId); return(ParseEventResult.InvalidUriShouldRetry); } var eventTawIdStr = uriPath.Split('/', '\\').Last().RemoveFromEnd(".aspx".Length); var parsedEventTawId = int.Parse(eventTawIdStr); if (eventTawId != parsedEventTawId) { throw new Exception($"should not happen, looking for tat event id:{eventTawId} but found:{parsedEventTawId}"); } var htmlText = response.ResponseText; htmlText = htmlText?.TakeStringAfter("ctl00_ctl00_bcr_bcr_UpdatePanel\">"); if (htmlText.Contains("This is a Base Event and should never be seen")) { log.Trace("invalid 'base event', skipping"); return(ParseEventResult.BaseEvent); // http://taw.net/event/65132.aspx } var evt = data.Events.FirstOrDefault(e => e.TawId == eventTawId); if (evt == null) { evt = new Event(); evt.TawId = eventTawId; evt = data.Events.Add(evt); await data.SaveChangesAsync(); } await ParseEventData_2(log, data, evt, htmlText, eventTawId); await data.SaveChangesAsync(); return(ParseEventResult.ValidEvent); }
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 + "]"); } } }