Esempio n. 1
0
        /// <summary>
        /// Scans the images from the scanner with auto configured settings
        /// The scanning is allowed only if the selected scanner supports Device Auto-Configured Scanning.
        /// </summary>
        /// <param name="deviceId">scanner device id</param>
        /// <param name="folder">the folder that receives the scanned files</param>
        public async void ScanToFolder(string deviceId, StorageFolder folder)
        {
            try
            {
                // Get the scanner object for this device id
                ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId);

                // Check to see if the use has already cancelled the scenario
                if (ModelDataContext.ScenarioRunning)
                {
                    if (myScanner.IsScanSourceSupported(ImageScannerScanSource.AutoConfigured))
                    {
                        cancellationToken = new CancellationTokenSource();

                        // Set the scan file format to PNG, if available
                        if (myScanner.AutoConfiguration.IsFormatSupported(ImageScannerFormat.Png))
                        {
                            myScanner.AutoConfiguration.Format = ImageScannerFormat.Png;
                        }

                        rootPage.NotifyUser("Scanning", NotifyType.StatusMessage);
                        var progress = new Progress <UInt32>(ScanProgress);
                        // Scan API call to start scanning with Auto-Configured settings
                        var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.AutoConfigured, folder).AsTask(cancellationToken.Token, progress);

                        ModelDataContext.ScenarioRunning = false;
                        if (result.ScannedFiles.Count > 0)
                        {
                            Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage);
                            if (result.ScannedFiles.Count > 1)
                            {
                                Utils.UpdateFileListData(result.ScannedFiles, ModelDataContext);
                            }
                        }
                        else
                        {
                            rootPage.NotifyUser("There were no files scanned.", NotifyType.ErrorMessage);
                        }
                    }
                    else
                    {
                        ModelDataContext.ScenarioRunning = false;
                        rootPage.NotifyUser("The selected scanner does not support Device Auto-Configured Scanning.", NotifyType.ErrorMessage);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Utils.DisplayScanCancelationMessage();
            }
            catch (Exception ex)
            {
                Utils.OnScenarioException(ex, ModelDataContext);
            }
        }
        /// <summary>
        /// Scans image from the Flatbed source of the scanner
        /// The scanning is allowed only if the selected scanner is equipped with a Flatbed
        /// </summary>
        /// <param name="deviceId">scanner device id</param>
        /// <param name="folder">the folder that receives the scanned files</param>
        public async void ScanToFolder(string deviceId, StorageFolder folder)
        {
            try
            {
                // Get the scanner object for this device id
                ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId);

                // Check to see if the user has already canceled the scenario
                if (ModelDataContext.ScenarioRunning)
                {
                    if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Flatbed))
                    {
                        // Set the scan file format to Device Independent Bitmap (DIB)
                        myScanner.FlatbedConfiguration.Format = ImageScannerFormat.DeviceIndependentBitmap;

                        cancellationToken = new CancellationTokenSource();

                        rootPage.NotifyUser("Scanning", NotifyType.StatusMessage);
                        // Scan API call to start scanning from the Flatbed source of the scanner.
                        var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Flatbed, folder).AsTask(cancellationToken.Token);

                        ModelDataContext.ScenarioRunning = false;
                        if (result.ScannedFiles.Count > 0)
                        {
                            Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage);
                        }
                        else
                        {
                            rootPage.NotifyUser("There are no files scanned from the Flatbed.", NotifyType.ErrorMessage);
                        }
                    }
                    else
                    {
                        ModelDataContext.ScenarioRunning = false;
                        rootPage.NotifyUser("The selected scanner does not report to be equipped with a Flatbed.", NotifyType.ErrorMessage);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Utils.DisplayScanCancelationMessage();
            }
            catch (Exception ex)
            {
                Utils.OnScenarioException(ex, ModelDataContext);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets all available Scan Sources for a scanner
        /// </summary>
        /// <param name="scanner"></param>
        /// <returns>List with all available ImageScannerScanSources for the given scanner</returns>
        public static List <ImageScannerScanSource> GetSupportedScanSources(ImageScanner scanner)
        {
            List <ImageScannerScanSource> availableScanSources = new List <ImageScannerScanSource>();

            foreach (ImageScannerScanSource scanSource in (ImageScannerScanSource[])Enum.GetValues(typeof(ImageScannerScanSource)))
            {
                if (scanner.IsScanSourceSupported(scanSource))
                {
                    if (scanSource != ImageScannerScanSource.Default)   // Disabling Default as it'll only be used for getting preferences from
                    {
                        availableScanSources.Add(scanSource);
                    }
                }
            }

            return(availableScanSources);
        }
        /// <summary>
        /// Scans all the images from Feeder source of the scanner
        /// The scanning is allowed only if the selected scanner is equipped with a Feeder
        /// </summary>
        /// <param name="deviceId">scanner device id</param>
        /// <param name="folder">the folder that receives the scanned files</param>
        public async void ScanToFolder(string deviceId, StorageFolder folder)
        {
            try
            {
                // Get the scanner object for this device id
                ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId);

                // Check to see if the use has already cancelled the scenario
                if (model.ScenarioRunning)
                {
                    if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Feeder))
                    {
                        // Set MaxNumberOfPages to zero to scanning all the pages that are present in the feeder
                        myScanner.FeederConfiguration.MaxNumberOfPages = 0;
                        myScanner.FeederConfiguration.Duplex           = tggDuplex.IsOn;
                        myScanner.FeederConfiguration.PageSize         = (Windows.Graphics.Printing.PrintMediaSize)model.ScannerDataContext.CurrentSize;

                        cancellationToken = new CancellationTokenSource();
                        rootPage.NotifyUser("Escaneando", NotifyType.StatusMessage);

                        // Scan API call to start scanning from the Feeder source of the scanner.
                        var operation = myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Feeder, folder);
                        operation.Progress = new AsyncOperationProgressHandler <ImageScannerScanResult, uint>(ScanProgress);
                        var result = await operation.AsTask <ImageScannerScanResult, UInt32>(cancellationToken.Token);

                        // Number of scanned files should be zero here since we already processed during scan progress notifications all the files that have been scanned
                        rootPage.NotifyUser("Escaneo completado.", NotifyType.StatusMessage);
                        model.ScenarioRunning = false;
                    }
                    else
                    {
                        model.ScenarioRunning = false;
                        rootPage.NotifyUser("El escáner seleccionado indica no tener Feeder.", NotifyType.ErrorMessage);
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                Utils.DisplayScanCancelationMessage();
            }
            catch (Exception ex)
            {
                Utils.OnScenarioException(ex, model);
            }
        }
        /// <summary>
        /// Scans all the images from Feeder source of the scanner
        /// The scanning is allowed only if the selected scanner is equipped with a Feeder
        /// </summary>
        /// <param name="deviceId">scanner device id</param>
        /// <param name="folder">the folder that receives the scanned files</param>
        public async void ScanToFolder(string deviceId, StorageFolder folder)
        {
            try
            {
                // Get the scanner object for this device id
                ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId);

                // Check to see if the use has already cancelled the scenario
                if (ModelDataContext.ScenarioRunning)
                {
                    if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Feeder))
                    {
                        // Set MaxNumberOfPages to zero to scanning all the pages that are present in the feeder
                        myScanner.FeederConfiguration.MaxNumberOfPages = 0;
                        cancellationToken = new CancellationTokenSource();
                        rootPage.NotifyUser("Scanning", NotifyType.StatusMessage);

                        // Scan API call to start scanning from the Feeder source of the scanner.
                        var operation = myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Feeder, folder);
                        operation.Progress = new AsyncOperationProgressHandler <ImageScannerScanResult, uint>(ScanProgress);
                        var result = await operation.AsTask <ImageScannerScanResult, UInt32>(cancellationToken.Token);

                        // Number of scanned files should be zero here since we already processed during scan progress notifications all the files that have been scanned
                        rootPage.NotifyUser("Scanning is complete.", NotifyType.StatusMessage);
                        ModelDataContext.ScenarioRunning = false;
                    }
                    else
                    {
                        ModelDataContext.ScenarioRunning = false;
                        rootPage.NotifyUser("The selected scanner does not report to be equipped with a Feeder.", NotifyType.ErrorMessage);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Utils.DisplayScanCancelationMessage();
            }
            catch (Exception ex)
            {
                Utils.OnScenarioException(ex, ModelDataContext);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Previews the image from the scanner with given device id
        /// The preview is allowed only if the selected scanner is equipped with a Flatbed and supports preview.
        /// </summary>
        /// <param name="deviceId">scanner device id</param>
        /// <param name="stream">RandomAccessStream in which preview given the by the scan runtime API is kept</param>
        public async void ScanPreview(string deviceId, IRandomAccessStream stream)
        {
            try
            {
                // Get the scanner object for this device id
                ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId);

                if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Flatbed))
                {
                    if (myScanner.IsPreviewSupported(ImageScannerScanSource.Flatbed))
                    {
                        rootPage.NotifyUser("Scanning", NotifyType.StatusMessage);
                        // Scan API call to get preview from the flatbed
                        var result = await myScanner.ScanPreviewToStreamAsync(ImageScannerScanSource.Flatbed, stream);

                        if (result.Succeeded)
                        {
                            Utils.SetImageSourceFromStream(stream, DisplayImage);
                            rootPage.NotifyUser("Preview scanning is complete. Below is the preview image.", NotifyType.StatusMessage);
                        }
                        else
                        {
                            rootPage.NotifyUser("Failed to preview from Flatbed.", NotifyType.ErrorMessage);
                        }
                    }
                    else
                    {
                        rootPage.NotifyUser("The selected scanner does not support preview from Flatbed.", NotifyType.ErrorMessage);
                    }
                }
                else
                {
                    rootPage.NotifyUser("The selected scanner does not report to be equipped with a Flatbed.", NotifyType.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                Utils.DisplayExceptionErrorMessage(ex);
            }
        }
Esempio n. 7
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // CONSTRUCTORS / FACTORIES /////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public DiscoveredScanner(ImageScanner device, string name)
        {
            Device = device;
            Id     = Device.DeviceId;

            Name = name;

            try
            {
                IsAutoAllowed    = device.IsScanSourceSupported(ImageScannerScanSource.AutoConfigured);
                IsFeederAllowed  = device.IsScanSourceSupported(ImageScannerScanSource.Feeder);
                IsFlatbedAllowed = device.IsScanSourceSupported(ImageScannerScanSource.Flatbed);
            }
            catch (Exception exc)
            {
                LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine supported scan sources.");
                throw;
            }

            // auto mode
            if (IsAutoAllowed)
            {
                LogService.Log.Information("DiscoveredScanner: Processing auto mode");
                IsAutoPreviewAllowed = device.IsPreviewSupported(ImageScannerScanSource.AutoConfigured);

                AutoFormats = GenerateFormats(device.AutoConfiguration);
            }

            // flatbed mode
            if (IsFlatbedAllowed)
            {
                LogService.Log.Information("DiscoveredScanner: Processing flatbed mode");
                IsFlatbedColorAllowed      = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.Color);
                IsFlatbedGrayscaleAllowed  = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.Grayscale);
                IsFlatbedMonochromeAllowed = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.Monochrome);
                IsFlatbedAutoColorAllowed  = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.AutoColor);

                if (!IsFlatbedColorAllowed && !IsFlatbedGrayscaleAllowed && !IsFlatbedMonochromeAllowed && !IsFlatbedAutoColorAllowed)
                {
                    // no color mode allowed, source mode is invalid
                    IsFlatbedAllowed = false;
                    LogService.Log.Warning("DiscoveredScanner: No color mode for flatbed allowed, invalid source mode");
                }
                else
                {
                    LogService.Log.Information("DiscoveredScanner: Flatbed supports at least one color mode");

                    try
                    {
                        IsFlatbedPreviewAllowed = device.IsPreviewSupported(ImageScannerScanSource.Flatbed);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine preview support for flatbed.");
                        throw;
                    }

                    try
                    {
                        IsFlatbedAutoCropSingleRegionAllowed = device.FlatbedConfiguration
                                                               .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.SingleRegion);
                        IsFlatbedAutoCropMultiRegionAllowed = device.FlatbedConfiguration
                                                              .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.MultipleRegion);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine auto crop support for flatbed.");
                        throw;
                    }

                    FlatbedResolutions = GenerateResolutions(device.FlatbedConfiguration);
                    LogService.Log.Information("Generated {@Resolutions} for flatbed.", FlatbedResolutions);

                    FlatbedFormats = GenerateFormats(device.FlatbedConfiguration);
                    LogService.Log.Information("Generated {@Formats} for feeder.", FlatbedFormats);

                    try
                    {
                        if (device.FlatbedConfiguration.BrightnessStep != 0)
                        {
                            FlatbedBrightnessConfig = GenerateBrightnessConfig(device.FlatbedConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine BrightnessConfig for flatbed.");
                        throw;
                    }

                    try
                    {
                        if (device.FlatbedConfiguration.ContrastStep != 0)
                        {
                            FlatbedContrastConfig = GenerateContrastConfig(device.FlatbedConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine ContrastConfig for flatbed.");
                        throw;
                    }
                }
            }

            // feeder mode
            if (IsFeederAllowed)
            {
                LogService.Log.Information("DiscoveredScanner: Processing feeder mode");
                IsFeederColorAllowed      = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Color);
                IsFeederGrayscaleAllowed  = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Grayscale);
                IsFeederMonochromeAllowed = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Monochrome);
                IsFeederAutoColorAllowed  = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.AutoColor);

                if (!IsFeederColorAllowed && !IsFeederGrayscaleAllowed && !IsFeederMonochromeAllowed && !IsFeederAutoColorAllowed)
                {
                    // no color mode allowed, source mode is invalid
                    IsFeederAllowed = false;
                    LogService.Log.Warning("DiscoveredScanner: No color mode for feeder allowed, invalid source mode");
                }
                else
                {
                    LogService.Log.Information("DiscoveredScanner: Feeder supports at least one color mode");

                    try
                    {
                        IsFeederDuplexAllowed = device.FeederConfiguration.CanScanDuplex;
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine duplex support for feeder.");
                        throw;
                    }

                    try
                    {
                        IsFeederPreviewAllowed = device.IsPreviewSupported(ImageScannerScanSource.Feeder);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine preview support for feeder.");
                        throw;
                    }

                    try
                    {
                        IsFeederAutoCropSingleRegionAllowed = device.FeederConfiguration
                                                              .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.SingleRegion);
                        IsFeederAutoCropMultiRegionAllowed = device.FeederConfiguration
                                                             .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.MultipleRegion);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine auto crop support for feeder.");
                        throw;
                    }

                    FeederResolutions = GenerateResolutions(device.FeederConfiguration);
                    LogService.Log.Information("Generated {@Resolutions} for feeder.", FeederResolutions);

                    FeederFormats = GenerateFormats(device.FeederConfiguration);
                    LogService.Log.Information("Generated {@Formats} for feeder.", FeederFormats);

                    try
                    {
                        if (device.FeederConfiguration.BrightnessStep != 0)
                        {
                            FeederBrightnessConfig = GenerateBrightnessConfig(device.FeederConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine BrightnessConfig for feeder.");
                        throw;
                    }

                    try
                    {
                        if (device.FeederConfiguration.ContrastStep != 0)
                        {
                            FeederContrastConfig = GenerateContrastConfig(device.FeederConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine ContrastConfig for feeder.");
                        throw;
                    }
                }
            }

            if (!IsAutoAllowed && !IsFlatbedAllowed && !IsFeederAllowed)
            {
                // no source mode allowed, scanner is invalid and useless
                throw new ArgumentException("Scanner doesn't support any source mode and can't be used.");
            }

            LogService.Log.Information("Created {@DiscoveredScanner}", this);
        }
Esempio n. 8
0
        /// <summary>
        /// Scans all the images from Feeder source of the scanner
        /// The scanning of the image is allowed only if the selected scanner has Feeder source
        /// </summary>
        /// <param name="deviceId">scanner device id</param>
        /// <param name="folder">the folder that receives the scanned files</param>
        public async void ScanToFolder(string deviceId, StorageFolder folder)
        {
            try
            {
                // Get the scanner object for this device id
                ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId);

                // Check to see if the use has already cancelled the scenario
                if (ModelDataContext.ScenarioRunning)
                {
                    if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Feeder))
                    {
                        // Update Feeder Configuration
                        // Set the scan file format to PNG, if available, if not to DIB
                        if (myScanner.FeederConfiguration.IsFormatSupported(ImageScannerFormat.Png))
                        {
                            myScanner.FeederConfiguration.Format = ImageScannerFormat.Png;
                        }
                        else
                        {
                            myScanner.FeederConfiguration.Format = ImageScannerFormat.DeviceIndependentBitmap;
                        }
                        // Set the color mode to Grayscale, if available
                        if (myScanner.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Grayscale))
                        {
                            myScanner.FeederConfiguration.ColorMode = ImageScannerColorMode.Grayscale;
                        }
                        // Set feeder to scan duplex
                        myScanner.FeederConfiguration.Duplex = myScanner.FeederConfiguration.CanScanDuplex;
                        // Set MaxNumberOfPages to zero to scanning all the pages that are present in the feeder
                        myScanner.FeederConfiguration.MaxNumberOfPages = 0;

                        rootPage.NotifyUser("Scanning", NotifyType.StatusMessage);

                        var progress = new Progress <UInt32>(ScanProgress);
                        cancellationToken = new CancellationTokenSource();
                        // Scan API call to start scanning from the Feeder source of the scanner.
                        var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Feeder, folder).AsTask(cancellationToken.Token, progress);

                        ModelDataContext.ScenarioRunning = false;
                        if (result.ScannedFiles.Count > 0)
                        {
                            Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage);
                            if (result.ScannedFiles.Count > 1)
                            {
                                Utils.UpdateFileListData(result.ScannedFiles, ModelDataContext);
                            }
                        }
                        else
                        {
                            rootPage.NotifyUser("There are no files scanned from the Feeder.", NotifyType.ErrorMessage);
                        }
                    }
                    else
                    {
                        ModelDataContext.ScenarioRunning = false;
                        rootPage.NotifyUser("The selected scanner does not report to be equipped with a Feeder.", NotifyType.ErrorMessage);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Utils.DisplayScanCancelationMessage();
            }
            catch (Exception ex)
            {
                Utils.OnScenarioException(ex, ModelDataContext);
            }
        }