protected Task FindFilesAsync()
        {
            return(Task.Run(async() =>
            {
                if (!Model.HasErrors)
                {
                    Dispatcher.Invoke(() => IsBusySearching = true);
                    Dispatcher.Invoke(CopyCommand.RaiseCanExecuteChanged);

                    _searchCancellationTokenSource = new CancellationTokenSource();
                    ClearPreviousSearchResults();

                    var path = Model.SourcePath;
                    try
                    {
                        await SpecificSearchAsync(path, _searchCancellationTokenSource.Token);
                    }
                    catch (OperationCanceledException) { }
                    finally
                    {
                        Dispatcher.Invoke(() =>
                        {
                            SetDefaultSortDescriptors();
                            CollectionViewSourceItems.Refresh();
                        });

                        RaisePropertyChanged(() => SelectedFilesCount);
                        CalculateTotalSelectedSize();
                        IsBusySearching = false;
                        Dispatcher.Invoke(CopyCommand.RaiseCanExecuteChanged);
                    }
                }
            }));
        }
 private void SetDefaultSortDescriptors()
 {
     if (!CollectionViewSourceItems.SortDescriptions.Any())
     {
         CollectionViewSourceItems.SortDescriptions.Add(new SortDescription("IsSelected", ListSortDirection.Descending));
         CollectionViewSourceItems.SortDescriptions.Add(new SortDescription(nameof(CopyRepresenter.Name), ListSortDirection.Ascending));
         CollectionViewSourceItems.Refresh();
     }
 }
        private async void ReSelectRandomFiles(IEnumerable <TCopyRepresenter> copyRepresenterList)
        {
            try
            {
                _reselectFilesCancellationTokenSource?.Cancel();
                _reselectFilesCancellationTokenSource = new CancellationTokenSource();
                foreach (var item in Model.Items)
                {
                    item.IsSelected = false;
                    item.Guid       = Guid.NewGuid();
                }

                var copiedFileList = GetFileListOrNullIfNotApplicable();

                await SelectRandomFilesAsync(copyRepresenterList, copiedFileList, _reselectFilesCancellationTokenSource.Token);
            }
            catch (TaskCanceledException) { }
            finally
            {
                HandleSelectionClicked();
                CollectionViewSourceItems.Refresh();
            }
        }