示例#1
0
        static void Main()
        {
            try
            {
                string recordText = File.ReadAllText
                                    (
                    "record.txt",
                    IrbisEncoding.Ansi
                                    );
                StringReader reader = new StringReader(recordText);
                MarcRecord   record = PlainText.ReadRecord(reader)
                                      .ThrowIfNull("record!");

                LocalFstProcessor processor = new LocalFstProcessor
                                              (
                    "C:\\IRBIS64",
                    "SANDBOX"
                                              );
                FstFile fstFile = processor.ReadFile("marc_irb.fst")
                                  .ThrowIfNull("fstFile!");

                MarcRecord transformed = processor.TransformRecord
                                         (
                    record,
                    fstFile
                                         );
                string result = transformed.ToPlainText();
                Console.WriteLine(result);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
示例#2
0
        private void ParseHtml()
        {
            string       recordText = _recordBox.Text;
            StringReader reader     = new StringReader(recordText);

            _record = PlainText.ReadRecord(reader);
            _recordGrid.SetRecord(_record);

            PftHtmlFormatter formatter = new PftHtmlFormatter();

            formatter.ParseProgram(_pftBox.Text);
            _program = formatter.Program;
            _pftTreeView.SetNodes(_program);
        }
示例#3
0
        private void Parse()
        {
            string       recordText = _recordBox.Text;
            StringReader reader     = new StringReader(recordText);

            _record = PlainText.ReadRecord(reader);
            if (!ReferenceEquals(_record, null))
            {
                _record.Mfn = 1; // TODO some other value?
            }
            _recordGrid.SetRecord(_record);

            PftLexer lexer = new PftLexer();

            _tokenList = lexer.Tokenize(_pftBox.Text);

            _tokenGrid.SetTokens(_tokenList);

            PftParser parser = new PftParser(_tokenList);

            _program = parser.Parse();
            _pftTreeView.SetNodes(_program);
        }
示例#4
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Need two arguments");
                return;
            }

            string inputFileName = args[0]
                                   .ThrowIfNull("inputFileName");
            string outputFileName = args[1]
                                    .ThrowIfNull("outputFileName");
            string mstFileName = Path.ChangeExtension(outputFileName, ".mst")
                                 .ThrowIfNull("mstFileName");
            string xrfFileName = Path.ChangeExtension(outputFileName, ".xrf")
                                 .ThrowIfNull("xrfFileName");

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                DirectUtility.CreateMasterFile64(outputFileName);

                int mfn = 0;
                using (Stream mstFile = new FileStream(mstFileName,
                                                       FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                    using (Stream xrfFile = File.OpenWrite(xrfFileName))
                        using (StreamReader reader = File.OpenText(inputFileName))
                        {
                            MstControlRecord64 control = new MstControlRecord64
                            {
                                NextPosition = MstControlRecord64.RecordSize
                            };
                            control.Write(mstFile);

                            MarcRecord marcRecord;
                            while ((marcRecord = PlainText.ReadRecord(reader)) != null)
                            {
                                if (mfn % 100 == 0)
                                {
                                    Console.Write(" {0} ", mfn);
                                }

                                marcRecord.Mfn     = ++mfn;
                                marcRecord.Version = 1;
                                marcRecord.Status  = RecordStatus.Last;
                                long        position  = mstFile.Position;
                                MstRecord64 mstRecord = MstRecord64.EncodeRecord(marcRecord);
                                mstRecord.Prepare();
                                mstRecord.Write(mstFile);

                                xrfFile.WriteInt64Network(position);
                                xrfFile.WriteInt32Network((int)RecordStatus.NonActualized);
                            }

                            if (mfn != 0)
                            {
                                // Update the control record
                                long nextPosition = mstFile.Length;
                                mstFile.Seek(0, SeekOrigin.Begin);
                                control              = MstControlRecord64.Read(mstFile);
                                control.Blocked      = 0;
                                control.NextMfn      = mfn;
                                control.NextPosition = nextPosition;

                                mstFile.Seek(0, SeekOrigin.Begin);
                                control.Write(mstFile);
                            }
                        }

                Console.WriteLine(" Total: {0}", mfn);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            stopwatch.Stop();
            TimeSpan elapsed = stopwatch.Elapsed;

            Console.WriteLine("Elapsed: {0}", elapsed.ToAutoString());
        }
示例#5
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Need two arguments");
                return;
            }

            string inputFileName  = args[0];
            string outputFileName = args[1];

            try
            {
                // Сначала прочитаем уже имеющиеся записи
                if (File.Exists(outputFileName))
                {
                    using (StreamReader stringReader = File.OpenText(outputFileName))
                    {
                        MarcRecord marcRecord;
                        while ((marcRecord = PlainText.ReadRecord(stringReader)) != null)
                        {
                            ReaderInfo           readerInfo = ReaderInfo.Parse(marcRecord);
                            DepersonalizedReader depersonalized
                                = DepersonalizedReader.FromReaderInfo(readerInfo);
                            string ticket = depersonalized.Ticket.ThrowIfNull();
                            readers.Add(ticket, depersonalized);
                        }
                    }
                }

                // Теперь будем вычитывать данные и объединять их с уже имеющимися
                string ext = Path.GetExtension(inputFileName);
                if (ext.SameString(".mst"))
                {
                    ProcessOneDatabase(inputFileName);
                }
                else
                {
                    string[] inputFiles = File.ReadAllLines(inputFileName);
                    foreach (string inputFile in inputFiles)
                    {
                        ProcessOneDatabase(inputFile);
                    }
                }

                // Сохраняем результат
                Console.WriteLine("Writing ");
                using (StreamWriter writer = File.CreateText(outputFileName))
                {
                    var allReaders = readers.Values;
                    foreach (DepersonalizedReader reader in allReaders)
                    {
                        MarcRecord record = reader.ToMarcRecord();
                        PlainText.WriteRecord(writer, record);
                    }
                }

                Console.WriteLine("DONE");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }