Esempio n. 1
0
        public UriParamList ToUriParamList()
        {
            var result = new UriParamList();

            if (!String.IsNullOrEmpty(Query))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_QUERY, Query));
            }
            if (!String.IsNullOrEmpty(Text))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_TEXT, Text));
            }
            if (!String.IsNullOrEmpty(Content))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_CONTENT, Content));
            }
            if (Count != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_COUNT, Count.Value.ToString()));
            }
            if (Include.Any())
            {
                result.AddRange(Include.Select(i => Tuple.Create(SEARCH_PARAM_INCLUDE, i)));
            }
            if (RevInclude.Any())
            {
                result.AddRange(RevInclude.Select(i => Tuple.Create(SEARCH_PARAM_REVINCLUDE, i)));
            }
            if (Sort.Any())
            {
                result.AddRange(Sort.Select(s => Tuple.Create(createSortParamName(s.Item2), s.Item1)));
            }
            if (Summary != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_SUMMARY, Summary.Value.ToString().ToLower()));
            }
            if (!String.IsNullOrEmpty(Filter))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_FILTER, Filter));
            }
            if (Contained != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_CONTAINED, Contained.Value.ToString().ToLower()));
            }
            if (ContainedType != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_CONTAINEDTYPE, ContainedType.Value.ToString().ToLower()));
            }
            if (Elements.Any())
            {
                result.Add(Tuple.Create(SEARCH_PARAM_ELEMENTS, String.Join(",", Elements)));
            }

            result.AddRange(Parameters);
            return(result);
        }
Esempio n. 2
0
        public static UriParamList FromQueryString(string query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var result = new UriParamList();

            if (query == String.Empty)
            {
                return(result);
            }

            var q = query.TrimStart('?');

            var querySegments = q.Split(new string[] { "&" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var segment in querySegments)
            {
                var kv = SplitParam(segment);
                result.Add(kv);
            }

            return(result);
        }
Esempio n. 3
0
        public RestUrl SetParam(string name, string value)
        {
            var ix = _parameters.FindIndex(p => p.Item1 == name);
            var tp = Tuple.Create(name, value);

            if (ix == -1)
            {
                _parameters.Add(tp);
            }
            else
            {
                _parameters.RemoveAll(p => p.Item1 == name);
                _parameters.Insert(ix, tp);
            }

            return(this);
        }
        public RestUrl AddParam(Tuple <string, string> keyValue)
        {
            if (keyValue == null)
            {
                throw Error.ArgumentNull("keyValue");
            }

            _parameters.Add(keyValue);

            return(this);
        }
Esempio n. 5
0
        public UriParamList ToUriParamList()
        {
            var result = new UriParamList();

            if (!String.IsNullOrEmpty(Query))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_QUERY, Query));
            }
            if (!String.IsNullOrEmpty(Text))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_TEXT, Text));
            }
            if (!String.IsNullOrEmpty(Content))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_CONTENT, Content));
            }
            if (Count != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_COUNT, Count.Value.ToString()));
            }
            if (Include.Any())
            {
                result.AddRange(Include.Select(i => Tuple.Create(SEARCH_PARAM_INCLUDE, i)));
            }
            if (RevInclude.Any())
            {
                result.AddRange(RevInclude.Select(i => Tuple.Create(SEARCH_PARAM_REVINCLUDE, i)));
            }
            if (Sort.Any())
            {
                result.Add(createSortParam(Sort));
            }
            if (Summary != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_SUMMARY, Summary.Value.ToString().ToLower()));
            }
            if (!String.IsNullOrEmpty(Filter))
            {
                result.Add(Tuple.Create(SEARCH_PARAM_FILTER, Filter));
            }
            if (Contained != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_CONTAINED, Contained.Value.ToString().ToLower()));
            }
            if (ContainedType != null)
            {
                result.Add(Tuple.Create(SEARCH_PARAM_CONTAINEDTYPE, ContainedType.Value.ToString().ToLower()));
            }
            if (Elements.Any())
            {
                result.Add(Tuple.Create(SEARCH_PARAM_ELEMENTS, String.Join(",", Elements)));
            }

            result.AddRange(Parameters);
            return(result);

            Tuple <string, string> createSortParam(IList <Tuple <string, SortOrder> > sorts)
            {
                var values =
                    from s in sorts
                    let orderPrefix = s.Item2 == SortOrder.Descending ? "-" : ""
                                      select orderPrefix + s.Item1;

                return(new Tuple <string, string>(SEARCH_PARAM_SORT, String.Join(",", values)));
            }
        }