Пример #1
0
        private void Import()
        {
            var ofd = new OpenFileDialog
            {
                Multiselect     = true,
                CheckFileExists = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (var fileName in ofd.FileNames.OrderBy(x => x))
                {
                    // TODO: Run in thread, and show a dialog (just like exporting)
                    // Need to provide count somehow (progress callback). count = # files or # pages
                    try
                    {
                        var images = scannedImageImporter.Import(fileName);
                        foreach (var img in images)
                        {
                            imageList.Images.Add(img);
                            AppendThumbnail(img);
                            thumbnailList1.Refresh();
                            changeTracker.HasUnsavedChanges = true;
                            Application.DoEvents();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorException(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)), ex);
                        errorOutput.DisplayError(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)));
                    }
                }
            }
        }
Пример #2
0
        private async Task ImportImages()
        {
            OutputVerbose(ConsoleResources.Importing);

            ConsolePdfPasswordProvider.PasswordToProvide = options.ImportPassword;

            var filePaths = options.ImportPath.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            int i         = 0;

            foreach (var filePath in filePaths)
            {
                i++;
                try
                {
                    var importParams = new ImportParams
                    {
                        Slice            = Slice.Parse(filePath, out string actualPath),
                        DetectPatchCodes = options.SplitPatchT,
                        NoThumbnails     = true
                    };
                    var images = await scannedImageImporter.Import(actualPath, importParams, (j, k) => { }, CancellationToken.None).ToList();

                    scanList.Add(images);
                }
                catch (Exception ex)
                {
                    Log.ErrorException(string.Format(ConsoleResources.ErrorImporting, filePath), ex);
                    errorOutput.DisplayError(string.Format(ConsoleResources.ErrorImporting, filePath));
                    continue;
                }
                OutputVerbose(ConsoleResources.ImportedFile, i, filePaths.Length);
            }
        }
Пример #3
0
        private void ImportImages()
        {
            OutputVerbose(ConsoleResources.Importing);

            ConsolePdfPasswordProvider.PasswordToProvide = options.ImportPassword;

            var filePaths = options.ImportPath.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            int i         = 0;

            foreach (var filePath in filePaths)
            {
                i++;
                try
                {
                    var images = scannedImageImporter.Import(filePath);
                    scannedImages.AddRange(images);
                }
                catch (Exception ex)
                {
                    Log.ErrorException(string.Format(ConsoleResources.ErrorImporting, filePath), ex);
                    errorOutput.DisplayError(string.Format(ConsoleResources.ErrorImporting, filePath));
                    continue;
                }
                OutputVerbose(ConsoleResources.ImportedFile, i, filePaths.Length);
            }
        }
Пример #4
0
        public IEnumerable <ScannedImage> Import(string filePath, ImportParams importParams, Func <int, int, bool> progressCallback)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }
            switch (Path.GetExtension(filePath).ToLowerInvariant())
            {
            case ".pdf":
                return(pdfImporter.Import(filePath, importParams, progressCallback));

            default:
                return(imageImporter.Import(filePath, importParams, progressCallback));
            }
        }
Пример #5
0
        public IEnumerable <IScannedImage> Import(string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }
            switch (Path.GetExtension(filePath).ToLowerInvariant())
            {
            case ".pdf":
                return(pdfImporter.Import(filePath));

            default:
                return(imageImporter.Import(filePath));
            }
        }
Пример #6
0
        public ScannedImageSource Import(string filePath, ImportParams importParams, ProgressHandler progressCallback, CancellationToken cancelToken)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }
            switch (Path.GetExtension(filePath).ToLowerInvariant())
            {
            case ".pdf":
                return(pdfImporter.Import(filePath, importParams, progressCallback, cancelToken));

            default:
                return(imageImporter.Import(filePath, importParams, progressCallback, cancelToken));
            }
        }
Пример #7
0
        public bool Start(List <string> filesToImport, Action <ScannedImage> imageCallback)
        {
            bool oneFile = filesToImport.Count == 1;

            Status = new OperationStatus
            {
                MaxProgress = oneFile ? 0 : filesToImport.Count
            };

            RunAsync(async() =>
            {
                try
                {
                    foreach (var fileName in filesToImport)
                    {
                        try
                        {
                            Status.StatusText = string.Format(MiscResources.ImportingFormat, Path.GetFileName(fileName));
                            InvokeStatusChanged();
                            var imageSrc = scannedImageImporter.Import(fileName, new ImportParams(), oneFile ? OnProgress : new ProgressHandler((j, k) => { }), CancelToken);
                            await imageSrc.ForEach(imageCallback);
                        }
                        catch (Exception ex)
                        {
                            Log.ErrorException(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)), ex);
                            InvokeError(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)), ex);
                        }
                        if (!oneFile)
                        {
                            Status.CurrentProgress++;
                            InvokeStatusChanged();
                        }
                    }
                    return(true);
                }
                finally
                {
                    GC.Collect();
                }
            });
            return(true);
        }
Пример #8
0
 private void Run(IEnumerable <string> filesToImport, Action <ScannedImage> imageCallback, bool oneFile)
 {
     foreach (var fileName in filesToImport)
     {
         try
         {
             Status.StatusText = string.Format(MiscResources.ImportingFormat, Path.GetFileName(fileName));
             InvokeStatusChanged();
             var images = scannedImageImporter.Import(fileName, (i, j) =>
             {
                 if (oneFile)
                 {
                     Status.CurrentProgress = i;
                     Status.MaxProgress     = j;
                     InvokeStatusChanged();
                 }
                 return(!cancel);
             });
             foreach (var img in images)
             {
                 imageCallback(img);
             }
         }
         catch (Exception ex)
         {
             Log.ErrorException(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)), ex);
             InvokeError(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)), ex);
         }
         if (!oneFile)
         {
             Status.CurrentProgress++;
             InvokeStatusChanged();
         }
     }
     Status.Success = true;
 }
Пример #9
0
        private void Run(IEnumerable <string> filesToImport, Action <ScannedImage> imageCallback, bool oneFile)
        {
            foreach (var fileName in filesToImport)
            {
                try
                {
                    Status.StatusText = string.Format(MiscResources.ImportingFormat, Path.GetFileName(fileName));
                    InvokeStatusChanged();
                    var images = scannedImageImporter.Import(fileName, (i, j) =>
                    {
                        if (oneFile)
                        {
                            Status.CurrentProgress = i;
                            Status.MaxProgress     = j;
                            InvokeStatusChanged();
                        }
                        return(!cancel);
                    });

                    ScanProfile profile = profileManager.DefaultProfile;

                    foreach (var img in images)
                    {
                        //Squeeze Barcode Separation
                        if (profile.AutoSaveSettings.Separator == SaveSeparator.Barcode)
                        {
                            IMultipleBarcodeReader multiReader = new BarcodeReader();
                            multiReader.Options.TryHarder = true;
                            if (profile.AutoSaveSettings.BarcodeType != null && profile.AutoSaveSettings.BarcodeType != "")
                            {
                                switch (profile.AutoSaveSettings.BarcodeType)
                                {
                                case "2of5 interleaved":
                                    multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                                    multiReader.Options.PossibleFormats.Add(BarcodeFormat.ITF);
                                    break;

                                case "Code 39":
                                    multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                                    multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_39);
                                    break;

                                case "Code 93":
                                    multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                                    multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_93);
                                    break;

                                case "Code 128":
                                    multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                                    multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_128);
                                    break;

                                case "EAN 8":
                                    multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                                    multiReader.Options.PossibleFormats.Add(BarcodeFormat.EAN_8);
                                    break;

                                case "EAN13":
                                    multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                                    multiReader.Options.PossibleFormats.Add(BarcodeFormat.EAN_13);
                                    break;
                                }
                            }
                            var test          = scannedImageRenderer.Render(img);
                            var barcodeResult = multiReader.DecodeMultiple(test);
                            if (barcodeResult != null)
                            {
                                foreach (var barcode in barcodeResult)
                                {
                                    if (profile.AutoSaveSettings.BarcodeRegEx != "")
                                    {
                                        Regex regex = new Regex(@"^" + profile.AutoSaveSettings.BarcodeRegEx + "$");
                                        Match match = regex.Match(barcode.Text);
                                        if (match.Success)
                                        {
                                            if (barcode.Text != profile.AutoSaveSettings.BarcodeIgnore)
                                            {
                                                img.Barcode = barcode.Text;
                                                System.Diagnostics.Debug.WriteLine(barcode.BarcodeFormat + " = " + barcode.Text);
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        img.Barcode = barcode.Text;
                                        System.Diagnostics.Debug.WriteLine(barcode.BarcodeFormat + " = " + barcode.Text);
                                        break;
                                    }
                                }
                            }
                        }
                        imageCallback(img);
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorException(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)), ex);
                    InvokeError(string.Format(MiscResources.ImportErrorCouldNot, Path.GetFileName(fileName)), ex);
                }
                if (!oneFile)
                {
                    Status.CurrentProgress++;
                    InvokeStatusChanged();
                }
            }
            Status.Success = true;
        }