New Rad Control version not allowing my code to compile, because number of member missing in interfaces which replaced older class

6 posts, 0 answers
  1. Pranay
    Pranay avatar
    11 posts
    Member since:
    Jul 2012

    Posted 27 Jul 2012 Link to this post

    I satrted using new RAD libarary but there is number of changes in that which is not allow my code to compile.

    I am using RadFilterSerializer  named file for waving my filter of gridview but with new version there is no support for old class not allowing to compile code .

    Not supported code in new version
    (item as DistinctValuesFilterDescriptor).Member
    (item as FieldFilterDescriptor).FieldName
    even if I convert to IDistinctValuesFilterDescriptor and IFieldFilterDescriptor the member associated with this are not available in new version.

    just compile the code with new version you will get the errors.

    Now what is the way to come out of this.

    using System;
    using System.IO;
    using System.Text;
    using System.Runtime.Serialization;
    using System.Collections.Generic;
    using System.Linq;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.GridView;
    using Telerik.Windows.Data;

    namespace IPVWorkbench.Helpers
    {
        /*
         
         --------------for saving
         RadFilterSerializer serializer = new RadFilterSerializer();
     
         string xml = serializer.Serialize(currentSelectionGridView.FilterDescriptors);
         
         --------------for restoring
         RadFilterSerializer serializer = new RadFilterSerializer();
        if (xml!= String.Empty)
                serializer.Rehydrate(xml, (CompositeFilterDescriptorCollection)currentSelectionGridView.FilterDescriptors, currentSelectionGridView.Columns);

        
         */
        public class Filter
        {
            public Filter()
            {
                IsCaseSensitive = false;
                Member = "";
                Value = null;
                Operator = FilterOperator.IsEqualTo;
                ClassType = "";
            }
            public bool IsCaseSensitive { get; set; }
            public string Member { get; set; }
            public object Value { get; set; }
            public FilterOperator Operator { get; set; }
            public string ClassType { get; set; }
        }

        public class FilterSet
        {

            public FilterSet()
            {
                Filters = null;
                Operator = FilterCompositionLogicalOperator.And;
                ClassType = "";
                Member = "";
                DataType = "";
            }
            public List<object> Filters;
            public FilterCompositionLogicalOperator Operator { get; set; }
            public string ClassType { get; set; }
            // JIM Add member for column cimposite filters
            public string Member { get; set; }
            public string DataType { get; set; }
        }

        public class RadFilterSerializer
        {

            private FilterSet _filterSet;

            protected FilterSet FilterSet
            {
                get { return _filterSet; }
                set { _filterSet = value; }
            }

            public List<object> GetFiltersFromFilterDescriptors(IEnumerable<IFilterDescriptor> list)
            {
                var results = new List<object>();
                foreach (var item in list)
                {
                    var cdf = item as CompositeFilterDescriptor;
                    if (cdf != null)
                    {
                        var fs = new FilterSet
                        {
                            Operator = cdf.LogicalOperator,
                            Filters = GetFiltersFromFilterDescriptors(cdf.FilterDescriptors.ToList()),
                            // JIM add Class Type to unserialized other specific base class of filter for gridview
                            ClassType = cdf.GetType().ToString()
                        };
                        try { fs.Member = (item as ColumnFilterDescriptor).Column.UniqueName; }
                        catch { }
                        try { fs.Member = (item as DistinctValuesFilterDescriptor).Member; }
                        catch { }
                        try { fs.Member = (item as FieldFilterDescriptor).FieldName; fs.DataType = (item as FieldFilterDescriptor).DataType.ToString(); }
                        catch { }
                        results.Add(fs);
                    }
                    else
                    {
                        var df = item as FilterDescriptor;
                        if (df != null && !df.Value.GetType().ToString().Equals("Telerik.Windows.Data.FilterDescriptor+FilterDescriptorUnsetValue"))
                        {
                            var f = new Filter
                            {
                                IsCaseSensitive = df.IsCaseSensitive,
                                Member = df.Member,
                                Operator = df.Operator,
                                Value = df.Value,
                                // JIM add Class Type to unserialized other specific base class of filter for gridview
                                ClassType = df.GetType().ToString()
                            };
                            results.Add(f);
                        }
                    }
                }
                return results;
            }
            public IEnumerable<IFilterDescriptor> GetFilterDescriptorsFromFilters(IEnumerable<object> list)
            {
                var results = new List<IFilterDescriptor>();
                foreach (var item in list)
                {
                    var fs = item as FilterSet;
                    if (fs != null)
                    {
                        var cdf = new CompositeFilterDescriptor { LogicalOperator = fs.Operator, FilterDescriptors = new FilterDescriptorCollection() };
                        cdf.FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters));
                        results.Add(cdf);
                    }
                    else
                    {
                        var f = item as Filter;
                        if (f != null)
                        {
                            var df = new FilterDescriptor
                            {
                                IsCaseSensitive = f.IsCaseSensitive,
                                Member = f.Member,
                                Operator = f.Operator,
                                Value = f.Value
                            };
                            results.Add(df);
                        }
                    }
                }
                return results;
            }
            public IEnumerable<IFilterDescriptor> GetFilterDescriptorsFromFilters(IEnumerable<object> list, GridViewColumnCollection columns)
            {
                try
                {
                    var results = new List<IFilterDescriptor>();
                    foreach (var item in list)
                    {
                        var fs = item as FilterSet;
                        if (fs != null)
                        {
                            object cdf = null;
                            if (fs.ClassType == typeof(CompositeFilterDescriptor).ToString())
                            {
                                cdf = new CompositeFilterDescriptor { LogicalOperator = fs.Operator, FilterDescriptors = new FilterDescriptorCollection() };
                                ((CompositeFilterDescriptor)cdf).FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters, columns));
                            }
                            if (fs.ClassType == typeof(ColumnFilterDescriptor).ToString())
                            {
                                cdf = new ColumnFilterDescriptor((IDataFieldDescriptor)columns[fs.Member]);
                                // Special case here, don't pass the filter directly
                                // cf http://www.telerik.com/help/silverlight/radgridview-filtering-column-filter-descriptors.html

                                IEnumerable<IFilterDescriptor> columnFilters = GetFilterDescriptorsFromFilters(fs.Filters, columns);

                                foreach (IFilterDescriptor filter in columnFilters)
                                {
                                    try
                                    {
                                        // usually the first is the DistinctValuesFilterDescriptor
                                        if (filter.GetType() == typeof(DistinctValuesFilterDescriptor))
                                        {
                                            foreach (object distinctVal in (filter as DistinctValuesFilterDescriptor).DistinctValues)
                                            {
                                                (cdf as ColumnFilterDescriptor).DistinctFilter.DistinctValues.Add(distinctVal);
                                            }
                                        }

                                        if (filter.GetType() == typeof(FieldFilterDescriptor))
                                        {
                                            FieldFilterDescriptor fieldfilter = filter as FieldFilterDescriptor;

                                            if (fieldfilter.FilterDescriptors.Count > 0)
                                            {
                                                (cdf as ColumnFilterDescriptor).FieldFilter.Filter1.Operator = ((FilterDescriptor)fieldfilter.FilterDescriptors[0]).Operator;
                                                (cdf as ColumnFilterDescriptor).FieldFilter.Filter1.Value = ((FilterDescriptor)fieldfilter.FilterDescriptors[0]).Value;
                                                (cdf as ColumnFilterDescriptor).FieldFilter.LogicalOperator = fieldfilter.LogicalOperator;
                                                if (fieldfilter.FilterDescriptors.Count > 1)
                                                {
                                                    (cdf as ColumnFilterDescriptor).FieldFilter.Filter2.Operator = ((FilterDescriptor)fieldfilter.FilterDescriptors[1]).Operator;
                                                    (cdf as ColumnFilterDescriptor).FieldFilter.Filter2.Value = ((FilterDescriptor)fieldfilter.FilterDescriptors[1]).Value;
                                                }
                                            }
                                        }
                                    }
                                    catch { }

                                }

                                //  (cdf as ColumnFilterDescriptor).FilterDescriptors.AddRange(columnFilters);
                            }
                            if (fs.ClassType == typeof(DistinctValuesFilterDescriptor).ToString())
                            {
                                cdf = new DistinctValuesFilterDescriptor(fs.Member) { LogicalOperator = fs.Operator, FilterDescriptors = new FilterDescriptorCollection() };
                                ((DistinctValuesFilterDescriptor)cdf).FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters, columns));
                            }
                            if (fs.ClassType == typeof(FieldFilterDescriptor).ToString())
                            {
                                // todo get real system.Type based on the serialized name :S
                                Type dataType = typeof(string);
                                cdf = new FieldFilterDescriptor(fs.Member, dataType) { LogicalOperator = fs.Operator, FilterDescriptors = new FilterDescriptorCollection() };
                                if (fs.Filters != null && fs.Filters.Count > 0)
                                    ((FieldFilterDescriptor)cdf).FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters, columns));
                            }
                            results.Add((IFilterDescriptor)cdf);
                        }
                        else
                        {
                            var f = item as Filter;
                            if (f != null)
                            {
                                object df = null;

                                if (f.ClassType == typeof(FilterDescriptor).ToString())
                                {
                                    df = new FilterDescriptor
                                    {
                                        IsCaseSensitive = f.IsCaseSensitive,
                                        Member = f.Member,
                                        Operator = f.Operator,
                                        Value = f.Value
                                    };
                                }

                                if (df != null)
                                    results.Add((IFilterDescriptor)df);
                            }
                        }
                    }
                    return results;
                }
                catch { return null; }
            }

            public FilterSet CreateFilterSet(CompositeFilterDescriptorCollection FilterDescriptors)
            {
                return new FilterSet { Operator = FilterDescriptors.LogicalOperator, Filters = GetFiltersFromFilterDescriptors(FilterDescriptors.ToList()) };
            }

            public FilterSet CreateFilterSet(FilterDescriptorCollection FilterDescriptors)
            {
                return new FilterSet { Operator = FilterCompositionLogicalOperator.And, Filters = GetFiltersFromFilterDescriptors(FilterDescriptors.ToList()) };
            }

            public string Serialize(CompositeFilterDescriptorCollection FilterDescriptors)
            {
                _filterSet = new FilterSet { Operator = FilterDescriptors.LogicalOperator, Filters = GetFiltersFromFilterDescriptors(FilterDescriptors.ToList()) };
                var serializer = new DataContractSerializer(typeof(FilterSet), new List<Type> { typeof(Filter) });
                var stream = new MemoryStream();
                serializer.WriteObject(stream, _filterSet);
                var encoding = new UTF8Encoding();
                var serializedFilters = encoding.GetString(stream.ToArray(), 0, (int)stream.Length);
                return serializedFilters;
            }

            public void Rehydrate(string xml, CompositeFilterDescriptorCollection FilterDescriptors)
            {
                var serializer = new DataContractSerializer(typeof(FilterSet), new List<Type> { typeof(Filter) });
                var encoding = new UTF8Encoding();
                var stream = new MemoryStream(encoding.GetBytes(xml));
                var fs = (FilterSet)serializer.ReadObject(stream);
                FilterDescriptors.Clear();

                FilterDescriptors.LogicalOperator = fs.Operator;
                FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters));
            }

            public string Serialize(FilterDescriptorCollection FilterDescriptors)
            {
                _filterSet = new FilterSet { Operator = FilterCompositionLogicalOperator.And, Filters = GetFiltersFromFilterDescriptors(FilterDescriptors.ToList()) };
                var serializer = new DataContractSerializer(typeof(FilterSet), new List<Type> { typeof(Filter) });
                var stream = new MemoryStream();
                serializer.WriteObject(stream, _filterSet);
                var encoding = new UTF8Encoding();
                var serializedFilters = encoding.GetString(stream.ToArray(), 0, (int)stream.Length);
                return serializedFilters;

            }

            public void Rehydrate(string xml, FilterDescriptorCollection FilterDescriptors, GridViewColumnCollection columns)
            {
                var serializer = new DataContractSerializer(typeof(FilterSet), new List<Type> { typeof(Filter) });
                var encoding = new UTF8Encoding();
                var stream = new MemoryStream(encoding.GetBytes(xml));
                var fs = (FilterSet)serializer.ReadObject(stream);
                FilterDescriptors.Clear();

                //FilterDescriptors.LogicalOperator = fs.Operator;
                FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters, columns));
            }

            public IEnumerable<IFilterDescriptor> Rehydrate(string xml, GridViewColumnCollection columns)
            {
                var serializer = new DataContractSerializer(typeof(FilterSet), new List<Type> { typeof(Filter) });
                var encoding = new UTF8Encoding();
                var stream = new MemoryStream(encoding.GetBytes(xml));
                var fs = (FilterSet)serializer.ReadObject(stream);
                return GetFilterDescriptorsFromFilters(fs.Filters, columns);
            }

            public static void CopyFilterDescriptorsToRadFilter(FilterDescriptorCollection FDListFrom, CompositeFilterDescriptorCollection FilterDescriptors)
            {
                FilterDescriptors.Clear();

                foreach (IFilterDescriptor iFilter in FDListFrom)
                {
                  
                    if (iFilter.GetType() == typeof(FilterDescriptor))
                        //FilterDescriptors.Add(((FilterDescriptor)iFilter).Clone());
                        FilterDescriptors.Add(((FilterDescriptor)iFilter));
                    if (iFilter.GetType() == typeof(ICompositeFilterDescriptor))
                        //FilterDescriptors.Add(((CompositeFilterDescriptor)iFilter).Clone());
                        FilterDescriptors.Add(((CompositeFilterDescriptor)iFilter));
                    if (iFilter.GetType() == typeof(ColumnFilterDescriptor))
                    {
                        //ICompositeFilterDescriptor clone = ((ColumnFilterDescriptor)iFilter).Clone();
                        ICompositeFilterDescriptor clone = ((ColumnFilterDescriptor)iFilter);
                        FilterDescriptors.Add(clone);
                    }

                }

            }

            public static T DeserializeObject<T>(string serialized)
            {

                if (serialized == null) throw new ArgumentNullException("serialized");
                DataContractSerializer dcs = new DataContractSerializer(typeof(T));
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(serialized));
                return (T)dcs.ReadObject(ms);
            }

            public static string SerializeObject(object obj)
            {
                if (obj == null) throw new ArgumentNullException("obj");
                DataContractSerializer dcs = new DataContractSerializer(obj.GetType());
                MemoryStream ms = new MemoryStream();
                dcs.WriteObject(ms, obj);
                return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Position);
            }
        }
    }

    Regards
    Waiting for reply from team

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 27 Jul 2012 Link to this post

    Hi,

    Your code does not compile as we have introduced breaking changes with the Q1 2012 version of the Controls. Part of the changes are:

    • The IColumnFilterDescriptor.FieldFilter property is now of type IFieldFilterDescriptor instead of FieldFilterDescriptor.
    • The DistinctValuesFilterDescriptor class has been made internal. It is not supposed to be used directly from your code. Use the IDistinctValuesFilterDescriptor interface instead.
    • The FieldFilterDescriptor class has been made internal. It is not supposed to be used directly from your code. Use the IFieldFilterDescriptor interface instead.
    Please check here for detailed information on all the changes done. 

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Pranay
    Pranay avatar
    11 posts
    Member since:
    Jul 2012

    Posted 27 Jul 2012 Link to this post

    I read that but can u suggest me

    item as DistinctValuesFilterDescriptor).Member
    (item as FieldFilterDescriptor).FieldName

    how can i replace this line of code. i.e any member related to this ?
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Jul 2012 Link to this post

    Hello,

    After the changes, you don't need Member and FieldName because you get the descriptor from the respective column. They are paired together so the Member is known. Still, you can take the Member of the column using its GetDataMemberName() method.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Pranay
    Pranay avatar
    11 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2012 Link to this post

    Still not getting all. Can you please send me Demo projec if you have any ..
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 31 Jul 2012 Link to this post

    Hi,

     You could check the filtering code in our online demos for an example:
    1. Programatic Filtering
    2. Search as you type
    3. PersistenceFramework

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top