/// <summary>
        /// Throw <see cref="IrbisNetworkException"/>
        /// if the record is empty.
        /// </summary>
        private static void _ThrowIfEmptyRecord
        (
            [NotNull] MarcRecord record,
            [NotNull] string line
        )
        {
            Sure.NotNull(record, "record");
            Sure.NotNull(line, "line");

            if (ThrowOnEmptyRecord &&
                record.Fields.Count == 0
                )
            {
                Log.Error
                (
                    "BatchAccessor::ThrowIfEmptyRecord: "
                    + "empty record detected"
                );

                byte[] bytes   = Encoding.UTF8.GetBytes(line);
                string dump    = IrbisNetworkUtility.DumpBytes(bytes);
                string message = string.Format
                                 (
                    "Empty record in BatchAccessor:{0}{1}",
                    Environment.NewLine,
                    dump
                                 );

                IrbisNetworkException exception  = new IrbisNetworkException(message);
                BinaryAttachment      attachment = new BinaryAttachment
                                                   (
                    "response",
                    bytes
                                                   );
                exception.Attach(attachment);
                throw exception;
            }
        }
Beispiel #2
0
        /// <inheritdoc cref="AbstractCommand.Execute" />
        public override ServerResponse Execute
        (
            ClientQuery query
        )
        {
            ServerResponse result = base.Execute(query);

            // Check whether no records read
            if (result.GetReturnCode() != -201)
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = Connection.Host,
                    Database = Database
                };

                record = ProtocolText.ParseResponseForReadRecord
                         (
                    result,
                    record
                         );
                record.Verify(ThrowOnVerify);

                if (ThrowOnEmptyRecord)
                {
                    IrbisNetworkUtility.ThrowIfEmptyRecord
                    (
                        record,
                        result
                    );
                }

                Record = record;
            }

            return(result);
        }