Пример #1
0
        public void PerformScan(ExtendedScanSettings scanSettings, IWin32Window dialogParent, IScanReceiver scanReceiver)
        {
            var driver = driverFactory.Create(scanSettings.DriverName);

            driver.DialogParent = dialogParent;
            driver.ScanSettings = scanSettings;
            try
            {
                if (scanSettings.Device == null)
                {
                    // The profile has no device specified, so prompt the user to choose one
                    var device = driver.PromptForDevice();
                    if (device == null)
                    {
                        // User cancelled
                        return;
                    }
                    driver.ScanDevice = device;
                }
                else
                {
                    // The profile has a device specified, so use it
                    driver.ScanDevice = scanSettings.Device;
                }

                foreach (IScannedImage scannedImage in driver.Scan())
                {
                    scanReceiver.ReceiveScannedImage(scannedImage);
                    Application.DoEvents();
                }
            }
            catch (ScanDriverException e)
            {
                if (e is ScanDriverUnknownException)
                {
                    Log.ErrorException(e.Message, e.InnerException);
                }
                errorOutput.DisplayError(e.Message);
            }
        }
Пример #2
0
        public void PerformScan(ExtendedScanSettings scanSettings, IWin32Window dialogParent, IScanReceiver scanReceiver)
        {
            var driver = driverFactory.Create(scanSettings.DriverName);
            driver.DialogParent = dialogParent;
            driver.ScanSettings = scanSettings;
            try
            {
                if (scanSettings.Device == null)
                {
                    // The profile has no device specified, so prompt the user to choose one
                    var device = driver.PromptForDevice();
                    if (device == null)
                    {
                        // User cancelled
                        return;
                    }
                    driver.ScanDevice = device;
                }
                else
                {
                    // The profile has a device specified, so use it
                    driver.ScanDevice = scanSettings.Device;
                }

                foreach (IScannedImage scannedImage in driver.Scan())
                {
                    scanReceiver.ReceiveScannedImage(scannedImage);
                    Application.DoEvents();
                }
            }
            catch (ScanDriverException e)
            {
                if (e is ScanDriverUnknownException)
                {
                    Log.ErrorException(e.Message, e.InnerException);
                }
                errorOutput.DisplayError(e.Message);
            }
        }
Пример #3
0
        private void PerformScan(ExtendedScanSettings profile)
        {
            OutputVerbose(ConsoleResources.BeginningScan);

            IWin32Window parentWindow = new Form { Visible = false };
            totalPagesScanned = 0;
            foreach (int i in Enumerable.Range(1, options.Number))
            {
                if (options.Delay > 0)
                {
                    OutputVerbose(ConsoleResources.Waiting, options.Delay);
                    Thread.Sleep(options.Delay);
                }
                OutputVerbose(ConsoleResources.StartingScan, i, options.Number);
                pagesScanned = 0;
                scanPerformer.PerformScan(profile, parentWindow, this);
                OutputVerbose(ConsoleResources.PagesScanned, pagesScanned);
            }
        }
Пример #4
0
        private void SaveSettings()
        {
            ScanPageSize pageSize;
            PageDimensions customPageSize = null;
            if (cmbPage.SelectedIndex > (int)ScanPageSize.Custom)
            {
                pageSize = ScanPageSize.Custom;
                customPageSize = (PageDimensions)cmbPage.SelectedItem;
            }
            else if (cmbPage.SelectedIndex == (int)ScanPageSize.Custom)
            {
                throw new InvalidOperationException("Custom page size should never be selected when saving");
            }
            else
            {
                pageSize = (ScanPageSize)cmbPage.SelectedIndex;
            }
            ScanSettings = new ExtendedScanSettings
            {
                Version = ExtendedScanSettings.CURRENT_VERSION,

                Device = CurrentDevice,
                IsDefault = isDefault,
                DriverName = DeviceDriverName,
                DisplayName = txtName.Text,
                IconID = iconID,
                MaxQuality = cbHighQuality.Checked,
                UseNativeUI = rdbNative.Checked,

                AfterScanScale = (ScanScale)cmbScale.SelectedIndex,
                BitDepth = (ScanBitDepth)cmbDepth.SelectedIndex,
                Brightness = trBrightness.Value,
                Contrast = trContrast.Value,
                PageAlign = (ScanHorizontalAlign)cmbAlign.SelectedIndex,
                PageSize = pageSize,
                CustomPageSize = customPageSize,
                Resolution = (ScanDpi)cmbResolution.SelectedIndex,
                PaperSource = (ScanSource)cmbSource.SelectedIndex
            };
        }
Пример #5
0
 private bool GetProfile(out ExtendedScanSettings profile)
 {
     try
     {
         if (options.ProfileName == null)
         {
             // If no profile is specified, use the default (if there is one)
             profile = profileManager.Profiles.Single(x => x.IsDefault);
         }
         else
         {
             // Use the profile with the specified name (case-sensitive)
             profile = profileManager.Profiles.FirstOrDefault(x => x.DisplayName == options.ProfileName);
             if (profile == null)
             {
                 // If none found, try case-insensitive
                 profile = profileManager.Profiles.First(x => x.DisplayName.ToLower() == options.ProfileName.ToLower());
             }
         }
     }
     catch (InvalidOperationException)
     {
         errorOutput.DisplayError(ConsoleResources.ProfileUnavailableOrAmbiguous);
         profile = null;
         return false;
     }
     return true;
 }