static void Main(string[] args) { var configFile = Path.GetFileNameWithoutExtension(typeof(Program).Assembly.Location) + ".xml"; if (null != args && args.Length > 0) { configFile = args[0]; } if (!File.Exists(configFile)) { Console.WriteLine("Error: could not find configuration file \"{0}\"", configFile); return; } var configuration=new Configuration(configFile); if (!File.Exists(configuration.InputFile)) { Console.WriteLine("Error: could not find input file \"{0}\"", configuration.InputFile); return; } var tail = new Tail(configuration.InputFile, Encoding.Default); var parser = new Parser(tail, configuration); var transfer = new HttpTransferModule(configuration); parser.Changed += transfer.ReceiveChanges; parser.Run(); Console.ReadKey(); }
public void ParserCanCollectFields() { var tail = new MockedTail(new[] { "foo_1", "xyz", }); var testObject = new Parser(tail, new MockedConfig(new List<IRule>() { new Rule(@"foo_(?<foo>\d+)") {Name = "firstrule"}, new Rule(@"bar_(?<bar>\d+)") {Name = "secondrule", ActionOnly = false} })); CheckRules(testObject.rules); IDictionary<string, string> testRecord = new ConcurrentDictionary<string, string>(); testObject.Changed += (rec) => { testRecord = rec; }; testObject.Run(); tail.AddLines("bar_1"); CheckFields(new Dictionary<string, string>() { { "foo", "1" }, { "bar", "1" } }, testRecord); }
public void ParserCanCleanFields() { var tail = new MockedTail(new[] { "foo_1", "bar_2", "xyz_3" }); var testObject = new Parser(tail, new MockedConfig(new List<IRule>() { new Rule(@"foo_(?<foo>\d+)") {Name = "firstrule"}, new Rule(@"bar_(?<bar>\d+)") {Name = "secondrule"}, new Rule(@"xyz_(?<xyz>\d+)") {Name = "thirdrule"}, new Rule(@"mr.proper") {Name = "cleanerrule", Clean = "foo,xyz", ActionOnly = true}, })); CheckRules(testObject.rules); IDictionary<string, string> testRecord = new ConcurrentDictionary<string, string>(); testObject.Changed += (rec) => { testRecord = rec; }; testObject.Run(); CheckFields(new Dictionary<string, string>() { { "foo", "1" }, { "bar", "2" }, { "xyz", "3" } }, testRecord); tail.AddLines("mr.proper"); CheckFields(new Dictionary<string, string>() { { "foo", "" }, { "bar", "2" }, { "xyz", "" } }, testRecord); }
public void ParserCanSendResult() { var initialLines = new[] { "foo", "bar", "xyz", }; var testObject = new Parser(new MockedTail(initialLines), new MockedConfig(new List<IRule>() {new Rule(".*") {Name = "blackhole"}})); CheckRules(testObject.rules); IDictionary<string, string> testRecord = new ConcurrentDictionary<string, string>(); var events = 0; testObject.Changed += (rec) => { events += 1; testRecord = rec; }; testObject.Run(); Assert.AreEqual(1, events, "Unexpected count of received events."); Assert.AreEqual(initialLines.Count(), testRecord.Count, "Unexpected count of received fields."); }
public void ParserTakesTheLastMatchingRule() { var testObject = new Parser( new MockedTail(new[] { "foo_1", "bar_2", "xyz_3" }), new MockedConfig(new List<IRule>() { new Rule(@"foo_(?<foo>\d+)") {Name = "foo"}, new Rule(@".*_(?<firstMatching>3)") {Name = "xyz1"}, new Rule(@"xyz_(?<secondMatching>\d+)") {Name = "xyz2"}, new Rule(@"bar_(?<bar>\d+)") {Name = "bar"}, })); CheckRules(testObject.rules); IDictionary<string, string> testRecord = new ConcurrentDictionary<string, string>(); testObject.Changed += (rec) => { testRecord = rec; }; testObject.Run(); CheckFields(new Dictionary<string, string>() { { "foo", "1" }, { "bar", "2" }, { "firstMatching", null }, { "secondMatching", "3" } }, testRecord); }