示例#1
0
        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
        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
        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
        private static PftFormatter _GetFormatter
        (
            [NotNull] PftProgram program
        )
        {
            PftFormatter result = new PftFormatter
            {
                Program = program
            };
            LocalProvider provider = (LocalProvider)result.Context.Provider;

            provider.FallForwardPath = ".";

            return(result);
        }
示例#5
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);
            }
        }
示例#6
0
        private static string _GetDescription
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_briefProgram, null))
            {
                string source = File.ReadAllText("sbrief_istu.pft", IrbisEncoding.Ansi);
                _briefProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_briefProgram);
            string       result    = formatter.FormatRecord(record);

            return(result.Limit(500));
        }
示例#7
0
        private static string _GetLink
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_linkProgram, null))
            {
                string source = File.ReadAllText("link.pft", IrbisEncoding.Ansi);
                _linkProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_linkProgram);
            string       result    = formatter.FormatRecord(record).Limit(200);

            return(result.EmptyToNull());
        }
示例#8
0
        private static int _GetExemplars
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_exemplarsProgram, null))
            {
                string source = File.ReadAllText("exemplars.pft", IrbisEncoding.Ansi);
                _exemplarsProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_exemplarsProgram);
            string       result    = formatter.FormatRecord(record);

            return(result.SafeToInt32());
        }
示例#9
0
        public FstItem
        (
            ManagedClient64 client,
            string format
        )
            : this()
        {
            Format = format;
            PftFormatter formatter = new PftFormatter
            {
                Context = { Client = client }
            };

            formatter.ParseInput(format);
            Program = formatter.Program;
        }
示例#10
0
        private static string _GetAuthors
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_authorsProgram, null))
            {
                string source = File.ReadAllText("authors.pft", IrbisEncoding.Ansi);
                _authorsProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_authorsProgram);
            string       merged    = formatter.FormatRecord(record);

            string[] lines  = merged.SplitLines().NonEmptyLines().ToArray();
            string   result = string.Join("; ", lines).Limit(200);

            return(result.EmptyToNull());
        }
示例#11
0
        private static string _GetTitle
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_titleProgram, null))
            {
                string source = File.ReadAllText("title.pft");
                _titleProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = new PftFormatter
            {
                Program = _titleProgram
            };
            string result = formatter.FormatRecord(record);

            return(result.Limit(250));
        }
示例#12
0
        private static string _GetHeading
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_headingProgram, null))
            {
                string source = File.ReadAllText("heading.pft");
                _headingProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = new PftFormatter
            {
                Program = _headingProgram
            };
            string result = formatter.FormatRecord(record).Limit(128);

            return(result.EmptyToNull());
        }
示例#13
0
        private static string _GetType
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_typeProgram, null))
            {
                string source = File.ReadAllText("type.pft", IrbisEncoding.Ansi);
                _typeProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_typeProgram);
            string       formatted = formatter.FormatRecord(record);
            string       result    = formatted.Contains("1")
                ? "электронный"
                : "традиционный";

            return(result);
        }
示例#14
0
 public string VerifyValue
 (
     string value
 )
 {
     if (string.IsNullOrEmpty(value))
     {
         throw new ArgumentException();
     }
     if (!ReferenceEquals(Client, null))
     {
         PftFormatter formatter = new PftFormatter();
         formatter.ParseInput(value);
         if (formatter.HaveError)
         {
             throw new ArgumentException();
         }
     }
     return(value);
 }
示例#15
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);
            }
        }
示例#16
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);
        }
示例#17
0
        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);
            }
        }
示例#18
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Need 1 argument");
                return;
            }

            string inputFileName = args[0];

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                stopwords = IrbisStopWords.ParseFile("IBIS.STW");

                string source = File.ReadAllText("words.pft");
                formatter = new PftFormatter()
                {
                    Program = PftUtility.CompileProgram(source)
                };

                //DataflowLinkOptions linkOptions = new DataflowLinkOptions
                //{
                //    PropagateCompletion = true
                //};
                //ExecutionDataflowBlockOptions executionOptions
                //    = new ExecutionDataflowBlockOptions
                //{
                //    MaxDegreeOfParallelism = 4
                //};
                //processBlock = new ActionBlock<MarcRecord>
                //    (
                //        (Action<MarcRecord>)ProcessRecord,
                //        executionOptions
                //    );

                using (FileStream stream = File.Create("words.bin"))
                    using (writer = new BinaryWriter(stream))
                        using (accessor = new DirectAccess64(inputFileName))
                        {
                            //maxMfn = accessor.GetMaxMfn();
                            maxMfn = 150000;
                            Console.WriteLine("Max MFN={0}", maxMfn);

                            // Сначала считываем все записи
                            for (int mfn = 1; mfn < maxMfn; mfn++)
                            {
                                ReadRecord(mfn);
                            }
                        }

                using (StreamWriter textWriter = File.CreateText("words.dic"))
                {
                    string[] keys = dictionary.Keys.ToArray();
                    Array.Sort(keys);
                    foreach (string key in keys)
                    {
                        textWriter.WriteLine("{0}\t{1}", key, dictionary[key]);
                    }
                }

                // Дожидаемся завершения
                // processBlock.Complete();
                // processBlock.Completion.Wait();

                Console.WriteLine
                (
                    "Good records={0}, dictionary size={1}, longest array={2}",
                    goodRecords,
                    dictionary.Count,
                    longest
                );

                DictionaryCounterInt32 <int> counter = new DictionaryCounterInt32 <int>();
                using (FileStream stream = File.OpenRead("words.bin"))
                    using (BinaryReader reader = new BinaryReader(stream))
                    {
                        while (stream.Position < stream.Length)
                        {
                            BookData data = new BookData();
                            data.RestoreFromStream(reader);
                            foreach (int word in data.Words)
                            {
                                counter.Increment(word);
                            }
                        }
                    }

                int maxCount  = counter.Values.Max();
                int threshold = maxCount / 5 + 1;
                Console.WriteLine
                (
                    "Max count={0}, threshold={1}",
                    maxCount,
                    threshold
                );

                using (FileStream stream = File.OpenRead("words.bin"))
                    using (BinaryReader reader = new BinaryReader(stream))
                        using (StreamWriter textWriter = File.CreateText("words.csv"))
                        {
                            while (stream.Position < stream.Length)
                            {
                                BookData data = new BookData();
                                data.RestoreFromStream(reader);

                                int i;
                                for (i = 0; i < data.Words.Length; i++)
                                {
                                    textWriter.Write("{0},", data.Words[i]);
                                }
                                for (; i < longest; i++)
                                {
                                    textWriter.Write("0,");
                                }
                                textWriter.WriteLine("{0}", data.Count);
                            }
                        }

                Console.WriteLine("Complete");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            stopwatch.Stop();
            TimeSpan elapsed = stopwatch.Elapsed;

            Console.WriteLine("Elapsed: {0}", elapsed.ToAutoString());
        }
示例#19
0
        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);
            }
        }