示例#1
0
        /// <summary>
        /// Поиск записей согласно спецификации.
        /// </summary>
        public List <IrbisRecord> SearchRecords
        (
            SelectionQuery query
        )
        {
            if (ReferenceEquals(query, null))
            {
                throw new ArgumentNullException("query");
            }
            if (!query.IsValid())
            {
                throw new ArgumentOutOfRangeException("query");
            }

            NumberRangeCollection ranges = null;

            if ((query.SelectionType == SelectionType.Mfn) ||
                (query.SelectionType == SelectionType.Sequential))
            {
                ranges = NumberRangeCollection.Parse(query.Statement);
            }

            Dictionary <int, IrbisRecord> result
                = new Dictionary <int, IrbisRecord>();

            bool databaseChanged = false;

            if (!string.IsNullOrEmpty(query.Database))
            {
                Client.PushDatabase(query.Database);
                databaseChanged = true;
            }

            _maxMfn = Client.GetMaxMfn();

            switch (query.SelectionType)
            {
            case SelectionType.Mfn:
                _SearchByMfn
                (
                    result,
                    ranges
                );
                break;

            case SelectionType.Sequential:
                _SearchBySequential
                (
                    result,
                    query.Prefix,
                    ranges
                );
                break;

            case SelectionType.Dictionary:
                _SearchByDictionary
                (
                    result,
                    query.Prefix,
                    ranges
                );
                break;

            case SelectionType.Search:
                _SearchByQuery
                (
                    result,
                    query.Statement
                );
                break;

            case SelectionType.Deep:
                _SearchByDeep
                (
                    result,
                    query.Prefix,
                    query.Statement
                );
                break;
            }

            if (databaseChanged)
            {
                Client.PopDatabase();
            }

            Output.WriteLine
            (
                "Total found={0}",
                result.Count
            );

            return(result.Values.ToList());
        }