Several questions

6 posts, 1 answers
  1. Lilia
    Lilia avatar
    32 posts
    Member since:
    Mar 2011

    Posted 06 Jul 2011 Link to this post

    Hello Telerik team,

    Great work with the Persistence Framework! I have several questions though :)

    1. Can I save and load multiple controls in the same stream? For example I want to save 2 TreeViews in the stream
    this.stream = this.manager.Save(this.treeView1);
    this.stream = this.manager.Save(this.treeView2);

    2. I'm looking through your example with the 'Save' / 'Load' buttons and the GridView (http://demos.telerik.com/silverlight/beta/#PersistenceFramework/GridViewCustomSerialization). It's working fine with the Save/Load buttons when they are on the same page, but I want to do s.th. else. To save the state when the user leaves the page and to load it when he comes back
    //save the state when leaving the page       
    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
         PersistenceManager manager = new PersistenceManager();
         stream = manager.Save(this.radGridView1);
         base.OnNavigatedFrom(e);
    }
    //load when comes back again
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
         if (stream != null)
         {
               stream.Position = 0L;
               PersistenceManager manager = new PersistenceManager();
               manager.Load(this.radGridView1, stream);
         }
    }

    For some reason that code throws an error: 
    "   at Telerik.Windows.Controls.GridView.ColumnSortDescriptor.ToSortDescription()\r\n   at Telerik.Windows.Data.SortDescriptorExtensions.AsSortDescription(ISortDescriptor sortDescriptor)\r\n   at Telerik.Windows.Data.DataItemCollection.ConvertSortDescriptorToSortDescription(Object descriptor)\r\n   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\r\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   at Telerik.Windows.Data.ConvertingObservableCollectionManager.GetSourceItems(Object source, IEnumerable items)\r\n   at Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)\r\n   at Telerik.Windows.Data.ObservableCollectionManager.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)\r\n   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)\r\n   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n   at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n   at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)\r\n   at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)\r\n   at System.Collections.ObjectModel.Collection`1.Add(T item)\r\n   at Silver.Presentation.Silverlight.GridViewCustomPropertyProvider.RestoreValue(CustomPropertyInfo customPropertyInfo, Object context, Object value)\r\n   at Telerik.Windows.Persistence.Serialization.Deserializer.LoadProperties(ReferenceValue refValue, String path, Object obj)\r\n   at Telerik.Windows.Persistence.Serialization.Deserializer.Deserialize(ReferenceValue refValue, Object obj)\r\n   at Telerik.Windows.Persistence.Serialization.Deserializer.Deserialize(Stream stream, Object objectToDeserialize)\r\n   at Telerik.Windows.Persistence.PersistenceManager.Load(Object obj, Stream stream)\r\n   at Silver.Presentation.Silverlight.TestPage.OnNavigatedTo(NavigationEventArgs e)"

    3. Can I use Persistence Framework to save the state of a DataFilter, i.e. I want to save the conditions of the DataFilter in a DB, to load these conditions in a stream and then load the DataFilter from that stream?


  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 06 Jul 2011 Link to this post

    Hi Lilia,

    Currently, the PersistenceFramework does not support serializing multiple objects (not in the same visual tree) in one stream. Please note that, if they share a common ancestor element, you could serialize it. However, this is on our to-do list and I have logged a public issue here, which you can track.

    Regarding the exception, what type of exception is this? If it is a NullReference exception, then probably the columns of the GridView have not yet been loaded. Is it possible to test this by invoking it with a dispatcher and see if the exception is still thrown?

    Regarding the third question, this will be supported with the official release version. Moreover, the QSF example will be updated and it will illustrate custom filter serialization as well. As the DataFilter uses the same filters, you should be able to serialize the filter descriptors.

    All the best,
    Alex Fidanov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
  4. Lilia
    Lilia avatar
    32 posts
    Member since:
    Mar 2011

    Posted 22 Jul 2011 Link to this post

    Can you give me an example how to persist DataFilter?
  5. Answer
    Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 25 Jul 2011 Link to this post

    Hi Lilia,

    I have attached a project demonstrating how to save DataFilter control's filters. Similar to persisting the filters of the RadGridView, you would need a custom property provider to serialize the filters, as the PersistenceFramework serializes only UI properties.

    I spotted a small issue when persisting an Enum value inside the filter, which I have already resolved.

    Please let me know if you have questions on this.

    All the best,
    Alex Fidanov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. Sean
    Sean avatar
    7 posts
    Member since:
    Mar 2009

    Posted 15 Sep 2011 Link to this post

    Sorry to reply to an older thread, but I have a question about this topic. I am trying to persist a RadDataFilter to the database, and then rebuild it on a load. The project below helps a lot, however it seems to be missing one thing. If I build a complex composite query (similar to the one in the End User Manual for the RadDataFilter), where the very top operator is an OR, that top operator does not get set when loading the saved query. All of the other pieces (ie. the 2 groups) come back properly, but the operator between these groups is not saved or loaded.

    When going through the collection of DataFilters, how can I tell what operator is between them? I have attached a screenshot showing my filter, and have circled the operator that is not saved.

    Thanks,
    Sean
  7. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 16 Sep 2011 Link to this post

    Hi Sean,

    Thank you for reporting this. It seems that the root filter's logical operator is store in the filter control itself. To handle this, you need to modify the custom property provider and save this value as well. Here are the changes that you need to make:

    1. Add a new property in the GetCustomProperties() method :
    new CustomPropertyInfo("LogicalOperator", typeof(FilterCompositionLogicalOperator)),
    2. Modify the ProviderValue method and return the value of the root filter's operator:
    if (customPropertyInfo.Name == "LogicalOperator")
    {
        return filter.ViewModel.CompositeFilter.LogicalOperator;
    }
    3. Modify the RestoreValue method and set the operator:
    if (customPropertyInfo.Name == "LogicalOperator")
    {
    filter.ViewModel.CompositeFilter.LogicalOperator = (FilterCompositionLogicalOperator)value;
    }
    Please let me know if you have questions on this.

    Kind regards,
    Alex Fidanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner