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(); }
private static void Main() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { string connectionString = ConfigurationUtility .GetString("connectionString") .ThrowIfNull("connectionString not set"); int delay = ConfigurationUtility .GetInt32("delay"); DateTime threshold = DateTime.Today .AddMonths(-delay); using (IrbisConnection connection = new IrbisConnection(connectionString)) { DatabaseInfo[] databases = connection.ListDatabases(); DebtorManager manager = new DebtorManager(connection) { ToDate = threshold }; manager.BatchRead += (sender, args) => { Console.Write("."); }; DebtorInfo[] debtors = manager.GetDebtors ( connection.Search("RB=$") ); debtors = debtors.Where ( debtor => !debtor.WorkPlace .SafeContains(LibraryName) ) .ToArray(); Console.WriteLine(); Console.WriteLine ( "Debtors: {0}", debtors.Length ); VisitInfo[] allDebt = debtors.SelectMany ( debtor => debtor.Debt ) .ToArray(); Console.WriteLine ( "Books in debt: {0}", allDebt.Length ); Workbook workbook = new Workbook(); workbook.CreateNewDocument(); Worksheet worksheet = workbook.Worksheets[0]; int row = 0; worksheet.Cells[row, 0].Value = "ФИО"; worksheet.Cells[row, 1].Value = "Билет"; worksheet.Cells[row, 2].Value = "Краткое описание"; worksheet.Cells[row, 3].Value = "Год"; worksheet.Cells[row, 4].Value = "Номер"; worksheet.Cells[row, 5].Value = "Цена"; worksheet.Cells[row, 6].Value = "Хранение"; worksheet.Cells[row, 7].Value = "Дата"; worksheet.Cells[row, 8].Value = "Отдел"; row++; for (int i = 0; i < allDebt.Length; i++) { if (i % 100 == 0) { Console.Write("."); } VisitInfo debt = allDebt[i]; string description = debt.Description; string inventory = debt.Inventory; string database = debt.Database; string year = string.Empty; string index = debt.Index; string price = string.Empty; if (!string.IsNullOrEmpty(index) && !string.IsNullOrEmpty(database)) { if (databases.FirstOrDefault ( db => db.Name.SameString(database) ) == null) { continue; } try { connection.Database = database; MarcRecord record = connection.SearchReadOneRecord ( "\"I={0}\"", index ); if (!ReferenceEquals(record, null)) { description = connection.FormatRecord ( FormatName, record.Mfn ); year = GetYear(record); price = GetPrice(debt, record); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } worksheet.Cells[row, 0].Value = debt.Reader.FullName; worksheet.Cells[row, 1].Value = debt.Reader.Ticket; worksheet.Cells[row, 2].Value = description; worksheet.Cells[row, 3].Value = year; worksheet.Cells[row, 4].Value = inventory; worksheet.Cells[row, 5].Value = price; worksheet.Cells[row, 6].Value = debt.Sigla; worksheet.Cells[row, 7].Value = debt.DateExpectedString; worksheet.Cells[row, 8].Value = debt.Department; for (int j = 0; j <= 6; j++) { Cell cell = worksheet.Cells[row, j]; cell.Borders.SetAllBorders ( Color.Black, BorderLineStyle.Hair ); } row++; } workbook.SaveDocument(OutputFile); Console.WriteLine("All done"); stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; Console.WriteLine("Elapsed: {0}", elapsed); } } catch (Exception e) { Console.WriteLine(e); } }
/// <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(); }