public async Task AcceptChangesFromChangeTracker() { if (_changeReader != null) { await _changeReader.AcceptChangesAsync(); } }
public async Task ApplyChangesAsync() { StorageLibraryChangeTracker?tracker = RootFolder?.TryGetChangeTracker(); if (tracker != null) { tracker.Enable(); StorageLibraryChangeReader changeReader = tracker.GetChangeReader(); var changes = await changeReader.ReadBatchAsync(); await changeReader.AcceptChangesAsync(); if (changes.Count > 0) { Task applyChangesTask = ApplyChangesToTemporaryFolderAsync(changes); StorageLibraryChanged?.Invoke(this, new StorageLibraryChangedEventArgs(changes)); await applyChangesTask; await LoadSolutionAsync(); } } }
private static async void OnPeriodicCheckTimerFired(object sender, object e) { if (m_isIndexing || m_libChangeReader == null) { return; } TelemetryHelper.LogEvent(); m_logger.LogInformation("Enter periodic check."); try { var isIndexingRequired = false; var changes = await m_libChangeReader.ReadBatchAsync(); foreach (var change in changes) { // For files, validate extension. if (change.IsOfType(StorageItemTypes.File) && change.Path != null) { if (!FileIndexer.SupportedFormats.Contains(Path.GetExtension(change.Path))) { continue; } } // Determine eligibility switch (change.ChangeType) { case StorageLibraryChangeType.Created: case StorageLibraryChangeType.Deleted: case StorageLibraryChangeType.MovedIntoLibrary: case StorageLibraryChangeType.MovedOrRenamed: case StorageLibraryChangeType.MovedOutOfLibrary: case StorageLibraryChangeType.ContentsChanged: case StorageLibraryChangeType.ContentsReplaced: isIndexingRequired = true; break; } // Exit the loop if (isIndexingRequired) { break; } } m_logger.LogInformation($"Periodic check result: Reindex: {isIndexingRequired}."); if (isIndexingRequired) { var updatedCount = await IndexInternalAsync(new ThumbnailOperations()); m_logger.LogInformation($"{updatedCount} files have been added."); } await m_libChangeReader.AcceptChangesAsync(); m_logger.LogInformation("Periodic check has been completed."); } catch (Exception ex) when((uint)ex.HResult == 0x80080222) { await DisableAutoTrackChangesAndNotifyUserAsync(); } catch (Exception ex) { // Log exceptions to ETW channel m_logger.LogError($"Type of {ex.GetType()} exception occurred in {ex.StackTrace} with message {ex.Message}"); } }
private static async Task <List <KeyValuePair <StorageLibraryChangeType, object> > > LoadChanges() { List <KeyValuePair <StorageLibraryChangeType, object> > changes = new List <KeyValuePair <StorageLibraryChangeType, object> >(); try { StorageLibrary musicLibray = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Music); musicLibray.ChangeTracker.Enable(); StorageLibraryChangeReader musicChangeReader = musicLibray.ChangeTracker.GetChangeReader(); IReadOnlyList <StorageLibraryChange> changeSet = await musicChangeReader.ReadBatchAsync(); //Below this line is for the blog post. Above the line is for the magazine foreach (StorageLibraryChange change in changeSet) { if (change.ChangeType == StorageLibraryChangeType.ChangeTrackingLost) { //We are in trouble. Nothing else is going to be valid. Debug.WriteLine("Tracking lost"); musicLibray.ChangeTracker.Reset(); return(changes); } if (change.IsOfType(StorageItemTypes.Folder)) { Debug.WriteLine("Folder changes detected"); } else if (change.IsOfType(StorageItemTypes.File)) { Debug.WriteLine("File changes detected"); switch (change.ChangeType) { case StorageLibraryChangeType.ContentsChanged: StorageFile file = await change.GetStorageItemAsync() as StorageFile; changes.Add(new KeyValuePair <StorageLibraryChangeType, object>(change.ChangeType, file)); break; case StorageLibraryChangeType.MovedOrRenamed: changes.Add(new KeyValuePair <StorageLibraryChangeType, object>(change.ChangeType, new KeyValuePair <string, string>(change.Path, change.PreviousPath))); break; case StorageLibraryChangeType.MovedOutOfLibrary: changes.Add(new KeyValuePair <StorageLibraryChangeType, object>(change.ChangeType, change.Path)); break; case StorageLibraryChangeType.MovedIntoLibrary: StorageFile File = await change.GetStorageItemAsync() as StorageFile; changes.Add(new KeyValuePair <StorageLibraryChangeType, object>(change.ChangeType, File)); break; } } } await musicChangeReader.AcceptChangesAsync(); Debug.WriteLine("Get changes succeed"); return(changes); } catch (Exception e) { Debug.WriteLine(e.ToString()); return(changes); } }