Exemple #1
0
        static void Test2(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("IrbisInteropTester <irbis_server.ini>");
                return;
            }

            try
            {
                ServerConfiguration configuration
                    = ServerConfiguration.FromIniFile(args[0]);
                using (Irbis64Dll irbis = new Irbis64Dll(configuration))
                {
                    Console.WriteLine
                    (
                        "Irbis64.dll version={0}",
                        Irbis64Dll.GetDllVersion()
                    );

                    irbis.UseDatabase("ibis");
                    //irbis.UseDatabase("ISTU");
                    Console.WriteLine
                    (
                        "Max MFN={0}",
                        irbis.GetMaxMfn()
                    );

                    string briefPft = irbis.GetPftPath("brief");
                    irbis.SetFormat("@" + briefPft);

                    for (int mfn = 10; mfn < 20; mfn++)
                    {
                        irbis.ReadRecord(mfn);
                        Console.WriteLine("Read record MFN={0}", mfn);

                        NativeRecord record = irbis.GetRecord();
                        Console.WriteLine(record);

                        string text = irbis.FormatRecord();
                        Console.WriteLine(text);

                        Console.WriteLine();
                    }

                    Console.WriteLine();

                    Console.WriteLine
                    (
                        "Record offset={0}, formatted offset={1}",
                        irbis.Layout.Value.RecordOffset,
                        irbis.Layout.Value.FormattedOffset
                    );

                    Console.WriteLine();

                    TermInfo[] terms = irbis.ListTerms("K=", 50);
                    for (int i = 0; i < terms.Length; i++)
                    {
                        Console.WriteLine(terms[i]);
                    }

                    Console.WriteLine();

                    terms = irbis.ExactSearchTrimEx("K=БЕТОН", 200);
                    for (int i = 0; i < terms.Length; i++)
                    {
                        Console.WriteLine(terms[i]);
                    }

                    Console.WriteLine();

                    TermLink[] links = irbis.ExactSearchLinks
                                       (
                        "K=1 КЛАСС"
                                       );
                    for (int i = 0; i < links.Length; i++)
                    {
                        Console.WriteLine(links[i]);
                    }

                    Console.WriteLine();

                    links = irbis.ExactSearchTrimLinks
                            (
                        "K=БЕТОН",
                        200
                            );
                    for (int i = 0; i < links.Length; i++)
                    {
                        Console.WriteLine(links[i]);
                    }

                    Console.WriteLine();

                    IrbisProvider provider = new NativeIrbisProvider(irbis);
                    SearchManager manager  = new SearchManager(provider);
                    SearchContext context  = new SearchContext(manager, provider);
                    links = irbis.Search("K=БЕТОН", context);
                    for (int i = 0; i < links.Length; i++)
                    {
                        Console.WriteLine(links[i]);
                    }

                    Console.WriteLine();

                    links = irbis.Search("K=БЕТОН * K=ЖЕЛЕЗО$", context);
                    for (int i = 0; i < links.Length; i++)
                    {
                        Console.WriteLine(links[i]);
                    }

                    Console.WriteLine();

                    string testDatabase = Path.Combine
                                          (
                        Path.GetDirectoryName
                        (
                            Assembly.GetEntryAssembly().Location
                        )
                        .ThrowIfNull("directory is unknown"),
                        "TestDb"
                                          );

                    irbis.UseStandaloneDatabase
                    (
                        testDatabase,
                        "TestDb"
                    );

                    for (int i = 0; i < 10; i++)
                    {
                        int          number = i + 1;
                        NativeRecord record = new NativeRecord();
                        for (int j = 0; j < 10; j++)
                        {
                            NativeField field = new NativeField
                            {
                                Tag   = 100 + j,
                                Value = "Запись номер " + number
                                        + " поле " + (100 + j)
                            };
                            record.Fields.Add(field);
                        }

                        irbis.NewRecord();
                        irbis.SetRecord(record);
                        irbis.WriteRecord(true, false);

                        irbis.SetFormat("v100");
                        string text = irbis.FormatRecord();
                        Console.WriteLine(text);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }