Exemple #1
0
        static void DoBenchmark()
        {
            using (IrbisConnection connection = new IrbisConnection())
            {
                connection.ParseConnectionString(ConnectionString);
                connection.Connect();
                Console.WriteLine("Connected");

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

                for (int i = 0; i < RetryCount; i++)
                {
                    connection.NoOp();
                }

                stopwatch.Stop();
                connection.Dispose();
                Console.WriteLine("Disconnected");

                long ms = stopwatch.ElapsedMilliseconds;
                Console.WriteLine("Elapsed: {0} ms", ms);
                long one = ms / RetryCount;
                Console.WriteLine("One: {0} ms", one);
            }
        }
Exemple #2
0
        public static T FindSocket <T>
        (
            [NotNull] IrbisConnection connection
        )
            where T : AbstractClientSocket
        {
            Sure.NotNull(connection, nameof(connection));

            T result = null;

            for (
                AbstractClientSocket socket = connection.Socket;
                !ReferenceEquals(socket, null);
                socket = socket.InnerSocket
                )
            {
                T temp = socket as T;
                if (!ReferenceEquals(temp, null))
                {
                    result = temp;
                    break;
                }
            }

            return(result);
        }
Exemple #3
0
        public void CreateDatabase_Test1()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            const string DatabaseName = "NEWDB2";
            const string Description  = "New database 2";

            connection.CreateDatabase
            (
                DatabaseName,
                Description,
                false,
                null
            );

            Write("{0} created | ", DatabaseName);

            Thread.Sleep(700);

            int maxMfn = connection.GetMaxMfn(DatabaseName);

            Write("MaxMfn={0} | ", maxMfn);

            Thread.Sleep(700);

            connection.DeleteDatabase(DatabaseName);

            Write("{0} deleted", DatabaseName);
        }
Exemple #4
0
        private void MainForm_Load
        (
            object sender,
            EventArgs e
        )
        {
            _client = new IrbisConnection();
            string connectionString = CM.AppSettings["connection-string"];

            _client.ParseConnectionString(connectionString);
            try
            {
                _client.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Application.Exit();
            }

            DatabaseInfo[] bases = _client.ListDatabases();
            _databaseBox.DisplayMember = "Name";
            _databaseBox.Items.AddRange(bases);
            _databaseBox.SelectedIndex = 0;
        }
        public void SearchManager_LoadSearchScenarios()
        {
            IrbisConnection connection
                = Connection.ThrowIfNull();

            IrbisProvider provider
                = new ConnectedClient(connection);
            SearchManager manager
                = new SearchManager(provider);
            FileSpecification file = new FileSpecification
                                     (
                IrbisPath.MasterFile,
                "ISTU",
                "istu.ini"
                                     );

            SearchScenario[] scenarios
                = manager.LoadSearchScenarios(file);

            string[] items = scenarios.Select
                             (
                scenario => scenario.Prefix
                + " " + scenario.Name
                             )
                             .ToArray();

            string text = string.Join
                          (
                Environment.NewLine,
                items
                          );

            Write(text);
        }
Exemple #6
0
        public void Search_Format_Utf8()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            FoundItem[] found = connection.SearchFormatUtf8
                                (
                "T=A$",
                "v200^a, ' Привет, мир!'"
                                );
            Write
            (
                "Found: " + found.Length + ": "
                + string.Join
                (
                    "| ",
                    found.Select
                    (
                        item => item.ToString()
                        .SafeSubstring(0, 20)
                    )
                )
                .SafeSubstring(0, 100)
            );
        }
Exemple #7
0
        public void Search_Format()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            FoundItem[] found = connection.SearchFormat
                                (
                "T=A$",
                IrbisFormat.Brief
                                );
            Write
            (
                "Found: " + found.Length + ": "
                + string.Join
                (
                    "| ",
                    found.Select
                    (
                        item => item.ToString()
                        .SafeSubstring(0, 20)
                    )
                )
                .SafeSubstring(0, 100)
            );
        }
Exemple #8
0
        public void GblSettingsTest_Construction3()
        {
            GblStatement[] statements =
            {
                new GblStatement(),
                new GblStatement(),
                new GblStatement()
            };
            IrbisConnection connection = new IrbisConnection();
            GblSettings     settings   = new GblSettings
                                         (
                connection,
                statements
                                         );

            Assert.AreEqual(true, settings.Actualize);
            Assert.AreEqual(false, settings.Autoin);
            Assert.AreEqual(connection.Database, settings.Database);
            Assert.AreEqual(null, settings.FileName);
            Assert.AreEqual(1, settings.FirstRecord);
            Assert.AreEqual(false, settings.FormalControl);
            Assert.AreEqual(0, settings.MaxMfn);
            Assert.AreEqual(null, settings.MfnList);
            Assert.AreEqual(0, settings.MinMfn);
            Assert.AreEqual(0, settings.NumberOfRecords);
            Assert.AreEqual(null, settings.SearchExpression);
            Assert.IsNotNull(settings.Statements);
            Assert.AreEqual(statements.Length, settings.Statements.Count);
        }
Exemple #9
0
        static void Main()
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            try
            {
                DeleteDoubles = CM.AppSettings["delete"].SameString("yes");

                string connectionString = CM.AppSettings["irbis-connection-string"];

                using (connection = new IrbisConnection())
                {
                    connection.ParseConnectionString(connectionString);
                    connection.Connect();
                    //Console.WriteLine("Connected");

                    DumpTerms();

                    Console.WriteLine();
                    Console.WriteLine("Doubled indexes: {0}", DoubleCount);
                    Console.WriteLine("Full double records: {0}", FullDoubleCount);

                    //Console.WriteLine("Disconnected");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemple #10
0
        public void GblSettings_Serialize()
        {
            GblSettings settings = new GblSettings();

            _TestSerialize(settings);

            GblStatement[] statements =
            {
                new GblStatement(),
                new GblStatement(),
                new GblStatement()
            };
            IrbisConnection connection = new IrbisConnection();

            settings = new GblSettings
                       (
                connection,
                statements
                       );
            settings
            .SetSearchExpression("A=AUTHOR$")
            .SetRange(100, 200)
            .SetFileName("hello.gbl");
            _TestSerialize(settings);
        }
Exemple #11
0
        public void GblSettings_Verify()
        {
            GblSettings settings = new GblSettings();

            Assert.AreEqual(false, settings.Verify(false));

            GblStatement[] statements =
            {
                new GblStatement(),
                new GblStatement(),
                new GblStatement()
            };
            IrbisConnection connection = new IrbisConnection();

            settings = new GblSettings
                       (
                connection,
                statements
                       );
            settings
            .SetSearchExpression("A=AUTHOR$")
            .SetRange(100, 200)
            .SetFileName("hello.gbl");
            Assert.AreEqual(true, settings.Verify(false));
        }
Exemple #12
0
        public void GblSettings_ForSearchExpression2()
        {
            const string searchExpression = "A=AUTHOR$";
            const string database         = "ISTU";

            GblStatement[] statements =
            {
                new GblStatement(),
                new GblStatement(),
                new GblStatement()
            };
            IrbisConnection connection = new IrbisConnection();
            GblSettings     settings   = GblSettings.ForSearchExpression
                                         (
                connection,
                database,
                searchExpression,
                statements
                                         );

            Assert.AreEqual(searchExpression, settings.SearchExpression);
            Assert.AreEqual(0, settings.MinMfn);
            Assert.AreEqual(0, settings.MaxMfn);
            Assert.AreEqual(null, settings.MfnList);
            Assert.AreEqual(searchExpression, settings.SearchExpression);
        }
Exemple #13
0
        public void GblSettings_ForList2()
        {
            int[]        mfnList  = new XRange(100, 200).ToArray();
            const string database = "ISTU";

            GblStatement[] statements =
            {
                new GblStatement(),
                new GblStatement(),
                new GblStatement()
            };
            IrbisConnection connection = new IrbisConnection();
            GblSettings     settings   = GblSettings.ForList
                                         (
                connection,
                database,
                mfnList,
                statements
                                         );

            Assert.AreEqual(database, settings.Database);
            Assert.AreEqual(0, settings.MinMfn);
            Assert.AreEqual(0, settings.MaxMfn);
            Assert.IsNotNull(settings.MfnList);
            Assert.AreEqual(mfnList.Length, settings.MfnList.Length);
        }
Exemple #14
0
        public void GblSettings_ForInterval2()
        {
            const int    minMfn = 100, maxMfn = 200;
            const string database = "ISTU";

            GblStatement[] statements =
            {
                new GblStatement(),
                new GblStatement(),
                new GblStatement()
            };
            IrbisConnection connection = new IrbisConnection();
            GblSettings     settings   = GblSettings.ForInterval
                                         (
                connection,
                database,
                minMfn,
                maxMfn,
                statements
                                         );

            Assert.AreEqual(database, settings.Database);
            Assert.AreEqual(minMfn, settings.MinMfn);
            Assert.AreEqual(maxMfn, settings.MaxMfn);
            Assert.AreEqual(null, settings.MfnList);
        }
Exemple #15
0
        public Form4()
        {
            InitializeComponent();

            string connectionString = CM.AppSettings["connectionString"];

            Connection = new IrbisConnection();
            Connection.ParseConnectionString(connectionString);
            Connection.Connect();

            Grid = new SiberianTermGrid
            {
                Dock = DockStyle.Fill
            };
            Controls.Add(Grid);

            TermParameters parameters = new TermParameters
            {
                //Database = "IBIS",
                NumberOfTerms = 100,
                //ReverseOrder = false,
                StartTerm = "K=",
                //Format = null
            };

            TermInfo[] terms = Connection.ReadTerms(parameters);
            terms = TermInfo.TrimPrefix(terms, "K=");

            Grid.Load(terms);

            FormClosed += _FormClosed;
        }
Exemple #16
0
        /*========================================================*/

        public static FstFile ParseServerFile
        (
            IrbisConnection client,
            string fileName
        )
        {
            FstFile result = new FstFile();

            FileSpecification specification = new FileSpecification
                                              (
                IrbisPath.MasterFile,
                fileName
                                              );
            string content = client.ReadTextFile(specification);

            content = content.Replace("\r", string.Empty);
            foreach (string textLine in content.Split
                     (
                         new[] { '\n' },
                         StringSplitOptions.RemoveEmptyEntries
                     ))
            {
                FstLine fstLine = FstLine.ParseLine(textLine);
                if (fstLine != null)
                {
                    result.Lines.Add(fstLine);
                }
            }

            return(result);
        }
        private void DatabaseList_SelectionChanged
        (
            object sender,
            SelectionChangedEventArgs e
        )
        {
            DatabaseInfo selectedDatabase = DatabaseList.SelectedItem as DatabaseInfo;

            if (ReferenceEquals(selectedDatabase, null))
            {
                return;
            }

            string name = selectedDatabase.Name.ThrowIfNull();
            DatabaseDescription description = new DatabaseDescription
            {
                Name        = name,
                Description = selectedDatabase.Description
            };

            using (IrbisConnection connection = GetConnection())
            {
                DatabaseInfo info = connection.GetDatabaseInfo(name);
                description.MaxMfn               = info.MaxMfn - 1;
                description.ExclusiveLock        = info.DatabaseLocked;
                description.LockedRecords        = info.LockedRecords.SafeLength();
                description.LogicallyDeleted     = info.LogicallyDeletedRecords.SafeLength();
                description.PhysicallyDeleted    = info.PhysicallyDeletedRecords.SafeLength();
                description.NonactualizedRecords = info.NonActualizedRecords.SafeLength();
            }

            DataContext = description;
        }
        public void DatabaseStat_Test1()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            StatDefinition.Item item = new StatDefinition.Item
            {
                Field  = "v200^a",
                Length = 10,
                Count  = 100,
                Sort   = StatDefinition.SortMethod.Ascending
            };
            StatDefinition definition = new StatDefinition
            {
                DatabaseName = "IBIS",
                SearchQuery  = "T=А$"
            };

            definition.Items.Add(item);
            string text     = connection.GetDatabaseStat(definition);
            string filePath = Path.Combine
                              (
                Path.GetTempPath(),
                "stat.rtf"
                              );

            File.WriteAllText
            (
                filePath,
                text,
                IrbisEncoding.Ansi
            );

            Write("stat written to {0}", filePath);
        }
Exemple #19
0
        //[TestMethod]
        public void Search_Many()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            string saveDatabase = connection.Database;

            try
            {
                // connection.Database = "ISTU";
                int[] found = connection.Search("K=А$");
                Write
                (
                    "Found: " + found.Length + ": "
                    + string.Join
                    (
                        ", ",
                        found.Select
                        (
                            mfn => mfn.ToInvariantString()
                        )
                    )
                    .Substring(0, 50)
                );
            }
            finally
            {
                connection.Database = saveDatabase;
            }
        }
Exemple #20
0
        public void CreateDictionary_Test1()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            connection.CreateDictionary("IBIS");
        }
Exemple #21
0
        public static IrbisConnection GetIrbisConnection()
        {
            IrbisConnection result
                = new IrbisConnection(ConnectionString);

            return(result);
        }
Exemple #22
0
        static int Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("IrbisPing version 0.0.1");
                Console.WriteLine("USAGE: IrbisPing <connection-string>");
                Console.WriteLine();

                return(1);
            }

            try
            {
                using (IrbisConnection connection = new IrbisConnection())
                {
                    string connectionString = args[0];
                    connection.ParseConnectionString(connectionString);

                    connection.Connect();

                    return(0);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                return(1);
            }
        }
Exemple #23
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public SmartClientSocket
 (
     [NotNull] IrbisConnection connection
 )
     : base(connection)
 {
 }
Exemple #24
0
        public void WssFile_ReadFromServer()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");
            IrbisProvider provider = new ConnectedClient(connection);

            FileSpecification specification = new FileSpecification
                                              (
                IrbisPath.MasterFile,
                "IBIS",
                "210m.wss"
                                              );
            WssFile wss = WssFile.ReadFromServer
                          (
                provider,
                specification
                          );

            if (!ReferenceEquals(wss, null))
            {
                string[] lines = wss.Items
                                 .Select
                                 (
                    item => item.Tag + ": " + item.Title
                                 )
                                 .ToArray();
                string text = string.Join("|", lines);
                Write(text);
            }
        }
Exemple #25
0
        /// <summary>
        /// Remove given socket from the socket chain.
        /// </summary>
        public static void RemoveSocket
        (
            [NotNull] IrbisConnection connection,
            [NotNull] AbstractClientSocket socket
        )
        {
            Sure.NotNull(connection, nameof(connection));
            Sure.NotNull(socket, nameof(socket));

            AbstractClientSocket inner = socket.InnerSocket;

            if (ReferenceEquals(connection.Socket, socket))
            {
                inner = inner.ThrowIfNull("socket.InnerSocket");
                connection.SetSocket(inner);
            }
            else
            {
                for (
                    AbstractClientSocket current = connection.Socket;
                    !ReferenceEquals(current, null);
                    )
                {
                    inner = current.InnerSocket;

                    if (ReferenceEquals(inner, socket))
                    {
                        current.InnerSocket = inner.InnerSocket;
                        break;
                    }

                    current = inner;
                }
            }
        }
Exemple #26
0
        private void _searchButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            _resultBox.Clear();
            _loginBox.Clear();
            _passwordBox.Clear();

            string ticket = _ticketBox.Text.Trim();

            if (string.IsNullOrEmpty(ticket))
            {
                _resultBox.Text = Environment.NewLine
                                  + Resources.MainForm_NoIogunbTicket;

                return;
            }

            using (IrbisConnection connection = GetConnection())
            {
                string expression = string.Format
                                    (
                    "\"RI={0}\"",
                    ticket
                                    );
                int[] found = connection.Search(expression);
                if (found.Length == 0)
                {
                    _resultBox.Text = Environment.NewLine
                                      + Resources.MainForm_NoReaderFound;
                    _ticketBox.Focus();

                    return;
                }
                if (found.Length != 1)
                {
                    _resultBox.Text = Environment.NewLine
                                      + Resources.MainForm_ManyReadersFound;
                    _ticketBox.Focus();

                    return;
                }

                MarcRecord record      = connection.ReadRecord(found[0]);
                string     description = connection.FormatRecord("@brief", found[0]);
                _resultBox.Text = Environment.NewLine + description;

                RecordField litresField = record.Fields
                                          .GetFirstField(_litresTag);
                if (!ReferenceEquals(litresField, null))
                {
                    _loginBox.Text    = litresField.GetFirstSubFieldValue('a');
                    _passwordBox.Text = litresField.GetFirstSubFieldValue('b');
                }

                _loginBox.Focus();
            }
        }
Exemple #27
0
        // private IrbisConnection _connection;

        public IrbisConnection GetConnection()
        {
            IrbisConnection result
                = IrbisConnectionUtility.GetClientFromConfig();

            return(result);
        }
Exemple #28
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            Connection = new IrbisConnection();
            _busyStripe.SubscribeTo(Connection);
        }
Exemple #29
0
        //[TestMethod]
        public void Connection_Failure()
        {
            IrbisConnection secondConnection
                = Connection.Clone(false);

            secondConnection.Username = "******";
            secondConnection.Password = "******";

            bool allOk = false;

            try
            {
                secondConnection.Connect();
            }
            catch (IrbisException)
            {
                allOk = true;
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {
                // Nothing to do
            }

            Write
            (
                allOk
                    ? "good"
                    : "bad"
            );
        }
        public void ConnectionSettings_FromConnection_3()
        {
            string source = "host=127.0.0.1;port=5555;"
                            + "database=NODB;username=john galt;password=who is;"
                            + "workstation=A;"
                            + "socket=" + typeof(MySocket).AssemblyQualifiedName + ";";

            ConnectionSettings expected = new ConnectionSettings()
                                          .ParseConnectionString(source);
            IrbisConnection connection = new IrbisConnection();

            expected.ApplyToConnection(connection);

            ConnectionSettings actual
                = ConnectionSettings.FromConnection(connection);

            Assert.AreEqual(expected.Host, connection.Host);
            Assert.AreEqual(expected.Port, connection.Port);
            Assert.AreEqual(expected.Username, connection.Username);
            Assert.AreEqual(expected.Password, connection.Password);
            Assert.AreEqual(expected.Database, connection.Database);
            Assert.AreEqual(expected.Workstation, connection.Workstation);

            string target = actual.Encode();

            Assert.AreEqual(source, target);
        }