Esempio n. 1
0
        public static MarcRecord AddField
        (
            [NotNull] this MarcRecord record,
            int tag,
            [NotNull] object value
        )
        {
            Sure.NotNull(record, "record");
            Sure.NotNull(value, "value");

            RecordField field = value as RecordField;

            if (!ReferenceEquals(field, null))
            {
                Debug.Assert(tag == field.Tag, "tag == field.Tag");
            }
            else
            {
                string text = value.ToString();
                if (!string.IsNullOrEmpty(text))
                {
                    field = RecordField.Parse(tag, value.ToString());
                }
                else
                {
                    field = new RecordField(tag);
                }
            }
            record.Fields.Add(field);

            return(record);
        }
Esempio n. 2
0
        public static MarcRecord[] ParseAllFormat
        (
            [NotNull] string database,
            [NotNull] ServerResponse response
        )
        {
            Sure.NotNullNorEmpty(database, "database");
            Sure.NotNull(response, "response");

            List <MarcRecord> result = new List <MarcRecord>();

            while (true)
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = response.Connection.Host,
                    Database = database
                };
                record = ProtocolText.ParseResponseForAllFormat
                         (
                    response,
                    record
                         );
                if (ReferenceEquals(record, null))
                {
                    break;
                }
                result.Add(record);
            }

            return(result.ToArray());
        }
Esempio n. 3
0
        public static MarcRecord SetSubField
        (
            [NotNull] this MarcRecord record,
            int tag,
            int fieldOccurrence,
            char code,
            int subFieldOccurrence,
            [CanBeNull] string newValue
        )
        {
            Sure.NotNull(record, "record");
            Sure.Positive(tag, "tag");

            RecordField field = record.Fields.GetField(tag, fieldOccurrence);

            if (!ReferenceEquals(field, null))
            {
                SubField subField = field.GetSubField(code, subFieldOccurrence);
                if (!ReferenceEquals(subField, null))
                {
                    subField.Value = newValue;
                }
            }

            return(record);
        }
Esempio n. 4
0
        public MarcRecord ReadRecord
        (
            [NotNull] IIrbisConnection connection
        )
        {
            Sure.NotNull(connection, "connection");

            Verify(true);

            if (Mfn != 0)
            {
                Record = connection.ReadRecord
                         (
                    Database.ThrowIfNull("Database"),
                    Mfn,
                    false,
                    null
                         );
            }
            else
            {
                Record = connection.SearchReadOneRecord
                         (
                    "\"I={0}\"",
                    Index
                         );
            }

            return(Record);
        }
Esempio n. 5
0
        public static MarcRecord[] ParseAllFormat
        (
            [NotNull] string database,
            [NotNull] IIrbisConnection connection,
            [NotNull] string[] lines
        )
        {
            Sure.NotNullNorEmpty(database, "database");
            Sure.NotNull(connection, "connection");
            Sure.NotNull(lines, "lines");

            List <MarcRecord> result = new List <MarcRecord>();

            foreach (string line in lines)
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = connection.Host,
                    Database = database
                };
                record = ProtocolText.ParseResponseForAllFormat
                         (
                    line,
                    record
                         );

                // coverity[NULL_RETURNS]
                result.Add(record.ThrowIfNull("record"));
            }

            return(result.ToArray());
        }
Esempio n. 6
0
        public static MarcRecord EndUpdate
        (
            [NotNull] this MarcRecord record
        )
        {
            record.Fields.EndUpdate();

            return(record);
        }
Esempio n. 7
0
        public static MarcRecord BeginUpdate
        (
            [NotNull] this MarcRecord record,
            int delta
        )
        {
            record.Fields.BeginUpdate();
            record.Fields.AddCapacity(delta);
            record.Modified = false;

            return(record);
        }
Esempio n. 8
0
        public static MarcRecord AddField
        (
            [NotNull] this MarcRecord record,
            [NotNull] RecordField field
        )
        {
            Sure.NotNull(record, "record");
            Sure.NotNull(field, "field");

            record.Fields.Add(field);

            return(record);
        }
Esempio n. 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public RecordReference
        (
            [NotNull] MarcRecord record
        )
        {
            Sure.NotNull(record, nameof(record));

            HostName = record.HostName;
            Database = record.Database;
            Mfn      = record.Mfn;
            Index    = record.Index ?? record.FM(903);
            Record   = record;
        }
Esempio n. 10
0
        internal RecordFieldCollection _SetRecord
        (
            [CanBeNull] MarcRecord newRecord
        )
        {
            _record = newRecord;

            foreach (RecordField field in this)
            {
                field.Record = newRecord;
            }

            return(this);
        }
Esempio n. 11
0
        public static MarcRecord ReplaceField
        (
            [NotNull] this MarcRecord record,
            int tag,
            [NotNull] IEnumerable <RecordField> newFields
        )
        {
            Sure.NotNull(record, "record");
            Sure.NotNull(newFields, "newFields");

            record.RemoveField(tag);
            record.Fields.AddRange(newFields);

            return(record);
        }
Esempio n. 12
0
        public static string ToYaml
        (
            [NotNull] this MarcRecord record
        )
        {
            Sure.NotNull(record, "record");

#if !CLASSIC && !NETCORE
            throw new System.NotImplementedException();
#else
            Serializer serializer = new Serializer();
            string     result     = serializer.Serialize(record);

            return(result);
#endif
        }
Esempio n. 13
0
        public static string ToJson
        (
            [NotNull] this MarcRecord record
        )
        {
            Sure.NotNull(record, "record");

#if WINMOBILE || PocketPC
            throw new System.NotImplementedException();
#else
            string result = JObject.FromObject(record)
                            .ToString(Formatting.None);

            return(result);
#endif
        }
Esempio n. 14
0
        public static MarcRecord RemoveField
        (
            [NotNull] this MarcRecord record,
            int tag
        )
        {
            Sure.NotNull(record, "record");

            RecordField[] found = record.Fields.GetField(tag);
            foreach (RecordField field in found)
            {
                record.Fields.Remove(field);
            }

            return(record);
        }
Esempio n. 15
0
        /// <summary>
        /// Нет ни одного поля с указанным тегом?
        /// </summary>
        public static bool HaveNotField
        (
            this MarcRecord record,
            int tag
        )
        {
            RecordFieldCollection fields = record.Fields;

            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Tag == tag)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 16
0
        /// <summary>
        /// Нет ни одного поля с указанными тегами?
        /// </summary>
        public static bool HaveNotField
        (
            this MarcRecord record,
            params int[] tags
        )
        {
            RecordFieldCollection fields = record.Fields;

            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Tag.OneOf(tags))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 17
0
        public static MarcRecord SetField
        (
            [NotNull] this MarcRecord record,
            int tag,
            int occurrence,
            string newText
        )
        {
            Sure.NotNull(record, "record");
            Sure.Positive(tag, "tag");

            RecordField field = record.Fields.GetField(tag, occurrence);

            if (!ReferenceEquals(field, null))
            {
                field.SubFields.Clear();
                field.Value = newText;
            }

            return(record);
        }
Esempio n. 18
0
        public static MarcRecord SetSubField
        (
            [NotNull] this MarcRecord record,
            int tag,
            char code,
            [CanBeNull] string newValue
        )
        {
            Sure.NotNull(record, "record");
            Sure.Positive(tag, "tag");

            RecordField field = record.Fields.GetFirstField(tag);

            if (ReferenceEquals(field, null))
            {
                field = new RecordField(tag);
                record.Fields.Add(field);
            }

            field.SetSubField(code, newValue);

            return(record);
        }
Esempio n. 19
0
        public static List <MarcRecord> ReadRecords
        (
            [NotNull] IIrbisConnection connection,
            [NotNull] IEnumerable <RecordReference> references,
            bool throwOnError
        )
        {
            Sure.NotNull(connection, "connection");
            Sure.NotNull(references, "references");

            List <MarcRecord> result = new List <MarcRecord>();

            foreach (RecordReference reference in references)
            {
                MarcRecord record = reference.ReadRecord(connection);
                if (ReferenceEquals(record, null))
                {
                    Log.Error
                    (
                        "RecordReference::ReadRecords: "
                        + "record not found: "
                        + reference
                    );

                    if (throwOnError)
                    {
                        throw new IrbisException("record not found");
                    }
                }
                else
                {
                    result.Add(record);
                }
            }

            return(result);
        }