示例#1
0
        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);
            }
        }
示例#2
0
        private void Run()
        {
            PftFormatter formatter = new PftFormatter
            {
                Program = _program
            };

            PftUiDebugger debugger
                = new PftUiDebugger(formatter.Context);

            formatter.Context.Debugger = debugger;

            DatabaseInfo database = _databaseBox.SelectedItem
                                    as DatabaseInfo;

            if (!ReferenceEquals(database, null))
            {
                _provider.Database = database.Name
                                     .ThrowIfNull("database.Name");
            }
            formatter.SetProvider(_provider);

            string result = formatter.FormatRecord(_record);

            _resutlBox.Text = result;
            try
            {
                _rtfBox.Rtf = result;
            }
            catch
            {
                _rtfBox.Text = result;
            }

            if (ReferenceEquals(_htmlBox.Document, null))
            {
                _htmlBox.Navigate("about:blank");
                while (_htmlBox.IsBusy)
                {
                    Application.DoEvents();
                }
            }
            if (!ReferenceEquals(_htmlBox.Document, null))
            {
                _htmlBox.Document.Write(result);
            }
            try
            {
                _htmlBox.DocumentText =
                    "<html>"
                    + result
                    + "</html>";
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Nothing to do
            }

            _recordGrid.SetRecord(_record);

            _warningBox.Text = formatter.Warning;

            _varsGrid.SetVariables(formatter.Context.Variables);
            _globalsGrid.SetGlobals(formatter.Context.Globals);
        }