Esempio n. 1
0
        public void CreateContactSortDescriptors()
        {
            if (SortDescriptors == null)
            {
                SortDescriptors = new ObservableCollection <GenericSortDescriptor <Contact, String> >();
            }

            GenericSortDescriptor <Contact, String> sort = new GenericSortDescriptor <Contact, String>();

            sort.SortMode    = MegaContactsSortMode;
            sort.KeySelector = (contact) =>
            {
                if (!String.IsNullOrWhiteSpace(contact.FirstName))
                {
                    return(contact.FirstName);
                }
                else if (!String.IsNullOrWhiteSpace(contact.LastName))
                {
                    return(contact.LastName);
                }
                else
                {
                    return(contact.Email);
                }
            };

            SortDescriptors.Add(sort);
        }
Esempio n. 2
0
        private void ObjectDataSource_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            // Load event will fire when return to page during navigation.
            if (_controlLoaded)
            {
                return;
            }

            // Initialize ControlParameters in descriptors now.
            SortDescriptors.ForEach(s => s.Initialize(this, this.Culture));
            FilterDescriptors.ForEach(f => f.Initialize(this, this.Culture));
            GroupDescriptors.ForEach(g => g.Initialize(this, this.Culture));

            // We have to listen for changes.
            SortDescriptors.CollectionChanged   += SortDescriptors_CollectionChanged;
            SortDescriptors.ItemChanged         += SortDescriptors_ItemChanged;
            FilterDescriptors.ItemChanged       += FilterDescriptors_ItemChanged;
            FilterDescriptors.CollectionChanged += FilterDescriptors_CollectionChanged;
            GroupDescriptors.ItemChanged        += GroupDescriptors_ItemChanged;
            GroupDescriptors.CollectionChanged  += GroupDescriptors_CollectionChanged;

            if (AutoLoad)
            {
                LoadCore();
            }
            _controlLoaded = true;
        }
Esempio n. 3
0
        private void RefreshViewAfterSortChange()
        {
            var view = DataView as ICollectionView;

            view.SortDescriptions.Clear();
            SortDescriptors.ForEach(s => view.SortDescriptions.Add(s.ToSortDescription()));
            if (AutoLoad)
            {
                view.Refresh();
            }
        }
Esempio n. 4
0
        public void SortContacts(ListSortMode sortMode)
        {
            if (sortMode != ListSortMode.None && MegaContactsSortMode != sortMode)
            {
                MegaContactsSortMode = sortMode;

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    GroupDescriptors.Clear(); GroupDescriptors = null;
                    SortDescriptors.Clear(); SortDescriptors   = null;

                    CreateContactsGroupDescriptors();
                    CreateContactSortDescriptors();
                });
            }
        }
Esempio n. 5
0
        public IndexDefinitionBase CreateAutoIndexDefinition()
        {
            if (IsMapReduce == false)
            {
                return(new AutoMapIndexDefinition(ForCollection, MapFields.Select(field =>
                                                                                  new IndexField
                {
                    Name = field.Name,
                    Storage = FieldStorage.No,
                    SortOption = SortDescriptors.FirstOrDefault(x => field.Name.Equals(x.Name))?.FieldType,
                    Highlighted = HighlightedFields.Any(x => field.Name.Equals(x))
                }).ToArray()));
            }

            if (MapFields.Length == 0)
            {
                throw new InvalidOperationException("Invalid dynamic map-reduce query mapping. There is no aggregation specified.");
            }

            if (GroupByFields.Length == 0)
            {
                throw new InvalidOperationException("Invalid dynamic map-reduce query mapping. There is no group by field specified.");
            }

            return(new AutoMapReduceIndexDefinition(new[] { ForCollection }, MapFields.Select(field =>
                                                                                              new IndexField
            {
                Name = field.Name,
                Storage = FieldStorage.Yes,
                MapReduceOperation = field.MapReduceOperation,
                SortOption = SortDescriptors.FirstOrDefault(x => field.Name.Equals(x.Name))?.FieldType,
            }).ToArray(),
                                                    GroupByFields.Select(field =>
                                                                         new IndexField
            {
                Name = field,
                Storage = FieldStorage.Yes,
                SortOption = SortDescriptors.FirstOrDefault(x => field.Equals(x.Name))?.FieldType,
            }).ToArray()));
        }
Esempio n. 6
0
        private void LoadView()
        {
            // Create and start loading the PCV.

            // Neither EQPCV nor PCV will work with anonymous types.
            if (AnonymousFns.IsAnonymousType(Query.ElementType))
            {
                throw new NotSupportedException("Anonymous types are not currently supported.  To work around this limitation, you can instead project into a custom type.");
            }

            if (IsEntityQuery)
            {
                EntityManager.GetEntityGroup(Query.ElementType).EntityChanged += ObjectDataSource_EntityChanged;
            }

            IsLoadingData = true;
            HasChanges    = false;

            // Convert from our "descriptors" to the "descriptions" known by a PCV.
            var sortFields = new SortDescriptionCollection();

            SortDescriptors.ForEach(s => sortFields.Add(s.ToSortDescription()));
            var groupFields = new ObservableCollection <GroupDescription>();

            GroupDescriptors.ForEach(g => groupFields.Add(g.ToGroupDescription()));

            // We'll use an EQPCV or PCV depending on a few factors: 1) an EntityQuery (so we can issue skip/take, 2) paging
            bool useEqpcv = Query is EntityQuery && PageSize > 0;

            if (useEqpcv)
            {
                EntityQueryPagedCollectionView pcv = null;
                var query  = Query as EntityQuery;
                var filter = GetQueryFilter();
                if (sortFields.Count > 0 || groupFields.Count > 0)
                {
                    pcv = new EntityQueryPagedCollectionView(query, PageSize, LoadSize, sortFields, groupFields, filter);
                }
                else
                {
                    pcv = new EntityQueryPagedCollectionView(query, PageSize, LoadSize, true, true);
                    pcv.SetQueryFilter(filter);
                    pcv.Refresh();
                }
                Data     = pcv;
                DataView = pcv;
            }
            else
            {
                // Use the standard PagedCollectionView (when paging isn't wanted or not an EntityQuery)
                IEntityQuery query = Query;
                if (Query is EntityQuery)
                {
                    query = GetFilteredQuery();
                }
                EntityManager.ExecuteQueryAsync(query, args => {
                    PagedCollectionView pcv = new PagedCollectionView(args.Results);
                    sortFields.ForEach(d => pcv.SortDescriptions.Add(d));
                    groupFields.ForEach(d => pcv.GroupDescriptions.Add(d));
                    pcv.PageSize = PageSize;
                    Data         = pcv;
                    DataView     = pcv;
                });
            }
        }