So I have a working save/load for my RadPivotGrid with LocalDataProvider, but had performance concerns so added set of wrappers and functionality for QueryableDataProvider.
My wrappers and set with properties (get; set;) of types int, double, string, bool?, string, MyEnum, DateTime[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
Im not applying any custom aggregates or similar, and in this example I had 1 column, 1 row property and 'count' of ItemID value.
The code works fine with LocalDataProvider (though not using wrappers there, instead more complex EF entities), but wit h my lighter QueryableDataProvider datasource it now my export throws an exception when it hits the serialize command `provider.Serialize(this.xPivotGrid_Reports.DataProvider)`
---
An exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.dll but was not handled in user code
Additional information: Type 'Telerik.Pivot.Queryable.QueryablePropertyAggregateDescription' with data contract name 'QueryablePropertyAggregateDescription:http://schemas.datacontract.org/2004/07/Telerik.Pivot.Queryable' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.
---
I cant remember original source, but I found the DataContract code online and changed very little.
And I am aware that the DataProviderSerializer subclass (where KnownTypes is defined) is called LocalDataSourceSerializer, but thats part of question:
Is there another list like `PivotSerializationHelper.KnownTypes` I should be using, because it seems comprehensive enough and im hardly doing anything strange?
---
[DataContract]
public class DataProviderSettings
{
[DataMember]
public object[] Aggregates { get; set; }
[DataMember]
public object[] Filters { get; set; }
[DataMember]
public object[] Rows { get; set; }
[DataMember]
public object[] Columns { get; set; }
[DataMember]
public int AggregatesLevel { get; set; }
[DataMember]
public PivotAxis AggregatesPosition { get; set; }
}
public class LocalDataSourceSerializer : DataProviderSerializer
{
public override IEnumerable<Type> KnownTypes
{
get
{
return PivotSerializationHelper.KnownTypes;
}
}
}
public abstract class DataProviderSerializer
{
public abstract IEnumerable<Type> KnownTypes { get; }
public string Serialize(object context)
{
string serialized = string.Empty;
IDataProvider dataProvider = context as IDataProvider;
if (dataProvider != null)
{
MemoryStream stream = new MemoryStream();
DataProviderSettings settings = new DataProviderSettings()
{
Aggregates = dataProvider.Settings.AggregateDescriptions.OfType<object>().ToArray(),
Filters = dataProvider.Settings.FilterDescriptions.OfType<object>().ToArray(),
Rows = dataProvider.Settings.RowGroupDescriptions.OfType<object>().ToArray(),
Columns = dataProvider.Settings.ColumnGroupDescriptions.OfType<object>().ToArray(),
AggregatesLevel = dataProvider.Settings.AggregatesLevel,
AggregatesPosition = dataProvider.Settings.AggregatesPosition
};
DataContractSerializer serializer = new DataContractSerializer(typeof(DataProviderSettings), KnownTypes);
serializer.WriteObject(stream, settings);
stream.Position = 0;
var streamReader = new StreamReader(stream);
serialized += streamReader.ReadToEnd();
}
return serialized;
}
public void Deserialize(object context, string savedValue)
{
IDataProvider dataProvider = context as IDataProvider;
if (dataProvider != null)
{
var stream = new MemoryStream();
var tw = new StreamWriter(stream);
tw.Write(savedValue);
tw.Flush();
stream.Position = 0;
DataContractSerializer serializer = new DataContractSerializer(typeof(DataProviderSettings), KnownTypes);
var result = serializer.ReadObject(stream);
dataProvider.Settings.AggregateDescriptions.Clear();
foreach (var aggregateDescription in (result as DataProviderSettings).Aggregates)
{
dataProvider.Settings.AggregateDescriptions.Add(aggregateDescription);
}
dataProvider.Settings.FilterDescriptions.Clear();
foreach (var filterDescription in (result as DataProviderSettings).Filters)
{
dataProvider.Settings.FilterDescriptions.Add(filterDescription);
}
dataProvider.Settings.RowGroupDescriptions.Clear();
foreach (var rowDescription in (result as DataProviderSettings).Rows)
{
dataProvider.Settings.RowGroupDescriptions.Add(rowDescription);
}
dataProvider.Settings.ColumnGroupDescriptions.Clear();
foreach (var columnDescription in (result as DataProviderSettings).Columns)
{
dataProvider.Settings.ColumnGroupDescriptions.Add(columnDescription);
}
dataProvider.Settings.AggregatesPosition = (result as DataProviderSettings).AggregatesPosition;
dataProvider.Settings.AggregatesLevel = (result as DataProviderSettings).AggregatesLevel;
}
}
}
---