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

            // Если в БД нет autoin.gbl, сервер не присылает
            // обработанную запись.

            string first = response.GetUtfString();

            if (string.IsNullOrEmpty(first))
            {
                return(record);
            }
            string second = response.GetUtfString();

            if (string.IsNullOrEmpty(second))
            {
                return(record);
            }

            try
            {
                record.Fields.BeginUpdate();
                record.Fields.Clear();

                string[] split = second.Split('\x1E');

                ParseMfnStatusVersion
                (
                    first,
                    split[0],
                    record
                );

                for (int i = 1; i < split.Length; i++)
                {
                    string      line  = split[i];
                    RecordField field = ParseLine(line);
                    if (field.Tag > 0)
                    {
                        record.Fields.Add(field);
                    }
                }
            }
            finally
            {
                record.Fields.EndUpdate();
                record.Modified = false;
            }

            return(record);
        }
示例#2
0
        public static TermInfo[] Parse
        (
            [NotNull] ServerResponse response
        )
        {
            Sure.NotNull(response, "response");

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

            Regex regex = new Regex(@"^(\d+)\#(.+)$");

            while (true)
            {
                string line = response.GetUtfString();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }
                Match match = regex.Match(line);
                if (match.Success)
                {
                    TermInfo item = new TermInfo
                    {
                        Count = int.Parse(match.Groups[1].Value),
                        Text  = match.Groups[2].Value
                    };
                    result.Add(item);
                }
            }

            return(result.ToArray());
        }
示例#3
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);
        }
示例#4
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());
        }
示例#5
0
        public static MarcRecord ParseResponseForAllFormat
        (
            [NotNull] ServerResponse response,
            [NotNull] MarcRecord record
        )
        {
            Sure.NotNull(response, "response");
            Sure.NotNull(record, "record");

            try
            {
                record.Fields.BeginUpdate();
                record.Fields.Clear();

                string line = response.GetUtfString();
                if (string.IsNullOrEmpty(line))
                {
                    return(null);
                }

                string[] split = line.Split('\x1F');
                ParseMfnStatusVersion
                (
                    split[1],
                    split[2],
                    record
                );

                for (int i = 3; i < split.Length; i++)
                {
                    line = split[i];
                    RecordField field = ParseLine(line);
                    if (field.Tag > 0)
                    {
                        record.Fields.Add(field);
                    }
                }
            }
            finally
            {
                record.Fields.EndUpdate();
                record.Modified = false;
            }

            return(record);
        }
示例#6
0
        public static List <FoundItem> ParseServerResponse
        (
            [NotNull] ServerResponse response,
            int sizeHint
        )
        {
            Sure.NotNull(response, "response");

            List <FoundItem> result = sizeHint > 0
                ? new List <FoundItem>(sizeHint)
                : new List <FoundItem>();

            string line;

            while ((line = response.GetUtfString()) != null)
            {
                FoundItem item = ParseLine(line);
                result.Add(item);
            }

            return(result);
        }
示例#7
0
        public static TermPosting[] Parse
        (
            [NotNull] ServerResponse response
        )
        {
            Sure.NotNull(response, nameof(response));

            // Example return:
            // 169#1510#1#2#Пожаровзрывобезопасность : Науч.- техн. журн. - Журнал

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

            while (true)
            {
                string line = response.GetUtfString();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                string[] parts = line.Split(CommonSeparators.NumberSign, 5);
                if (parts.Length < 4)
                {
                    break;
                }

                TermPosting item = new TermPosting
                {
                    Mfn        = int.Parse(parts[0]),
                    Tag        = int.Parse(parts[1]),
                    Occurrence = int.Parse(parts[2]),
                    Count      = int.Parse(parts[3]),
                    Text       = parts.GetItem(4)
                };
                result.Add(item);
            }

            return(result.ToArray());
        }
示例#8
0
        public static TermInfoEx[] ParseEx
        (
            [NotNull] ServerResponse response
        )
        {
            Sure.NotNull(response, nameof(response));

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

            Regex regex = new Regex(@"^(\d+)\#(\d+)#(\d+)#(\d+)#(\d+)$");

            while (true)
            {
                string line = response.GetUtfString();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                string[] parts = line.Split(_separators, 3);
                if (parts.Length != 3)
                {
                    Log.Error
                    (
                        "TermInfoEx::ParseEx: "
                        + "bad format: "
                        + line.ToVisibleString()
                    );

                    throw new IrbisNetworkException();
                }

                Match match = regex.Match(parts[0]);
                if (!match.Success)
                {
                    Log.Error
                    (
                        "TermInfoEx::ParseEx: "
                        + "bad format: "
                        + parts[0].ToVisibleString()
                    );

                    throw new IrbisNetworkException();
                }

                TermInfoEx item = new TermInfoEx
                {
                    Count      = int.Parse(match.Groups[1].Value),
                    Mfn        = int.Parse(match.Groups[2].Value),
                    Tag        = int.Parse(match.Groups[3].Value),
                    Occurrence = int.Parse(match.Groups[4].Value),
                    Index      = int.Parse(match.Groups[5].Value),
                    Text       = parts[1],
                    Formatted  = parts[2]
                };
                result.Add(item);
            }


            return(result.ToArray());
        }