Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var pump = new FileDataSource(new StreamReader(@"data\TestData.txt"));
            var shifter = new CircularShifter();
            var alphabetizer = new Alphabetizer();

            #region Modifying the requirement - add a 'noise' list to remove words from the index

            //var noiseWords = new FileDataSource(new StreamReader(@"data\noise.txt")).Begin();
            //var noiseRemover = new NoiseRemoval(noiseWords);
            //pump.Successor = noiseRemover;
            //noiseRemover.Successor = shifter;

            #endregion

            pump.Successor = shifter;
            shifter.Successor = alphabetizer;

            var pipeline = new Pipeline<string>(pump: pump, sink: new ConsoleWriter());
            Console.WriteLine("Begin Execution At:{0}", DateTime.UtcNow);
            pipeline.Execute();
            Console.WriteLine("Stop Execution At:{0}", DateTime.UtcNow);

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void IndexFile(string fileName)
        {
            var input = new Input();
            var shifter = new CircularShifter();
            var alphabetizer = new Alphabetizer();

            input.Lines.ItemAdded += shifter.OnNewLine;
            shifter.ShiftedLines.ItemAdded += alphabetizer.OnShiftedLine;
            alphabetizer.SortedLines.ItemAdded += this.OnItemsSorted;

            input.Parse(fileName);
            alphabetizer.Sort();
        }
Exemplo n.º 3
0
        public void IndexFile(string fileName)
        {
            var input        = new Input();
            var shifter      = new CircularShifter();
            var alphabetizer = new Alphabetizer();

            input.Lines.ItemAdded              += shifter.OnNewLine;
            shifter.ShiftedLines.ItemAdded     += alphabetizer.OnShiftedLine;
            alphabetizer.SortedLines.ItemAdded += this.OnItemsSorted;

            input.Parse(fileName);
            alphabetizer.Sort();
        }
        public void AlphabetizesGivenStrings()
        {
            List <string> testSentences = new List <string> {
                "f", "d", "s", "a"
            };
            List <string> expectedSentences = new List <string> {
                "a", "d", "f", "s"
            };

            Alphabetizer  alphabetizer          = new Alphabetizer();
            List <string> alphabetizedSentences = alphabetizer.Alphabetize(testSentences);

            Assert.That(alphabetizedSentences, Is.EqualTo(expectedSentences));
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            const int bufferSize = 32;
            var rawDataBuffer = new BlockingCollection<string>(bufferSize);
            var shiftedDataBuffer = new BlockingCollection<string>(bufferSize);
            var alphabetizedDataBuffer = new BlockingCollection<string>(bufferSize);

            var pump = new FileDataSource(rawDataBuffer , new StreamReader(@"data\TestData.txt"));

            var shifter = new CircularShifter(rawDataBuffer, shiftedDataBuffer);
            var alphabetizer = new Alphabetizer(shiftedDataBuffer, alphabetizedDataBuffer);
            var writer = new ConsoleWriter(alphabetizedDataBuffer);

            var pipeline = new Pipeline<string>(pump: pump, sink: writer, filters: new List<IAmAFilter<string>> {shifter, alphabetizer});
            Console.WriteLine("Begin Execution At:{0}", DateTime.UtcNow);
            pipeline.Execute();
            Console.WriteLine("Stop Execution At:{0}", DateTime.UtcNow);

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }