Exemplo n.º 1
0
        public static RecordField[] WithSubFields
        (
            this MarcRecord record
        )
        {
            FieldCollection    fields = record.Fields;
            int                count  = fields.Length;
            List <RecordField> result = null;

            for (int i = 0; i < count; i++)
            {
                if (fields[i].SubFields.Length != 0)
                {
                    if (ReferenceEquals(result, null))
                    {
                        result = new List <RecordField>();
                    }
                    result.Add(fields[i]);
                }
            }

            return(ReferenceEquals(result, null)
                ? EmptyFieldArray
                : result.ToArray());
        }
Exemplo n.º 2
0
        public static string FormatRecordRetry(this IrbisClient client,
                                               string format, MarcRecord record)
        {
            Func <string, MarcRecord, string> func = client.FormatRecord;

            return(Try(func, format, record));
        }
Exemplo n.º 3
0
        public static MarcRecord WriteRecordRetry(this IrbisClient client,
                                                  MarcRecord record)
        {
            Func <MarcRecord, MarcRecord> func = client.WriteRecord;

            return(Try(func, record));
        }
Exemplo n.º 4
0
        public MarcRecord WriteRecord(MarcRecord record)
        {
            string database = record.Database;

            if (Utility.IsNullOrEmpty(database))
            {
                database = Database;
            }
            Query query = new Query(this, "D");

            query.AddAnsi(database);
            query.Add(0);
            query.Add(1);
            query.AddUtf(record.Encode());
            using (Response response = ExecuteQuery(query))
            {
                response.CheckReturnCode(-201, -600, -602, -603);
                record.Database = Database;
                string line1 = response.ReadUtf();
                string line2 = response.ReadUtf();
                if (string.IsNullOrEmpty(line1) ||
                    string.IsNullOrEmpty(line2))
                {
                    // If AUTOIN.GBL missin from the database,
                    // server returns no updated record
                    return(record);
                }

                MarcRecord.ParseOneOfMany(record,
                                          line1 + Utility.ShortDelimiter + line2);
                return(record);
            }
        }
Exemplo n.º 5
0
 internal static void ParseOneOfMany(MarcRecord record,
                                     string text)
 {
     record.Fields.Clear();
     string[] delimiters = new string[1];
     delimiters[0] = Utility.ShortDelimiter;
     string[] lines = Utility.SplitString(delimiters, text);
     ParseSingle(record, lines);
 }
Exemplo n.º 6
0
        public string FormatRecord(string format,
                                   MarcRecord record)
        {
            Query query = new Query(this, "G");

            query.AddAnsi(Database);
            query.AddAnsi(format);
            query.Add(-2);
            query.AddUtf(record.Encode());
            using (Response response = ExecuteQuery(query))
            {
                response.CheckReturnCode();
                return(response.ReadUtf().Trim());
            }
        }
Exemplo n.º 7
0
        public MarcRecord ReadRecord(int mfn)
        {
            Query query = new Query(this, "C");

            query.AddAnsi(Database);
            query.Add(mfn);
            using (Response response = ExecuteQuery(query))
            {
                response.CheckReturnCode(-201, -600, -602, -603);
                string[]   lines  = response.ReadRemainingUtfLines();
                MarcRecord result = new MarcRecord();
                MarcRecord.ParseSingle(result, lines);
                result.Database = Database;
                return(result);
            }
        }
Exemplo n.º 8
0
        internal static void ParseSingle(MarcRecord record,
                                         string[] text)
        {
            char[] delimiters = { '#' };
            string line       = text[0];

            string[] parts = Utility.SplitString(delimiters, line);
            record.Mfn = int.Parse(parts[0]);
            if (parts.Length != 1)
            {
                record.Status = int.Parse(parts[1]);
            }
            line           = text[1];
            parts          = line.Split(delimiters);
            record.Version = int.Parse(parts[1]);
            for (int i = 2; i < text.Length; i++)
            {
                RecordField field = RecordField.Parse(text[i]);
                record.Fields.Add(field);
            }
        }
Exemplo n.º 9
0
 public static Task <string> FormatRecordAsync(this IrbisClient client, string format, MarcRecord record)
 {
     return(Task.Factory.StartNew(() => client.FormatRecord(format, record))
            .ConfigureSafe());
 }
Exemplo n.º 10
0
 public static Task <MarcRecord> WriteRecordAsync(this IrbisClient client, MarcRecord record)
 {
     return(Task.Factory.StartNew(() => client.WriteRecord(record))
            .ConfigureSafe());
 }