Esempio n. 1
0
        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();
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
        public void ParserCanLoadRules()
        {
            var testObject = new Parser(null, new MockedConfig(new List<IRule>()
            {
                new Rule("foo") {Name = "firstrule"},
                new Rule("bar") {Name = "secondrule"}
            }));
            CheckRules(testObject.rules);
            Assert.IsNotNull(testObject.rules, "Rules could not be loaded.");
            Assert.AreEqual(2, testObject.rules.Count, "Missing rules.");
            Assert.AreEqual("firstrule", testObject.rules[0].Name);
            Assert.AreEqual("foo", testObject.rules[0].Pattern);

            testObject = new Parser(null, new MockedConfig(new List<IRule>() {new Rule(".*") {Name = "blackhole"}}));
            CheckRules(testObject.rules);
            Assert.IsNotNull(testObject.rules, "Rules could not be loaded.");
            Assert.AreEqual(1, testObject.rules.Count, "Missing rules.");
            Assert.AreEqual("blackhole", testObject.rules[0].Name);
            Assert.AreEqual(".*", testObject.rules[0].Pattern);
        }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 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.");
 }
Esempio n. 6
0
 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);
 }