public static void Connect() { Db = new DbManager("mssql"); string connectionString = ConfigurationUtility .GetString("ConnectionString.irbis") .ThrowIfNull("ConnectionString.irbis = null"); Irbis = new IrbisConnection(connectionString); }
private void MainForm_Load ( object sender, EventArgs e ) { CheckFileExist("irbis64.dll"); CheckFileExist("irbis65.dll"); CheckFileExist("borlndmm.dll"); string serverIniPath = ConfigurationUtility.GetString ( "server-ini" ); if (string.IsNullOrEmpty(serverIniPath)) { ExceptionUtility.Throw ( "server-ini parameter is empty" ); } }
static void Main(string[] args) { if (args.Length < 1 || args.Length > 2) { Console.WriteLine ( "Usage: ReaderKiller <readerList>" ); return; } string fileName = args[0]; doDelete = ConfigurationUtility.GetBoolean ( "delete", false ); databases = ConfigurationUtility.GetString ( "databases", null ) .ThrowIfNull("Databases not specified") .Split ( new[] { ';', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries ); if (databases.Length == 0) { throw new Exception("Empty database list"); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { string connectionString = args.Length > 1 ? args[2] : CM.AppSettings["connectionString"]; string[] tickets = File.ReadAllLines ( fileName, Encoding.UTF8 ); Console.WriteLine ( "Tickets loaded: {0}", tickets.Length ); using (connection = new IrbisConnection()) { connection.SetRetry(10, ExceptionResolver); connection.ParseConnectionString ( connectionString ); connection.Connect(); Console.WriteLine("Connected"); for (int i = 0; i < tickets.Length; i++) { string ticket = tickets[i]; ProcessReader(i, ticket); } } Console.WriteLine("Disconnected"); stopwatch.Stop(); Console.WriteLine ( "Time elapsed: {0}", stopwatch.Elapsed.ToAutoString() ); } catch (Exception exception) { Console.WriteLine(exception); } }
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); } }
private static void Main() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { string connectionString = ConfigurationUtility .GetString("connectionString") .ThrowIfNull("connectionString not set"); Threshold = IrbisDate.ConvertStringToDate ( ConfigurationUtility .GetString("threshold") .ThrowIfNull("threshold not set") ); LowerBound = DateTime.MinValue; string lowerText = ConfigurationUtility.GetString("lowerBound"); if (!string.IsNullOrEmpty(lowerText)) { LowerBound = IrbisDate.ConvertStringToDate(lowerText); } Console.WriteLine("Loading readers"); List <ReaderInfo> allReaders = new List <ReaderInfo>(); OldReaders = new BlockingCollection <ReaderInfo>(); using (IrbisConnection connection = new IrbisConnection(connectionString)) { ReaderManager manager = new ReaderManager(connection) { OmitDeletedRecords = true }; manager.BatchRead += (obj, ea) => Console.Write("."); string[] databases = ConfigurationUtility.GetString("databases") .ThrowIfNull("databases not specified") .Split ( new[] { ' ', ';', ',' }, StringSplitOptions.RemoveEmptyEntries ); foreach (string database in databases) { Console.WriteLine ( "Database: {0}, records: {1}", database, connection.GetMaxMfn(database) - 1 ); allReaders.AddRange ( manager.GetAllReaders(database) ); Console.WriteLine(); } } WriteDelimiter(); Console.WriteLine("Merging"); Console.WriteLine("Records before merging: {0}", allReaders.Count); allReaders = ReaderManager.MergeReaders(allReaders); Console.WriteLine("Records after merging: {0}", allReaders.Count); WriteDelimiter(); Console.WriteLine("Filtering"); ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 4 }; Parallel.ForEach(allReaders, options, ProcessReader); ReaderInfo[] oldReaders = OldReaders.ToArray(); WriteDelimiter(); Console.WriteLine("Sorting"); oldReaders = oldReaders.OrderBy ( reader => reader.FullName ) .ToArray(); WriteDelimiter(); Console.WriteLine ( "Create table: {0} lines", oldReaders.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 = "Отделы"; DrawBorders(worksheet, row); row++; for (int i = 0; i < oldReaders.Length; i++) { if (i % 100 == 0) { Console.Write("."); } ReaderInfo reader = oldReaders[i]; string lastDate = (string)reader.UserData; if (string.IsNullOrEmpty(lastDate)) { lastDate = "--"; } string departments = StringUtility.Join ( ", ", reader.Registrations .Select(reg => reg.Chair) .Concat ( reader.Visits .Select(visit => visit.Department) ) .NonEmptyLines() .Distinct() ); worksheet.Cells[row, 0].Value = reader.FullName; worksheet.Cells[row, 1].Value = reader.Ticket; worksheet.Cells[row, 2].Value = reader.RegistrationDate .ToShortDateString(); worksheet.Cells[row, 3].Value = reader.Visits.Length + reader.Registrations.Length; worksheet.Cells[row, 4].Value = lastDate; worksheet.Cells[row, 5].Value = departments; DrawBorders(worksheet, row); row++; } WriteDelimiter(); workbook.SaveDocument(OutputFile); Console.WriteLine("All done"); stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; Console.WriteLine("Elapsed: {0}", elapsed); Console.WriteLine("Old readers: {0}", oldReaders.Length); } catch (Exception exception) { Console.WriteLine(exception); } }