/// <summary> /// When a user clicks the delete button, deletes the content that were imported. /// Calling DeleteImportedItemsFromSourceAsync does not delete content that were not imported. /// </summary> /// <param name="sender">Source of the click event</param> /// <param name="e">Detials about the click event</param> private async void OnDeleteButtonClicked(object sender, RoutedEventArgs e) { rootPage.NotifyUser("Deleting items...", NotifyType.StatusMessage); // Prevent unexpected reentrance. this.deleteButton.IsEnabled = false; cts = new CancellationTokenSource(); try { if (importedResult == null) { rootPage.NotifyUser("Nothing was imported for deletion.", NotifyType.StatusMessage); } else { var progress = new Progress <double>((result) => { this.progressBar.Value = result; }); this.deleteResult = await this.importedResult.DeleteImportedItemsFromSourceAsync().AsTask(cts.Token, progress); DisplayDeletedResults(); if (!this.deleteResult.HasSucceeded) { rootPage.NotifyUser("Delete operation did not succeed or was not completed", NotifyType.StatusMessage); } } } catch (Exception ex) { rootPage.NotifyUser("Files could not be Deleted." + "Exception: " + ex.ToString(), NotifyType.ErrorMessage); } // set the CancellationTokenSource to null when the work is complete. cts = null; // content is removed, disable the appropriate buttons this.findSourceButton.IsEnabled = true; this.importButton.IsEnabled = false; this.findNewItemsButton.IsEnabled = false; this.findAllItemsButton.IsEnabled = false; this.selectNewButton.IsEnabled = false; this.selectAllButton.IsEnabled = false; this.selectNoneButton.IsEnabled = false; this.deleteButton.IsEnabled = false; this.fileListView.IsEnabled = false; }
// </SnippetImportClick> // <SnippetDeleteClick> private async void deleteButton_Click(object sender, RoutedEventArgs e) { cts = new CancellationTokenSource(); progressBar.Value = 0; try { if (importedResult == null) { System.Diagnostics.Debug.WriteLine("Nothing was imported for deletion."); } else { var progress = new Progress <double>((result) => { this.progressBar.Value = result; }); PhotoImportDeleteImportedItemsFromSourceResult deleteResult = await this.importedResult.DeleteImportedItemsFromSourceAsync().AsTask(cts.Token, progress); if (deleteResult != null) { StringBuilder deletedResults = new StringBuilder(); deletedResults.AppendLine(String.Format("Total Photos Deleted:\t{0} ", deleteResult.PhotosCount)); deletedResults.AppendLine(String.Format("Total Videos Deleted:\t{0} ", deleteResult.VideosCount)); deletedResults.AppendLine(String.Format("Total Sidecars Deleted:\t{0} ", deleteResult.SidecarsCount)); deletedResults.AppendLine(String.Format("Total Sibilings Deleted:\t{0} ", deleteResult.SiblingsCount)); deletedResults.AppendLine(String.Format("Total Files Deleted:\t{0} ", deleteResult.TotalCount)); deletedResults.AppendLine(String.Format("Total Bytes Deleted:\t{0} ", deleteResult.TotalSizeInBytes)); System.Diagnostics.Debug.WriteLine(deletedResults.ToString()); } if (!deleteResult.HasSucceeded) { System.Diagnostics.Debug.WriteLine("Delete operation did not succeed or was not completed"); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Files could not be Deleted." + "Exception: " + ex.ToString()); } // set the CancellationTokenSource to null when the work is complete. cts = null; }
/// <summary /// This app is registered as a hanlder for WPD\IMageSourceAutoPlay event. /// When a user connects a WPD device (ie: Camera), OnNavigatedTo is called with DeviceInformationId /// that we can call FromIdAsync() and preselect the device. /// /// We also need to handle the situation where the client was terminated while an import operation was in flight. /// Import will continue and we attempt to reconnect back to the session. /// </summary> /// <param name="e">Details about the NavigationEventArgs</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); rootPage = MainPage.Current; try { //An photo import session was in progress if (e.Parameter is PhotoImportOperation) { PhotoImportOperation op = e.Parameter as PhotoImportOperation; switch (op.Stage) { // file enumeration was running case PhotoImportStage.FindingItems: cts = new CancellationTokenSource(); rootPage.NotifyUser("Reconnected back to the file enumeration stage", NotifyType.StatusMessage); // Set up progress handler for existing file enumeration var findAllItemsProgress = new Progress <uint>((result) => { rootPage.NotifyUser(String.Format("Found {0} Files", result.ToString()), NotifyType.StatusMessage); }); // retrieve previous session this.session = op.Session; // get to the operation for the existing FindItemsAsync session this.itemsResult = await op.ContinueFindingItemsAsync.AsTask(cts.Token, findAllItemsProgress); // display the items we found in the previous session setIncrementalFileList(this.itemsResult); this.selectAllButton.IsEnabled = true; this.selectNoneButton.IsEnabled = true; this.selectNewButton.IsEnabled = true; this.importButton.IsEnabled = true; DisplayFindItemsResult(); cts = null; break; // Import was running case PhotoImportStage.ImportingItems: rootPage.NotifyUser("Reconnected back to the importing stage.", NotifyType.StatusMessage); setButtonState(false); cts = new CancellationTokenSource(); // Set up progress handler for the existing import session var importSelectedItemsProgress = new Progress <PhotoImportProgress>((result) => { progressBar.Value = result.ImportProgress; }); // retrieve the previous operation this.session = op.Session; // get the itemsResult that were found in the previous session this.itemsResult = await op.ContinueFindingItemsAsync.AsTask(); // hook up the ItemImported Handler to show progress this.itemsResult.ItemImported += async(s, a) => { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser(String.Format("Imported: {0}", a.ImportedItem.Name), NotifyType.StatusMessage); }); }; // Get the operation for the import operation that was in flight this.importedResult = await op.ContinueImportingItemsAsync.AsTask(cts.Token, importSelectedItemsProgress); DisplayImportedSummary(); this.findSourceButton.IsEnabled = true; this.deleteButton.IsEnabled = true; cts = null; break; // Delete operation is in progress case PhotoImportStage.DeletingImportedItemsFromSource: rootPage.NotifyUser("Reconnected to the deletion stage.", NotifyType.StatusMessage); this.findSourceButton.IsEnabled = false; this.deleteButton.IsEnabled = false; cts = new CancellationTokenSource(); var progress = new Progress <double>((result) => { this.progressBar.Value = result; }); // get the operation for the existing delete session this.deleteResult = await op.ContinueDeletingImportedItemsFromSourceAsync.AsTask(cts.Token, progress); DisplayDeletedResults(); if (!deleteResult.HasSucceeded) { rootPage.NotifyUser("Deletion did not succeeded or was cancelled.", NotifyType.StatusMessage); } this.findSourceButton.IsEnabled = true; // Set the CancellationTokenSource to null when the work is complete. cts = null; break; // Idle State. case PhotoImportStage.NotStarted: rootPage.NotifyUser("No import tasks was started.", NotifyType.StatusMessage); this.session = op.Session; break; default: break; } } // Activated by AutoPlay if (e.Parameter is DeviceActivatedEventArgs) { this.arguments = e.Parameter as DeviceActivatedEventArgs; bool importSupported = await PhotoImportManager.IsSupportedAsync(); this.sourceListBox.Items.Clear(); List <PhotoImportSource> source = new List <PhotoImportSource>(); // Create the source from a device Id source.Add(await PhotoImportSource.FromIdAsync(this.arguments.DeviceInformationId)); // bind and preselects source this.sourceListBox.ItemsSource = source; this.sourceListBox.SelectedIndex = 0; rootPage.NotifyUser("Device selected from AutoPlay", NotifyType.StatusMessage); } } catch (Exception ex) { rootPage.NotifyUser("Exception: " + ex.ToString(), NotifyType.ErrorMessage); } }
/// <summary /// This app is registered as a hanlder for WPD\IMageSourceAutoPlay event. /// When a user connects a WPD device (ie: Camera), OnNavigatedTo is called with DeviceInformationId /// that we can call FromIdAsync() and preselect the device. /// /// We also need to handle the situation where the client was terminated while an import operation was in flight. /// Import will continue and we attempt to reconnect back to the session. /// </summary> /// <param name="e">Details about the NavigationEventArgs</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); rootPage = MainPage.Current; try { //An photo import session was in progress if (e.Parameter is PhotoImportOperation) { PhotoImportOperation op = e.Parameter as PhotoImportOperation; switch (op.Stage) { // file enumeration was running case PhotoImportStage.FindingItems: cts = new CancellationTokenSource(); rootPage.NotifyUser("Reconnected back to the file enumeration stage", NotifyType.StatusMessage); // Set up progress handler for existing file enumeration var findAllItemsProgress = new Progress<uint>((result) => { rootPage.NotifyUser(String.Format("Found {0} Files", result.ToString()), NotifyType.StatusMessage); }); // retrieve previous session this.session = op.Session; // get to the operation for the existing FindItemsAsync session this.itemsResult = await op.ContinueFindingItemsAsync.AsTask(cts.Token, findAllItemsProgress); // display the items we found in the previous session setIncrementalFileList(this.itemsResult); this.selectAllButton.IsEnabled = true; this.selectNoneButton.IsEnabled = true; this.selectNewButton.IsEnabled = true; this.importButton.IsEnabled = true; DisplayFindItemsResult(); cts = null; break; // Import was running case PhotoImportStage.ImportingItems: rootPage.NotifyUser("Reconnected back to the importing stage.", NotifyType.StatusMessage); setButtonState(false); cts = new CancellationTokenSource(); // Set up progress handler for the existing import session var importSelectedItemsProgress = new Progress<PhotoImportProgress>((result) => { progressBar.Value = result.ImportProgress; }); // retrieve the previous operation this.session = op.Session; // get the itemsResult that were found in the previous session this.itemsResult = await op.ContinueFindingItemsAsync.AsTask(); // hook up the ItemImported Handler to show progress this.itemsResult.ItemImported += async (s, a) => { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser(String.Format("Imported: {0}", a.ImportedItem.Name), NotifyType.StatusMessage); }); }; // Get the operation for the import operation that was in flight this.importedResult = await op.ContinueImportingItemsAsync.AsTask(cts.Token, importSelectedItemsProgress); DisplayImportedSummary(); this.findSourceButton.IsEnabled = true; this.deleteButton.IsEnabled = true; cts = null; break; // Delete operation is in progress case PhotoImportStage.DeletingImportedItemsFromSource: rootPage.NotifyUser("Reconnected to the deletion stage.",NotifyType.StatusMessage); this.findSourceButton.IsEnabled = false; this.deleteButton.IsEnabled = false; cts = new CancellationTokenSource(); var progress = new Progress<double>((result) => { this.progressBar.Value = result; }); // get the operation for the existing delete session this.deleteResult = await op.ContinueDeletingImportedItemsFromSourceAsync.AsTask(cts.Token, progress); DisplayDeletedResults(); if (!deleteResult.HasSucceeded) { rootPage.NotifyUser("Deletion did not succeeded or was cancelled.", NotifyType.StatusMessage); } this.findSourceButton.IsEnabled = true; // Set the CancellationTokenSource to null when the work is complete. cts = null; break; // Idle State. case PhotoImportStage.NotStarted: rootPage.NotifyUser("No import tasks was started.", NotifyType.StatusMessage); this.session = op.Session; break; default: break; } } // Activated by AutoPlay if (e.Parameter is DeviceActivatedEventArgs) { this.arguments = e.Parameter as DeviceActivatedEventArgs; bool importSupported = await PhotoImportManager.IsSupportedAsync(); this.sourceListBox.Items.Clear(); List<PhotoImportSource> source = new List<PhotoImportSource>(); // Create the source from a device Id source.Add(await PhotoImportSource.FromIdAsync(this.arguments.DeviceInformationId)); // bind and preselects source this.sourceListBox.ItemsSource = source; this.sourceListBox.SelectedIndex = 0; rootPage.NotifyUser("Device selected from AutoPlay", NotifyType.StatusMessage); } } catch (Exception ex) { rootPage.NotifyUser("Exception: " + ex.ToString(), NotifyType.ErrorMessage); } }
/// <summary> /// When a user clicks the delete button, deletes the content that were imported. /// Calling DeleteImportedItemsFromSourceAsync does not delete content that were not imported. /// </summary> /// <param name="sender">Source of the click event</param> /// <param name="e">Detials about the click event</param> private async void OnDeleteButtonClicked(object sender, RoutedEventArgs e) { rootPage.NotifyUser("Deleting items...", NotifyType.StatusMessage); // Prevent unexpected reentrance. this.deleteButton.IsEnabled = false; cts = new CancellationTokenSource(); try { if (importedResult == null) { rootPage.NotifyUser("Nothing was imported for deletion.", NotifyType.StatusMessage); } else { var progress = new Progress<double>((result) => { this.progressBar.Value = result; }); this.deleteResult = await this.importedResult.DeleteImportedItemsFromSourceAsync().AsTask(cts.Token, progress); DisplayDeletedResults(); if (!this.deleteResult.HasSucceeded) { rootPage.NotifyUser("Delete operation did not succeed or was not completed", NotifyType.StatusMessage); } } } catch (Exception ex) { rootPage.NotifyUser("Files could not be Deleted." + "Exception: " + ex.ToString(), NotifyType.ErrorMessage); } // set the CancellationTokenSource to null when the work is complete. cts = null; // content is removed, disable the appropriate buttons this.findSourceButton.IsEnabled = true; this.importButton.IsEnabled = false; this.findNewItemsButton.IsEnabled = false; this.findAllItemsButton.IsEnabled = false; this.selectNewButton.IsEnabled = false; this.selectAllButton.IsEnabled = false; this.selectNoneButton.IsEnabled = false; this.deleteButton.IsEnabled = false; this.fileListView.IsEnabled = false; }