Serialize CompositeFilterDescriptorCollection

12 posts, 0 answers
  1. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 10 Aug 2011 Link to this post

    Hi,

    I need to serialize the CompositeFilterDescriptorCollection class but the following code.does not work.  Can you explain how I can do this.

    Thanks
    Rich
     

     public static Byte[] Serialize(object obj)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
                    serializer.WriteObject(memoryStream, obj);
                    return memoryStream.ToArray();
                }
            }


  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 11 Aug 2011 Link to this post

    Hi Richard Harrigan,

    You will have to serialize it in XML. 

    Please, take a look at this forum topic. It discusses the same thing. The topic is for WPF, but I suppose that the same rules apply for Silverlight.

    I hope this helps.

    All the best,
    Ross
    the Telerik team

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

  3. DevCraft banner
  4. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 11 Aug 2011 Link to this post

    Hi,

    I don't think that works for me.  I'm not sure that will work in silverlight4.  Seems like alot of work with maybe no payback.  Is ther any other options.

    Thanks
    Rich
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 11 Aug 2011 Link to this post

    Hi Richard Harrigan,

    The XML serialization is the only possible way.

    Kind regards,
    Ross
    the Telerik team

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

  6. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 12 Aug 2011 Link to this post

    Hi

    I executed the following xml serialization code and got "Cannot serialize interface Telerik.Windows.Data.IFilterDescriptor."

    Is there something I can change in the code?

    Thanks
    Rich

    static public string SerializeObj(CompositeFilterDescriptorCollection obj)
            {
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(CompositeFilterDescriptorCollection));
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                serializer.Serialize(ms, obj);
                byte[] bytes = ms.ToArray();
                ms.Close();
                return System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            }

  7. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 15 Aug 2011 Link to this post

    Hi,

    Is there any other suggestions?  I think the need to serialiaze the CompositeFilterDescriptorCollection is a critical one.   If a  user enters a filter for a query and at a later time wants to make a minor adjustment to the filter they will not be happy that they have to re-create the filter from scratch. Please see my previous reply.

    Thanks
    Rich
  8. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 17 Aug 2011 Link to this post

    Hi,

    I have sent two replies to your post but have not yet received a response.  Please help, this is almost a drop-dead issue for me.

    Thanks
    Rich 
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 18 Aug 2011 Link to this post

    Hi Richard Harrigan,

    Basically, you cannot serialize interface - just as the error states. Did you check out the example in the mentioned code-library, did you use the approach illustrated there ? May you provide more information about your implementation ? 
     

    Greetings,
    Maya
    the Telerik team

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

  10. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 18 Aug 2011 Link to this post

    Hi,

    Yes, and i tried it out and replied back the following:

    I don't think that works for me. I'm not sure that will work in silverlight 4. Seems like a lot of work with maybe no payback. Is there any other options.

    I could not get the code to compile in Silverlight 4.   If possible please try to get this working in Silverlight 4.  I would not normally ask but this is very critical to me.  I think the DataFilter is the type of control that begs for serialization. 

    Thanks
    Rich

     
  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 22 Aug 2011 Link to this post

    Hello Richard Harrigan,

    Although the example mentioned is for WPF, you may follow the exact same idea for serialization. Generally, what you need to do is to serialize the properties for each of the filter descriptors - Member, MemberType, IsCaseSensitive, Operator, Value. As the composite filter descriptor consists of more than one filter descriptors, you have to traverse its tree and serialize the properties for each of the filter descriptors.
    Another possible approach would be to use the Telerik RadPersistentFramework (demos and documentation). I am sending you a sample project illustrating how you may save the state of the RadDataFilter.
     

    Greetings,
    Maya
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  12. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 22 Aug 2011 Link to this post

    Hi Maya,

    First the good news.  I used your example and modified the load save event to convert Stream to Byte[] and the load event to convert Byte[] to Stream.  In testing this i created a filter and saved it. I then changed the filter and then re-loaded it.  The filter on screen was correctly changed back to the original filter value.

    I ran into a problem trying to implement in my program.  First of all I did have Telerik.Windows.PersistenceFramework.dll.  I added your dll to my project but the he namespace Telerik.Windows.Persistence.Services was missing.

    I am using Runtime Version v2.0.50727 and Version 2011.1.419.1040.  Your version was 2011.2.712.1040.  What do I have to do to get this going?  Was the persistence framework not available in my Telerik version?

    Thanks
    Rich
  13. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 23 Aug 2011 Link to this post

    Hello Richard Harrigan,

    The Telerik RadPersistenceFramework  is available together with Q2 2011 release. 

    Best wishes,
    Maya
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
DevCraft banner