Example #1
0
        /// <summary>
        /// Helper method to Enumerate all importable items
        /// </summary>
        /// <param name="contentType">the content type</param>
        /// <param name="selectionMode">the selection mode</param>
        private async void findItems(PhotoImportContentTypeFilter contentType, PhotoImportItemSelectionMode selectionMode)
        {
            rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage);

            // Disable buttons and lists to prevent unexpected reentrance.
            setButtonState(false);
            this.sourceListBox.IsEnabled = false;

            this.cts = new CancellationTokenSource();

            try
            {
                this.progressRing.IsActive    = true;
                this.itemsToImport            = null;
                this.fileListView.ItemsSource = null;

                // Dispose any created import session
                if (this.session != null)
                {
                    this.session.Dispose();
                }

                // Create the import session from the source selected
                this.session = importSource.CreateImportSession();

                RaisePropertyChanged("AppendSessionDateToDestinationFolder");

                // Progress handler for FindItemsAsync
                var progress = new Progress <uint>((result) =>
                {
                    rootPage.NotifyUser(String.Format("Found {0} Files", result.ToString()), NotifyType.StatusMessage);
                });

                // Find all items available importable item from our source
                this.itemsResult = await session.FindItemsAsync(contentType, selectionMode).AsTask(cts.Token, progress);

                setIncrementalFileList(this.itemsResult);
                DisplayFindItemsResult();

                if (this.itemsResult.HasSucceeded)
                {
                    // disable Find New , Find All and Delete button.
                    this.findNewItemsButton.IsEnabled = false;
                    this.findAllItemsButton.IsEnabled = false;
                    this.deleteButton.IsEnabled       = false;

                    // enable list selection , folder options and import buttons
                    this.selectNewButton.IsEnabled      = true;
                    this.selectNoneButton.IsEnabled     = true;
                    this.selectAllButton.IsEnabled      = true;
                    this.importButton.IsEnabled         = true;
                    this.fileListView.IsEnabled         = true;
                    this.AddSessionDateFolder.IsEnabled = true;
                    this.NoSubFolder.IsEnabled          = true;
                    this.FileDateSubfolder.IsEnabled    = true;
                    this.ExifDateSubfolder.IsEnabled    = true;
                    this.KeepOriginalFolder.IsEnabled   = true;
                }
                else
                {
                    rootPage.NotifyUser("FindItemsAsync did not succeed or was not completed.", NotifyType.StatusMessage);

                    // re-enable Find New and Find All buttons
                    this.findNewItemsButton.IsEnabled = true;
                    this.findAllItemsButton.IsEnabled = true;

                    this.progressRing.IsActive = false;
                }

                this.progressRing.IsActive = false;

                // Set the CancellationTokenSource to null when the work is complete.
                cts = null;
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Error: Operation incomplete. " + "Exception: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
        /// <summary>
        /// Helper method to Enumerate all importable items
        /// </summary>
        /// <param name="contentType">the content type</param>
        /// <param name="selectionMode">the selection mode</param>
        private async void findItems(PhotoImportContentTypeFilter contentType, PhotoImportItemSelectionMode selectionMode)
        {
            rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage);

            // Disable buttons and lists to prevent unexpected reentrance.
            setButtonState(false);
            this.sourceListBox.IsEnabled = false;

            this.cts = new CancellationTokenSource();

            try
            {
                this.progressRing.IsActive = true;
                this.itemsToImport = null;
                this.fileListView.ItemsSource = null;

                // Dispose any created import session
                if (this.session != null)
                {
                    this.session.Dispose();
                    this.session = null;
                }

                // Create the import session from the source selected
                this.session = importSource.CreateImportSession();

                RaisePropertyChanged("AppendSessionDateToDestinationFolder");

                // Progress handler for FindItemsAsync
                var progress = new Progress<uint>((result) =>
                {
                    rootPage.NotifyUser(String.Format("Found {0} Files", result.ToString()), NotifyType.StatusMessage);
                });

                // Find all items available importable item from our source
                this.itemsResult = await session.FindItemsAsync(contentType, selectionMode).AsTask(cts.Token, progress);

                setIncrementalFileList(this.itemsResult);
                DisplayFindItemsResult();

                if (this.itemsResult.HasSucceeded)
                {
                    // disable Find New , Find All and Delete button. 
                    this.findNewItemsButton.IsEnabled = false;
                    this.findAllItemsButton.IsEnabled = false;
                    this.deleteButton.IsEnabled = false;
                    
                    // enable list selection , folder options and import buttons
                    this.selectNewButton.IsEnabled = true;
                    this.selectNoneButton.IsEnabled = true;
                    this.selectAllButton.IsEnabled = true;
                    this.importButton.IsEnabled = true;
                    this.fileListView.IsEnabled = true;
                    this.AddSessionDateFolder.IsEnabled = true;
                    this.NoSubFolder.IsEnabled = true;
                    this.FileDateSubfolder.IsEnabled = true;
                    this.ExifDateSubfolder.IsEnabled = true;
                    this.KeepOriginalFolder.IsEnabled = true;

                }
                else
                {                    
                    rootPage.NotifyUser("FindItemsAsync did not succeed or was not completed.", NotifyType.StatusMessage);
                    
                    // re-enable Find New and Find All buttons
                    this.findNewItemsButton.IsEnabled = true;
                    this.findAllItemsButton.IsEnabled = true;

                    this.progressRing.IsActive = false;
                }

                this.progressRing.IsActive = false;
                
                // Set the CancellationTokenSource to null when the work is complete.
                cts = null;
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Error: Operation incomplete. " + "Exception: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }