Beispiel #1
0
        public static MarcRecord ParseResponseForReadRecord
        (
            [NotNull] ServerResponse response,
            [NotNull] MarcRecord record
        )
        {
            Sure.NotNull(response, "response");
            Sure.NotNull(record, "record");

            try
            {
                record.Fields.BeginUpdate();

                ParseMfnStatusVersion
                (
                    response.RequireUtfString(),
                    response.RequireUtfString(),
                    record
                );

                string line;
                while (true)
                {
                    line = response.GetUtfString();
                    if (string.IsNullOrEmpty(line))
                    {
                        break;
                    }
                    if (line == "#")
                    {
                        break;
                    }
                    RecordField field = ParseLine(line);
                    if (field.Tag > 0)
                    {
                        record.Fields.Add(field);
                    }
                }
                if (line == "#")
                {
                    int returnCode = response.RequireInt32();
                    if (returnCode >= 0)
                    {
                        line = response.RequireUtfString();
                        line = IrbisText.IrbisToWindows(line);
                        record.Description = line;
                    }
                }
            }
            finally
            {
                record.Fields.EndUpdate();
                record.Modified = false;
            }

            return(record);
        }
Beispiel #2
0
        public static string[] GetFormatResult
        (
            [NotNull] ServerResponse response,
            int itemCount
        )
        {
            Sure.NotNull(response, nameof(response));

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

            if (itemCount == 1)
            {
                string line = response.RemainingUtfText();
                if (!string.IsNullOrEmpty(line))
                {
                    line = line.Trim();
                }
                result.Add(line);
            }
            else
            {
                while (true)
                {
                    string line = response.GetUtfString();
                    if (ReferenceEquals(line, null))
                    {
                        break;
                    }
                    int index = line.IndexOf('#');
                    if (index > 0)
                    {
                        string mfnPart = line.Substring(0, index);
                        int    mfn     = mfnPart.SafeToInt32();
                        if (mfn > 0)
                        {
                            line = line.Substring(index + 1);
                        }
                    }

                    line = IrbisText.IrbisToWindows(line);
                    if (!string.IsNullOrEmpty(line))
                    {
                        line = line.Trim();
                    }
                    result.Add(line);
                }
            }

            return(result.ToArray());
        }
        private void _TestIrbisToWindows
        (
            string source,
            string expected
        )
        {
            string actual = IrbisText.IrbisToWindows(source);

            Assert.AreEqual
            (
                expected,
                actual
            );
        }
        /// <inheritdoc cref="AbstractCommand.Execute"/>
        public override ServerResponse Execute
        (
            ClientQuery query
        )
        {
            Sure.NotNull(query, nameof(query));

            ServerResponse result = base.Execute(query);

            List <string> files = result.RemainingAnsiStrings();

            Files = files.SelectMany
                    (
                line => IrbisText.IrbisToWindows(line).SplitLines()
                    )
                    .ToArray();

            return(result);
        }
        public string[] GetFileText
        (
            [NotNull] ServerResponse response
        )
        {
            Sure.NotNull(response, nameof(response));

            int count = Files.Count;

            string[] result = new string[count];

            for (int i = 0; i < count; i++)
            {
                string text = response.GetAnsiString();
                text      = IrbisText.IrbisToWindows(text);
                result[i] = text;
            }

            return(result);
        }
Beispiel #6
0
        public static FoundItem ParseLine
        (
            [NotNull] string line
        )
        {
            Sure.NotNull(line, nameof(line));

            string[]  parts  = line.Split(_delimiters, 2);
            FoundItem result = new FoundItem
            {
                Mfn = int.Parse(parts[0])
            };

            if (parts.Length > 1)
            {
                string text = parts[1].EmptyToNull();
                text        = IrbisText.IrbisToWindows(text);
                result.Text = text;
            }

            return(result);
        }