private void _startupTimer_Tick ( object sender, EventArgs e ) { Timer timer = (Timer)sender; timer.Enabled = false; _litresTag = ConfigurationUtility.GetInt32("litresTag", 101); using (IrbisConnection connection = GetConnection()) { connection.NoOp(); } }
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); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: grab <url>"); return; } try { _sleep = ConfigurationUtility.GetInt32("sleep", 3000); Console.WriteLine($"Sleep={_sleep}ms"); _scale = ConfigurationUtility.GetInt32("scale", 4); Console.WriteLine($"Scale={_scale}x"); _pageUrl = Url.Create(args[0]); _pdfFileName = Path.ChangeExtension ( Path.GetFileNameWithoutExtension(_pageUrl.Path), ".pdf" ); _browsingConfiguration = Configuration.Default.WithDefaultLoader(); _browsingContext = BrowsingContext.New(_browsingConfiguration); IDocument document = _browsingContext.OpenAsync(_pageUrl).Result; Console.WriteLine("HTML downloaded"); string selector = "script"; IHtmlCollection <IElement> scripts = document.QuerySelectorAll(selector); Console.WriteLine($"Scripts: {scripts.Length}"); IElement scriptElement = scripts.First ( e => e.InnerHtml.StartsWith("jQuery.extend") ); string json = scriptElement.InnerHtml; int offset = json.IndexOf('{'); int length = json.LastIndexOf('}') - offset + 1; json = json.Substring(offset, length); JObject root = JObject.Parse(json); JValue token = (JValue)root.SelectToken("$.diva.1.options.objectData"); if (ReferenceEquals(token, null)) { Console.WriteLine("Not a book"); return; } string dataUrl = (string)token.Value; Console.WriteLine($"Data URL={dataUrl}"); token = (JValue)root.SelectToken("$.diva.1.options.iipServerURL"); if (ReferenceEquals(token, null)) { Console.WriteLine("No ServerUrl"); return; } _serverUrl = (string)token.Value; Console.WriteLine($"Server URL={_serverUrl}"); token = (JValue)root.SelectToken("$.diva.1.options.imageDir"); if (ReferenceEquals(token, null)) { Console.WriteLine("No imageDir"); return; } _imageDir = (string)token.Value; Console.WriteLine($"Image dir={_imageDir}"); _webClient = new WebClient(); json = _webClient.DownloadString(dataUrl); root = JObject.Parse(json); JArray array = (JArray)root.SelectToken("pgs"); _pages = array.ToObject <Page[]>(); Console.WriteLine($"Total pages={_pages.Length}"); int pageNumber = 1; foreach (Page page in _pages) { if (DownloadPage(pageNumber, page)) { Thread.Sleep(_sleep); } pageNumber++; } BuildDocument(); } catch (Exception exception) { Console.WriteLine(exception); } }