Exemple #1
0
        private void LoadReaders()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            WriteLine("Начало загрузки читателей");

            IEnumerable <MarcRecord> records
                = BatchRecordReader.WholeDatabase
                  (
                      Connection,
                      Connection.Database,
                      1000
                  );
            BatchRecordReader batch
                = records as BatchRecordReader;

            if (!ReferenceEquals(batch, null))
            {
                batch.BatchRead += Batch_BatchRead;
            }

            records.ProcessData(ParseAndAddReader);
            Readers.CompleteAdding();

            WriteDelimiter();
            WriteLine("Распределение читателей");
            string[] keys = ReadersByStatus.Keys;
            foreach (string key in keys)
            {
                WriteLine
                (
                    "Статус {0}: {1} читателей",
                    key,
                    ReadersByStatus[key].Length
                );
            }
            WriteDelimiter();

            DateTime today = DateTime.Today;

            _debtorManager
                = new DebtorManager(Connection)
                {
                FromDate = today.AddYears(-1),
                ToDate   = today.AddMonths(-1)
                };
            _debtorManager.SetupDates();

            ReadersByStatus["0"].ProcessData(AnalyzeCandidate);
            Debtors.CompleteAdding();

            WriteLine
            (
                "Кандидатов в должники: {0}",
                Debtors.Count
            );

            WriteLine("Окончание загрузки читателей");
            stopwatch.Stop();
            WriteLine
            (
                "Загрузка заняла: {0}",
                stopwatch.Elapsed.ToAutoString()
            );
            WriteLine("Загружено: {0}", Readers.Count);
            WriteDelimiter();
        }
Exemple #2
0
        /// <summary>
        /// Load readers from database.
        /// </summary>
        public void LoadReaders()
        {
            int       maxMfn = Connection.GetMaxMfn(Database);
            const int delta  = 1000;

            DataflowLinkOptions linkOptions = new DataflowLinkOptions
            {
                PropagateCompletion = true
            };

            TransformBlock <string, MarcRecord> parseRecordBlock
                = new TransformBlock <string, MarcRecord>
                  (
                      line => _ParseRecord(line),
                      new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism    = 6,
                SingleProducerConstrained = true
            }
                  );

            TransformBlock <MarcRecord, ReaderInfo> parseReaderBlock
                = new TransformBlock <MarcRecord, ReaderInfo>
                  (
                      record => _ParseReader(record),
                      new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 4
            }
                  );

            ActionBlock <ReaderInfo> analyzeReaderBlock
                = new ActionBlock <ReaderInfo>
                  (
                      reader => _AnalyzeReader(reader),
                      new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 4
            }
                  );

            parseRecordBlock.LinkTo
            (
                parseReaderBlock,
                linkOptions
            );

            parseReaderBlock.LinkTo
            (
                analyzeReaderBlock,
                linkOptions
            );

            DateTime today = DateTime.Today;

            _debtorManager
                = new DebtorManager(Connection)
                {
                FromDate = today.AddYears(-1),
                ToDate   = today.AddMonths(-1)
                };
            _debtorManager.SetupDates();

            for (int offset = 1; offset < maxMfn; offset += delta)
            {
                WriteLine
                (
                    "Загружается: {0} из {1}",
                    offset - 1,
                    maxMfn - 1
                );

                int portion = Math.Min(delta, maxMfn - offset);

                int[] list = Enumerable.Range(offset, portion)
                             .ToArray();
                string[] lines = _ReadRawRecords(list);
                foreach (string line in lines)
                {
                    parseRecordBlock.Post(line);
                }
            }
            parseRecordBlock.Complete();

            analyzeReaderBlock.Completion.Wait();

            Readers.CompleteAdding();
            Debtors.CompleteAdding();
        }