Пример #1
0
        private void ProduceAndConsume(Stream stream)
        {
            long      counter   = 0;
            Stopwatch stopWatch = Stopwatch.StartNew();

            using (Indexer indexer = _indexer)
                using (XmlReader reader = XmlReader.Create(stream))
                    using (DataFlow dataflow = new DataFlow(reader))
                    {
                        reader.MoveToContent();

                        var buffer   = new BufferBlock <object>();
                        var consumer = dataflow.ConsumeAsync(buffer, (page) =>
                        {
                            indexer.Index(page);

                            if (counter % 1000 == 0)
                            {
                                Console.WriteLine("{0} documents in {1} minutes {2} seconds", counter, stopWatch.Elapsed.Minutes, stopWatch.Elapsed.Seconds);
                                stopWatch = Stopwatch.StartNew();
                            }

                            counter++;
                        });

                        dataflow.Produce(buffer);

                        consumer.Wait();
                    }
        }