Exemplo n.º 1
0
        static void Main
        (
            string[] args
        )
        {
            if (args.Length != 3)
            {
                return;
            }

            _connectionString = args[0];
            _fond             = args[1];
            _fileName         = args[2];
            string[] numbers = File.ReadAllLines(_fileName)
                               .NonEmptyLines().ToArray();

            NativeIrbisProvider.Register();

            try
            {
                using (_provider = ProviderManager
                                   .GetAndConfigureProvider(_connectionString))
                {
                    foreach (string number in numbers)
                    {
                        _ProcessNumber(number);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 2
0
        private void _keyBox_ButtonClick
        (
            object sender,
            EventArgs e
        )
        {
            try
            {
                Provider = GetProvider();

                string         startTerm  = Prefix + _keyBox.Text;
                TermParameters parameters = new TermParameters
                {
                    Database      = Provider.Database,
                    StartTerm     = startTerm,
                    NumberOfTerms = 100
                };
                TermData[] termData = null;
                Controller.Run
                (
                    () =>
                {
                    TermInfo[] rawTerms
                             = Provider.ReadTerms(parameters);
                    termData = TermData.FromRawTerms
                               (
                        rawTerms,
                        Prefix
                               );
                }
                );
                _termDataBindingSource.DataSource = termData;
            }
            finally
            {
                ReleaseProvider();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public EffectiveReport
        (
            [NotNull] IrbisProvider provider
        )
        {
            Provider = provider;
            Context  = new ReportContext(provider);

            Header = new HeaderBand();
            Header.Cells.Add(new TextCell("КСУ",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Дата",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Сигла",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("ББК",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Назв.",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Экз.",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Руб.",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Выдач",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Выд./экз.",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Руб/выд.",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Выд/день",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Чит. эффект.",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
            Header.Cells.Add(new TextCell("Фин. эффект.",
                                          new ReportAttribute(ReportAttribute.Bold, true)));
        }
Exemplo n.º 4
0
        static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("BiblioGrinder <configurationString> <biblioDocument.json>");
                return(1);
            }

            log = new TeeOutput(AbstractOutput.Console);

            configurationString = args[0];
            documentPath        = args[1];

            ReadRecordCommand.ThrowOnVerify = false;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                AbstractOutput logFile = new FileOutput("grinder.log");
                log.Output.Add(logFile);

                NativeIrbisProvider.Register();

                using (provider = ProviderManager
                                  .GetAndConfigureProvider(configurationString))
                {
                    log.WriteLine
                    (
                        "Connected to database {0}, max MFN={1}",
                        provider.Database,
                        provider.GetMaxMfn()
                    );
                    document = BiblioDocument.LoadFile(documentPath);
                    context  = new BiblioContext(document, provider, log);

                    processor = new BiblioProcessor();
                    processor.Initialize(context);
                    processor.BuildDocument(context);

                    string outputText = processor.Output.Text;

                    // TODO implement properly
                    outputText = Regex.Replace
                                 (
                        outputText,
                        @"\s(-|–|\\u8211.)\sIS[BS]N\s[0-9XxХх-]*\.?",
                        string.Empty
                                 );
                    outputText = Regex.Replace
                                 (
                        outputText,
                        @"([А-Я]\.)\s([А-Я])",
                        "$1\\~$2"
                                 );

                    outputText = Regex.Replace
                                 (
                        outputText,
                        "\\\"([\\w])",
                        "«$1"
                                 );
                    outputText = Regex.Replace
                                 (
                        outputText,
                        "([\\w\\.])\\\"",
                        "$1»"
                                 );

                    outputText = Regex.Replace
                                 (
                        outputText,
                        "\\\"(\\.\\.\\.|\\(|\\[)",
                        "«$1"
                                 );
                    outputText = Regex.Replace
                                 (
                        outputText,
                        "(\\.\\.\\.|\\!|\\?|\\)|\\])\\\"",
                        "$1»"
                                 );

                    outputText = outputText
                                 .Replace(" - ", " \\u8211? ")
                                 .Replace("}- ", "}\\u8211? ")
                                 .Replace(" -}", " \\u8211?}")
                                 .Replace(" -\\", " \\u8211?\\")
                                 .Replace("\\u8470? ", "\u8470?\\~")
                                 .Replace("...", "\\'85")
                                 .Replace("С. ", "С.\\~")
                    ;

                    File.WriteAllText
                    (
                        "output.rtf",
                        outputText,
                        IrbisEncoding.Ansi
                    );

                    stopwatch.Stop();
                    TimeSpan elapsed = stopwatch.Elapsed;
                    log.WriteLine
                    (
                        "Elapsed: {0}",
                        elapsed.ToAutoString()
                    );
                    log.WriteLine
                    (
                        "Finished at: {0}",
                        DateTime.Now
                    );
                }
            }
            catch (Exception exception)
            {
                log.WriteLine
                (
                    "Exception: {0}",
                    exception
                );

                return(1);
            }

            return(0);
        }
Exemplo n.º 5
0
        static void Main()
        {
            try
            {
                _outputBooks = ConfigurationUtility.GetBoolean("books", false);
                string connectionString
                    = IrbisConnectionUtility.GetStandardConnectionString();
                using (_connection = new IrbisConnection(connectionString))
                {
                    _provider = new ConnectedClient(_connection);
                    //_provider = new SemiConnectedClient(_connection);
                    EffectiveReport.Instance = new EffectiveReport(_provider);
                    MenuFile      menu      = MenuFile.ParseLocalFile("ksu.mnu");
                    EffectiveStat totalStat = new EffectiveStat
                    {
                        Description = "Всего по всем КСУ"
                    };
                    bool first = true;

                    foreach (MenuEntry entry in menu.Entries)
                    {
                        if (_outputBooks)
                        {
                            if (!first)
                            {
                                EffectiveReport.AddLine(string.Empty);
                            }

                            first = false;

                            string title = string.Format
                                           (
                                "{0} {1}",
                                entry.Code,
                                entry.Comment
                                           );
                            EffectiveReport.BoldLine(title);
                        }

                        EffectiveStat ksuStat = ProcessKsu(entry);
                        ksuStat.Output(false);
                        totalStat.Add(ksuStat);
                    }

                    EffectiveReport.AddLine(string.Empty);
                    totalStat.Output(false);
                }

                ExcelDriver driver   = new ExcelDriver();
                string      fileName = "output.xlsx";
                FileUtility.DeleteIfExists(fileName);
                driver.OutputFile = fileName;
                EffectiveReport report = EffectiveReport.Instance;
                report.Context.SetDriver(driver);

                report.Render(report.Context);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine
                (
                    "RecordDumper <connection-string> "
                    + "<search-expression> <output-file>"
                );

                return;
            }

            string connectionString = args[0];
            string searchExpression = args[1];
            string outputFileName   = args[2];

            try
            {
                JObject config
                    = JsonUtility.ReadObjectFromFile("dumperConfig.json");
                int   etalonTag   = config["etalonTag"].Value <int>();
                int[] excludeTags = config["excludeTags"]
                                    .Values <int>().ToArray();
                string[] excludePages = config["excludePages"]
                                        .Values <string>().ToArray();

                using (IrbisProvider provider = ProviderManager
                                                .GetAndConfigureProvider(connectionString))
                    using (StreamWriter writer = TextWriterUtility.Create
                                                 (
                               outputFileName,
                               IrbisEncoding.Utf8
                                                 ))
                    {
                        FileSpecification specification = new FileSpecification
                                                          (
                            IrbisPath.MasterFile,
                            provider.Database,
                            "WS31.OPT"
                                                          );
                        IrbisOpt opt = IrbisOpt.LoadFromServer
                                       (
                            provider,
                            specification
                                       );
                        if (ReferenceEquals(opt, null))
                        {
                            throw new IrbisException("Can't load OPT file!");
                        }

                        int[] found = provider.Search(searchExpression);
                        Console.WriteLine("Found: {0}", found.Length);

                        foreach (int mfn in found)
                        {
                            MarcRecord record = provider.ReadRecord(mfn);
                            if (ReferenceEquals(record, null))
                            {
                                continue;
                            }
                            string title = record.FM(etalonTag);
                            if (string.IsNullOrEmpty(title))
                            {
                                continue;
                            }

                            string wsName = opt.SelectWorksheet(opt.GetWorksheet(record));
                            if (string.IsNullOrEmpty(wsName))
                            {
                                continue;
                            }
                            specification = new FileSpecification
                                            (
                                IrbisPath.MasterFile,
                                provider.Database,
                                wsName + ".ws"
                                            );
                            WsFile worksheet = WsFile.ReadFromServer
                                               (
                                provider,
                                specification
                                               );
                            if (ReferenceEquals(worksheet, null))
                            {
                                continue;
                            }

                            Console.WriteLine("MFN={0}: {1}", mfn, title);
                            writer.WriteLine("<h3>{0}</h3>", title);

                            string description = provider.FormatRecord(record, "@");
                            writer.WriteLine(description);

                            RecordField[] fields = record.Fields
                                                   .Where(field => !field.Tag.OneOf(excludeTags))
                                                   .ToArray();

                            writer.WriteLine
                            (
                                "<table border=\"1\" "
                                + "cellpadding=\"3\" "
                                + "cellspacing=\"0\" "
                                + ">"
                            );
                            writer.WriteLine
                            (
                                "<tr bgcolor=\"black\">"
                                + "<th style=\"color:white;text-align:left;\">Поле</th>"
                                + "<th style=\"color:white;text-align:left;\">Подполе</th>"
                                + "<th style=\"color:white;text-align:left;\">Значение</th>"
                                + "</tr>"
                            );
                            foreach (WorksheetPage page in worksheet.Pages)
                            {
                                if (page.Name.OneOf(excludePages))
                                {
                                    continue;
                                }

                                int[] tags = page.Items
                                             .Select(item => item.Tag)
                                             .Select(NumericUtility.ParseInt32)
                                             .ToArray();
                                if (!fields.Any(field => field.Tag.OneOf(tags)))
                                {
                                    continue;
                                }
                                writer.WriteLine
                                (
                                    "<tr><td colspan=\"3\"><b>Вкладка «{0}»</b></td></tr>",
                                    page.Name
                                );

                                foreach (WorksheetItem item in page.Items)
                                {
                                    if (string.IsNullOrEmpty(item.Tag))
                                    {
                                        continue;
                                    }

                                    int tag = NumericUtility.ParseInt32(item.Tag);
                                    if (tag <= 0)
                                    {
                                        continue;
                                    }

                                    RecordField[] itemFields = fields.GetField(tag);
                                    for (int i = 0; i < itemFields.Length; i++)
                                    {
                                        RecordField field = itemFields[i];
                                        title = item.Title;
                                        title = StringUtility.Sparse(title);
                                        if (i != 0)
                                        {
                                            title = string.Format
                                                    (
                                                "(повторение {0})",
                                                i + 1
                                                    );
                                        }
                                        int rowspan = 1;
                                        if (string.IsNullOrEmpty(field.Value))
                                        {
                                            rowspan = 1 + field.SubFields.Count;
                                        }
                                        writer.WriteLine
                                        (
                                            "<tr><td rowspan=\"{0}\" \"width=\"{1}\"><b>{2}</b></td><td colspan=\"2\"><b>{3}</b></td></tr>",
                                            rowspan,
                                            FirstWidth,
                                            field.Tag,
                                            HtmlText.Encode(title)
                                        );

                                        if (!string.IsNullOrEmpty(field.Value))
                                        {
                                            writer.WriteLine
                                            (
                                                "<tr><td colspan=\"2\">&nbsp;</td><td>{0}</td></tr>",
                                                HtmlText.Encode(field.Value)
                                            );
                                        }

                                        if (item.EditMode == "5")
                                        {
                                            string inputInfo = item.InputInfo
                                                               .ThrowIfNull("item.InputInfo");

                                            // Поле с подполями
                                            specification = new FileSpecification
                                                            (
                                                IrbisPath.MasterFile,
                                                provider.Database,
                                                inputInfo
                                                            );
                                            WssFile wss = WssFile.ReadFromServer
                                                          (
                                                provider,
                                                specification
                                                          );
                                            if (ReferenceEquals(wss, null))
                                            {
                                                Console.WriteLine
                                                (
                                                    "Can't load: " + inputInfo
                                                );
                                            }
                                            else
                                            {
                                                foreach (WorksheetItem line in wss.Items)
                                                {
                                                    char     code     = line.Tag.FirstChar();
                                                    SubField subField = field.GetFirstSubField(code);
                                                    if (!ReferenceEquals(subField, null))
                                                    {
                                                        writer.WriteLine
                                                        (
                                                            "<tr>"
                                                            + "<td width=\"{0}\"><b>{1}</b>: {2}</td>"
                                                            + "<td width=\"{3}\">{4}</td></tr>",
                                                            SecondWidth,
                                                            CharUtility.ToUpperInvariant(code),
                                                            HtmlText.Encode(line.Title),
                                                            ThirdWidth,
                                                            HtmlText.Encode(subField.Value)
                                                        );
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            writer.WriteLine("</table>");
                        }
                    }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 7
0
        private void _applyButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            AuthorInfo ethalon = _propertyGrid.SelectedObject as AuthorInfo;

            if (ReferenceEquals(ethalon, null))
            {
                WriteLine("Не задан эталон");
                return;
            }
            string familyName = ethalon.FamilyName;

            if (string.IsNullOrEmpty(familyName))
            {
                WriteLine("Эталон пуст");
                return;
            }
            TermData[] terms = _termDataBindingSource.DataSource as TermData[];
            if (ArrayUtility.IsNullOrEmpty(terms))
            {
                WriteLine("Нет записей для коррекции");
                return;
            }
            string[] selectedTerms = terms
                                     .Where(term => term.Selected)
                                     .Select(term => term.Text)
                                     .ToArray();
            if (ArrayUtility.IsNullOrEmpty(selectedTerms))
            {
                WriteLine("Нет записей для коррекции");
                return;
            }

            StringBuilder query = new StringBuilder();
            bool          first = true;

            foreach (string term in selectedTerms)
            {
                if (!first)
                {
                    query.Append(" + ");
                }
                query.AppendFormat
                (
                    "\"{0}{1}\"",
                    Prefix,
                    term
                );

                first = false;
            }

            try
            {
                Provider = GetProvider();
                Controller.Run
                (
                    () =>
                {
                    int[] found = Provider.Search(query.ToString());
                    WriteLine
                    (
                        "Отобрано для коррекции: {0}",
                        found.Length
                    );
                    foreach (int mfn in found)
                    {
                        MarcRecord record
                            = Provider.ReadRecord(mfn);
                        if (!ReferenceEquals(record, null))
                        {
                            AuthorInfo[] authors
                                = AuthorInfo.ParseRecord
                                  (
                                      record,
                                      AuthorInfo.AllKnownTags
                                  );
                            AuthorInfo[] selected = authors.Where
                                                    (
                                a => a.FamilyName
                                .SameString(familyName)
                                                    )
                                                    .ToArray();
                            if (selected.Length == 0)
                            {
                                WriteLine
                                (
                                    "MFN {0} пропущен",
                                    mfn
                                );
                            }
                            else
                            {
                                foreach (AuthorInfo theAuthor in selected)
                                {
                                    WriteLine
                                    (
                                        "MFN {0}: {1}",
                                        mfn,
                                        theAuthor.Field
                                    );
                                    ethalon.ApplyToField
                                    (
                                        theAuthor.Field
                                        .ThrowIfNull("theAuthor.Field")
                                    );
                                }
                                Provider.WriteRecord(record);
                            }
                        }
                    }
                }
                );
            }
            finally
            {
                ReleaseProvider();
            }

            _keyBox_ButtonClick(sender, e);
            WriteLine("Обработка завершена");
        }
Exemplo n.º 8
0
        private void _termGrid_CellContentClick
        (
            object sender,
            DataGridViewCellEventArgs e
        )
        {
            DataGridView grid = sender as DataGridView;

            if (ReferenceEquals(grid, null))
            {
                return;
            }
            if (e.ColumnIndex < 0 ||
                e.ColumnIndex >= grid.ColumnCount ||
                e.RowIndex < 0 ||
                e.RowIndex >= grid.RowCount)
            {
                return;
            }
            DataGridViewButtonColumn column
                = grid.Columns[e.ColumnIndex] as DataGridViewButtonColumn;

            if (ReferenceEquals(column, null))
            {
                return;
            }
            if (ReferenceEquals(grid.CurrentRow, null))
            {
                return;
            }
            TermData term = grid.CurrentRow.DataBoundItem as TermData;

            if (ReferenceEquals(term, null))
            {
                return;
            }
            string text = term.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            string familyName = AuthorInfo.ExtractFamilyName(text);

            if (string.IsNullOrEmpty(familyName))
            {
                return;
            }

            _propertyGrid.SelectedObject = null;

            string query = Prefix + text;

            try
            {
                Provider = GetProvider();
                AuthorInfo theAuthor = null;
                Controller.Run
                (
                    () =>
                {
                    TermLink[] links
                        = Provider.ExactSearchLinks(query);
                    if (links.Length != 0)
                    {
                        int mfn = links[0].Mfn;
                        MarcRecord record
                            = Provider.ReadRecord(mfn);
                        if (!ReferenceEquals(record, null))
                        {
                            AuthorInfo[] authors
                                = AuthorInfo.ParseRecord
                                  (
                                      record,
                                      AuthorInfo.AllKnownTags
                                  );
                            theAuthor = authors.FirstOrDefault
                                        (
                                a => a.FamilyName
                                .SameString(familyName)
                                        );
                        }
                    }
                }
                );

                _propertyGrid.SelectedObject = theAuthor;
                term.Ethalon = true;
                _propertyGrid.Invalidate();
                WriteLine
                (
                    "Задан эталон: {0}",
                    theAuthor.Field
                );
            }
            finally
            {
                ReleaseProvider();
            }
        }
Exemplo n.º 9
0
 public void ReleaseProvider()
 {
     MainForm.ReleaseProvider();
     Provider = null;
 }