Esempio n. 1
0
        // method to do the actual scanning
        public void Scan()
        {
            StatusText = "Сканирование...";
            var scanner = new ScannerService();

            try
            {
                ImageFile file = scanner.Scan();

                if (file != null)
                {
                    var converter = new ScannerImageConverter();

                    _image = converter.ConvertScannedImage(file);
                }
                else
                {
                    _image = null;
                }
                ImageBrush = new ImageBrush(_image)
                {
                    Stretch = Stretch.Uniform
                };
            }
            catch (ScannerException ex)
            {
                // yeah, I know. Showing UI from the VM. Shoot me now.
                MessageBox.Show(ex.Message, "Не удалось выполнить сканирование изображения", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            StatusText = "Готово.";
        }
Esempio n. 2
0
        // method to do the actual scanning
        public void Scan()
        {
            var scanner = new ScannerService();

            try
            {
                ImageFile file = scanner.Scan();

                if (file != null)
                {
                    var converter = new ScannerImageConverter();

                    ScannedImage = converter.ConvertScannedImage(file);
                }
                else
                {
                    ScannedImage = null;
                }
            }
            catch (ScannerException ex)
            {
                // yeah, I know. Showing UI from the VM. Shoot me now.
                MessageBox.Show(ex.Message, "Unable to Scan Image");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Esempio n. 3
0
        public async void Scan()
        {
            _model.VisibilityHeader = Visibility.Hidden;
            var pAsync = await activeWindow.ShowProgressAsync("Status", "Starting...", false, s_without_animation);

            pAsync.SetIndeterminate();
            await Task.Delay(500);

            var scanner = new ScannerService();

            activeWindow.FindChild <WebBrowser>("pdfview").Navigate("about:blank");

            if (File.Exists($"{_model.TempFolder}Preview.pdf"))
            {
                AcrobatProcess();
                await Task.Delay(500);

                File.Delete($"{_model.TempFolder}Preview.pdf");
            }


            var file = await Task <ImageFile> .Factory.StartNew(() => scanner.Scan(pAsync, _model.ColorSetting)).ContinueWith(async(t) =>
            {
                try
                {
                    if (t != null)
                    {
                        var converter           = new ScannerImageConverter(_model.TempFolder);
                        _model.OpenedFileName   = "Preview";
                        _model.FileNameToSave   = _model.OpenedFileName;
                        _model.OpenedFileFolder = _model.TempFolder;
                        _model.ScannedImage     = converter.ConvertScannedImage(t.Result);
                        var saveResult          = converter.SaveOnPDF(_model.ScannedImage as BitmapFrame, pAsync);

                        _model.FullPathOpenedFile = $@"{_model.TempFolder}{_model.OpenedFileName}";
                        await pAsync.CloseAsync();
                        _model.SaveAsEnable     = true;
                        _model.VisibilityHeader = Visibility.Visible;
                        App.Current.Dispatcher.Invoke(() => {
                            activeWindow.FindChild <WebBrowser>("pdfview").Navigate($"{_model.FullPathOpenedFile}.pdf");
                        });
                    }
                    else
                    {
                        _model.ScannedImage = null;
                        _model.SaveAsEnable = false;
                    }
                }
                catch (Exception ex)
                {
                    ControlsErrorState();
                    await pAsync.CloseAsync();
                    ShowErrorMessage(message: ex.Message);
                    _model.ScannedImage     = null;
                    _model.VisibilityHeader = (string.IsNullOrWhiteSpace(_model.OpenedFileName)) ? Visibility.Hidden : Visibility.Visible;
                }
            });
        }
        public void digitalizar()
        {
            var scanner = new ScannerService();

            try
            {
                ImageFile file = scanner.Scan();

                if (file != null)
                {
                    var converter = new ScannerImageConverter();
                    converter.ConvertScannedImage(file);
                    uriImagem = converter.fileName;
                }
                else
                {
                    uriImagem = null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async void ShowScanAndAdd()
        {
            _model.IsMsgVisible = true;
            var scanner = new ScannerService();
            var pAsync  = await activeWindow.ShowProgressAsync("Status", "Starting...", false, s_without_animation);

            pAsync.SetIndeterminate();

            var converter = new ScannerImageConverter(_model.TempFolder);

            switch (_model.AutoAdd)
            {
            case true:
                await Task.Factory.StartNew(async() =>
                {
                    try
                    {
                        var filee = scanner.ScanAll(pAsync, _model.ColorSetting);
                        if (filee.Count == 0)
                        {
                            await pAsync.CloseAsync();
                            return;
                        }

                        converter.SavePDFsOn(filee, pAsync);
                        await pAsync.CloseAsync();
                        _model.IsMsgVisible = false;
                        AcrobatProcess();
                        await Task.Delay(500);

                        pAsync.SetMessage("Adding pages to file...");
                        await Task.Factory.StartNew(() => converter.AddToExistingPDF($@"{_model.TempFolder}Preview.pdf", $@"{_model.TempFolder}{_model.FileNameAdded}.pdf"));
                        App.Current.Dispatcher.Invoke(() => {
                            activeWindow.FindChild <WebBrowser>("pdfview").Navigate($@"{_model.TempFolder}{_model.FileNameAdded}.pdf");
                        });
                        await pAsync.CloseAsync();
                        _model.IsMsgVisible = false;
                    }
                    catch (Exception ex)
                    {
                        await pAsync.CloseAsync();


                        App.Current.Dispatcher.Invoke(() => {
                            ShowErrorMessage(ex.Message);
                        });
                    }
                });

                break;

            case false:
                var file = await Task <ImageFile> .Factory.StartNew(() => scanner.Scan(pAsync, _model.ColorSetting)).ContinueWith(async(t) =>
                {
                    try
                    {
                        if (t != null)
                        {
                            var scannedImage = converter.ConvertScannedImage(t.Result);
                            var saveResult   = converter.SaveOnPDF(scannedImage as BitmapFrame, pAsync);
                            AcrobatProcess();
                            await Task.Delay(500);

                            pAsync.SetMessage("Adding pages to file...");
                            await Task.Factory.StartNew(() => converter.AddToExistingPDF($@"{_model.TempFolder}Preview.pdf", $@"{_model.TempFolder}{_model.FileNameAdded}.pdf"));
                            App.Current.Dispatcher.Invoke(() => {
                                activeWindow.FindChild <WebBrowser>("pdfview").Navigate($@"{_model.TempFolder}{_model.FileNameAdded}.pdf");
                            });

                            await pAsync.CloseAsync();
                            _model.IsMsgVisible = false;
                        }
                        else
                        {
                        }
                    }
                    catch (Exception ex)
                    {
                        await pAsync.CloseAsync();

                        App.Current.Dispatcher.Invoke(() => {
                            ShowErrorMessage(ex.Message);
                        });
                    }
                });

                break;


            default:
                break;
            }

            // _model.IsMsgVisible = false;
        }