Exemplo n.º 1
0
        static void AnalyzeYear
        (
            int year
        )
        {
            string expression = string.Format("RD={0}$", year.ToInvariantString());

            int[]             found   = connection.Search(expression);
            List <MarcRecord> records = new BatchRecordReader
                                        (
                connection,
                connection.Database,
                500,
                true,
                found
                                        )
                                        .ReadAll(true);

            foreach (MarcRecord record in records)
            {
                ReaderInfo reader = ReaderInfo.Parse(record);

                DateTime registrationDate = reader.RegistrationDate;
                DateTime lastVisitDate    = reader.LastVisitDate;
                if (lastVisitDate == DateTime.MinValue)
                {
                    lastVisitDate = reader.LastRegistrationDate;
                }
                if (lastVisitDate == DateTime.MinValue)
                {
                    if (!ReferenceEquals(reader.Enrollment, null) &&
                        reader.Enrollment.Length != 0)
                    {
                        lastVisitDate = reader.Enrollment.Max(e => e.Date);
                    }
                }
                if (lastVisitDate == DateTime.MinValue)
                {
                    lastVisitDate = registrationDate;
                }
                int visitDays = (int)(lastVisitDate - registrationDate).TotalDays;
                if (visitDays == 0)
                {
                    visitDays = 1;
                }
                int    visits = reader.Visits.Length;
                double rate   = (double)visits / visitDays;
                Console.WriteLine
                (
                    "{0}\t{1}\t{2}\t{3}\t{4}\t{5:F3}",
                    reader.Ticket,
                    registrationDate.ToShortDateString(),
                    visitDays,
                    reader.LastVisitDate.ToShortDateString(),
                    visits,
                    rate
                );
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: NetworkReaderBenchmark <path-to-MST>");

                return;
            }

            string connectionString = args[0];

            try
            {
                IrbisEncoding.RelaxUtf8();

                Console.WriteLine("Open");

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

                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    int maxMfn = connection.GetMaxMfn();
                    Console.WriteLine("Max MFN={0}", maxMfn);

                    IEnumerable <MarcRecord> batch
                        = BatchRecordReader.WholeDatabase
                          (
                              connection,
                              connection.Database,
                              1000,
                              reader => { Console.Write('.'); }
                          );
                    foreach (MarcRecord record in batch)
                    {
                        if (record.Modified)
                        {
                            Console.WriteLine("Very strange!");
                        }
                    }
                }

                stopwatch.Stop();

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Close");
                Console.WriteLine
                (
                    "Elapsed: {0} sec",
                    stopwatch.Elapsed.ToSecondString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 3
0
        static void AnalyzeCategories
        (
            int year,
            int month
        )
        {
            string expression = string.Format
                                (
                CultureInfo.InvariantCulture,
                "RD={0:0000}{1:00}$",
                year,
                month
                                );

            int[]             found   = connection.Search(expression);
            List <MarcRecord> records = new BatchRecordReader
                                        (
                connection,
                connection.Database,
                500,
                true,
                found
                                        )
                                        .ReadAll(true);

            ReaderInfo[] readers = records.Select(ReaderInfo.Parse).ToArray();
            DictionaryCounterInt32 <string> counter = new DictionaryCounterInt32 <string>();

            foreach (ReaderInfo reader in readers)
            {
                string category = reader.Category;
                if (!string.IsNullOrEmpty(category))
                {
                    counter.Increment(category);
                }
            }

            CultureInfo        culture = CultureInfo.CurrentCulture;
            DateTimeFormatInfo format  = culture.DateTimeFormat;

            Console.Write("{0} {1}", format.GetAbbreviatedMonthName(month), year);
            foreach (string category in knownCategories)
            {
                Console.Write("\t{0}", counter.GetValue(category));
            }
            int others = 0;

            foreach (string key in counter.Keys)
            {
                if (!knownCategories.Contains(key))
                {
                    int value = counter[key];
                    others += value;
                }
            }

            Console.WriteLine("\t{0}", others);
        }
Exemplo n.º 4
0
 protected bool ProcessBatch
 (
     BatchRecordReader batch
 )
 {
     TotalProcessed = 0;
     _stopwatch.Start();
     try
     {
         using (
             IEnumerator <IrbisRecord> enumerator =
                 batch.GetEnumerator())
         {
             while (true)
             {
                 try
                 {
                     if (!enumerator.MoveNext())
                     {
                         break;
                     }
                     IrbisRecord record = enumerator.Current;
                     bool        flag   = ProcessRecord(record);
                     TotalProcessed++;
                     flag &= ReportProgress();
                     if (!flag)
                     {
                         return(false);
                     }
                 }
                 catch (Exception exception)
                 {
                     if (!OnError(exception))
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         OnError(exception);
         return(false);
     }
     finally
     {
         _stopwatch.Stop();
         WriteLine(string.Empty);
         WriteLine
         (
             "Processed: {0}, elapsed: {1}",
             TotalProcessed,
             Elapsed
         );
     }
     return(true);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Process all the records in the server database.
        /// </summary>
        public bool ProcessRecords()
        {
            BatchRecordReader batch = new BatchRecordReader
                                      (
                Context.Client
                                      );

            return(ProcessRecords(batch));
        }
Exemplo n.º 6
0
        public static List <ReaderInfo> LoadReaders
        (
            [NotNull] ManagedClient64 client,
            [NotNull] List <ReaderInfo> readers,
            [NotNull] string dbName
        )
        {
            if (ReferenceEquals(client, null))
            {
                throw new ArgumentNullException("client");
            }
            if (ReferenceEquals(readers, null))
            {
                throw new ArgumentNullException("readers");
            }
            if (string.IsNullOrEmpty(dbName))
            {
                throw new ArgumentNullException("dbName");
            }

            try
            {
                client.PushDatabase(dbName);
                readers.Capacity += client.GetMaxMfn();

                BatchRecordReader batch = new BatchRecordReader
                                          (
                    client,
                    1500
                                          );

                Parallel.ForEach
                (
                    batch,
                    record =>
                {
                    if (!record.Deleted)
                    {
                        ReaderInfo reader
                            = ReaderInfo.Parse(record);
                        lock (readers)
                        {
                            readers.Add(reader);
                        }
                    }
                }
                );
            }
            finally
            {
                client.PopDatabase();
            }

            return(readers);
        }
Exemplo n.º 7
0
        public static List <ExemplarInfo> GetExemplars
        (
            [NotNull] string ksu
        )
        {
            Code.NotNullNorEmpty(ksu, "ksu");

            List <ExemplarInfo> result;

            using (IrbisConnection connection = GetIrbisConnection())
            {
                ExemplarManager manager
                    = new ExemplarManager(connection, Output)
                    {
                    Format = Format
                    };

                string expression = string.Format
                                    (
                    "\"{0}{1}\"",
                    Prefix,
                    ksu
                                    );

                result = BatchRecordReader.Search
                         (
                    connection,
                    connection.Database,
                    expression,
                    500
                         )
                         .SelectMany
                         (
                    x => ExemplarInfo.Parse(x)
                         )
                         .Where
                         (
                    exemplar => exemplar.KsuNumber1.SameString(ksu)
                         )
                         .Select
                         (
                    exemplar => manager.Extend(exemplar, null)
                         )
                         .ToList();

                result.Sort(_ExemplarComparison);
            }

            return(result);
        }
Exemplo n.º 8
0
        private void Batch_BatchRead
        (
            object sender,
            EventArgs e
        )
        {
            BatchRecordReader batch = (BatchRecordReader)sender;

            WriteLine
            (
                "Загружено: {0} из {1}",
                batch.RecordsRead,
                batch.TotalRecords
            );
        }
        public void BatchRecordReader_NoRecords()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            BatchRecordReader reader = new BatchRecordReader
                                       (
                connection,
                "IBIS",
                100,
                new int[0]
                                       );
            List <MarcRecord> records = reader.ReadAll();

            Write("readed: {0}", records.Count);
        }
Exemplo n.º 10
0
        public bool ProcessRecords
        (
            IEnumerable <int> mfns
        )
        {
            BatchRecordReader batch = new BatchRecordReader
                                      (
                Client,
                mfns
                                      );

            return(ProcessBatch
                   (
                       batch
                   ));
        }
Exemplo n.º 11
0
        static EffectiveStat ProcessKsu
        (
            [NotNull] MenuEntry entry
        )
        {
            Code.NotNull(entry, "entry");

            string ksu = entry.Code.ThrowIfNull("entry.Code");

            if (_outputBooks)
            {
                Console.WriteLine();
                Console.WriteLine("КСУ {0} {1}", ksu, entry.Comment);
                Console.WriteLine();
            }

            EffectiveStat result = new EffectiveStat
            {
                Description = string.Format
                              (
                    _outputBooks ? "Итого по КСУ {0}" : "{0} {1}",
                    ksu,
                    entry.Comment
                              )
            };

            string expression = string.Format("\"NKSU={0}\"", ksu);
            IEnumerable <MarcRecord> batch = BatchRecordReader.Search
                                             (
                _connection,
                _connection.Database,
                expression,
                500
                                             );

            foreach (MarcRecord record in batch)
            {
                EffectiveStat bookStat = ProcessBook(record, ksu);
                if (_outputBooks)
                {
                    bookStat.Output(false);
                }
                result.Add(bookStat);
            }

            return(result);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Process the sequence of records.
        /// </summary>
        public bool ProcessRecords
        (
            [NotNull] IEnumerable <int> range
        )
        {
            if (ReferenceEquals(range, null))
            {
                throw new ArgumentNullException("range");
            }

            BatchRecordReader batch = new BatchRecordReader
                                      (
                Context.Client,
                range
                                      );

            return(ProcessRecords(batch));
        }
Exemplo n.º 13
0
        public bool ProcessRecords
        (
            string expression,
            params object[] args
        )
        {
            BatchRecordReader batch = new BatchRecordReader
                                      (
                Client,
                expression,
                args
                                      );

            return(ProcessBatch
                   (
                       batch
                   ));
        }
Exemplo n.º 14
0
        public ReaderInfo[] GetAllReaders()
        {
            List <ReaderInfo> result = new List <ReaderInfo>
                                       (
                Client.GetMaxMfn() + 1
                                       );
            BatchRecordReader batch = new BatchRecordReader(Client);

            foreach (IrbisRecord record in batch)
            {
                if (!ReferenceEquals(record, null))
                {
                    ReaderInfo reader = ReaderInfo.Parse(record);
                    result.Add(reader);
                }
            }
            return(result.ToArray());
        }
Exemplo n.º 15
0
        private void _backgroundWorker_DoWork
        (
            object sender,
            DoWorkEventArgs e
        )
        {
            try
            {
                BatchRecordReader reader = new BatchRecordReader
                                           (
                    _client,
                    _client.Database,
                    500,
                    _deletedRecords
                                           );
                int index = 0;
                foreach (MarcRecord record in reader)
                {
                    string text = record.ToPlainText().ToUpperInvariant();
                    bool   flag = true;
                    foreach (string word in _targetWords)
                    {
                        if (!text.Contains(word))
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        _foundRecords.Add(record.Mfn);
                    }

                    index++;
                    _backgroundWorker.ReportProgress(index);
                }
            }
            catch (Exception ex)
            {
                _SetStatus("Возникло исключение: {0}", ex);
            }
        }
Exemplo n.º 16
0
        public void BatchRecordReader_OneRecord()
        {
            IrbisConnection connection = Connection
                                         .ThrowIfNull("Connection");

            BatchRecordReader reader = new BatchRecordReader
                                       (
                connection,
                "IBIS",
                100,
                new[] { 1 }
                                       );
            List <MarcRecord> records = reader.ReadAll();
            string            text    = StringUtility.Join
                                        (
                ", ",
                records.Select(r => r.Mfn)
                                        );

            Write("MFN: {0}", text);
        }
Exemplo n.º 17
0
        public MagazineInfo[] GetAllMagazines()
        {
            List <MagazineInfo> result = new List <MagazineInfo>();

            BatchRecordReader batch = new BatchRecordReader
                                      (
                Client,
                String.Concat(Newspaper, " + ", Magazine)
                                      );

            foreach (IrbisRecord record in batch)
            {
                if (!ReferenceEquals(record, null))
                {
                    MagazineInfo magazine = MagazineInfo.Parse(record);
                    if (!ReferenceEquals(magazine, null))
                    {
                        result.Add(magazine);
                    }
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 18
0
        static List <int> AnalyzeAttendance
        (
            int year
        )
        {
            string expression = string.Format("RD={0}$", year.ToInvariantString());

            int[]             found   = connection.Search(expression);
            List <MarcRecord> records = new BatchRecordReader
                                        (
                connection,
                connection.Database,
                500,
                true,
                found
                                        )
                                        .ReadAll(true);

            ReaderInfo[] readers = records.Select(ReaderInfo.Parse).ToArray();
            foreach (ReaderInfo reader in readers)
            {
                ProcessReader(reader);
            }

            List <int> result = new List <int> {
                readers.Length
            };

            for (int attendance = 1; attendance < MaxAttendance; attendance++)
            {
                int count = readers.Count(r => r.Visits.Length >= attendance);
                result.Add(count);
            }

            return(result);
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
        static int Main(string[] arguments)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

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

                if (string.IsNullOrEmpty(connectionString))
                {
                    Console.WriteLine("Connection string not specified");
                    return(1);
                }

                CommandLineParser parser = new CommandLineParser();
                ParsedCommandLine parsed = parser.Parse(arguments);
                if (parsed.PositionalArguments.Count != 0)
                {
                    connectionString = parsed.PositionalArguments[0];
                }

                using (IrbisConnection connection = new IrbisConnection(connectionString))
                {
                    int maxMfn = connection.GetMaxMfn();

                    string expression = RequestPrefixes.Unfulfilled /* I=0 */
                                        + " + "
                                        + RequestPrefixes.Reserved; /* I=2 */

                    if (parsed.HaveSwitch("expression"))
                    {
                        expression = parsed.GetSwitch("expression")
                                     .ThrowIfNull()
                                     .Value;
                    }

                    expression = expression.ThrowIfNull("expression");

                    Console.Write("Reading good records ");

                    MarcRecord[] goodRecords = BatchRecordReader.Search
                                               (
                        connection,
                        connection.Database,
                        expression,
                        1000,
                        batch => Console.Write(".")
                                               )
                                               .ToArray();

                    Console.WriteLine();
                    Console.WriteLine
                    (
                        "Good records loaded: {0}",
                        goodRecords.Length
                    );

                    if (goodRecords.Length == maxMfn)
                    {
                        Console.WriteLine("No truncation needed, exiting");
                        return(0);
                    }

                    connection.TruncateDatabase(connection.Database);

                    Console.WriteLine("Database truncated");

                    using (BatchRecordWriter writer = new BatchRecordWriter
                                                      (
                               connection,
                               connection.Database,
                               500
                                                      ))
                    {
                        foreach (MarcRecord record in goodRecords)
                        {
                            record.Version = 0;
                            record.Mfn     = 0;
                            writer.Append(record);
                        }
                    }

                    Console.WriteLine("Good records restored");

                    stopwatch.Stop();
                    Console.WriteLine
                    (
                        "Elapsed: {0}",
                        stopwatch.Elapsed.ToAutoString()
                    );
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                return(1);
            }

            return(0);
        }
Exemplo n.º 21
0
        static int Main(string[] arguments)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

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

                if (string.IsNullOrEmpty(connectionString))
                {
                    Console.WriteLine("Connection string not specified");
                    return(1);
                }

                CommandLineParser parser = new CommandLineParser();
                ParsedCommandLine parsed = parser.Parse(arguments);
                if (parsed.PositionalArguments.Count != 0)
                {
                    connectionString = parsed.PositionalArguments[0];
                }

                string searchExpression = "V=01  + V=02";
                string filterExpression = null;

                if (parsed.HaveSwitch("search"))
                {
                    searchExpression = parsed.GetSwitch("search")
                                       .ThrowIfNull().Value;
                }

                searchExpression = searchExpression.ThrowIfNull();

                if (parsed.HaveSwitch("filter"))
                {
                    filterExpression = parsed.GetSwitch("filter")
                                       .ThrowIfNull().Value;
                }

                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    IEnumerable <MarcRecord> allRecords = BatchRecordReader.Search
                                                          (
                        connection,
                        connection.Database,
                        searchExpression,
                        500,
                        batch => Console.Write(".")
                                                          );
                }

                stopwatch.Stop();
                Console.WriteLine
                (
                    "Elapsed: {0}",
                    stopwatch.Elapsed.ToAutoString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(1);
            }

            return(0);
        }
Exemplo n.º 22
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);
            }
        }
Exemplo n.º 23
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);
            }
        }
Exemplo n.º 24
0
        static void Main()
        {
            Console.WriteLine(new string('=', 80));
            Console.WriteLine("Start: {0}", DateTime.Now);
            deadline = DateTime.Today.AddDays(-1.0);

            try
            {
                string baseUri          = CM.AppSettings["baseUri"];
                string apiID            = CM.AppSettings["apiID"];
                string apiKey           = CM.AppSettings["apiKey"];
                string connectionString = CM.AppSettings["connectionString"];
                string messageText      = CM.AppSettings["message"];

                client = new OsmiCardsClient
                         (
                    baseUri,
                    apiID,
                    apiKey
                         );

                Console.WriteLine("PING:");
                JObject ping = client.Ping();
                Console.WriteLine(ping);

                string[] cards = client.GetCardList();
                Console.Write("CARDS: {0}", cards.Length);

                List <string> recipients = new List <string>();
                using (connection = new IrbisConnection(connectionString))
                {
                    IEnumerable <MarcRecord> batch = BatchRecordReader.Search
                                                     (
                        connection,
                        "RDR",
                        "RB=$",
                        1000
                                                     );

                    foreach (MarcRecord record in batch)
                    {
                        ReaderInfo reader = ReaderInfo.Parse(record);
                        string     ticket = reader.Ticket;
                        if (!ticket.OneOf(cards))
                        {
                            continue;
                        }
                        VisitInfo[] outdated = reader.Visits
                                               .Where(v => !v.IsVisit)
                                               .Where(v => !v.IsReturned)
                                               .Where(v => v.DateExpected < deadline)
                                               .ToArray();
                        if (outdated.Length != 0)
                        {
                            Console.WriteLine
                            (
                                "[{0}] {1}: {2} book(s)",
                                reader.Ticket,
                                reader.FullName,
                                outdated.Length
                            );
                            recipients.Add(reader.Ticket);
                        }
                    }
                }

                Console.WriteLine();
                Console.WriteLine("Total recipient(s): {0}", recipients.Count);

                if (recipients.Count != 0)
                {
                    client.SendPushMessage
                    (
                        recipients.ToArray(),
                        messageText
                    );
                    Console.WriteLine("Send OK");
                }

                Console.WriteLine("Finish: {0}", DateTime.Now);
                Console.WriteLine(new string('=', 80));
                Console.WriteLine();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            _irbisConnectionString = args[0];
            _sqlConnectionString   = args[1];

            try
            {
                _stopwatch = new Stopwatch();
                _stopwatch.Start();

                Sql2000DataProvider dataProvider = new Sql2000DataProvider();
                using (_irbisConnection = new IrbisConnection(_irbisConnectionString))
                    using (_database = new DbManager(dataProvider, _sqlConnectionString))
                    {
                        Console.WriteLine
                        (
                            "Started at: {0}",
                            DateTime.Now.ToLongUniformString()
                        );

                        int maxMfn = _irbisConnection.GetMaxMfn();
                        Console.WriteLine("Max MFN={0}", maxMfn);

                        _database
                        .SetCommand("delete from [dbo].[irbisdata]")
                        .ExecuteNonQuery();
                        Console.WriteLine("table truncated");

                        BatchRecordReader batch = (BatchRecordReader)BatchRecordReader.WholeDatabase
                                                  (
                            _irbisConnection,
                            _irbisConnection.Database,
                            500
                                                  );

                        foreach (MarcRecord record in batch)
                        {
                            try
                            {
                                ProcessRecord(record);
                            }
                            catch (Exception exception)
                            {
                                Console.WriteLine("Exception: {0}", exception.Message);
                                Debug.WriteLine(exception);
                            }
                        }

                        _database
                        .SetCommand("EXECUTE [upload_done]")
                        .ExecuteNonQuery();

                        _database
                        .SetCommand("insert into [FlagTable] default values")
                        .ExecuteNonQuery();

                        _stopwatch.Stop();
                        TimeSpan elapsed = _stopwatch.Elapsed;
                        Console.WriteLine
                        (
                            "Elapsed: {0}",
                            elapsed.ToAutoString()
                        );
                    }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 26
0
        private void LoadReaders()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            WriteLine("Начало загрузки читателей");

            IEnumerable <MarcRecord> records
                = BatchRecordReader.WholeDatabase
                  (
                      Connection,
                      Connection.Database,
                      1000
                  );
            BatchRecordReader batch
                = records as BatchRecordReader;

            if (!ReferenceEquals(batch, null))
            {
                batch.BatchRead += Batch_BatchRead;
            }

            records.ProcessData(ParseAndAddReader);
            Readers.CompleteAdding();

            WriteDelimiter();
            WriteLine("Распределение читателей");
            string[] keys = ReadersByStatus.Keys;
            foreach (string key in keys)
            {
                WriteLine
                (
                    "Статус {0}: {1} читателей",
                    key,
                    ReadersByStatus[key].Length
                );
            }
            WriteDelimiter();

            DateTime today = DateTime.Today;

            _debtorManager
                = new DebtorManager(Connection)
                {
                FromDate = today.AddYears(-1),
                ToDate   = today.AddMonths(-1)
                };
            _debtorManager.SetupDates();

            ReadersByStatus["0"].ProcessData(AnalyzeCandidate);
            Debtors.CompleteAdding();

            WriteLine
            (
                "Кандидатов в должники: {0}",
                Debtors.Count
            );

            WriteLine("Окончание загрузки читателей");
            stopwatch.Stop();
            WriteLine
            (
                "Загрузка заняла: {0}",
                stopwatch.Elapsed.ToAutoString()
            );
            WriteLine("Загружено: {0}", Readers.Count);
            WriteDelimiter();
        }