public void MarcRecordUtility_AddField_6()
        {
            MarcRecord record = new MarcRecord();
            object     value  = null;

            record.AddField(701, value);
        }
        public void MarcRecordUtility_ParseAllFormat_2()
        {
            string host = "host";
            Mock <IIrbisConnection> mock = new Mock <IIrbisConnection>();

            mock.SetupGet(c => c.Host).Returns(host);
            IIrbisConnection connection = mock.Object;

            string database = "IBIS";

            string[]     lines   = _GetLines();
            MarcRecord[] records = MarcRecordUtility.ParseAllFormat
                                   (
                database,
                connection,
                lines
                                   );
            Assert.AreEqual(lines.Length, records.Length);
            for (int i = 0; i < records.Length; i++)
            {
                MarcRecord record = records[i];
                Assert.AreEqual(host, record.HostName);
                Assert.AreEqual(database, record.Database);
            }
        }
Пример #3
0
        static int GetMarcLength(string strXml)
        {
            string strError = "";

            string strMarc          = "";
            string strOutMarcSyntax = "";
            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            int nRet = MarcUtil.Xml2Marc(strXml,
                                         true, // 2013/1/12 修改为true
                                         "",   // strMarcSyntax
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);

            if (nRet == -1)
            {
                return(0);
            }

            MarcRecord record = new MarcRecord(strMarc);

            return(record.Text.Length);
        }
Пример #4
0
        static void ProcessNumber
        (
            string number
        )
        {
            int[] found = irbis.ExactSearch(string.Format
                                            (
                                                "IN={0}",
                                                number
                                            ));
            if (found.Length == 0)
            {
                return;
            }
            int mfn = found[0];

            irbis.ReadRecord(mfn);
            NativeRecord native      = irbis.GetRecord();
            MarcRecord   record      = native.ToMarcRecord();
            string       description = irbis.FormatRecord(mfn);
            int          count       = record.FM(999).SafeToInt32();

            Console.WriteLine
            (
                "{0}\t{1}\t{2}",
                number,
                count,
                description
            );
        }
Пример #5
0
        private MarcRecord _ParseRecord
        (
            [CanBeNull] string line
        )
        {
            if (string.IsNullOrEmpty(line))
            {
                return(null);
            }

            MarcRecord result = new MarcRecord
            {
                HostName = Connection.Host,
                Database = Database
            };

            result = ProtocolText.ParseResponseForAllFormat
                     (
                line,
                result
                     );

            if (!ReferenceEquals(result, null))
            {
                if (result.Deleted)
                {
                    return(null);
                }
            }

            return(result);
        }
Пример #6
0
        public void RecordReference_ToString_2()
        {
            MarcRecord      record    = _GetRecord();
            RecordReference reference = new RecordReference(record);

            Assert.AreEqual("db123#00#0200#^aSubA^bSubB300#Field300", reference.ToString());
        }
Пример #7
0
        public void RecordReference_ReadRecord_1()
        {
            Mock <IIrbisConnection> mock = new Mock <IIrbisConnection>();

            mock.Setup(c => c.ReadRecord(It.IsAny <string>(),
                                         It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>()))
            .Returns(_GetRecord());

            IIrbisConnection connection = mock.Object;
            RecordReference  reference  = new RecordReference
            {
                HostName = "host",
                Database = "db",
                Mfn      = 123
            };
            MarcRecord record = reference.ReadRecord(connection);

            Assert.IsNotNull(record);
            Assert.AreEqual("host", record.HostName);
            Assert.AreEqual("db", record.Database);
            Assert.AreEqual(123, record.Mfn);

            mock.Verify(c => c.ReadRecord(It.IsAny <string>(),
                                          It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>()),
                        Times.Once);
        }
Пример #8
0
        public static List <Key> BuildKeys(MarcRecord record,
                                           string strBiblioRecPath,
                                           string xpath,
                                           string type)
        {
            List <string> values = new List <string>();

            foreach (MarcSubfield subfield in record.select(xpath))
            {
                values.Add(subfield.Content);
            }

            // TODO: SQL Server 无法区分大小写 key 字符串,会认为重复
            values.Sort((a, b) => string.Compare(a, b, true));
            _removeDup(ref values);
            StringUtil.RemoveBlank(ref values);

            List <Key> results = new List <Key>();
            int        index   = 0;

            foreach (string class_string in values)
            {
                Key key = new Key
                {
                    Text          = class_string,
                    Type          = type,
                    BiblioRecPath = strBiblioRecPath,
                    Index         = index++,
                };
                results.Add(key);
            }

            return(results);
        }
Пример #9
0
        public void MarcDiff_MergeOldNew_5_1()
        {
            string strUserRights    = "level-1";
            string strFieldNameList = "*:***-***"; // 所有字段都允许操作

            MarcRecord old_record = new MarcRecord();

            // 旧记录没有 856 字段
            old_record.add(new MarcField("001A1234567"));
            old_record.add(new MarcField('$', "2001 $atitle$fauthor"));
            old_record.add(new MarcField('$', "701  $aauthor"));

            MarcRecord new_record = new MarcRecord();

            // 新记录增加一个 856 字段
            new_record.add(new MarcField("001A1234567"));
            new_record.add(new MarcField('$', "2001 $atitle$fauthor"));
            new_record.add(new MarcField('$', "85642$3Cover image 1$uURL1$qimage/jpeg$xtype:FrontCover.SmallImage;rights:group"));
            new_record.add(new MarcField('$', "701  $aauthor"));

            MarcRecord target_record = new MarcRecord();

            // 结果记录没有 856 字段
            target_record.add(new MarcField("001A1234567"));
            target_record.add(new MarcField('$', "2001 $atitle$fauthor"));
            target_record.add(new MarcField('$', "701  $aauthor"));

            MarcDiff_MergeOldNew(
                strUserRights,
                strFieldNameList,
                old_record,
                new_record,
                target_record,
                "856!");
        }
Пример #10
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);
            }
        }
Пример #11
0
        private MarcRecord _GetRecord()
        {
            MarcRecord result = new MarcRecord();

            RecordField field = new RecordField("700");

            field.AddSubField('a', "Иванов");
            field.AddSubField('b', "И. И.");
            result.Fields.Add(field);

            field = new RecordField("701");
            field.AddSubField('a', "Петров");
            field.AddSubField('b', "П. П.");
            result.Fields.Add(field);

            field = new RecordField("200");
            field.AddSubField('a', "Заглавие");
            field.AddSubField('e', "подзаголовочное");
            field.AddSubField('f', "И. И. Иванов, П. П. Петров");
            result.Fields.Add(field);

            field = new RecordField(300, "Первое примечание");
            result.Fields.Add(field);
            field = new RecordField(300, "Второе примечание");
            result.Fields.Add(field);
            field = new RecordField(300, "Третье примечание");
            result.Fields.Add(field);

            return(result);
        }
Пример #12
0
        static string GetMaterialType(MarcRecord record)
        {
            if ("at".IndexOf(record.Header[6]) != -1 &&
                "acdm".IndexOf(record.Header[7]) != -1)
            {
                return("Book");  // Books
            }
            if (record.Header[6] == "m")
            {
                return("Computer Files");
            }

            if ("df".IndexOf(record.Header[6]) != -1)
            {
                return("Map");  // Maps
            }
            if ("cdij".IndexOf(record.Header[6]) != -1)
            {
                return("Music");  // Music
            }
            if ("a".IndexOf(record.Header[6]) != -1 &&
                "bis".IndexOf(record.Header[7]) != -1)
            {
                return("Periodical or Newspaper");  // Continuing Resources
            }
            if ("gkor".IndexOf(record.Header[6]) != -1)
            {
                return("Visual Material");  // Visual Materials
            }
            if (record.Header[6] == "p")
            {
                return("Mixed Material");    // Mixed Materials
            }
            return("");
        }
Пример #13
0
 /// <summary>
 /// Write the record.
 /// </summary>
 public virtual void WriteRecord
 (
     [NotNull] MarcRecord record
 )
 {
     // Nothing to do here
 }
Пример #14
0
        private static int _GetYear
        (
            [NotNull] MarcRecord record
        )
        {
            string result = record.FM(210, 'd');

            if (string.IsNullOrEmpty(result))
            {
                result = record.FM(461, 'h');
            }
            if (string.IsNullOrEmpty(result))
            {
                result = record.FM(461, 'z');
            }
            if (string.IsNullOrEmpty(result))
            {
                result = record.FM(934);
            }
            if (string.IsNullOrEmpty(result))
            {
                return(0);
            }

            Match match = Regex.Match(result, @"\d{4}");

            if (match.Success)
            {
                result = match.Value;
            }
            return(result.SafeToInt32());
        }
Пример #15
0
        public static int ScriptUnimarc(
            string strRecPath,
            string strMARC,
            out List <NameValueLine> results,
            out string strError)
        {
            strError = "";
            results  = new List <NameValueLine>();

            MarcRecord record = new MarcRecord(strMARC);

            if (record.ChildNodes.count == 0)
            {
                return(0);
            }

            // 010
            MarcNodeList fields = record.select("field[@name='010' or @name='011' or @name='091']");

            if (fields.count > 0)
            {
                results.Add(new NameValueLine("获得方式", BuildFields(fields)));
            }

            return(0);
        }
Пример #16
0
        private void _ParseRecord <T>
        (
            [NotNull] string line,
            [NotNull] string database,
            [NotNull] Func <MarcRecord, T> func,
            [NotNull] BlockingCollection <T> collection
        )
        {
            if (!string.IsNullOrEmpty(line))
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = Connection.Host,
                    Database = database
                };

                record = ProtocolText.ParseResponseForAllFormat
                         (
                    line,
                    record
                         );

                if (!ReferenceEquals(record, null))
                {
                    if (!record.Deleted)
                    {
                        T result = func(record);

                        collection.Add(result);
                    }
                }
            }
        }
Пример #17
0
        public static MarcRecord ParseMfnStatusVersion
        (
            [NotNull] string line1,
            [NotNull] string line2,
            [NotNull] MarcRecord record
        )
        {
            Sure.NotNullNorEmpty(line1, "line1");
            Sure.NotNullNorEmpty(line2, "line2");
            Sure.NotNull(record, "record");

            Regex regex = new Regex(@"^(-?\d+)\#(\d*)?");
            Match match = regex.Match(line1);

            record.Mfn = Math.Abs(int.Parse(match.Groups[1].Value));
            if (match.Groups[2].Length > 0)
            {
                record.Status = (RecordStatus)int.Parse
                                (
                    match.Groups[2].Value
                                );
            }
            match = regex.Match(line2);
            if (match.Groups[2].Length > 0)
            {
                record.Version = int.Parse(match.Groups[2].Value);
            }

            return(record);
        }
Пример #18
0
        private async void _findButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            SetHtml(string.Empty);

            string mfnText = _mfnBox.Text.Trim();

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

            int mfn = mfnText.SafeToInt32();

            if (mfn <= 0)
            {
                WriteLine("Bad MFN: {0}", mfnText);
            }

            try
            {
                string formatted = string.Empty;

                await Task.Run
                (
                    () =>
                {
                    string format
                              = CM.AppSettings["format"];
                    formatted = Connection.FormatRecord
                                (
                        format,
                        mfn
                                );

                    MarcRecord record
                        = Connection.ReadRecord(mfn);
                    if (record.Deleted)
                    {
                        formatted
                            = "<strong>DELETED</strong><br/>"
                              + formatted;
                    }
                }
                );

                SetHtml(formatted);

                WriteLine("MFN: {0}", mfn);
                CurrentMfn = mfn;
            }
            catch (Exception ex)
            {
                WriteLine("Searching for MFN: {0}", mfn);
                WriteLine("Exception: {0}", ex);
            }
        }
Пример #19
0
        private void _searchButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            _resultBox.Clear();
            _loginBox.Clear();
            _passwordBox.Clear();

            string ticket = _ticketBox.Text.Trim();

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

                return;
            }

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

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

                    return;
                }

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

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

                _loginBox.Focus();
            }
        }
Пример #20
0
        /// <inheritdoc cref="AbstractCommand.Execute" />
        public override ServerResponse Execute
        (
            ClientQuery query
        )
        {
            Sure.NotNull(query, nameof(query));

            string database = Record.ThrowIfNull("Record").Database
                              ?? Connection.Database;

            ServerResponse result = base.Execute(query);

            MaxMfn = result.GetReturnCode();

            MarcRecord record = Record.ThrowIfNull("Record");

            record.Database = database;
            record.HostName = Connection.Host;

            if (!DontParseResponse)
            {
                ProtocolText.ParseResponseForWriteRecord
                (
                    result,
                    record
                );
            }

            return(result);
        }
Пример #21
0
        public void MarcRecord_Renumbering_1()
        {
            MarcRecord record = _GetRecord();

            int[] tags = record.Fields
                         .Select(field => field.Tag)
                         .Distinct()
                         .ToArray();

            foreach (int tag in tags)
            {
                RecordField[] fields = record.Fields.GetField(tag);
                for (int i = 0; i < fields.Length; i++)
                {
                    RecordField field = fields[i];
                    Assert.AreEqual(i + 1, field.Repeat);
                    Assert.AreEqual(record, field.Record);

                    foreach (SubField subField in field.SubFields)
                    {
                        Assert.AreEqual(field, subField.Field);
                    }
                }
            }
        }
Пример #22
0
        public int UpdateRecord
        (
            string number,
            string cardId
        )
        {
            using (new IrbisContextSaver(Client))
            {
                Client.Database = CM.AppSettings["cards-database"];

                int[] found = Client.Search
                              (
                    "\"IN={0}\"",
                    number
                              );
                MarcRecord  record   = Client.ReadRecord(found[0]);
                RecordField oldField = record.Fields.GetField(2020).First();
                int         index    = record.Fields.IndexOf(oldField);
                RecordField newField = new RecordField(2020)
                                       .AddSubField('a', cardId)
                                       .AddSubField('b', IdToPath(cardId))
                                       .AddSubField('c', "4");
                record.Fields.Insert(index, newField);
                Client.WriteRecord(record);
                return(record.Mfn);
            }
        }
Пример #23
0
        private void _ParseRecord
        (
            [NotNull] string line,
            [NotNull] string database
        )
        {
            if (!string.IsNullOrEmpty(line))
            {
                MarcRecord result = new MarcRecord
                {
                    HostName = Connection.Host,
                    Database = database
                };

                result = ProtocolText.ParseResponseForAllFormat
                         (
                    line,
                    result
                         );

                if (!ReferenceEquals(result, null))
                {
                    _ThrowIfEmptyRecord(result, line);

                    if (!result.Deleted)
                    {
                        result.Modified = false;
                        _records.Add(result);
                    }
                }
            }
        }
Пример #24
0
        private string EncodeRecord
        (
            [NotNull] MarcRecord record
        )
        {
            StringBuilder result = new StringBuilder();

            AppendIrbisLine
            (
                result,
                "0#{0}",
                record.Version
            );
            AppendIrbisLine
            (
                result,
                "{0}#{1}",
                record.Mfn,
                (int)record.Status
            );

            foreach (RecordField field in record.Fields)
            {
                EncodeField(result, field);
            }

            return(result.ToString());
        }
Пример #25
0
 private int RecordToMfn
 (
     [NotNull] MarcRecord record
 )
 {
     return(record.Mfn);
 }
Пример #26
0
        static void ProcessRecord
        (
            MarcRecord record
        )
        {
            BookInfo info      = new BookInfo(provider, record);
            string   worksheet = info.Worksheet;

            if (worksheet != "SPEC" && worksheet != "PAZK")
            {
                return;
            }

            string[] publishers = info.Publishers;
            int      count      = info.UsageCount;
            int      exemplars  = info.Exemplars.Length;

            if (count != 0)
            {
                foreach (string publisher in publishers)
                {
                    string trimmed = publisher.Trim(charsToTrim);
                    counter1.Augment(trimmed, count);
                    counter2.Augment(trimmed, exemplars);
                }
            }
        }
Пример #27
0
        public void MarcRecord_FM_1()
        {
            MarcRecord record = _GetRecord();

            Assert.AreEqual("Иванов", record.FM(700, 'a'));
            Assert.AreEqual("Первое примечание", record.FM(300));
        }
Пример #28
0
        public void MarcRecord_Deleted_1()
        {
            MarcRecord record = new MarcRecord();

            Assert.IsFalse(record.Deleted);
            Assert.AreEqual
            (
                (RecordStatus)0,
                record.Status & RecordStatus.LogicallyDeleted
            );
            record.Deleted = true;
            Assert.IsTrue(record.Deleted);
            Assert.AreEqual
            (
                RecordStatus.LogicallyDeleted,
                record.Status & RecordStatus.LogicallyDeleted
            );
            record.Deleted = false;
            Assert.AreEqual
            (
                (RecordStatus)0,
                record.Status & RecordStatus.LogicallyDeleted
            );
            Assert.IsFalse(record.Deleted);
        }
Пример #29
0
 public virtual string FormatRecord
 (
     [NotNull] MarcRecord record,
     string format
 )
 {
     return(string.Empty);
 }
Пример #30
0
        public void MarcRecord_HostName_1()
        {
            const string miron  = "mironxp";
            MarcRecord   record = new MarcRecord();

            record.HostName = miron;
            Assert.AreEqual(miron, record.HostName);
        }