Esempio n. 1
0
        public DataSource()
        {
            Transport = new Transport();

            Filters = new List<IFilterDescriptor>();
            OrderBy = new List<SortDescriptor>();
            Groups = new List<GroupDescriptor>();
            Aggregates = new List<AggregateDescriptor>();

            Events = new Dictionary<string, object>();

            Schema = new DataSourceSchema();
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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 }
                };
            }
        }