コード例 #1
0
ファイル: FileDataSource2.cs プロジェクト: ice0/test
        // Called after a reset to figure out the new indexes for the selected items
        private async Task RemapSelection()
        {
            ItemIndexRangeList        oldSelection      = selection;
            ItemCacheManager <string> oldSelectionCache = selectionCache;
            ItemIndexRangeList        newSelection      = new ItemIndexRangeList();
            ItemCacheManager <string> newSelectionCache = new ItemCacheManager <string>(fetchSelectionDataCallback, 50, "newSelectionCache");

            foreach (ItemIndexRange r in oldSelection)
            {
                IReadOnlyList <StorageFile> results = null;
                int lastResultOffset = 0, lastResultsItemIndex = 0;
                for (int i = 0; i < r.Length; i++)
                {
                    int    origIndex = r.FirstIndex + i;
                    string fileid    = oldSelectionCache[origIndex];
                    bool   matched   = false;

                    // Optimization to be able to work in batches. Once we get a batch of files from the filesystem we use that to hunt
                    // for matches rather than having to go ask for the index of each file
                    if (results != null)
                    {
                        for (int j = lastResultOffset + 1; j < results.Count; j++)
                        {
                            if (results[j].FolderRelativeId == fileid)
                            {
                                lastResultOffset = j;
                                int itemIndex = lastResultsItemIndex + j;
                                newSelection.Add((uint)itemIndex, 1);
                                newSelectionCache[itemIndex] = oldSelectionCache[origIndex];
                                matched = true;
                                break;
                            }
                        }
                    }
                    if (!matched)
                    {
                        // Get a starting point for the index of the file
                        lastResultsItemIndex = (int)(await _queryResult.FindStartIndexAsync(fileid.Substring(fileid.LastIndexOf('\\') + 1)));
                        lastResultOffset     = 0;
                        // Get the files at that point and see if the keys actually match
                        results = await _queryResult.GetFilesAsync((uint)lastResultsItemIndex, 50);

                        if (results[lastResultOffset].FolderRelativeId == fileid)
                        {
                            newSelection.Add((uint)lastResultsItemIndex, 1);
                            newSelectionCache[lastResultsItemIndex] = oldSelectionCache[origIndex];
                        }
                        else
                        {
                            // We can't find the item, so its no longer part of the selection
                        }
                    }
                }
            }
            // Update the fields for the new selection
            selection      = newSelection;
            selectionCache = newSelectionCache;
        }
コード例 #2
0
        private FileDataSource()
        {
            //Setup the dispatcher for the UI thread
            _dispatcher = Windows.UI.Xaml.Window.Current.Dispatcher;

            // The ItemCacheManager does most of the heavy lifting. We pass it a callback that it will use to actually fetch data, and the max size of a request
            this.itemCache = new ItemCacheManager <FileItem>(fetchDataCallback, 50);
            this.itemCache.CacheChanged += ItemCache_CacheChanged;
        }
コード例 #3
0
        // Handles a change notification for the list of files from the OS
        private void ResetCollection()
        {
            // Unhook the old change notification
            if (itemCache != null)
            {
                this.itemCache.CacheChanged -= ItemCache_CacheChanged;
            }

            // Create a new instance of the cache manager
            this.itemCache = new ItemCacheManager <FileItem>(fetchDataCallback, 50);
            this.itemCache.CacheChanged += ItemCache_CacheChanged;
            if (CollectionChanged != null)
            {
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
コード例 #4
0
ファイル: FileDataSource2.cs プロジェクト: ice0/test
        // Handles a change notification for the list of files from the OS
        public async void ResetCollection()
        {
            // Update the selection cache to match the filesystem after the updates
            await RemapSelection();

            // Unhook the old change notification
            if (itemCache != null)
            {
                this.itemCache.CacheChanged -= ItemCache_CacheChanged;
            }

            // Create a new instance of the cache manager
            this.itemCache = new ItemCacheManager <FileItem>(fetchDataCallback, 50);
            this.itemCache.CacheChanged += ItemCache_CacheChanged;
            if (CollectionChanged != null)
            {
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
コード例 #5
0
ファイル: FileDataSource2.cs プロジェクト: ice0/test
 //Required for the IItemsRangeInfo interface
 public void Dispose()
 {
     itemCache = null;
 }