Exemplo n.º 1
0
        public void TailUpdateHandler(object o, TailEventArgs e)
        {
            bool changed = false;
            foreach (var line in e.NewLines)
            {
                IRule matching;
                matching = rules.LastOrDefault(r => r.IsMatching(line));
                if (null == matching) continue;
                var lineFields = matching.Parse(line);
                if (!matching.ActionOnly)
                {
                    foreach (var field in lineFields)
                    {
                        changed = !record.ContainsKey(field.Key) ||
                                  (record.ContainsKey(field.Key) && record[field.Key] != field.Value);
                        //Console.WriteLine("{2} {{([{0}]: \"{1}\"}} to record", field.Key, field.Value, record.ContainsKey(field.Key) ? "changing" : "adding");
                        record[field.Key] = field.Value;
                    }

                }
                if (!string.IsNullOrEmpty(matching.Clean))
                {
                    matching.Clean.Split(',').Select(f => f.Trim()).ToList().ForEach(field =>
                    {
                        if (record.ContainsKey(field))
                        {
                            record[field] = string.Empty;
                        }
                    });
                }
            }
            if (changed)
            {
                OnChanged(record);
            }
        }
Exemplo n.º 2
0
 protected virtual void OnChanged(TailEventArgs e)
 {
     if (Changed != null)
         Changed(this, e);
 }