Ejemplo n.º 1
0
        /// <summary>
        /// Event Handler for progress of scanning
        /// </summary>
        /// <param name="operation">async operation for scanning</param>
        /// <param name="numberOfFiles">The Number of files scanned so far</param>
        private async void ScanProgress(IAsyncOperationWithProgress <ImageScannerScanResult, UInt32> operation, UInt32 numberOfScannedFiles)
        {
            ImageScannerScanResult result = null;

            try
            {
                result = operation.GetResults();
            }
            catch (OperationCanceledException)
            {
                // The try catch is placed here for scenarios in which operation has already been cancelled when progress call is made
                Utils.DisplayScanCancelationMessage();
            }

            if (result != null && result.ScannedFiles.Count > 0)
            {
                IReadOnlyList <StorageFile> fileStorageList = result.ScannedFiles;
                await MainPage.Current.Dispatcher.RunAsync(
                    Windows.UI.Core.CoreDispatcherPriority.Normal,
                    new Windows.UI.Core.DispatchedHandler(() =>
                {
                    StorageFile file = fileStorageList[0];
                    Utils.SetImageSourceFromFile(file, DisplayImage);

                    rootPage.NotifyUser("Escaneo en progreso...", NotifyType.StatusMessage);
                    Utils.UpdateFileListData(fileStorageList, model);

                    ScanerListView.SelectedItem = model.FileList.Last();
                }
                                                          ));
            }
        }
        /// <summary>
        /// Event Handler for progress of scanning
        /// </summary>
        /// <param name="operation">async operation for scanning</param>
        /// <param name="numberOfFiles">The Number of files scanned so far</param>
        private async void ScanProgress(IAsyncOperationWithProgress <ImageScannerScanResult, UInt32> operation, UInt32 numberOfScannedFiles)
        {
            ImageScannerScanResult result = null;

            try
            {
                result = operation.GetResults();
            }
            catch (OperationCanceledException)
            {
                // The try catch is placed here for scenarios in which operation has already been cancelled when progress call is made
                Utils.DisplayScanCancelationMessage();
            }

            if (result != null && result.ScannedFiles.Count > 0)
            {
                IReadOnlyList <StorageFile> fileStorageList = result.ScannedFiles;
                await MainPage.Current.Dispatcher.RunAsync(
                    Windows.UI.Core.CoreDispatcherPriority.Normal,
                    new Windows.UI.Core.DispatchedHandler(() =>
                {
                    StorageFile file = fileStorageList[0];
                    Utils.SetImageSourceFromFile(file, DisplayImage);

                    rootPage.NotifyUser("Scanning is in progress. The Number of files scanned so far: " + numberOfScannedFiles + ". Below is the latest scanned image. \n" +
                                        "All the files that have been scanned are saved to local My Pictures folder.", NotifyType.StatusMessage);
                    Utils.UpdateFileListData(fileStorageList, ModelDataContext);
                }
                                                          ));
            }
        }