private void _goButton_Click ( object sender, EventArgs e ) { _console.Clear(); string searchExpression = _searchBox.Text.Trim(); if (string.IsNullOrEmpty(searchExpression)) { return; } try { int counter = 0; string programText = _programBox.Text; IrbisProvider provider = new ConnectedClient(Connection); PftFormatter formatter = new PftFormatter(); formatter.SetProvider(provider); formatter.ParseProgram(programText); formatter.Context.Functions.Add("print", _Printer); DatabaseInfo database = (DatabaseInfo)_dbBox.SelectedItem; string databaseName = database.Name.ThrowIfNull(); SearchParameters parameters = new SearchParameters { Database = databaseName, SearchExpression = searchExpression }; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int[] found = Connection.SequentialSearch(parameters); Output.WriteLine("Found: {0}", found.Length); BatchRecordReader batch = new BatchRecordReader ( Connection, databaseName, 500, found ); using (BatchRecordWriter buffer = new BatchRecordWriter ( Connection, databaseName, 100 )) { foreach (MarcRecord record in batch) { record.Modified = false; formatter.Context.ClearAll(); string text = formatter.FormatRecord(record); if (!string.IsNullOrEmpty(text)) { Output.WriteLine(text); } if (record.Modified) { counter++; Output.WriteLine ( "[{0}] modified", record.Mfn ); buffer.Append(record); } Application.DoEvents(); } } stopwatch.Stop(); Output.WriteLine(string.Empty); Output.WriteLine("Done: {0}", stopwatch.Elapsed); Output.WriteLine("Records modified: {0}", counter); Output.WriteLine(string.Empty); } catch (Exception ex) { Output.WriteLine("Exception: {0}", ex); } }
static int Main(string[] arguments) { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string connectionString = CM.AppSettings["connectionString"]; if (string.IsNullOrEmpty(connectionString)) { Console.WriteLine("Connection string not specified"); return(1); } CommandLineParser parser = new CommandLineParser(); ParsedCommandLine parsed = parser.Parse(arguments); if (parsed.PositionalArguments.Count != 0) { connectionString = parsed.PositionalArguments[0]; } using (IrbisConnection connection = new IrbisConnection(connectionString)) { int maxMfn = connection.GetMaxMfn(); string expression = RequestPrefixes.Unfulfilled /* I=0 */ + " + " + RequestPrefixes.Reserved; /* I=2 */ if (parsed.HaveSwitch("expression")) { expression = parsed.GetSwitch("expression") .ThrowIfNull() .Value; } expression = expression.ThrowIfNull("expression"); Console.Write("Reading good records "); MarcRecord[] goodRecords = BatchRecordReader.Search ( connection, connection.Database, expression, 1000, batch => Console.Write(".") ) .ToArray(); Console.WriteLine(); Console.WriteLine ( "Good records loaded: {0}", goodRecords.Length ); if (goodRecords.Length == maxMfn) { Console.WriteLine("No truncation needed, exiting"); return(0); } connection.TruncateDatabase(connection.Database); Console.WriteLine("Database truncated"); using (BatchRecordWriter writer = new BatchRecordWriter ( connection, connection.Database, 500 )) { foreach (MarcRecord record in goodRecords) { record.Version = 0; record.Mfn = 0; writer.Append(record); } } Console.WriteLine("Good records restored"); stopwatch.Stop(); Console.WriteLine ( "Elapsed: {0}", stopwatch.Elapsed.ToAutoString() ); } } catch (Exception ex) { Console.WriteLine(ex); return(1); } return(0); }