private void AddQueryString(string query) { if (string.IsNullOrEmpty(query)) { return; } query = query.TrimStart("?"); string[] querySplit = query.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries); foreach (string queryPart in querySplit) { string[] equalSplit = queryPart.Split(new[] { '=' }, 2); if (TryAddValue(UrlDecode(equalSplit[0]), () => UrlDecode(equalSplit[1]))) { continue; } if (_configuration.SpecialFilterKeysEnabled) { var filter = new QueryFilterInstruction(_configuration, queryPart); AddToList(ref _filterInstructions, filter); } } }
private bool TryAddValue(string key, Func <string> getValue) { if (_configuration.SelectFieldQueryKeys.Contains(key)) { if (_selectFields == null) { _selectFields = new List <string>(); } string[] fieldNames = getValue().Split(_configuration.SelectFieldDelimiters); _selectFields.AddRange(fieldNames); return(true); } if (_configuration.WhereFilterQueryKeys.Contains(key)) { // TODO what about separators like ?where=start>2016-01-01,end<2017-01-01 ? var filter = new QueryFilterInstruction(_configuration, getValue()); AddToList(ref _filterInstructions, filter); return(true); } if (_configuration.SortOrderQueryKeys.Contains(key)) { string[] sortStrings = getValue().Split(_configuration.SortInstructionDelimiters); foreach (string sortString in sortStrings) { var sort = new QuerySortInstruction(_configuration, sortString); AddToList(ref _sortInstructions, sort); } return(true); } if (_configuration.PageSizeQueryKeys.Contains(key)) { int size = PrepareNumberForPaging(getValue(), "size"); PageInstruction.Size = size; return(true); } if (_configuration.PageOffsetQueryKeys.Contains(key)) { int offset = PrepareNumberForPaging(getValue(), "offset"); PageInstruction.Offset = offset; return(true); } if (_configuration.PageNumberQueryKeys.Contains(key)) { int pageNumber = PrepareNumberForPaging(getValue(), "number", _configuration.SpecialPageNumbers); PageInstruction.PageNumber = pageNumber; return(true); } return(false); }
private void AddQueryCollection(NameValueCollection query) { foreach (string key in query.AllKeys) { if (TryAddValue(key, () => query[key])) { continue; } if (_configuration.SpecialFilterKeysEnabled) { string fullString = key + "=" + query[key]; // TODO well this is horrible... var filter = new QueryFilterInstruction(_configuration, fullString); AddToList(ref _filterInstructions, filter); } } }