public DirectProfileTransfer(ScanProfile profile)
        {
            ProcessID = Process.GetCurrentProcess().Id;
            ScanProfile = profile.Clone();

            Locked = ScanProfile.IsLocked;

            ScanProfile.IsDefault = false;
            ScanProfile.IsLocked = false;
            ScanProfile.IsDeviceLocked = false;
        }
Beispiel #2
0
        public async Task PerformScan(ScanProfile scanProfile, ScanParams scanParams, IWin32Window dialogParent, ISaveNotify notify,
                                      Action <ScannedImage> imageCallback, CancellationToken cancelToken = default)
        {
            var driver = driverFactory.Create(scanProfile.DriverName);

            driver.DialogParent = dialogParent;
            driver.ScanProfile  = scanProfile;
            driver.ScanParams   = scanParams;
            driver.CancelToken  = cancelToken;
            try
            {
                if (scanProfile.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;
                    }
                    if (appConfigManager.Config.AlwaysRememberDevice)
                    {
                        scanProfile.Device = device;
                        profileManager.Save();
                    }
                    driver.ScanDevice = device;
                }
                else
                {
                    // The profile has a device specified, so use it
                    driver.ScanDevice = scanProfile.Device;
                }

                // Start the scan
                int imageCount = 0;
                var source     = driver.Scan().Then(img => imageCount++);

                bool doAutoSave = !scanParams.NoAutoSave && !appConfigManager.Config.DisableAutoSave && scanProfile.EnableAutoSave && scanProfile.AutoSaveSettings != null;
                if (doAutoSave)
                {
                    if (scanProfile.AutoSaveSettings.ClearImagesAfterSaving)
                    {
                        // Auto save without piping images
                        var images = await source.ToList();

                        if (await autoSave.Save(scanProfile.AutoSaveSettings, images, notify))
                        {
                            foreach (ScannedImage img in images)
                            {
                                img.Dispose();
                            }
                        }
                        else
                        {
                            // Fallback in case auto save failed; pipe all the images back at once
                            foreach (ScannedImage img in images)
                            {
                                imageCallback(img);
                            }
                        }
                    }
                    else
                    {
                        // Basic auto save, so keep track of images as we pipe them and try to auto save afterwards
                        var images = new List <ScannedImage>();
                        await source.ForEach(scannedImage =>
                        {
                            imageCallback(scannedImage);
                            images.Add(scannedImage);
                        });

                        await autoSave.Save(scanProfile.AutoSaveSettings, images, notify);
                    }
                }
                else
                {
                    // No auto save, so just pipe images back as we get them
                    await source.ForEach(imageCallback);
                }

                if (imageCount > 0)
                {
                    Log.Event(EventType.Scan, new Event
                    {
                        Name        = MiscResources.Scan,
                        Pages       = imageCount,
                        DeviceName  = scanProfile.Device?.Name,
                        ProfileName = scanProfile.DisplayName,
                        BitDepth    = scanProfile.BitDepth.Description()
                    });
                }
            }
            catch (ScanDriverException e)
            {
                if (e is ScanDriverUnknownException)
                {
                    Log.ErrorException(e.Message, e.InnerException);
                    errorOutput.DisplayError(e.Message, e);
                }
                else
                {
                    errorOutput.DisplayError(e.Message);
                }
            }
        }
Beispiel #3
0
        public void PerformScan(ScanProfile scanProfile, ScanParams scanParams, IWin32Window dialogParent, ISaveNotify notify, Action <ScannedImage> imageCallback)
        {
            var driver = driverFactory.Create(scanProfile.DriverName);

            driver.DialogParent = dialogParent;
            driver.ScanProfile  = scanProfile;
            driver.ScanParams   = scanParams;
            try
            {
                if (scanProfile.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;
                    }
                    if (appConfigManager.Config.AlwaysRememberDevice)
                    {
                        scanProfile.Device = device;
                        profileManager.Save();
                    }
                    driver.ScanDevice = device;
                }
                else
                {
                    // The profile has a device specified, so use it
                    driver.ScanDevice = scanProfile.Device;
                }

                bool doAutoSave = !scanParams.NoAutoSave && !appConfigManager.Config.DisableAutoSave && scanProfile.EnableAutoSave && scanProfile.AutoSaveSettings != null;
                if (doAutoSave)
                {
                    if (scanProfile.AutoSaveSettings.ClearImagesAfterSaving)
                    {
                        // Auto save without piping images
                        var images = driver.Scan().ToList();
                        if (autoSave.Save(scanProfile.AutoSaveSettings, images, notify))
                        {
                            foreach (ScannedImage img in images)
                            {
                                img.Dispose();
                            }
                        }
                        else
                        {
                            // Fallback in case auto save failed; pipe all the images back at once
                            foreach (ScannedImage img in images)
                            {
                                imageCallback(img);
                            }
                        }
                    }
                    else
                    {
                        // Basic auto save, so keep track of images as we pipe them and try to auto save afterwards
                        var images = new List <ScannedImage>();
                        foreach (ScannedImage scannedImage in driver.Scan())
                        {
                            imageCallback(scannedImage);
                            images.Add(scannedImage);
                        }
                        autoSave.Save(scanProfile.AutoSaveSettings, images, notify);
                    }
                }
                else
                {
                    // No auto save, so just pipe images back as we get them
                    foreach (ScannedImage scannedImage in driver.Scan())
                    {
                        imageCallback(scannedImage);
                    }
                }
            }
            catch (ScanDriverException e)
            {
                if (e is ScanDriverUnknownException)
                {
                    Log.ErrorException(e.Message, e.InnerException);
                    errorOutput.DisplayError(e.Message, e);
                }
                else
                {
                    errorOutput.DisplayError(e.Message);
                }
            }
        }
Beispiel #4
0
        public void PerformScan(ScanProfile scanProfile, ScanParams scanParams, IWin32Window dialogParent, Action<IScannedImage> imageCallback)
        {
            var driver = driverFactory.Create(scanProfile.DriverName);
            driver.DialogParent = dialogParent;
            driver.ScanProfile = scanProfile;
            driver.ScanParams = scanParams;
            try
            {
                if (scanProfile.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 = scanProfile.Device;
                }

                bool doAutoSave = !appConfigManager.Config.DisableAutoSave && scanProfile.EnableAutoSave && scanProfile.AutoSaveSettings != null;
                if (doAutoSave)
                {
                    if (scanProfile.AutoSaveSettings.ClearImagesAfterSaving)
                    {
                        // Auto save without piping images
                        var images = driver.Scan().ToList();
                        if (!autoSave.AutoSave(scanProfile.AutoSaveSettings, images))
                        {
                            // Fallback in case auto save failed; pipe all the images back at once
                            foreach (IScannedImage img in images)
                            {
                                imageCallback(img);
                            }
                        }
                    }
                    else
                    {
                        // Basic auto save, so keep track of images as we pipe them and try to auto save afterwards
                        var images = new List<IScannedImage>();
                        foreach (IScannedImage scannedImage in driver.Scan())
                        {
                            imageCallback(scannedImage);
                            images.Add(scannedImage);
                        }
                        autoSave.AutoSave(scanProfile.AutoSaveSettings, images);
                    }
                }
                else
                {
                    // No auto save, so just pipe images back as we get them
                    foreach (IScannedImage scannedImage in driver.Scan())
                    {
                        imageCallback(scannedImage);
                    }
                }
            }
            catch (ScanDriverException e)
            {
                if (e is ScanDriverUnknownException)
                {
                    Log.ErrorException(e.Message, e.InnerException);
                }
                errorOutput.DisplayError(e.Message);
            }
        }
Beispiel #5
0
 private bool GetProfile(out ScanProfile 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;
 }
Beispiel #6
0
        private void PerformScan(ScanProfile 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, new ScanParams(), parentWindow, ReceiveScannedImage);
                OutputVerbose(ConsoleResources.PagesScanned, pagesScanned);
            }
        }
Beispiel #7
0
 public List<RecoveryIndexImage> TwainScan(int recoveryFileNumber, ScanDevice scanDevice, ScanProfile scanProfile, ScanParams scanParams)
 {
     RecoveryImage.RecoveryFileNumber = recoveryFileNumber;
     return twainWrapper.Scan(ParentForm, true, scanDevice, scanProfile, scanParams).Select(x => x.RecoveryIndexImage).ToList();
 }
Beispiel #8
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;
            }
            if (ScanProfile.DisplayName != null)
            {
                profileNameTracker.RenamingProfile(ScanProfile.DisplayName, txtName.Text);
            }
            scanProfile = new ScanProfile
            {
                Version = ScanProfile.CURRENT_VERSION,

                Device = CurrentDevice,
                IsDefault = isDefault,
                DriverName = DeviceDriverName,
                DisplayName = txtName.Text,
                IconID = iconID,
                MaxQuality = ScanProfile.MaxQuality,
                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,

                EnableAutoSave = cbAutoSave.Checked,
                AutoSaveSettings = ScanProfile.AutoSaveSettings,
                Quality = ScanProfile.Quality,
                BrightnessContrastAfterScan = ScanProfile.BrightnessContrastAfterScan,
                ForcePageSize = ScanProfile.ForcePageSize,
                TwainImpl = ScanProfile.TwainImpl,

                ExcludeBlankPages = ScanProfile.ExcludeBlankPages,
                BlankPageWhiteThreshold = ScanProfile.BlankPageWhiteThreshold,
                BlankPageCoverageThreshold = ScanProfile.BlankPageCoverageThreshold
            };
        }
Beispiel #9
0
        private void PerformScan(ScanProfile profile)
        {
            OutputVerbose(ConsoleResources.BeginningScan);

            bool autoSaveEnabled = !appConfigManager.Config.DisableAutoSave && profile.EnableAutoSave && profile.AutoSaveSettings != null;
            if (options.AutoSave && !autoSaveEnabled)
            {
                errorOutput.DisplayError(ConsoleResources.AutoSaveNotEnabled);
                if (options.OutputPath == null && options.EmailFileName == null)
                {
                    return;
                }
            }

            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, new ScanParams { NoUI = true, NoAutoSave = !options.AutoSave }, parentWindow, null, ReceiveScannedImage);
                OutputVerbose(ConsoleResources.PagesScanned, pagesScanned);
            }
        }
Beispiel #10
0
 private void UpdateValues(ScanProfile scanProfile)
 {
     cbHighQuality.Checked = scanProfile.MaxQuality;
     tbImageQuality.Value = scanProfile.Quality;
     txtImageQuality.Text = scanProfile.Quality.ToString("G");
     cbBrightnessContrastAfterScan.Checked = scanProfile.BrightnessContrastAfterScan;
     cbWiaOffsetWidth.Checked = scanProfile.WiaOffsetWidth;
     cbForcePageSize.Checked = scanProfile.ForcePageSize;
     cbFlipDuplex.Checked = scanProfile.FlipDuplexedPages;
     if (scanProfile.TwainImpl != TwainImpl.X64 || Environment.Is64BitProcess)
     {
         cmbTwainImpl.SelectedIndex = (int) scanProfile.TwainImpl;
     }
     cbExcludeBlankPages.Checked = scanProfile.ExcludeBlankPages;
     tbWhiteThreshold.Value = scanProfile.BlankPageWhiteThreshold;
     txtWhiteThreshold.Text = scanProfile.BlankPageWhiteThreshold.ToString("G");
     tbCoverageThreshold.Value = scanProfile.BlankPageCoverageThreshold;
     txtCoverageThreshold.Text = scanProfile.BlankPageCoverageThreshold.ToString("G");
 }
Beispiel #11
0
        private void SaveSettings()
        {
            if (ScanProfile.IsLocked)
            {
                if (!ScanProfile.IsDeviceLocked)
                {
                    ScanProfile.Device = CurrentDevice;
                }
                return;
            }
            var pageSize = (PageSizeListItem) cmbPage.SelectedItem;
            if (ScanProfile.DisplayName != null)
            {
                profileNameTracker.RenamingProfile(ScanProfile.DisplayName, txtName.Text);
            }
            scanProfile = new ScanProfile
            {
                Version = ScanProfile.CURRENT_VERSION,

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

                AfterScanScale = (ScanScale)cmbScale.SelectedIndex,
                BitDepth = (ScanBitDepth)cmbDepth.SelectedIndex,
                Brightness = trBrightness.Value,
                Contrast = trContrast.Value,
                PageAlign = (ScanHorizontalAlign)cmbAlign.SelectedIndex,
                PageSize = pageSize.Type,
                CustomPageSizeName = pageSize.CustomName,
                CustomPageSize = pageSize.CustomDimens,
                Resolution = (ScanDpi)cmbResolution.SelectedIndex,
                PaperSource = (ScanSource)cmbSource.SelectedIndex,

                EnableAutoSave = cbAutoSave.Checked,
                AutoSaveSettings = ScanProfile.AutoSaveSettings,
                Quality = ScanProfile.Quality,
                BrightnessContrastAfterScan = ScanProfile.BrightnessContrastAfterScan,
                WiaOffsetWidth = ScanProfile.WiaOffsetWidth,
                ForcePageSize = ScanProfile.ForcePageSize,
                FlipDuplexedPages = ScanProfile.FlipDuplexedPages,
                TwainImpl = ScanProfile.TwainImpl,

                ExcludeBlankPages = ScanProfile.ExcludeBlankPages,
                BlankPageWhiteThreshold = ScanProfile.BlankPageWhiteThreshold,
                BlankPageCoverageThreshold = ScanProfile.BlankPageCoverageThreshold
            };
        }
Beispiel #12
0
 private void AddProfile(ScanProfile profile)
 {
     profileManager.Profiles.Add(profile);
     if (profileManager.Profiles.Count == 1)
     {
         profileManager.DefaultProfile = profile;
     }
     UpdateProfiles();
     SelectProfile(x => x == profile);
     profileManager.Save();
 }