Exemplo n.º 1
0
Arquivo: Form1.cs Projeto: gas3/twain
        private async void btnScan_Click(object sender, EventArgs e)
        {
            // prepare the scan profile
            if (defaultScanProfile == null)
            {
                defaultScanProfile = new ScanProfile {
                    Version = ScanProfile.CURRENT_VERSION
                };
                defaultScanProfile.DriverName = "twain";

                defaultScanParams = new ScanParams();

                var driver = driverFactory.Create(defaultScanProfile.DriverName);
                driver.ScanProfile = defaultScanProfile;
                driver.ScanParams  = defaultScanParams;
                var deviceList = driver.GetDeviceList();
                if (!deviceList.Any())
                {
                    MessageBox.Show("There is no connected device!");
                    return;
                }
                defaultScanProfile.Device = deviceList[0];
            }

            // perfor scan
            do
            {
                await scanPerformer.PerformScan(defaultScanProfile, defaultScanParams, this, notify, ReceiveScannedImage());
            } while (MessageBox.Show("Would you like to continue?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes);

            SavePDF(imageList.Images);
            imageList.Delete(Enumerable.Range(0, imageList.Images.Count));
        }
Exemplo n.º 2
0
 private void PerformScan()
 {
     if (profileManager.Profiles.Count == 0)
     {
         var editSettingsForm = FormFactory.Create <FEditScanSettings>();
         editSettingsForm.ScanSettings = new ExtendedScanSettings
         {
             Version = ExtendedScanSettings.CURRENT_VERSION
         };
         editSettingsForm.ShowDialog();
         if (!editSettingsForm.Result)
         {
             return;
         }
         profileManager.Profiles.Add(editSettingsForm.ScanSettings);
         profileManager.Save();
         UpdateProfiles();
         lvProfiles.SelectedIndices.Add(0);
     }
     if (SelectedProfile == null)
     {
         MessageBox.Show(MiscResources.SelectProfileBeforeScan, MiscResources.ChooseProfile, MessageBoxButtons.OK,
                         MessageBoxIcon.Warning);
         return;
     }
     profileManager.Save();
     scanPerformer.PerformScan(SelectedProfile, this, ScanReceiver);
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        private async Task ScanDefault()
        {
            if (profileManager.DefaultProfile != null)
            {
                await scanPerformer.PerformScan(profileManager.DefaultProfile, new ScanParams(), this, notify, ReceiveScannedImage());

                Activate();
            }
            else if (profileManager.Profiles.Count == 0)
            {
                await ScanWithNewProfile();
            }
            else
            {
                ShowProfilesForm();
            }
        }
 private async Task DoScan(int scanNumber, List <ScannedImage> scan, int pageNumber)
 {
     await scanPerformer.PerformScan(profile, scanParams, BatchForm, null, image =>
     {
         scan.Add(image);
         CancelToken.ThrowIfCancellationRequested();
         ProgressCallback(scanNumber == -1
             ? string.Format(MiscResources.BatchStatusPage, pageNumber++)
             : string.Format(MiscResources.BatchStatusScanPage, pageNumber++, scanNumber + 1));
     }, CancelToken);
 }
Exemplo n.º 6
0
 private void DoScan(int scanNumber, List <ScannedImage> scan, int pageNumber)
 {
     scanPerformer.PerformScan(profile, scanParams, BatchForm, null, image =>
     {
         scan.Add(image);
         if (!ProgressCallback(scanNumber == -1
             ? string.Format(MiscResources.BatchStatusPage, pageNumber++)
             : string.Format(MiscResources.BatchStatusScanPage, pageNumber++, scanNumber + 1)))
         {
             throw new OperationCanceledException();
         }
     });
 }
Exemplo n.º 7
0
        private void UpdateScanButton()
        {
            // Clean up the dropdown
            while (tsScan.DropDownItems.Count > 1)
            {
                tsScan.DropDownItems.RemoveAt(0);
            }

            // Populate the dropdown
            var defaultProfile = profileManager.DefaultProfile;

            foreach (var profile in profileManager.Profiles)
            {
                var item = new ToolStripMenuItem
                {
                    Text         = profile.DisplayName.Replace("&", "&&"),
                    Image        = profile == defaultProfile ? Icons.accept_small : null,
                    ImageScaling = ToolStripItemImageScaling.None
                };
                item.Click += (sender, args) =>
                {
                    profileManager.DefaultProfile = profile;
                    profileManager.Save();

                    UpdateScanButton();

                    scanPerformer.PerformScan(profile, this, this);
                    Activate();
                };
                tsScan.DropDownItems.Insert(tsScan.DropDownItems.Count - 1, item);
            }

            if (profileManager.Profiles.Any())
            {
                tsScan.DropDownItems.Insert(tsScan.DropDownItems.Count - 1, new ToolStripSeparator());
            }
        }
Exemplo n.º 8
0
        public async Task <int> Scan(ScanProfile scanProfile, ScanParams scanParams)
        {
            if (scanProfile.DriverName == ProxiedScanDriver.DRIVER_NAME)
            {
                scanProfile.DriverName = scanProfile.ProxyDriverName;
            }

            if (scanProfile.TwainImpl == TwainImpl.Legacy)
            {
                scanProfile.TwainImpl = TwainImpl.OldDsm;
            }

            scanProfile.UseNativeUi = false;

            var internalParams = new ScanParams
            {
                DetectPatchCodes   = scanParams.DetectPatchCodes,
                NoUi               = true,
                NoAutoSave         = true,
                DoOcr              = false,
                NoThumbnails       = true,
                SkipPostProcessing = true
            };

            var callback = OperationContext.Current.GetCallbackChannel <IScanCallback>();

            var pages = 0;
            await scanPerformer.PerformScan(scanProfile, internalParams, null, null, image =>
            {
                // TODO: Should stream this
                // TODO: Also should think about avoiding the intermediate filesystem
                using (image)
                {
                    var indexImage          = image.RecoveryIndexImage;
                    var imageBytes          = File.ReadAllBytes(image.RecoveryFilePath);
                    var sanitizedIndexImage = new RecoveryIndexImage
                    {
                        FileName      = Path.GetExtension(indexImage.FileName),
                        TransformList = indexImage.TransformList,
                        BitDepth      = indexImage.BitDepth,
                        HighQuality   = indexImage.HighQuality
                    };
                    callback.ImageReceived(imageBytes, sanitizedIndexImage);
                    pages++;
                }
            }, cancellation.Token);

            return(pages);
        }
        private async Task PerformScan(ScanProfile profile)
        {
            OutputVerbose(ConsoleResources.BeginningScan);

            var 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;
                }
            }

            totalPagesScanned = 0;
            foreach (var 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;
                scanList.Add(new List <ScannedImage>());
                var scanParams = new ScanParams
                {
                    NoUi             = !options.Progress,
                    NoAutoSave       = !options.AutoSave,
                    NoThumbnails     = true,
                    DetectPatchCodes = options.SplitPatchT,
                    DoOcr            = ocrParams?.LanguageCode != null,
                    OcrParams        = ocrParams
                };
                await scanPerformer.PerformScan(profile, scanParams, null, null, ReceiveScannedImage);

                OutputVerbose(ConsoleResources.PagesScanned, pagesScanned);
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        private async void PerformScan()
        {
            if (profileManager.Profiles.Count == 0)
            {
                var editSettingsForm = FormFactory.Create <FEditProfile>();
                editSettingsForm.ScanProfile = new ScanProfile
                {
                    Version = ScanProfile.CURRENT_VERSION
                };
                editSettingsForm.ShowDialog();
                if (!editSettingsForm.Result)
                {
                    return;
                }
                profileManager.Profiles.Add(editSettingsForm.ScanProfile);
                profileManager.DefaultProfile = editSettingsForm.ScanProfile;
                profileManager.Save();
                UpdateProfiles();
                lvProfiles.SelectedIndices.Add(0);
            }
            if (SelectedProfile == null)
            {
                MessageBox.Show(MiscResources.SelectProfileBeforeScan, MiscResources.ChooseProfile, MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }
            if (profileManager.DefaultProfile == null)
            {
                var profile = SelectedProfile;
                profileManager.DefaultProfile = profile;
                UpdateProfiles();
                SelectProfile(x => x == profile);
            }
            profileManager.Save();
            await scanPerformer.PerformScan(SelectedProfile, new ScanParams(), this, null, ImageCallback);

            Activate();
        }