Exemple #1
0
        object ICloneable.Clone()
        {
            var retval = new FieldFilter {
                Comparer = this.Comparer, Name = this.Name, DataType = this.DataType
            };

            ((IFieldFilter)retval).Value = ((IFieldFilter)this).Value;
            return(retval);
        }
        /// <summary />
        public BaseListingQuery(string url)
            : this()
        {
            if (string.IsNullOrEmpty(url))
            {
                return;
            }
            //The URL comes in sometimes encoded, hack
            if (url.Contains("%"))
            {
                url = System.Web.HttpUtility.UrlDecode(url);
            }
            var originalUrl = url;

            var pageBreak = url.IndexOf('?');

            if (pageBreak != -1 && pageBreak < url.Length - 1)
            {
                this.PageName = url.Substring(0, pageBreak);
                url           = url.Substring(pageBreak + 1, url.Length - pageBreak - 1);
            }
            else
            {
                this.PageName = url;
                return;
            }

            #region Parse Query String
            var tuplets = url.Split('&');
            foreach (var gset in tuplets)
            {
                var values = gset.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length == 2)
                {
                    switch (values[0])
                    {
                    case "_ied":
                        if (values[1] == "1" || values[1] == "true")
                        {
                            this.IncludeEmptyDimensions = true;
                        }
                        else if (values[1] == "0" || values[1] == "false")
                        {
                            this.IncludeEmptyDimensions = false;
                        }
                        break;

                    case "_edc":
                        if (values[1] == "1" || values[1] == "true")
                        {
                            this.ExcludeDimensionCount = true;
                        }
                        else if (values[1] == "0" || values[1] == "false")
                        {
                            this.ExcludeDimensionCount = false;
                        }
                        break;

                    case "_ec":
                        if (values[1] == "1" || values[1] == "true")
                        {
                            this.ExcludeCount = true;
                        }
                        else if (values[1] == "0" || values[1] == "false")
                        {
                            this.ExcludeCount = false;
                        }
                        break;

                    case "_id":
                        if (values[1] == "0" || values[1] == "false")
                        {
                            this.IncludeDimensions = false;
                        }
                        else if (values[1] == "1" || values[1] == "true")
                        {
                            this.IncludeDimensions = true;
                        }
                        break;

                    case "_iad":
                        if (values[1] == "0" || values[1] == "false")
                        {
                            this.IncludeAllDimensions = false;
                        }
                        else if (values[1] == "1" || values[1] == "true")
                        {
                            this.IncludeAllDimensions = true;
                        }
                        break;

                    case "_ir":
                        if (values[1] == "0" || values[1] == "false")
                        {
                            this.IncludeRecords = false;
                        }
                        else if (values[1] == "1" || values[1] == "true")
                        {
                            this.IncludeRecords = true;
                        }
                        break;

                    case "d":
                    {
                        var dValues = values[1].Split(new char[] { '+', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var dvidxV in dValues)
                        {
                            long dvidx;
                            if (long.TryParse(dvidxV, out dvidx))
                            {
                                this.DimensionValueList.Add(dvidx);
                            }
                        }
                    }
                    break;

                    case "po":
                    {
                        if (int.TryParse(values[1], out int po))
                        {
                            this.PageOffset = po;
                        }
                    }
                    break;

                    case "rpp":
                    {
                        if (int.TryParse(values[1], out int rpp))
                        {
                            this.RecordsPerPage = rpp;
                        }
                    }
                    break;

                    case "srch":
                        this.Keyword = HttpUtility.UrlDecode(values[1]);
                        break;

                    case "ff":
                    {
                        var filters = values[1].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var s in filters)
                        {
                            var svalues = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();

                            IFieldFilter ff = new FieldFilter();
                            if (ff.FromUrl(s))
                            {
                                if (svalues.Length == 5 &&
                                    ff.Comparer != ComparisonConstants.ContainsAll &&
                                    ff.Comparer != ComparisonConstants.ContainsAny &&
                                    ff.Comparer != ComparisonConstants.ContainsNone)
                                {
                                    IFieldFilter ff2 = new GeoCodeFieldFilter();
                                    if (ff2.FromUrl(s))
                                    {
                                        this.FieldFilters.Add(ff2);
                                    }
                                }
                                else
                                {
                                    this.FieldFilters.Add(ff);
                                }
                            }
                            else if (svalues.Length == 5)
                            {
                                IFieldFilter ff2 = new GeoCodeFieldFilter();
                                if (ff2.FromUrl(s))
                                {
                                    this.FieldFilters.Add(ff2);
                                }
                            }
                        }
                    }
                    break;

                    case "fs":
                    {
                        var sorts = values[1].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var s in sorts)
                        {
                            var svalues = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
                            if (svalues.Length > 0)
                            {
                                this.FieldSorts.Add(new FieldSort()
                                    {
                                        Name = svalues[0], SortDirection = (svalues.Length == 1 || svalues[1] != "0" ? Gravitybox.Datastore.Common.SortDirectionConstants.Asc : Gravitybox.Datastore.Common.SortDirectionConstants.Desc)
                                    });
                            }
                        }
                    }
                    break;

                    case "fsel":
                        this.FieldSelects = values[1].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        break;

                    case "gf":
                        this.GroupFields = values[1].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        break;

                    case "ul":
                    {
                        if (this.UserList == null)
                        {
                            this.UserList = new List <int>();
                        }
                        else
                        {
                            this.UserList.Clear();
                        }
                        var lsv = values[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var lv in lsv)
                        {
                            if (int.TryParse(lv, out int v))
                            {
                                this.UserList.Add(v);
                            }
                        }
                    }
                    break;

                    case "skipd":
                    {
                        if (this.SkipDimensions == null)
                        {
                            this.SkipDimensions = new List <long>();
                        }
                        else
                        {
                            this.SkipDimensions.Clear();
                        }
                        var lsv = values[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var lv in lsv)
                        {
                            if (long.TryParse(lv, out long v))
                            {
                                this.SkipDimensions.Add(v);
                            }
                        }
                    }
                    break;

                    default:
                        if (values.Length >= 2)
                        {
                            if (this.NonParsedFieldList.Count(x => x.Key == values[0]) > 0)
                            {
                                this.NonParsedFieldList.First(x => x.Key == values[0]).Value = values[1];
                            }
                            else
                            {
                                this.NonParsedFieldList.Add(new NamedItem()
                                {
                                    Key = values[0], Value = values[1]
                                });
                            }
                        }
                        break;
                    }
                }
            }
            #endregion
        }