コード例 #1
0
ファイル: Program.cs プロジェクト: fossabot/ManagedIrbis
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: FormatBenchmark <rootPath> <format>");

                return;
            }

            string rootPath = args[0];
            string format   = args[1];

            try
            {
                IrbisEncoding.RelaxUtf8();

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    provider.Database = "IBIS";
                    int maxMfn = provider.GetMaxMfn();
                    Console.WriteLine("Max MFN={0}", maxMfn);

                    PftContext context = new PftContext(null);
                    context.SetProvider(provider);
                    PftFormatter formatter = new PftFormatter(context);
                    formatter.ParseProgram(format);

                    for (int mfn = 1; mfn <= maxMfn; mfn++)
                    {
                        MarcRecord record = provider.ReadRecord(mfn);
                        if (ReferenceEquals(record, null))
                        {
                            continue;
                        }

                        string text = formatter.FormatRecord(record);
                        Console.WriteLine(text);
                    }
                }

                stopwatch.Stop();

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine
                (
                    "Elapsed: {0} sec",
                    stopwatch.Elapsed.ToSecondString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: fossabot/ManagedIrbis
        static void Main()
        {
            try
            {
                if (!Directory.Exists(LocalRootPath))
                {
                    throw new ApplicationException
                          (
                              "Root path doesn't exist!"
                          );
                }

                using (LocalClient client
                           = new LocalClient(LocalRootPath))
                {
                    client.Database = "IBIS";

                    MarcRecord record = client.ReadRecord
                                        (
                        client.GetMaxMfn() / 2
                                        );
                    if (ReferenceEquals(record, null))
                    {
                        throw new ApplicationException
                              (
                                  "Can't read record"
                              );
                    }

                    // See the record content (for debug)
                    // Console.WriteLine(record.ToPlainText());

                    using (PftFormatter formatter = new PftFormatter())
                    {
                        formatter.SetEnvironment(client);

                        formatter.ParseProgram(ScriptText);

                        // We can use @file syntax
                        // formatter.ParseProgram("@brief");

                        string result = formatter.Format(record);

                        Console.WriteLine(result);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: fossabot/ManagedIrbis
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            string rootPath = args[0];
            string format   = args[1];

            // Log.ApplyDefaultsForConsoleApplication();

            try
            {
                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    FileSpecification specification = new FileSpecification
                                                      (
                        IrbisPath.MasterFile,
                        provider.Database,
                        format
                                                      );
                    string source = provider.ReadFile(specification);
                    if (string.IsNullOrEmpty(source))
                    {
                        Console.WriteLine("No file: {0}", format);
                    }
                    else
                    {
                        PftContext context = new PftContext(null);
                        context.SetProvider(provider);
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(source);

                        PftProgram       program = formatter.Program;
                        AbstractOutput   console = new ConsoleOutput();
                        PftPrettyPrinter printer = new PftPrettyPrinter();
                        console.WriteLine(string.Empty);
                        console.WriteLine(new string('=', 60));
                        console.WriteLine(string.Empty);
                        console.WriteLine(string.Empty);
                        program.PrettyPrint(printer);
                        console.WriteLine(printer.ToString());
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: ParseBenchmark <format>");

                return;
            }

            string formatFile  = args[0];
            string programText = File.ReadAllText(formatFile, IrbisEncoding.Ansi);

            try
            {
                IrbisEncoding.RelaxUtf8();

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                using (NullProvider provider = new NullProvider())
                {
                    provider.Database = "IBIS";

                    PftContext context = new PftContext(null);
                    context.SetProvider(provider);

                    for (int i = 0; i < 10000; i++)
                    {
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(programText);
                    }
                }

                stopwatch.Stop();

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine
                (
                    "Elapsed: {0} sec",
                    stopwatch.Elapsed.ToSecondString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: fossabot/ManagedIrbis
        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);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: fossabot/ManagedIrbis
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                return;
            }

            string rootPath = args[0];
            string fileName = args[1];
            string format   = args[2];

            Log.ApplyDefaultsForConsoleApplication();

            try
            {
                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    FileSpecification specification = new FileSpecification
                                                      (
                        IrbisPath.MasterFile,
                        provider.Database,
                        format
                                                      );
                    string source = provider.ReadFile(specification);
                    if (string.IsNullOrEmpty(source))
                    {
                        Console.WriteLine("No file: {0}", format);
                    }
                    else
                    {
                        PftContext context = new PftContext(null);
                        context.SetProvider(provider);
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(source);

                        PftSerializer.Save(formatter.Program, fileName);

                        PftProgram program
                            = (PftProgram)PftSerializer.Read(fileName);

                        PftSerializationUtility.VerifyDeserializedProgram
                        (
                            formatter.Program,
                            program
                        );

                        PftNodeInfo nodeInfo = program.GetNodeInfo();

                        AbstractOutput console = new ConsoleOutput();
                        PftNodeInfo.Dump(console, nodeInfo, 0);

                        byte[] bytes
                            = PftSerializer.ToMemory(formatter.Program);

                        for (int i = 0; i < 10000; i++)
                        {
                            PftProgram restoredProgram
                                = (PftProgram)PftSerializer.FromMemory(bytes);
                            console.WriteLine("{0}", i + 1);
                            //console.WriteLine(restoredProgram.ToString());
                        }

                        PftPrettyPrinter printer = new PftPrettyPrinter();
                        program.PrettyPrint(printer);
                        console.WriteLine(printer.ToString());
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: fossabot/ManagedIrbis
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            string rootPath   = args[0];
            string formatName = args[1];

            try
            {
                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    FileSpecification specification = new FileSpecification
                                                      (
                        IrbisPath.MasterFile,
                        provider.Database,
                        formatName
                                                      );
                    string source = provider.ReadFile(specification);
                    if (string.IsNullOrEmpty(source))
                    {
                        Console.WriteLine("No file: {0}", formatName);
                    }
                    else
                    {
                        PftContext context = new PftContext(null);
                        context.SetProvider(provider);
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(source);

                        PftProgram program
                            = (PftProgram)formatter.Program.Clone();
                        program.Optimize();

                        //Console.WriteLine(program.DumpToText());
                        //Console.WriteLine();

                        if (!Directory.Exists("Out"))
                        {
                            Directory.CreateDirectory("Out");
                        }

                        PftCompiler compiler = new PftCompiler
                        {
                            Debug      = true,
                            KeepSource = true,
                            //OutputPath = "Out"
                            OutputPath = "."
                        };
                        compiler.SetProvider(provider);
                        string className = compiler.CompileProgram
                                           (
                            program
                                           );

                        //string sourceCode = compiler.GetSourceCode();
                        //Console.WriteLine(sourceCode);

                        AbstractOutput output       = AbstractOutput.Console;
                        string         assemblyPath = compiler.CompileToDll
                                                      (
                            output,
                            className
                                                      );
                        if (!ReferenceEquals(assemblyPath, null))
                        {
                            Console.WriteLine
                            (
                                "Compiled to {0}",
                                assemblyPath
                            );

                            MarcRecord record = provider.ReadRecord(1);

                            //if (!ReferenceEquals(record, null))
                            //{
                            //    Assembly assembly
                            //        = Assembly.LoadFile(assemblyPath);
                            //    Func<PftContext, PftPacket> creator
                            //        = CompilerUtility.GetEntryPoint(assembly);
                            //    PftPacket packet = creator(context);
                            //    string formatted = packet.Execute(record);
                            //    Console.WriteLine(formatted);

                            //    Stopwatch stopwatch = new Stopwatch();
                            //    stopwatch.Start();
                            //    for (int i = 0; i < 100000; i++)
                            //    {
                            //        if (i % 1000 == 0)
                            //        {
                            //            Console.WriteLine(i);
                            //        }
                            //        packet.Execute(record);
                            //    }
                            //    stopwatch.Stop();
                            //    Console.WriteLine(stopwatch.Elapsed);
                            //}

                            if (!ReferenceEquals(record, null))
                            {
                                using (RemoteFormatter remote
                                           = new RemoteFormatter(assemblyPath))
                                {
                                    PftPacket packet = remote.GetFormatter(context);
                                    Console.WriteLine(RemotingServices.IsTransparentProxy(packet));
                                    string formatted = packet.Execute(record);
                                    Console.WriteLine(formatted);

                                    Stopwatch stopwatch = new Stopwatch();
                                    stopwatch.Start();
                                    for (int i = 0; i < 100; i++)
                                    {
                                        if (i % 10 == 0)
                                        {
                                            Console.WriteLine(i);
                                        }
                                        packet.Execute(record);
                                    }
                                    stopwatch.Stop();
                                    Console.WriteLine(stopwatch.Elapsed);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }