예제 #1
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;
        }
예제 #2
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"
            );
        }
예제 #3
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);
            }
        }
예제 #4
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);
            }
        }
예제 #5
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;
        }
예제 #6
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);
            }
        }
예제 #7
0
        public static void Main()
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            try
            {
                using (connection = new IrbisConnection())
                {
                    connection.ParseConnectionString(ConnectionString);
                    connection.Connect();
                    Console.WriteLine("Подключились");

                    connection.Database = MainDatabase;
                    int[] found = connection.Search(SearchExpression);
                    Console.WriteLine("Отобрано записей: {0}", found.Length);


                    foreach (int mfn in found)
                    {
                        if (Cancel)
                        {
                            break;
                        }
                        try
                        {
                            ProcessRecord(mfn);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine
                            (
                                "MFN={0}, {1}: {2}",
                                mfn,
                                exception.GetType(),
                                exception.Message
                            );
                        }
                    }
                }
                Console.WriteLine("Отключились");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
예제 #8
0
 static void Main()
 {
     try
     {
         using (IrbisConnection connection = new IrbisConnection())
         {
             connection.ParseConnectionString("host=127.0.0.1;port=6666;user=1;password=1;db=IBIS;");
             connection.Connect();
             IrbisVersion version = connection.GetServerVersion();
             Console.WriteLine(version);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
예제 #9
0
 static void Main()
 {
     try
     {
         using (IrbisConnection connection = new IrbisConnection())
         {
             connection.ParseConnectionString("host=127.0.0.1;port=6666;user=1;password=1;db=IBIS;");
             connection.Connect();
             IrbisVersion version = connection.GetServerVersion();
             MessageBox.Show(version.ToString(), "SharpIrbis");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "SharpIrbis");
     }
 }
예제 #10
0
        public Form5()
        {
            InitializeComponent();

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

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

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

            List <FoundLine> lines = new List <FoundLine>();

            for (int i = 1; i < 100; i++)
            {
                try
                {
                    string    description = Connection.FormatRecord("@brief", i);
                    FoundLine line        = new FoundLine
                    {
                        Mfn          = i,
                        Materialized = true,
                        Description  = description
                    };
                    lines.Add(line);
                }
                catch
                {
                    // Nothing to do
                }
            }

            Connection.Dispose();

            Grid.Load(lines.ToArray());

            //FormClosed += _FormClosed;
        }
예제 #11
0
    static void Main()
    {
        try
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            using (IrbisConnection connection = new IrbisConnection())
            {
                string connectionString = CM.AppSettings["connectionString"];
                connection.ParseConnectionString(connectionString);
                connection.Connect();

                string[] databases = CM.AppSettings["databases"].Split
                                     (
                    new [] { ' ', ',', ';' },
                    StringSplitOptions.RemoveEmptyEntries
                                     );

                monitor = new IrbisMonitor
                          (
                    connection,
                    databases
                          );

                TextMonitoringSink sink = new TextMonitoringSink(Console.Out);
                monitor.Sink = sink;

                monitor.StartMonitoring();
                Console.WriteLine("Monitoring started");
                Console.WriteLine();

                while (monitor.Active)
                {
                    Thread.Sleep(100);
                }
            }
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
        }
    }
예제 #12
0
        private void MainForm_Load
        (
            object sender,
            EventArgs e
        )
        {
            this.ShowVersionInfoInTitle();

            _connection = GetConnection();
            _connection.Connect();

            this.Text += ": " + _connection.Host;

            _pinger = new IrbisPing(_connection)
            {
                Active = true
            };
            _pinger.StatisticsUpdated += _pinger_StatisticsUpdated;
            _plotter.Statistics        = _pinger.Statistics;
        }
예제 #13
0
        public DataAccessLevel
        (
            AbstractOutput output
        )
        {
            if (ReferenceEquals(output, null))
            {
                throw new ArgumentNullException("output");
            }
            Output = output;

            string sqlConnectionString
                = CM.AppSettings["sql-connection-string"];

            Db = new DbManager
                 (
                new Sql2008DataProvider(),
                sqlConnectionString
                 );
            Output.WriteLine
            (
                "Подключились к SQL-серверу"
            );

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

            Client = new IrbisConnection();
            Client.ParseConnectionString(irbisConnectionString);
            Client.Connect();
            Output.WriteLine("Подключились к ИРБИС-серверу");

            _timer = new Timer
            {
                Enabled  = true,
                Interval = 60 * 1000
            };
            _timer.Tick += _timer_Tick;
        }
예제 #14
0
        private static void DoFormat
        (
            object arg
        )
        {
            try
            {
                RecordTask taskInfo = (RecordTask)arg;
                using (IrbisConnection client = new IrbisConnection())
                {
                    client.ParseConnectionString(ConnectionString);
                    client.Connect();

                    MarcRecord targetRecord = Fst.Execute
                                              (
                        client,
                        taskInfo.Record
                                              );
                    if (targetRecord != null)
                    {
                        targetRecord.SetSubField(463, 'w', taskInfo.CurrentIssue);
                        targetRecord.SetSubField(463, 'c', taskInfo.Magazine.Title);

                        lock (SyncRoot)
                        {
                            RecordCount++;
                            //Buffer.Append(targetRecord);
                            client.WriteRecord(targetRecord, false, true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogLine("EXCEPTION: {0}", ex);
            }
        }
예제 #15
0
    static void Main()
    {
        const string connectionString = "host=127.0.0.1;port=6666;user=1;password=1;db=IMAGE;arm=C;";

        try
        {
            using (IrbisConnection client = new IrbisConnection())
            {
                client.ParseConnectionString(connectionString);
                client.Connect();

                const string fileName = @"CARDS\АЙЗИКОВИЧ - АКАДЕМИЯ ГРАЖДАНСКОЙ АВИАЦИИ\Q0001.jpg";

                FileSpecification specification = new FileSpecification
                                                  (
                    IrbisPath.FullText,
                    "IMAGE",
                    fileName
                                                  );

                byte[] bytes = client.ReadBinaryFile(specification);

                if (ReferenceEquals(bytes, null))
                {
                    Console.WriteLine("no data read");
                }
                else
                {
                    Console.WriteLine("bytes read: {0}", bytes.Length);
                }
            }
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
        }
    }
예제 #16
0
        static void Main(string[] args)
        {
            if (args.Length < 1 ||
                args.Length > 2)
            {
                Console.WriteLine
                (
                    "Usage: ReaderKiller <readerList>"
                );

                return;
            }

            string fileName = args[0];

            doDelete = ConfigurationUtility.GetBoolean
                       (
                "delete",
                false
                       );
            databases = ConfigurationUtility.GetString
                        (
                "databases",
                null
                        )
                        .ThrowIfNull("Databases not specified")
                        .Split
                        (
                new[] { ';', ',', ' ' },
                StringSplitOptions.RemoveEmptyEntries
                        );
            if (databases.Length == 0)
            {
                throw new Exception("Empty database list");
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                string connectionString = args.Length > 1
                    ? args[2]
                    : CM.AppSettings["connectionString"];

                string[] tickets = File.ReadAllLines
                                   (
                    fileName,
                    Encoding.UTF8
                                   );
                Console.WriteLine
                (
                    "Tickets loaded: {0}",
                    tickets.Length
                );

                using (connection = new IrbisConnection())
                {
                    connection.SetRetry(10, ExceptionResolver);

                    connection.ParseConnectionString
                    (
                        connectionString
                    );
                    connection.Connect();

                    Console.WriteLine("Connected");

                    for (int i = 0; i < tickets.Length; i++)
                    {
                        string ticket = tickets[i];
                        ProcessReader(i, ticket);
                    }
                }

                Console.WriteLine("Disconnected");

                stopwatch.Stop();
                Console.WriteLine
                (
                    "Time elapsed: {0}",
                    stopwatch.Elapsed.ToAutoString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
예제 #17
0
        static void Main()
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            try
            {
                using (connection = new IrbisConnection())
                {
                    connection.ParseConnectionString(ConnectionString);
                    connection.Connect();
                    connection.Database = DatabaseName;
                    Console.WriteLine("Подключились");

                    IEnumerable <MarcRecord> records
                        = BatchRecordReader.WholeDatabase
                          (
                              connection,
                              DatabaseName,
                              500
                              //, rdr =>
                              //{
                              //    Console.WriteLine
                              //        (
                              //            "{0} из {1}",
                              //            rdr.RecordsRead,
                              //            rdr.TotalRecords
                              //        );
                              //}
                          );

                    foreach (MarcRecord record in records)
                    {
                        if (Cancel)
                        {
                            break;
                        }

                        if (record.Deleted)
                        {
                            continue;
                        }

                        ReaderInfo reader = ReaderInfo.Parse(record);
                        if (reader.WorkPlace.SafeContains("ИОГУНБ"))
                        {
                            continue;
                        }

                        int age    = reader.Age;
                        int visits = reader.Visits.Count(v => v.IsVisit);

                        if (reader.Gender.SameString("ж"))
                        {
                            FemaleCount++;
                            FemaleAge.Increment(age);
                            FemaleVisits.Augment(age, visits);
                        }
                        else
                        {
                            MaleCount++;
                            MaleAge.Increment(age);
                            MaleVisits.Augment(age, visits);
                        }
                    }
                }
                Console.WriteLine("Отключились");

                Console.WriteLine(";Муж;Жен;М пос;Ж пос");
                Console.WriteLine
                (
                    "Всего;{0};{1};{2};{3}",
                    MaleCount,
                    FemaleCount,
                    MaleVisits.Total,
                    FemaleVisits.Total
                );
                for (int age = 12; age < 100; age++)
                {
                    Console.WriteLine
                    (
                        "{0};{1};{2};{3};{4}",
                        age,
                        MaleAge.GetValue(age),
                        FemaleAge.GetValue(age),
                        MaleVisits.GetValue(age),
                        FemaleVisits.GetValue(age)
                    );
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
예제 #18
0
        static void Main()
        {
            try
            {
                StartTime = DateTime.Now;

                // Устанавливаем обработчик прерывания
                Console.CancelKeyPress += Console_CancelKeyPress;

                ReadConfiguration();

                using (Log = new StreamWriter(LogFileName, true, Encoding.Default))
                {
                    int mfnBefore, mfnAfter;

                    WriteLogLine(new string('=', 70));
                    WriteLogLine("Импорт начат: {0}", StartTime);
                    WriteLogLine(string.Empty);

                    string[] inputFiles = DiscoverFiles();
                    WriteLogLine("Найдено файлов: {0}", inputFiles.Length);
                    if (inputFiles.Length == 0)
                    {
                        WriteLogLine("Нет импортируемых файлов, завершаемся");
                        return;
                    }
                    Array.Sort(inputFiles);

                    using (Client = new IrbisConnection())
                    {
                        //using (Buffer = new RecordBuffer(Client, 100))
                        {
                            //Buffer.Actualize = true;
                            //Buffer.Database = Client.Database;
                            //Buffer.BatchWrite += Buffer_BatchWrite;

                            Client.ParseConnectionString(ConnectionString);
                            WriteLog("Подключение к серверу... ");
                            Client.Connect();
                            WriteLogLine("успешно");

                            Fst = FstFile.ParseServerFile
                                  (
                                Client,
                                FstFileName
                                  );
                            WriteLogLine("Файл FST содержит {0} строк", Fst.Lines.Count);
                            if (Fst.Lines.Count == 0)
                            {
                                WriteLogLine("Плохой файл FST, завершаемся");
                                return;
                            }

                            Magazines = LoadMagazines();
                            WriteLogLine
                            (
                                "Сводных описаний импортируемых журналов в каталоге: {0}",
                                Magazines.Count
                            );
                            if (Magazines.Count == 0)
                            {
                                WriteLogLine("Нет импортируемых журналов в каталоге");
                                return;
                            }

                            mfnBefore = Client.GetMaxMfn();

                            using (Queue = new QueueEngine <RecordTask>
                                           (
                                       Environment.ProcessorCount,
                                       QueueLength
                                           ))
                            {
                                //Queue.Waiting += Queue_Waiting;

                                int index = 0;
                                foreach (string inputFile in inputFiles)
                                {
                                    if (GoOn)
                                    {
                                        ProcessFile
                                        (
                                            ++index,
                                            inputFile
                                        );
                                        if (GoOn && DeleteProcessedFiles)
                                        {
                                            WriteLog("Удаляем файл... ");
                                            File.Delete(inputFile);
                                            WriteLogLine("удален");
                                        }
                                    } // if
                                }     // foreach

                                WriteLogLine("Длина очереди: {0}", Queue.QueueLength);
                                WriteLog("Ожидаем завершения обработки записей в очереди: ");
                            } // using Queue

                            if (!GoOn)
                            {
                                WriteLogLine("Импорт прерван пользователем");
                            }

                            WriteLogLine("Отправка на сервер оставшихся записей");
                        } // using Buffer

                        mfnAfter = Client.GetMaxMfn();
                    } // using Client

                    WriteLogLine("Произведено корректное отключение от сервера");

                    TimeSpan elapsedTime = DateTime.Now - StartTime;
                    WriteLogLine
                    (
                        "Затрачено времени: {0}",
                        elapsedTime
                    );
                    WriteLogLine
                    (
                        "Импортировано файлов: {0}, записей: {1}",
                        FileCount,
                        RecordCount
                    );
                    WriteLogLine
                    (
                        "MFN до={0}, после={1}",
                        mfnBefore,
                        mfnAfter
                    );
                }
            }
            catch (Exception exception)
            {
                Log = null;
                WriteLogLine
                (
                    "ВОЗНИКЛА ОШИБКА: {0}",
                    exception
                );
                WriteLogLine("Аварийное завершение");
            }
        }
예제 #19
0
        static void Main(string[] args)
        {
            string connectionString = ConnectionString;

            if (args.Length != 0)
            {
                connectionString = args[0];
            }

            try
            {
                //IrbisEncoding.RelaxUtf8();
                using (Connection = new IrbisConnection())
                {
                    Connection.ParseConnectionString(connectionString);
                    Connection.Connect();

                    BatchRecordReader batch
                        = (BatchRecordReader)BatchRecordReader.Search
                          (
                              Connection,
                              Connection.Database,
                              //@"V=KN * G=201$",
                              @"V=KN",
                              1000
                          );
                    batch.BatchRead += (sender, eventArgs) =>
                    {
                        Console.Write(".");
                    };

                    //BatchRecordReader batch = records as BatchRecordReader;
                    //if (!ReferenceEquals(batch, null))
                    //{
                    //    Console.WriteLine("Found: {0}", batch.TotalRecords);
                    //    batch.BatchRead += (sender, args)
                    //        => Console.WriteLine(batch.RecordsRead);
                    //}

                    foreach (MarcRecord record in batch)
                    {
                        ProcessRecord(record);
                    }

                    Console.WriteLine();

                    Pair <int, int>[] top = list.OrderByDescending
                                            (
                        pair => pair.Second
                                            )
                                            .Take(100)
                                            .ToArray();

                    foreach (Pair <int, int> pair in top)
                    {
                        string description = EnhanceText
                                             (
                            Connection.FormatRecord
                            (
                                "@sbrief",
                                pair.First
                            )
                                             );

                        Console.WriteLine("{0}\t{1}", description, pair.Second);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }