public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IPageResponse message = value as IPageResponse; if (message != null) { writer.WritePropertyName("sEcho"); writer.WriteValue(message.Draw); writer.WritePropertyName("iTotalRecords"); writer.WriteValue(message.TotalRecords); writer.WritePropertyName("iTotalDisplayRecords"); writer.WriteValue(message.TotalFilteredRecords); writer.WritePropertyName("aaData"); serializer.Serialize(writer, message.Data); } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse)).Select(x => x.Name).Contains(prop.Name) || JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse <>)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }
public static IPageResponse <object> ToMutableResponse(IPageResponse <TSource> source) { IPageResponse <object> mutableResponse = new PageResponse <object>(source.Draw, source.TotalRecords, source.TotalFilteredRecords, source.Data != null ? source.Data.Cast <object>().ToArray() : null); return(mutableResponse); }
public static Type GetPageResponseArgument(this IPageResponse response) { Type genericType = typeof(object); if (response != null) { Type baseType = response.GetType(); for (var current = baseType; current != null; current = current.BaseType) { if (current.IsGenericType && current.GetGenericTypeDefinition() == typeof(PageResponse <>)) { if (response.Data != null && response.Data.Length > 0) { genericType = response.Data[0].GetType(); } else { genericType = current.GetGenericArguments()[0]; } break; } } } return(genericType); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IPageResponse message = value as IPageResponse; if (message != null) { writer.WritePropertyName("draw"); writer.WriteValue(message.Draw); writer.WritePropertyName("recordsTotal"); writer.WriteValue(message.TotalRecords); writer.WritePropertyName("recordsFiltered"); writer.WriteValue(message.TotalFilteredRecords); writer.WritePropertyName("data"); serializer.Serialize(writer, message.Data); if (!string.IsNullOrWhiteSpace(message.Error)) { writer.WritePropertyName("error"); writer.WriteValue(message.Error); } } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse)).Select(x => x.Name).Contains(prop.Name) || JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse <>)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }
public PageChangeSet(IChangeSet<T> virtualChangeSet, IPageResponse response) { if (virtualChangeSet == null) throw new ArgumentNullException(nameof(virtualChangeSet)); if (response == null) throw new ArgumentNullException(nameof(response)); _virtualChangeSet = virtualChangeSet; Response = response; }
public void Update(IPageResponse response) { CurrentPage = response.Page; PageSize = response.PageSize; PageCount = response.Pages; TotalCount = response.TotalSize; _nextPageCommand.Refresh(); _previousPageCommand.Refresh(); }
public MutableDataTableResult(IQueryable <object> query, IFilterRequest request, OutputType?outputType = null) : base(outputType) { IDataTableFilterProcessor filterProcessor = new DataTableFilterProcessor(); IDataTableProcessor processor = new DataTableProcessor(filterProcessor); IPageResponse <object> response = processor.Process(query, request); this.Data = response; }
// POST api/values public IHttpActionResult Post([FromBody] FilterRequest filter) { IDataTableFilterProcessor filterProcessor = new DataTableFilterProcessor(); IDataTableProcessor processor = new DataTableProcessor(filterProcessor); IPageResponse <UserProfile> response = processor.Process(UserProfiles.AsQueryable(), filter, (x) => x.Where(y => y.BirthDate > new DateTime(2014, 01, 01))); return(Ok(response)); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jsonObject = JObject.Load(reader); IEnumerable <JProperty> properties = jsonObject.Properties(); Dictionary <string, JProperty> otherProperties = new Dictionary <string, JProperty>(); IPageResponse message = Activator.CreateInstance(objectType) as IPageResponse; foreach (JProperty property in properties) { if (property.Name == "draw") { message.Draw = property.Value.ToObject <int>(); } else if (property.Name == "recordsTotal") { message.TotalRecords = property.Value.ToObject <int>(); } else if (property.Name == "recordsFiltered") { message.TotalFilteredRecords = property.Value.ToObject <int>(); } else if (property.Name == "data") { if (objectType.IsGenericType) { Type genericType = objectType.GetGenericArguments()[0].MakeArrayType(); object genericArray = property.Value.ToObject(genericType); message.Data = (object[])genericArray; } else { message.Data = property.Value.ToObject <object[]>(); } } else if (property.Name == "error") { message.Error = property.Value.ToObject <string>(); } else { otherProperties.Add(property.Name, property); } } JsonConvertHelper.ReadJson(message, otherProperties, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse)).Select(x => x.Name).Contains(prop.Name) || JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse <>)).Select(x => x.Name).Contains(prop.Name)); return(message); }
public static MutableDataTableResult CreateMutableFromResponse <TSource>(IPageResponse <TSource> response, OutputType?outputType = null, ArrayOutputType?arrayOutputType = null) { IPageResponse <object> mutableResponse = PageResponse <TSource> .ToMutableResponse(response); var result = new MutableDataTableResult(mutableResponse, outputType); result.Data = result.Data .Transform <TSource, Dictionary <string, object> >(DataTablesTypeInfo <TSource> .ToDictionary) .Transform <Dictionary <string, object>, Dictionary <string, object> >(StringTransformers.StringifyValues); result.Data = ApplyOutputRulesForMutable(result.Data, arrayOutputType); return(result); }
private static IPageResponse <object> ApplyOutputRulesForMutable(IPageResponse <object> sourceData, ArrayOutputType?arrayOutputType = null) { IPageResponse <object> outputData = sourceData; switch (arrayOutputType) { case ArrayOutputType.Index: outputData = sourceData.Transform <Dictionary <string, object>, object[]>(d => d.Values.ToArray()); break; case ArrayOutputType.Name: default: // Nothing is needed break; } return(outputData); }
public override Task <object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) { var task = Task <object> .Factory.StartNew(() => { if (type == typeof(IPageResponse) || type.IsSubclassOf(typeof(IPageResponse))) { IPageResponse message = Activator.CreateInstance(type) as IPageResponse; Type dataSourceType = message.GetPageResponseArgument(); if (dataSourceType != null && !_knownTypes.Contains(dataSourceType)) { _knownTypes.Add(dataSourceType); } } XmlReader reader = XmlReader.Create(readStream, _readerSettings); XmlSerializer ser = new XmlSerializer(type, _knownTypes.ToArray()); object val = ser.Deserialize(reader); return(val); }); return(task); }
private PagedChangeSet() { SortedItems = new KeyValueCollection <TObject, TKey>(); Response = new PageResponse(0, 0, 0, 0); }
public PagedChangeSet(IKeyValueCollection <TObject, TKey> sortedItems, IEnumerable <Change <TObject, TKey> > updates, IPageResponse response) : base(updates) { Response = response; SortedItems = sortedItems; }
public PlainDataTableResult(IPageResponse <TSource> data, OutputType?outputType = null) : base(outputType) { this.Data = data; }
public MutableDataTableResult(IPageResponse <object> data, OutputType?outputType = null) : base(outputType) { this.Data = data; }
public PageChangeSet(IChangeSet <T> virtualChangeSet, IPageResponse response) { _virtualChangeSet = virtualChangeSet ?? throw new ArgumentNullException(nameof(virtualChangeSet)); Response = response ?? throw new ArgumentNullException(nameof(response)); }
public static PlainDataTableResult <TSource> CreatePlainFromResponse <TSource>(IPageResponse <TSource> response, OutputType?outputType = null) { var result = new PlainDataTableResult <TSource>(response, outputType); return(result); }