예제 #1
0
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            if (IsServerPaging && (!OnNextPage.HasDelegate || !OnPreviousPage.HasDelegate))
            {
                throw new ArgumentException("When server paging is enabled OnNextPage and OnPreviousPage have to be bound.");
            }

            if (!IsServerPaging)
            {
                CurrentPage = 1;
            }

            ItemsToShow = Items;

            // TODO: Filtering and sorting needs to be server side
            if (_filterPredicate != null)
            {
                ItemsToShow = ItemsToShow.Where(_filterPredicate);
            }

            if (OrderBy != null && OrderBy.Any())
            {
                foreach (var orderConfig in OrderBy)
                {
                    ItemsToShow = orderConfig.IsDescending ? ItemsToShow.OrderByDescending(orderConfig.Property) : ItemsToShow.OrderBy(orderConfig.Property);
                }
            }

            if (!IsServerPaging)
            {
                TotalPages = (int)Math.Ceiling(Items.Count() / (decimal)PageSize);
            }
        }
예제 #2
0
 public bool CanInLine()
 {
     return(Fields.Count <= MaxInlineColumns
            &&
            From.Count == 1 &&
            !From.First().Joins.Any() &&
            (Where == null || Where.CanInline) &&
            (GroupBy == null || !GroupBy.Any()) &&
            (OrderBy == null || !OrderBy.Any()));
 }
예제 #3
0
        private IEnumerable <QueryOption> GetAllOptions()
        {
            if (Filter != null)
            {
                yield return(new QueryOption("$filter", Uri.EscapeDataString(Filter)));
            }

            if (HighlightPreTag != null)
            {
                yield return(new QueryOption("highlightPreTag", Uri.EscapeDataString(HighlightPreTag)));
            }

            if (HighlightPostTag != null)
            {
                yield return(new QueryOption("highlightPostTag", Uri.EscapeDataString(HighlightPostTag)));
            }

            if (MinimumCoverage != null)
            {
                yield return(new QueryOption("minimumCoverage", MinimumCoverage.ToString()));
            }

            if (OrderBy.Any())
            {
                yield return(new QueryOption("$orderby", OrderBy));
            }

            if (SearchFields.Any())
            {
                yield return(new QueryOption("searchFields", SearchFields));
            }

            if (Select.Any())
            {
                yield return(new QueryOption("$select", Select));
            }
            else
            {
                yield return(new QueryOption("$select", "*"));
            }

            if (Top != null)
            {
                yield return(new QueryOption("$top", Top.ToString()));
            }

            yield return(new QueryOption("fuzzy", UseFuzzyMatching.ToString().ToLowerInvariant()));
        }
예제 #4
0
        public Dictionary <string, string> GetPageHeader()
        {
            var dict = new Dictionary <string, string>();

            if (Filter.Any())
            {
                dict.Add("filter", Filter.GetQuery());
            }
            if (OrderBy.Any())
            {
                dict.Add("orderBy", OrderBy.GetQuery());
            }
            if (Select.Any())
            {
                dict.Add("select", Select.GetQuery());
            }
            if (Expand.Any())
            {
                dict.Add("expand", Expand.GetQuery());
            }

            return(dict);
        }
            protected override IEnumerable <string> GetParts()
            {
                if (Aggregates.Any())
                {
                    var aggregate = $"aggregate({String.Join(",", Aggregates)})";

                    if (Groups.Any())
                    {
                        aggregate = $"groupby(({String.Join(",", Groups)}),{aggregate})";
                    }

                    if (Filter.Any())
                    {
                        aggregate = $"filter({String.Join(" and ", Filter)})/{aggregate}";
                    }

                    yield return("$apply=" + aggregate);

                    yield break;
                }

                foreach (var part in base.GetParts())
                {
                    yield return(part);
                }

                if (OrderBy.Any())
                {
                    yield return("$orderby=" + String.Join(",", OrderBy));
                }

                if (Top != null)
                {
                    yield return("$top=" + Top);
                }
            }
        private IEnumerable <QueryOption> GetAllOptions()
        {
            yield return(new QueryOption("$count", IncludeTotalResultCount.ToString().ToLowerInvariant()));

            foreach (string facetExpr in Facets)
            {
                yield return(new QueryOption("facet", Uri.EscapeDataString(facetExpr)));
            }

            if (Filter != null)
            {
                yield return(new QueryOption("$filter", Uri.EscapeDataString(Filter)));
            }

            if (HighlightFields.Any())
            {
                yield return(new QueryOption("highlight", HighlightFields));
            }

            if (HighlightPreTag != null)
            {
                yield return(new QueryOption("highlightPreTag", Uri.EscapeDataString(HighlightPreTag)));
            }

            if (HighlightPostTag != null)
            {
                yield return(new QueryOption("highlightPostTag", Uri.EscapeDataString(HighlightPostTag)));
            }

            if (MinimumCoverage != null)
            {
                yield return(new QueryOption("minimumCoverage", MinimumCoverage.ToString()));
            }

            if (OrderBy.Any())
            {
                yield return(new QueryOption("$orderby", OrderBy));
            }

            foreach (string scoringParameterExpr in ScoringParameters)
            {
                yield return(new QueryOption("scoringParameter", scoringParameterExpr));
            }

            if (ScoringProfile != null)
            {
                yield return(new QueryOption("scoringProfile", ScoringProfile));
            }

            if (SearchFields.Any())
            {
                yield return(new QueryOption("searchFields", SearchFields));
            }

            yield return(new QueryOption("searchMode", SearchIndexClient.SearchModeToString(SearchMode)));

            if (Select.Any())
            {
                yield return(new QueryOption("$select", Select));
            }

            if (Skip != null)
            {
                yield return(new QueryOption("$skip", Skip.ToString()));
            }

            if (Top != null)
            {
                yield return(new QueryOption("$top", Top.ToString()));
            }
        }
예제 #7
0
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (Transport.Read.Url == null)
            {
                // If Url is not set assume the current url (used in server binding)
                Transport.Read.Url = "";
            }

            var transport = Transport.ToJson();

            if (transport.Keys.Any())
            {
                json["transport"] = transport;
            }

            if (PageSize > 0)
            {
                json["pageSize"] = PageSize;
                json["page"]     = Page;
                json["total"]    = Total;
            }

            if (ServerPaging)
            {
                json["serverPaging"] = ServerPaging;
            }

            if (ServerSorting)
            {
                json["serverSorting"] = ServerSorting;
            }

            if (ServerFiltering)
            {
                json["serverFiltering"] = ServerFiltering;
            }

            if (ServerGrouping)
            {
                json["serverGrouping"] = ServerGrouping;
            }

            if (ServerAggregates)
            {
                json["serverAggregates"] = ServerAggregates;
            }

            if (Type != null)
            {
                json["type"] = "aspnetmvc-" + Type.ToString().ToLower();
            }

            if (OrderBy.Any())
            {
                json["sort"] = OrderBy.ToJson();
            }

            if (Groups.Any())
            {
                json["group"] = Groups.ToJson();
            }

            if (Aggregates.Any())
            {
                json["aggregate"] = Aggregates.SelectMany(agg => agg.Aggregates.ToJson());
            }

            if (Filters.Any() || ServerFiltering)
            {
                json["filter"] = Filters.OfType <FilterDescriptorBase>().ToJson();
            }

            if (Events.Keys.Any())
            {
                json.Merge(Events);
            }

            json["schema"] = Schema.ToJson();

            if (Batch)
            {
                json["batch"] = Batch;
            }

            if (AutoSync)
            {
                json["autoSync"] = AutoSync;
            }

            if (IsClientOperationMode && RawData != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    { Schema.Data, SerializeDataSource(RawData) },
                    { Schema.Total, Total }
                };
            }
            else if (Type == DataSourceType.Ajax && !IsClientOperationMode && Data != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    { Schema.Data, SerializeDataSource(Data) },
                    { Schema.Total, Total }
                };
            }
        }
예제 #8
0
        private IEnumerable <QueryOption> GetAllOptions()
        {
            yield return(new QueryOption("$count", IncludeTotalResultCount.ToString().ToLowerInvariant()));

            foreach (string facetExpr in Facets ?? Empty)
            {
                yield return(new QueryOption("facet", Uri.EscapeDataString(facetExpr)));
            }

            if (Filter != null)
            {
                yield return(new QueryOption("$filter", Uri.EscapeDataString(Filter)));
            }

            if (HighlightFields != null && HighlightFields.Any())
            {
                yield return(new QueryOption("highlight", HighlightFields));
            }

            if (HighlightPreTag != null)
            {
                yield return(new QueryOption("highlightPreTag", Uri.EscapeDataString(HighlightPreTag)));
            }

            if (HighlightPostTag != null)
            {
                yield return(new QueryOption("highlightPostTag", Uri.EscapeDataString(HighlightPostTag)));
            }

            if (MinimumCoverage != null)
            {
                yield return(new QueryOption("minimumCoverage", MinimumCoverage.ToString()));
            }

            if (OrderBy != null && OrderBy.Any())
            {
                yield return(new QueryOption("$orderby", OrderBy));
            }

            yield return(new QueryOption("queryType", (QueryType == Models.QueryType.Simple) ? "simple" : "full"));

            foreach (string scoringParameterExpr in ScoringParameterStrings)
            {
                yield return(new QueryOption("scoringParameter", scoringParameterExpr));
            }

            if (ScoringProfile != null)
            {
                yield return(new QueryOption("scoringProfile", ScoringProfile));
            }

            if (SearchFields != null && SearchFields.Any())
            {
                yield return(new QueryOption("searchFields", SearchFields));
            }

            yield return(new QueryOption("searchMode", (SearchMode == Models.SearchMode.Any) ? "any" : "all"));

            if (Select != null && Select.Any())
            {
                yield return(new QueryOption("$select", Select));
            }

            if (Skip != null)
            {
                yield return(new QueryOption("$skip", Skip.ToString()));
            }

            if (Top != null)
            {
                yield return(new QueryOption("$top", Top.ToString()));
            }
        }
예제 #9
0
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (Transport.Read.Url == null)
            {
                // If Url is not set assume the current url (used in server binding)
                Transport.Read.Url = "";
            }

            var transport = Transport.ToJson();

            if (transport.Keys.Any())
            {
                json["transport"] = transport;
            }

            if (PageSize > 0)
            {
                json["pageSize"] = PageSize;
                json["page"]     = Page;
                json["total"]    = Total;
            }

            if (ServerPaging)
            {
                json["serverPaging"] = ServerPaging;
            }

            if (ServerSorting)
            {
                json["serverSorting"] = ServerSorting;
            }

            if (ServerFiltering)
            {
                json["serverFiltering"] = ServerFiltering;
            }

            if (ServerGrouping)
            {
                json["serverGrouping"] = ServerGrouping;
            }

            if (ServerAggregates)
            {
                json["serverAggregates"] = ServerAggregates;
            }
            if (Events.Keys.Any())
            {
                SerializeDataSourceEvents(Events, json);
            }
            if (Type != null)
            {
                json["type"] = "aspnetmvc-" + Type.ToString().ToLower();
            }

            if (OrderBy.Any())
            {
                json["sort"] = OrderBy.ToJson();
            }

            if (Groups.Any())
            {
                json["group"] = Groups.ToJson();
            }

            if (Aggregates.Any())
            {
                var aggObjectList = new List <IDictionary <string, object> >();
                foreach (var item in Aggregates)
                {
                    var jsonDic = item.ToJson();
                    aggObjectList.Add(jsonDic);
                }
                json["aggregate"] = aggObjectList;// Aggregates.SelectMany(agg => agg.Aggregates.ToJson());
            }

            if (Filters.Any() || ServerFiltering)
            {
                json["filter"] = Filters.OfType <FilterDescriptorBase>().ToJson();
            }

            if (Filter != null && ServerFiltering)
            {
                //var f = Filter.Trim(new char[] { '\\', '"' });
                var filter = (Filter as FilterItem);
                if (filter != null)
                {
                    json["filter"] = filter.ToJson();
                }
                else
                {
                    var compFilter = (Filter as CompositeFilterItem);
                    json["filter"] = compFilter.ToJson();
                }
            }


            if (Schema.Model != null)
            {
                json["schema"] = Schema.ToJson();
            }


            json["batch"] = Batch;


            if (IsClientOperationMode && RawData != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    { Schema.Data, SerializeDataSource(RawData) },
                    { Schema.Total, Total }
                };
            }
            else if (Type == DataSourceType.Ajax && !IsClientOperationMode && Data != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    //{ Schema.Data,  SerializeDataSource(Data) },
                    { Schema.Total, Total }
                };
                //json["type"] = "aspnetmvc-ajax";
            }
        }
예제 #10
0
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (Transport.Read.Url == null & Type != DataSourceType.Custom)
            {
                // If Url is not set assume the current url (used in server binding)
                Transport.Read.Url = "";
            }

            if (Type != null)
            {
                if (Type == DataSourceType.Ajax || Type == DataSourceType.Server)
                {
                    json["type"] = "aspnetmvc-" + Type.ToString().ToLower();
                }
                else if (Type == DataSourceType.Custom)
                {
                    if (!string.IsNullOrEmpty(CustomType))
                    {
                        json["type"] = CustomType;
                    }
                }
                else
                {
                    json["type"] = Type.ToString().ToLower();

                    if (Type == DataSourceType.WebApi && Schema.Model.Id != null)
                    {
                        Transport.IdField = Schema.Model.Id.Name;
                    }
                }
            }

            if (CustomTransport != null)
            {
                json["transport"] = CustomTransport;
            }
            else
            {
                var transport = Transport.ToJson();

                if (transport.Keys.Any())
                {
                    json["transport"] = transport;
                }
            }

            if (PageSize > 0)
            {
                json["pageSize"] = PageSize;
                json["page"]     = Page;
                json["total"]    = Total;
            }

            if (ServerPaging)
            {
                json["serverPaging"] = ServerPaging;
            }

            if (ServerSorting)
            {
                json["serverSorting"] = ServerSorting;
            }

            if (ServerFiltering)
            {
                json["serverFiltering"] = ServerFiltering;
            }

            if (ServerGrouping)
            {
                json["serverGrouping"] = ServerGrouping;
            }

            if (ServerAggregates)
            {
                json["serverAggregates"] = ServerAggregates;
            }

            if (OrderBy.Any())
            {
                json["sort"] = OrderBy.ToJson();
            }

            if (Groups.Any())
            {
                json["group"] = Groups.ToJson();
            }

            if (Aggregates.Any())
            {
                json["aggregate"] = Aggregates.SelectMany(agg => agg.Aggregates.ToJson());
            }

            if (Filters.Any() || ServerFiltering)
            {
                json["filter"] = Filters.OfType <FilterDescriptorBase>().ToJson();
            }

            if (Events.Keys.Any())
            {
                json.Merge(Events);
            }

            var schema = Schema.ToJson();

            if (schema.Keys.Any())
            {
                json["schema"] = schema;
            }

            if (Batch)
            {
                json["batch"] = Batch;
            }

            if (AutoSync)
            {
                json["autoSync"] = AutoSync;
            }

            if (IsClientOperationMode && Type == DataSourceType.Custom && CustomType != "aspnetmvc-ajax")
            {
                RawData = Data;
            }

            if (IsClientOperationMode && RawData != null)
            {
                SerializeData(json, RawData);
            }
            else if (IsClientBinding && !IsClientOperationMode && Data != null)
            {
                SerializeData(json, Data);
            }
        }