private void _searchButton_Click ( object sender, EventArgs e ) { _resultBox.Clear(); _loginBox.Clear(); _passwordBox.Clear(); string ticket = _ticketBox.Text.Trim(); if (string.IsNullOrEmpty(ticket)) { _resultBox.Text = Environment.NewLine + Resources.MainForm_NoIogunbTicket; return; } using (IrbisConnection connection = GetConnection()) { string expression = string.Format ( "\"RI={0}\"", ticket ); int[] found = connection.Search(expression); if (found.Length == 0) { _resultBox.Text = Environment.NewLine + Resources.MainForm_NoReaderFound; _ticketBox.Focus(); return; } if (found.Length != 1) { _resultBox.Text = Environment.NewLine + Resources.MainForm_ManyReadersFound; _ticketBox.Focus(); return; } MarcRecord record = connection.ReadRecord(found[0]); string description = connection.FormatRecord("@brief", found[0]); _resultBox.Text = Environment.NewLine + description; RecordField litresField = record.Fields .GetFirstField(_litresTag); if (!ReferenceEquals(litresField, null)) { _loginBox.Text = litresField.GetFirstSubFieldValue('a'); _passwordBox.Text = litresField.GetFirstSubFieldValue('b'); } _loginBox.Focus(); } }
static void DumpTerm ( [NotNull] IrbisConnection connection, [NotNull] TermInfo term ) { Console.WriteLine(term.Text); PostingParameters parameters = new PostingParameters { Database = connection.Database, Term = term.Text }; TermPosting[] postings = connection.ReadPostings(parameters); Console.WriteLine("\tPostings: {0}", postings.Length); foreach (TermPosting posting in postings) { Console.WriteLine ( "\tMFN={0} Tag={1} Occ={2} Count={3}", posting.Mfn, posting.Tag, posting.Occurrence, posting.Count ); try { MarcRecord record = connection.ReadRecord(posting.Mfn); RecordField field = record.Fields .GetField(posting.Tag) .GetOccurrence(posting.Occurrence - 1); if (ReferenceEquals(field, null)) { Console.WriteLine(); } else { Console.WriteLine ( "\t{0}", field.ToText() ); Console.WriteLine(); } } catch { // Nothing to do here } } Console.WriteLine(); }
public void DatabaseInfo_Test1() { IrbisConnection connection = Connection .ThrowIfNull("Connection"); connection.ReadRecord("IBIS", 3, true, null); DatabaseInfo info = connection.GetDatabaseInfo("IBIS"); Write(info); Write(" "); connection.UnlockRecords("IBIS", 3); info = connection.GetDatabaseInfo("IBIS"); Write(info); Write(" "); }
private void _undeleteButton_Click ( object sender, EventArgs e ) { int mfn = CurrentMfn; if (mfn != 0) { MarcRecord record = _client.ReadRecord(mfn); if (record.Deleted) { _client.UndeleteRecord(record.Mfn); } } }
private void _TestBinaryResource ( int mfn ) { IrbisConnection connection = Connection .ThrowIfNull("Connection"); MarcRecord record = connection.ReadRecord(mfn); BinaryResource[] resources = BinaryResource.Parse(record); for (int i = 0; i < resources.Length; i++) { BinaryResource resource = resources[i]; string fileName = string.Format ( "res{0:00000}-{1}.{2}", mfn, (i + 1), resource.Kind ); string filePath = Path.Combine ( Path.GetTempPath(), fileName ); byte[] array = resource.Decode(); File.WriteAllBytes ( filePath, array ); Write ( "{0} ", filePath ); } }
public void Search_Read() { IrbisConnection connection = Connection .ThrowIfNull("Connection"); MarcRecord[] records = connection.SearchRead("T=ABA$"); int[] mfns = records.Select(r => r.Mfn).ToArray(); bool ok = true; int count = Math.Min(10, records.Length); for (int i = 0; i < count; i++) { MarcRecord record = connection.ReadRecord ( records[i].Mfn ); string diagnostic = string.Format ( "MFN={0}, Version={1}, Version={2} Fields={3}{4}", record.Mfn, record.Version, record.Version, record.Fields.Count, Environment.NewLine ); Write(diagnostic); ok = ok && records[i].Version == record.Version; } if (!ok) { throw new IrbisException("SearchRead -> wrong version!"); } }
static void Main() { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Threshold = new DateTime(DateTime.Today.Year, 1, 1); string thresholdString = CM.AppSettings["threshold"]; if (!string.IsNullOrEmpty(thresholdString)) { Threshold = DateTime.Parse(thresholdString); } TailDb = CM.AppSettings["tail-db"]; int total = 0; int cropped = 0; string connectionString = CM.AppSettings["connection-string"]; using (IrbisConnection connection = new IrbisConnection(connectionString)) { int[] mfns = connection.Search ( "RI=$" ); const int delta = 1000; for (int i = 0; i < mfns.Length; i += delta) { int[] sub = mfns .Skip(i) .Take(delta) .ToArray(); MarcRecord[] records = connection.ReadRecords ( connection.Database, sub ); foreach (MarcRecord record in records) { if (record.Deleted) { continue; } total++; Console.WriteLine("ELAPSED: {0}", FormatSpan(stopwatch.Elapsed)); ReaderInfo reader = ReaderInfo.Parse(record); Console.WriteLine(reader); VisitInfo[] visits = record .Fields .GetField(40) .Select(VisitInfo.Parse) .Where(loan => loan.IsVisit || loan.IsReturned) .ToArray(); VisitInfo[] old = visits .Where(visit => visit.DateGiven < Threshold) .ToArray(); Console.WriteLine("VISITS TOTAL: {0}", visits.Length); Console.WriteLine("VISITS TO DELETE: {0}", old.Length); if (old.Length != 0) { if (!string.IsNullOrEmpty(TailDb)) { connection.PushDatabase(TailDb); int[] tailMfns = new int[0]; try { tailMfns = connection.Search("\"RI={0}\"", reader.Ticket); } catch (Exception ex) { Debug.WriteLine(ex); } MarcRecord copy; if (tailMfns.Length != 0) { copy = connection.ReadRecord(tailMfns[0]); Console.WriteLine("USING OLD RECORD {0}", tailMfns[0]); } else { copy = new MarcRecord(); RecordField[] non40 = record .Fields .Where(field => field.Tag != 40) .ToArray(); copy.Fields.AddRange(non40); Console.WriteLine("COPY CREATED"); } RecordField[] old40 = old.Select(loan => loan.Field).ToArray(); copy.Fields.AddRange(old40); try { connection.WriteRecord(copy, false, true); } catch (Exception ex) { Console.WriteLine("CAN'T WRITE COPY, SKIP"); Debug.WriteLine(ex); continue; } finally { connection.PopDatabase(); } Console.WriteLine("COPY WRITTEN"); } MarcRecord r2; try { r2 = connection.ReadRecord(record.Mfn); } catch (Exception ex) { Console.WriteLine("CAN'T REREAD RECORD, SKIP"); Debug.WriteLine(ex); continue; } RecordField[] toDelete = r2 .Fields .GetField(40) .Select(VisitInfo.Parse) .Where(loan => loan.IsVisit || loan.IsReturned) .Where(visit => visit.DateGiven < Threshold) .Select(visit => visit.Field) .ToArray(); foreach (RecordField field in toDelete) { r2.Fields.Remove(field); } try { connection.WriteRecord(r2, false, true); } catch (Exception ex) { Console.WriteLine("CAN'T WRITE MODIFIED RECORD, SKIP"); Debug.WriteLine(ex); continue; } Console.WriteLine("RECORD WRITTEN"); cropped++; } Console.WriteLine(new string('=', 60)); } } } stopwatch.Stop(); Console.WriteLine("TOTAL={0}", total); Console.WriteLine("CROPPED={0}", cropped); Console.WriteLine("ELAPSED={0}", FormatSpan(stopwatch.Elapsed)); } catch (Exception exception) { Console.WriteLine(exception); } }
private static void ProcessRecord ( int mfn ) { connection.Database = MainDatabase; MarcRecord mainRecord = connection.ReadRecord(mfn); string linkValue = mainRecord.FM(LinkTag); connection.Database = BackupDatabase; MarcRecord backupRecord = connection.SearchReadOneRecord ( "\"{0}{1}\"", LinkPrefix, linkValue ); if (ReferenceEquals(backupRecord, null)) { Console.WriteLine ( "Не нашлось парной записи для MFN={0} ({1}{2})", mfn, LinkPrefix, linkValue ); Console.WriteLine(new string('=', 70)); return; } Console.WriteLine("MFN={0}", mfn); RevisionInfo[] revisions = RevisionInfo.Parse(mainRecord) .Where(rev => rev.Name != "avd") .ToArray(); if (revisions.Length == 0) { Console.WriteLine("Запись без ревизий!"); Console.WriteLine(new string('=', 70)); return; } RevisionInfo lastRevision = revisions.Last(); DateTime lastEdit = IrbisDate.ConvertStringToDate(lastRevision.Date); Console.WriteLine ( "Последнее редактирование: {0} {1:d}", lastRevision.Name, lastEdit ); if (lastEdit > ThresholdDate) { Console.WriteLine("Запись редактировалась, надо восстанавливать вручную"); Console.WriteLine(new string('=', 70)); return; } if (CompareRecords(mainRecord, backupRecord)) { Console.WriteLine("Нет различий между MAIN и BACKUP"); goto DONE; } if (DoRestore) { RecordField[] residuaryFields = mainRecord.Fields .Where(field => field.Tag.OneOf(ResiduaryTags)) .Select(field => field.Clone()) .ToArray(); RecordField[] backupFields = backupRecord.Fields .Where(field => !field.Tag.OneOf(ResiduaryTags)) .Select(field => field.Clone()) .ToArray(); mainRecord.Fields.Clear(); mainRecord.Fields.AddRange(backupFields); mainRecord.Fields.AddRange(residuaryFields); Console.WriteLine ( "Сформирована новая версия записи: {0} новых и {1} старых полей", residuaryFields.Length, backupFields.Length ); connection.WriteRecord(mainRecord); } DONE: Console.WriteLine(new string('=', 70)); Console.WriteLine(); }
private void _bindButton_Click ( object sender, EventArgs e ) { _resultBox.Clear(); string ticket = _ticketBox.Text.Trim(); if (string.IsNullOrEmpty(ticket)) { _resultBox.Text = Environment.NewLine + Resources.MainForm_NoIogunbTicket; _ticketBox.Focus(); return; } string login = _loginBox.Text.Trim(); string pasword = _passwordBox.Text.Trim(); if (string.IsNullOrEmpty(login) != string.IsNullOrEmpty(pasword)) { _resultBox.Text = Environment.NewLine + Resources.MainForm_BothLoginAndPasswordRequired; _loginBox.Focus(); return; } using (IrbisConnection connection = GetConnection()) { string expression = string.Format ( "\"RI={0}\"", ticket ); int[] found = connection.Search(expression); if (found.Length == 0) { _resultBox.Text = Environment.NewLine + Resources.MainForm_NoReaderFound; _ticketBox.Focus(); return; } if (found.Length != 1) { _resultBox.Text = Environment.NewLine + Resources.MainForm_ManyReadersFound; _ticketBox.Focus(); return; } MarcRecord record = connection.ReadRecord(found[0]); record.Modified = false; RecordField litresField = record.Fields .GetFirstField(_litresTag); if (ReferenceEquals(litresField, null)) { if (!string.IsNullOrEmpty(login)) { litresField = new RecordField(_litresTag) .AddSubField('a', login) .AddSubField('b', pasword); record.Fields.Add(litresField); } else { MessageBox.Show ( Resources.MainForm_NothingToDo, Resources.MainForm_QuestionTitle, MessageBoxButtons.OK, MessageBoxIcon.Error ); } } else { if (_AskForRewrite()) { if (string.IsNullOrEmpty(login)) { litresField.RemoveSubField('a'); } else { litresField.SetSubField('a', login); } if (string.IsNullOrEmpty(pasword)) { litresField.RemoveSubField('b'); } else { litresField.SetSubField('b', pasword); } } } if (record.Modified) { connection.WriteRecord(record); _resultBox.Text = Environment.NewLine + Resources.MainForm_DataWasCommited; } _ticketBox.Clear(); _loginBox.Clear(); _passwordBox.Clear(); _ticketBox.Focus(); } }
private void _HandleNumber ( [CanBeNull] string number ) { _currentRecord = null; _currentExemplar = null; _SetHtml(string.Empty); if (string.IsNullOrEmpty(number)) { return; } _logBox.Output.WriteLine ( "Введен номер: {0}", number ); string prefix = CM.AppSettings["prefix"]; int[] found = _client.Search ( "\"{0}{1}\"", prefix, number ); if (found.Length == 0) { _SetHtml ( "Не найден номер {0}", number ); return; } if (found.Length != 1) { _SetHtml ( "Много записей для номера {0}", number ); return; } MarcRecord record = _client.ReadRecord(found[0]); RecordField[] fields = record.Fields .GetField(910) .GetField('b', number); if (fields.Length == 0) { _SetHtml ( "Не найдено поле с номером {0}", number ); return; } if (fields.Length != 1) { _SetHtml ( "Много полей с номером {0}", number ); return; } ExemplarInfo exemplar = ExemplarInfo.Parse(fields[0]); StringBuilder diagnosis = new StringBuilder(); diagnosis.AppendFormat ( "<b>{0}</b><br/>", number ); if (!string.IsNullOrEmpty(exemplar.RealPlace)) { diagnosis.AppendFormat ( "<font color='red'>Экземпляр уже был проверен " + "в фонде</font> <b>{0}</b> ({1})<br/>", exemplar.RealPlace, exemplar.CheckedDate ); } if (exemplar.Status != "0") { diagnosis.AppendFormat ( "<font color='red'>Неверный статус " + "экземпляра: </font><b>{0}</b><br/>", exemplar.Status ); } if (!exemplar.Place.SameString(CurrentFond)) { diagnosis.AppendFormat ( "<font color='red'>Неверное место хранения " + "экземпляра: </font><b>{0}</b><br/>", exemplar.Place ); } string currentShelf = CurrentShelf; if (!string.IsNullOrEmpty(currentShelf)) { string[] items = currentShelf .Split(',', ';') .Select(item => item.Trim()) .NonEmptyLines() .Select(item => item.ToUpperInvariant()) .ToArray(); string shelf = record.FM(906); if (string.IsNullOrEmpty(shelf)) { diagnosis.AppendFormat ( "<font color='red'>Для книги не указан " + "расстановочный шифр</font><br/>" ); } else if (items.Length != 0) { shelf = shelf.ToUpperInvariant(); bool good = false; foreach (string item in items) { if (shelf.StartsWith(item)) { good = true; break; } } if (!good) { diagnosis.AppendFormat ( "<font color='red'>Неверный шифр: " + "</font><b>{0}</b><br/>", shelf ); } } } string currentCollection = CurrentCollection; if (!string.IsNullOrEmpty(currentCollection)) { string collection = exemplar.Collection; if (currentCollection != collection) { if (string.IsNullOrEmpty(collection)) { diagnosis.AppendFormat ( "<font color='red'>Для книги не указана " + "коллекция" ); } else { diagnosis.AppendFormat ( "<font color='red'>Неверная коллекция: " + "</font><b>{0}</b><br/>", collection ); } } } diagnosis.AppendLine("<br/>"); string cardFormat = CM.AppSettings["card-format"]; string briefDescription = _client.FormatRecord ( cardFormat, record.Mfn ).Trim(); diagnosis.Append(briefDescription); record.UserData = briefDescription; _SetHtml ( "{0}", diagnosis.ToString() ); _currentRecord = record; _currentExemplar = exemplar; }