This is a migrated thread and some comments may be shown as answers.

Serialize CompositeFilterDescriptorCollection

11 Answers 190 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 11 Aug 2011, 04:25 AM
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();
            }
        }


11 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 11 Aug 2011, 08:34 AM
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 >>

0
Richard Harrigan
Top achievements
Rank 1
answered on 11 Aug 2011, 07:44 PM
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
0
Rossen Hristov
Telerik team
answered on 11 Aug 2011, 08:53 PM
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 >>

0
Richard Harrigan
Top achievements
Rank 1
answered on 12 Aug 2011, 05:34 PM
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);
        }

0
Richard Harrigan
Top achievements
Rank 1
answered on 15 Aug 2011, 04:17 PM
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
0
Richard Harrigan
Top achievements
Rank 1
answered on 17 Aug 2011, 10:53 PM
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 
0
Maya
Telerik team
answered on 18 Aug 2011, 09:15 AM
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 >>

0
Richard Harrigan
Top achievements
Rank 1
answered on 18 Aug 2011, 05:08 PM
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

 
0
Maya
Telerik team
answered on 22 Aug 2011, 02:31 PM
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 >>

0
Richard Harrigan
Top achievements
Rank 1
answered on 22 Aug 2011, 09:39 PM
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
0
Maya
Telerik team
answered on 23 Aug 2011, 09:32 AM
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 >>

Tags
DataFilter
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Richard Harrigan
Top achievements
Rank 1
Maya
Telerik team
Share this question
or