Exemple #1
0
        protected virtual void BgWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            ItemSourceOperation operations = default(ItemSourceOperation);

            while (this.queuedOperations.Count > 0 && this.perform)
            {
                OperationParameters currentParams;
                if (!this.queuedOperations.TryDequeue(out currentParams))
                {
                    System.Threading.Thread.Sleep(100);
                    continue;
                }

                this.backgroundWorker.ReportProgress(0, currentParams.Operation);
                switch (currentParams.Operation)
                {
                case ItemSourceOperation.Filtering:
                    this.Filter(currentParams.Descriptors as FilterDescriptorCollection);
                    break;

                case ItemSourceOperation.Sorting:
                    this.Sort(currentParams.Descriptors as SortDescriptorCollection);
                    break;

                default:
                    break;
                }

                operations |= currentParams.Operation;
            }

            e.Result = new ItemSourceOperationCompletedEventArgs(operations, !this.perform);
        }
Exemple #2
0
        public void PerformOperation(ItemSourceOperation operation, IList descriptors, bool force = false)
        {
            switch (operation)
            {
            case ItemSourceOperation.Filtering:
                FilterDescriptorCollection filterDescriptors = descriptors as FilterDescriptorCollection;
                if (this.lastFilterExpression == filterDescriptors.Expression && !force)
                {
                    return;
                }

                this.lastFilterExpression = filterDescriptors.Expression;
                break;

            case ItemSourceOperation.Sorting:
                SortDescriptorCollection sortDescriptors = descriptors as SortDescriptorCollection;
                if (this.lastSortExpression == sortDescriptors.Expression && !force)
                {
                    return;
                }

                this.lastSortExpression = sortDescriptors.Expression;
                break;

            default:
                break;
            }

            OperationParameters operationParams = new OperationParameters(operation, descriptors);

            this.queuedOperations.Enqueue(operationParams);
            if (this.backgroundWorker.IsBusy)
            {
                OperationParameters peek;
                bool peeked = this.queuedOperations.TryPeek(out peek);
                if (peeked && peek.Operation == operationParams.Operation && peek != operationParams)
                {
                    OperationParameters dequeued;
                    this.queuedOperations.TryDequeue(out dequeued);
                }
                else if (peeked && peek.Operation != operationParams.Operation)
                {
                    this.perform = false;
                }
            }

            if (!this.backgroundWorker.IsBusy)
            {
                this.perform = true;
                this.backgroundWorker.RunWorkerAsync();
                this.OnOperationStarted(new ItemSourceOperationEventArgs(operationParams.Operation));
            }
        }
Exemple #3
0
 public OperationParameters(ItemSourceOperation operation, IList descriptors)
 {
     this.Operation   = operation;
     this.Descriptors = descriptors;
 }
Exemple #4
0
 public ItemSourceOperationCompletedEventArgs(ItemSourceOperation operation, bool canceled)
     : base(operation)
 {
     this.Canceled = canceled;
 }
Exemple #5
0
 public ItemSourceOperationEventArgs(ItemSourceOperation operation)
 {
     this.OperationType = operation;
 }