Exemplo n.º 1
0
 private void _twain32_AcquireError(object sender, Twain32.AcquireErrorEventArgs e)
 {
     if (MessageBox.Show(e.Exception.Message, "Error!", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
     {
         _twain32?.CloseDSM();
         _twain32?.CloseDataSource();
         _twain32.Dispose();
         Environment.ExitCode = (int)ExitCodes.ExitCode.ERROR_NOT_ENOUGH_MEMORY;
         this.Close();
     }
 }
Exemplo n.º 2
0
        private void _scannersListPreview_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            try
            {
                _twain32?.Dispose();
                _twain32 = new Twain32
                {
                    ShowUI         = true,
                    IsTwain2Enable = true
                };

                _twain32.OpenDSM();
                _twain32.SourceIndex = Scanners.IndexOf(SelectedScanner);
                _twain32.OpenDataSource();

                _twain32.EndXfer          += _twain32_EndXfer;
                _twain32.AcquireCompleted += _twain32_AcquireCompleted;
                _twain32.AcquireError     += _twain32_AcquireError;
                _twain32.MemXferEvent     += _twain32_MemXferEvent;

                _twain32.Acquire();

                if (_scannedImage != null)
                {
                    SaveImage();
                }

                Environment.ExitCode = (int)ExitCodes.ExitCode.SUCCESS;

                CustomMessageBox.Show($"Save photo: {Path.GetFileName(_filePath)}\n{_destinationPath}", "Succes", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                var messagebox = CustomMessageBox.Show(ex.Message, "Scanner Error!", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error);
                if (messagebox == System.Windows.Forms.DialogResult.Yes)
                {
                    Environment.ExitCode = (int)ExitCodes.ExitCode.ERROR_DEVICE_UNREACHABLE;
                }
            }
            finally
            {
                _twain32?.CloseDSM();
                _twain32?.CloseDataSource();
                _twain32.Dispose();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                this.Close();
            }
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     try
     {
         if (twain != null)
         {
             twain.CloseDataSource();
             twain.CloseDSM();
             twain.Dispose();
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
 }
Exemplo n.º 4
0
        public IEnumerable <HWDeviceDesciption> GetDevices()
        {
            var twain       = new Twain32();
            var isDsmOpened = false;

            try
            {
                //twain.OpenDataSource();
                isDsmOpened = twain.OpenDSM();
                if (twain.IsTwain2Supported)
                {
                    twain.IsTwain2Enable = true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            if (isDsmOpened)
            {
                for (int i = 0; i < twain.SourcesCount; i++)
                {
                    yield return(new HWDeviceDesciption
                    {
                        Device = DeviceType.Scanner,
                        Name = twain.GetSourceProductName(i),
                        DeviceId = i.ToString()
                    });
                }
            }

            if (twain != null)
            {
                twain.CloseDataSource();
                twain.CloseDSM();
                twain.Dispose();
            }

            yield break;
        }
Exemplo n.º 5
0
        private void LoadParametes()
        {
            try
            {
                _twain32 = new Twain32
                {
                    ShowUI         = true,
                    IsTwain2Enable = true
                };
                _twain32.OpenDSM();

                #region GetScanners

                for (int i = 0; i < _twain32.SourcesCount; i++)
                {
                    _scanners.Add(_twain32.GetSourceProductName(i));
                }
                #endregion GetScanners

                if (Scanners.Count > 0)
                {
                    SelectedScanner = Scanners.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                var messagebox = CustomMessageBox.Show(ex.Message, "Error!", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error);
                if (messagebox == System.Windows.Forms.DialogResult.Yes)
                {
                    _twain32?.CloseDSM();
                    _twain32?.CloseDataSource();
                    _twain32.Dispose();
                    Environment.ExitCode = (int)ExitCodes.ExitCode.ERROR_DEVICE_UNREACHABLE;
                    this.Close();
                }
            }
        }
Exemplo n.º 6
0
 public void Dispose()
 {
     _twain32?.Dispose();
 }
Exemplo n.º 7
0
 public void Close()
 {
     logger.Debug("Close Scanworks");
     _twain32.Dispose();
 }
Exemplo n.º 8
0
 private void MTwain_AcquireError(object sender, Twain32.AcquireErrorEventArgs e)
 {
     mTwain.Dispose();
 }