Beispiel #1
0
        public void WatchingDependsOnFileName()
        {
            var firstLines = new List<string>()
            {
                "hello world",
                "foo bar",
                "lorem ipsum"
            };

            var tail = new Tail(TestFileName, Encoding.ASCII);
            int[] changeEventRaised = { 0 };
            tail.Changed += (o, e) => { ++changeEventRaised[0]; };
            tail.Watch();
            try
            {
                WriteTestLines(false, firstLines);
                Assert.AreNotEqual(0, changeEventRaised[0], "Change event has not been raised at all.");

                changeEventRaised[0] = 0;
                WriteTestLines(FakeTestFileName, false, firstLines);
                Assert.AreEqual(0, changeEventRaised[0], "Change event has been raised at changing of an indifferent file.");
            }
            finally
            {
                tail.StopWatching();
            }
        }
Beispiel #2
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();
        }
Beispiel #3
0
        public void GetNewLines()
        {
            var source = new MockedFileStream(FIRSTLINE);
            var reader = new FileReader("dummyFileName") { myFileStream = source, File = new MockedFile() };

            var tail = new Tail("dummyFileName", Encoding.Default, reader);

            Assert.AreEqual(Encoding.ASCII, tail.myFileType, "Encoding detected wrong.");
            var lines = tail.GetNewLines();
            Assert.AreEqual(1, lines.Count, "Unexpected count of lines read.");
            StringAssert.Matches(lines.First(), firstLineRegex, "Wrong content.");
        }
Beispiel #4
0
        public void WatchingWhileTargetIsGrowing()
        {
            var firstLines = new List<string>()
            {
                "hello world",
                "foo bar",
                "lorem ipsum"
            };
            var additionalLines = new List<string>()
            {
                "monday",
                "tuesday",
                "wednesday",
                "thursday",
                "friday"
            };

            var tail = new Tail(TestFileName, Encoding.ASCII);
            var results = new List<string>();
            int[] changeEventRaised = { 0 };
            tail.Changed += (o, e) => { ++changeEventRaised[0]; results.AddRange(e.NewLines); };
            tail.Watch();
            try
            {
                WriteTestLines(false, firstLines);
                Assert.AreNotEqual(0, changeEventRaised[0], "Change event has not been raised at all.");
                Assert.AreEqual(firstLines.Count, results.Count, "Mismatching count of collected lines.");

                changeEventRaised[0] = 0;
                results.Clear();
                WriteTestLines(true, additionalLines);
                Assert.AreNotEqual(0, changeEventRaised[0], "Change event has not been raised at all.");
                Assert.AreEqual(additionalLines.Count, results.Count, "Mismatching count of collected lines.");
            }
            finally
            {
                tail.StopWatching();
            }
        }
Beispiel #5
0
        public void GetNewLines_ContinuousReading()
        {
            var input = new List<string>
            {
                "first line",
                "second line",
                "third line"
            };
            var additionalLines = new List<string>
            {
                "fourth line",
                "fifth line",
                "sixth line",
                "7th line"
            };
            var source = new MockedFileStream(input);
            var reader = new FileReader("dummyFileName") { myFileStream = source, File = new MockedFile() };
            var tail = new Tail("dummyFileName", Encoding.Default, reader);

            var output = tail.GetNewLines();
            Assert.AreEqual(input.Count, output.Count, "Unexpected count of lines at start");
            for (var i = 0; i < input.Count; i++)
            {
                StringAssert.Matches(output[i], new Regex(input[i]), "Unmatching line in the 1st round.");
            }

            source.AddNewLines(additionalLines, Encoding.Default);
            output = tail.GetNewLines();
            Assert.AreEqual(additionalLines.Count, output.Count, "Unexpected count of lines after new lines added.");
            for (var i = 0; i < additionalLines.Count; i++)
            {
                StringAssert.Matches(output[i], new Regex(additionalLines[i]), "Unmatching line in the 2nd round.");
            }
        }