public bool Update(HitEventItem hit) { if (isNew) { isNew = false; start = hit.when; last = hit.when; key = hit.key; user = hit.user; userAgent = hit.userAgent; } else { if (hit.when < start) { start = hit.when; } if (hit.when > last) { last = hit.when; } } lastTouch = DateTime.Now; Hit h = new Hit(); h.when = hit.when; h.timeZone = hit.timeZone; h.reqMethod = hit.reqMethod; h.reqURI = hit.reqURI; h.reqProtocol = hit.reqProtocol; h.status = hit.status; h.byteSent = hit.byteSent; h.refer = hit.refer; long tick = hit.when.Ticks; while (hits.ContainsKey(tick)) { tick++; } hits.Add(tick, h); return(true); }
private bool ProcessWebLog(Regex fmt, RowItem row) { HitEventItem ev = null; bool ok = false; Match m = fmt.Match(row.line); if (m.Groups.Count >= 11) { string[] fld = new string[m.Groups.Count]; int count = 0; foreach (Group g in m.Groups) { foreach (Capture c in g.Captures) { fld[count] = c.Value; count++; } } try { ev = new HitEventItem(); ev.type = EventType.HIT; if (ParseLogTimeStamp(fld[4], out ev.when)) { ev.remoteHost = NormalizeField(fld[1]); ev.authUser = NormalizeField(fld[2]); ev.remoteLogName = NormalizeField(fld[3]); ev.timeZone = NormalizeField(fld[5]); ev.reqMethod = NormalizeField(fld[6]); ev.reqProtocol = NormalizeField(fld[8]); ev.status = NormalizeIntField(fld[9]); ev.byteSent = NormalizeIntField(fld[10]); ev.reqURI = new Uri(server, fld[7]); if (row.type == LogFormat.COMBINED) { string refer = NormalizeField(fld[11]); if (refer != null) { ev.refer = new Uri(refer); } ev.userAgent = NormalizeField(fld[12]); } if (ev.authUser != null) { ev.user = "******" + ev.authUser; } else { if (ev.userAgent != null) { ev.user = "******" + ev.remoteHost + "." + ev.userAgent; } else { ev.user = "******" + ev.remoteHost; } } ev.key = ev.user.GetHashCode(); ok = true; } } catch (Exception e) { Console.WriteLine("ERR=" + e.Message); ok = false; } } if (ok) { outQueue.Insert(ev); } else { Console.WriteLine("ERR " + row.line); } return(ok); }