Beispiel #1
0
        public ODataVirtualDataSourceDataProviderWorker(ODataVirtualDataSourceDataProviderWorkerSettings settings)
            : base(settings)
        {
            _baseUri           = settings.BaseUri;
            _entitySet         = settings.EntitySet;
            _sortDescriptions  = settings.SortDescriptions;
            _filterExpressions = settings.FilterExpressions;
            _desiredPropeties  = settings.PropertiesRequested;
            _groupDescriptions = settings.GroupDescriptions;
            if (_groupDescriptions != null && _groupDescriptions.Count > 0)
            {
                _sortDescriptions = new SortDescriptionCollection();
                foreach (var sd in settings.SortDescriptions)
                {
                    _sortDescriptions.Add(sd);
                }

                for (var i = 0; i < _groupDescriptions.Count; i++)
                {
                    _sortDescriptions.Insert(i, _groupDescriptions[i]);
                }
            }
            _isAggregationSupportedByServer = settings.IsAggregationSupportedByServer;
            Task.Factory.StartNew(() => DoWork(), TaskCreationOptions.LongRunning);
        }
Beispiel #2
0
        public SQLiteVirtualDataSourceDataProviderWorker(SQLiteVirtualDataSourceDataProviderWorkerSettings settings)
            : base(settings)
        {
            _tableExpression          = settings.TableExpression;
            _projectionType           = settings.ProjectionType;
            _selectExpressionOverride = settings.SelectExpressionOverride;
            _connection        = settings.Connection;
            _sortDescriptions  = settings.SortDescriptions;
            _groupDescriptions = settings.GroupDescriptions;
            _groupingField     = settings.GroupingColumn;

            if (_groupDescriptions != null && _groupDescriptions.Count > 0)
            {
                _sortDescriptions = new SortDescriptionCollection();
                foreach (var sd in settings.SortDescriptions)
                {
                    _sortDescriptions.Add(sd);
                }

                for (var i = 0; i < _groupDescriptions.Count; i++)
                {
                    _sortDescriptions.Insert(i, _groupDescriptions[i]);
                }
            }
            _filterExpressions = settings.FilterExpressions;
            _desiredPropeties  = settings.PropertiesRequested;
            _propertyMappings  = ResolvePropertyMappings();
            ActualSchema       = ResolveSchema();
            if (_groupDescriptions != null && _groupDescriptions.Count > 0)
            {
                _groupInformation = ResolveGroupInformation();
            }

            Task.Factory.StartNew(() => DoWork(), TaskCreationOptions.LongRunning);
        }
Beispiel #3
0
        private void GridViewColumnHeader_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                SortDescriptionCollection sortDescriptions = View.SortDescriptions;
                Image  columnSortImage = ((Image)((StackPanel)((GridViewColumnHeader)sender).Content).Children[0]);
                object columnContent   = ((GridViewColumnHeader)sender).Content;

                foreach (GridViewColumn column in ((GridView)listViewMain.View).Columns)
                {
                    if (((GridViewColumnHeader)column.Header).Content.Equals(columnContent))
                    {
                        string propertyName = column.DisplayMemberBinding == null ? "PriorityInt" : ((Binding)column.DisplayMemberBinding).Path.Path;
                        bool   contained    = false;
                        int    position     = 0;

                        for (int i = 0; i < sortDescriptions.Count; i++)
                        {
                            if (sortDescriptions[i].PropertyName.Equals(propertyName))
                            {
                                contained = true;
                                position  = i;

                                break;
                            }
                        }

                        if (!contained)
                        {
                            sortDescriptions.Add(new SortDescription(propertyName, ListSortDirection.Ascending));
                            columnSortImage.Source = new BitmapImage(new Uri(@"/Resources/Images/SortedAscending.png", UriKind.Relative));
                        }
                        else
                        {
                            if (sortDescriptions[position].Direction == ListSortDirection.Ascending)
                            {
                                sortDescriptions.RemoveAt(position);
                                sortDescriptions.Insert(position, new SortDescription(propertyName, ListSortDirection.Descending));
                                columnSortImage.Source = new BitmapImage(new Uri(@"/Resources/Images/SortedDescending.png", UriKind.Relative));
                            }
                            else
                            {
                                sortDescriptions.RemoveAt(position);
                                columnSortImage.Source = new BitmapImage(new Uri(@"/Resources/Images/Unsorted.png", UriKind.Relative));
                            }
                        }
                    }
                }
            }
        }
    private static void ApplyColumnSort( DataGridContext dataGridContext, SortDescriptionCollection sortDescriptions, ColumnCollection columns, ColumnBase column, SortDirection sortDirection )
    {
      if( column == null )
        throw new ArgumentNullException( "column" );

      Debug.Assert( ( dataGridContext != null ) || ( column.ParentDetailConfiguration != null ) );

      if( ( dataGridContext == null ) && ( column.ParentDetailConfiguration == null ) )
        throw new DataGridInternalException( "DataGridContext or ParentDetailConfiguration cannot be null." );

      if( !columns.Contains( column ) )
        throw new ArgumentException( "The specified column is not part of the DataGridContext.", "column" );

      string fieldName = column.FieldName;

      bool canSort = ( dataGridContext != null ) ? dataGridContext.Items.CanSort : true;

      if( ( !string.IsNullOrEmpty( fieldName ) ) && ( canSort == true ) )
      {
        SortDescription existingSort;
        int sortDescriptionIndex = sortDescriptions.Count;

        for( int i = sortDescriptions.Count - 1; i >= 0; i-- )
        {
          existingSort = sortDescriptions[ i ];

          if( existingSort.PropertyName == fieldName )
          {
            if( ( ( existingSort.Direction == ListSortDirection.Ascending ) && ( sortDirection == SortDirection.Ascending ) ) ||
                ( ( existingSort.Direction == ListSortDirection.Descending ) && ( sortDirection == SortDirection.Descending ) ) )
            {
              // Nothing to change!
              sortDescriptionIndex = -1;
            }
            else
            {
              sortDescriptionIndex = i;
              sortDescriptions.Remove( existingSort );
            }

            break;
          }
        }

        int maxDescriptions = ( dataGridContext != null ) ? dataGridContext.MaxSortLevels 
          : column.ParentDetailConfiguration.MaxSortLevels;

        if( ( maxDescriptions != -1 ) && ( sortDescriptions.Count >= maxDescriptions ) )
        {
          // Cannot insert sort description since it would go beyond the max sort description count.
          sortDescriptionIndex = -1;
          sortDirection = SortDirection.None;
        }

        if( ( sortDescriptionIndex > -1 ) && ( sortDirection != SortDirection.None ) )
        {
          SortDescription sortDescription = new SortDescription( fieldName,
            ( sortDirection == SortDirection.Ascending ) ? ListSortDirection.Ascending : ListSortDirection.Descending );

          sortDescriptions.Insert( sortDescriptionIndex, sortDescription );
          column.SetSortIndex( sortDescriptionIndex );
          column.SetSortDirection( sortDirection );
        }

        SortingHelper.SynchronizeSortIndexes( sortDescriptions, columns );
      }
    }
        private static void ApplyColumnSort(DataGridContext dataGridContext, SortDescriptionCollection sortDescriptions, ColumnCollection columns, ColumnBase column, SortDirection sortDirection)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column");
            }

            Debug.Assert((dataGridContext != null) || (column.ParentDetailConfiguration != null));

            if ((dataGridContext == null) && (column.ParentDetailConfiguration == null))
            {
                throw new DataGridInternalException("DataGridContext or ParentDetailConfiguration cannot be null.");
            }

            if (!columns.Contains(column))
            {
                throw new ArgumentException("The specified column is not part of the DataGridContext.", "column");
            }

            string fieldName = column.FieldName;

            bool canSort = (dataGridContext != null) ? dataGridContext.Items.CanSort : true;

            if ((!string.IsNullOrEmpty(fieldName)) && (canSort == true))
            {
                SortDescription existingSort;
                int             sortDescriptionIndex = sortDescriptions.Count;

                for (int i = sortDescriptions.Count - 1; i >= 0; i--)
                {
                    existingSort = sortDescriptions[i];

                    if (existingSort.PropertyName == fieldName)
                    {
                        if (((existingSort.Direction == ListSortDirection.Ascending) && (sortDirection == SortDirection.Ascending)) ||
                            ((existingSort.Direction == ListSortDirection.Descending) && (sortDirection == SortDirection.Descending)))
                        {
                            // Nothing to change!
                            sortDescriptionIndex = -1;
                        }
                        else
                        {
                            sortDescriptionIndex = i;
                            sortDescriptions.Remove(existingSort);
                        }

                        break;
                    }
                }

                int maxDescriptions = (dataGridContext != null) ? dataGridContext.MaxSortLevels
          : column.ParentDetailConfiguration.MaxSortLevels;

                if ((maxDescriptions != -1) && (sortDescriptions.Count >= maxDescriptions))
                {
                    // Cannot insert sort description since it would go beyond the max sort description count.
                    sortDescriptionIndex = -1;
                    sortDirection        = SortDirection.None;
                }

                if ((sortDescriptionIndex > -1) && (sortDirection != SortDirection.None))
                {
                    SortDescription sortDescription = new SortDescription(fieldName,
                                                                          (sortDirection == SortDirection.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending);

                    sortDescriptions.Insert(sortDescriptionIndex, sortDescription);
                    column.SetSortIndex(sortDescriptionIndex);
                    column.SetSortDirection(sortDirection);
                }

                SortingHelper.SynchronizeSortIndexes(sortDescriptions, columns);
            }
        }
Beispiel #6
0
        // keep inner and outer CollViews' SortDescription collections in synch
        private void SynchronizeSortDescriptions(NotifyCollectionChangedEventArgs e, SortDescriptionCollection origin, SortDescriptionCollection clone)
        { 
            if (clone == null)
                return;             // the clone might be lazily-created _sort 
 
            switch (e.Action)
            { 
                case NotifyCollectionChangedAction.Add:
                    Debug.Assert(e.NewStartingIndex >= 0);
                    if (clone.Count + e.NewItems.Count != origin.Count)
                        goto case NotifyCollectionChangedAction.Reset; 
                    for (int i = 0; i < e.NewItems.Count; i++)
                    { 
                        clone.Insert(e.NewStartingIndex + i, (SortDescription) e.NewItems[i]); 
                    }
                    break; 
                case NotifyCollectionChangedAction.Remove:
                    if (clone.Count - e.OldItems.Count != origin.Count)
                        goto case NotifyCollectionChangedAction.Reset;
                    Debug.Assert(e.OldStartingIndex >= 0); 
                    for (int i = 0; i < e.OldItems.Count; i++)
                    { 
                        clone.RemoveAt(e.OldStartingIndex); 
                    }
                    break; 

                case NotifyCollectionChangedAction.Replace:
                    Debug.Assert(e.OldStartingIndex >= 0);
                    if (clone.Count != origin.Count) 
                        goto case NotifyCollectionChangedAction.Reset;
                    for (int i = 0; i < e.OldItems.Count; i++) 
                    { 
                        clone[e.OldStartingIndex + i] = (SortDescription) e.NewItems[i];
                    } 
                    break;

                case NotifyCollectionChangedAction.Move:
                    Debug.Assert(e.OldStartingIndex >= 0); 
                    if (clone.Count != origin.Count)
                        goto case NotifyCollectionChangedAction.Reset; 
                    if (e.NewItems.Count == 1) 
                    {
                        clone.RemoveAt(e.OldStartingIndex); 
                        clone.Insert(e.NewStartingIndex, (SortDescription) e.NewItems[0]);
                    }
                    else
                    { 
                        for (int i = 0; i < e.OldItems.Count; i++)
                        { 
                            clone.RemoveAt(e.OldStartingIndex); 
                        }
                        for (int i = 0; i < e.NewItems.Count; i++) 
                        {
                            clone.Insert(e.NewStartingIndex + i, (SortDescription) e.NewItems[i]);
                        }
                    } 
                    break;
 
                // this arm also handles cases where the two collections have gotten 
                // out of [....] (typically because exceptions prevented a previous [....]
                // from happening) 
                case NotifyCollectionChangedAction.Reset:
                    CloneList(clone, origin);
                    break;
 
                default:
                    throw new NotSupportedException(SR.Get(SRID.UnexpectedCollectionChangeAction, e.Action)); 
            } 
        }