DeviceSupportsDuplex() public static method

public static DeviceSupportsDuplex ( Device device ) : bool
device Device
return bool
Beispiel #1
0
 protected override IEnumerable <ScannedImage> ScanInternal()
 {
     using (var eventLoop = new WiaBackgroundEventLoop(ScanProfile, ScanDevice, threadFactory))
     {
         bool supportsFeeder = eventLoop.GetSync(wia => WiaApi.DeviceSupportsFeeder(wia.Device));
         if (ScanProfile.PaperSource != ScanSource.Glass && !supportsFeeder)
         {
             throw new NoFeederSupportException();
         }
         bool supportsDuplex = eventLoop.GetSync(wia => WiaApi.DeviceSupportsDuplex(wia.Device));
         if (ScanProfile.PaperSource == ScanSource.Duplex && !supportsDuplex)
         {
             throw new NoDuplexSupportException();
         }
         int  pageNumber = 1;
         int  retryCount = 0;
         bool retry      = false;
         bool cancel     = false;
         do
         {
             ScannedImage image;
             try
             {
                 if (pageNumber > 1 && ScanProfile.WiaDelayBetweenScans)
                 {
                     int delay = (int)(ScanProfile.WiaDelayBetweenScansSeconds.Clamp(0, 30) * 1000);
                     Thread.Sleep(delay);
                 }
                 image = TransferImage(eventLoop, pageNumber, out cancel);
                 pageNumber++;
                 retryCount = 0;
                 retry      = false;
             }
             catch (ScanDriverException e)
             {
                 if (ScanProfile.WiaRetryOnFailure && e.InnerException is COMException &&
                     (uint)((COMException)e.InnerException).ErrorCode == 0x80004005 && retryCount < MAX_RETRIES)
                 {
                     Thread.Sleep(1000);
                     retryCount += 1;
                     retry       = true;
                     continue;
                 }
                 throw;
             }
             catch (Exception e)
             {
                 throw new ScanDriverUnknownException(e);
             }
             if (image != null)
             {
                 yield return(image);
             }
         } while (retry || (!cancel && ScanProfile.PaperSource != ScanSource.Glass));
     }
 }
Beispiel #2
0
        protected override async Task ScanInternal(ScannedImageSource.Concrete source)
        {
            using (var eventLoop = new WiaBackgroundEventLoop(ScanProfile, ScanDevice))
            {
                bool supportsFeeder = eventLoop.GetSync(wia => WiaApi.DeviceSupportsFeeder(wia.Device));
                if (ScanProfile.PaperSource != ScanSource.Glass && !supportsFeeder)
                {
                    throw new NoFeederSupportException();
                }
                bool supportsDuplex = eventLoop.GetSync(wia => WiaApi.DeviceSupportsDuplex(wia.Device));
                if (ScanProfile.PaperSource == ScanSource.Duplex && !supportsDuplex)
                {
                    throw new NoDuplexSupportException();
                }
                int  pageNumber = 1;
                int  retryCount = 0;
                bool retry      = false;
                bool done       = false;
                do
                {
                    ScannedImage image;
                    try
                    {
                        if (pageNumber > 1 && ScanProfile.WiaDelayBetweenScans)
                        {
                            int delay = (int)(ScanProfile.WiaDelayBetweenScansSeconds.Clamp(0, 30) * 1000);
                            Thread.Sleep(delay);
                        }
                        (image, done) = await TransferImage(eventLoop, pageNumber);

                        pageNumber++;
                        retryCount = 0;
                        retry      = false;
                    }
                    catch (ScanDriverException e)
                    {
                        if (ScanProfile.WiaRetryOnFailure && e.InnerException is COMException comError &&
                            (uint)comError.ErrorCode == 0x80004005 && retryCount < MAX_RETRIES)
                        {
                            Thread.Sleep(1000);
                            retryCount += 1;
                            retry       = true;
                            continue;
                        }
                        throw;
                    }
                    if (image != null)
                    {
                        source.Put(image);
                    }
                } while (!CancelToken.IsCancellationRequested && (retry || !done && ScanProfile.PaperSource != ScanSource.Glass));
            }
        }
Beispiel #3
0
 protected override IEnumerable <ScannedImage> ScanInternal()
 {
     using (var eventLoop = new WiaBackgroundEventLoop(ScanProfile, ScanDevice, threadFactory))
     {
         bool supportsFeeder = eventLoop.GetSync(wia => WiaApi.DeviceSupportsFeeder(wia.Device));
         if (ScanProfile.PaperSource != ScanSource.Glass && !supportsFeeder)
         {
             throw new NoFeederSupportException();
         }
         bool supportsDuplex = eventLoop.GetSync(wia => WiaApi.DeviceSupportsDuplex(wia.Device));
         if (ScanProfile.PaperSource == ScanSource.Duplex && !supportsDuplex)
         {
             throw new NoDuplexSupportException();
         }
         int  pageNumber = 1;
         int  retryCount = 0;
         bool retry      = false;
         bool cancel     = false;
         do
         {
             ScannedImage image;
             try
             {
                 image = TransferImage(eventLoop, pageNumber, out cancel);
                 pageNumber++;
                 Debug.WriteLine("Succeeded with retry count {0}", retryCount);
                 retryCount = 0;
                 retry      = false;
             }
             catch (ScanDriverException e)
             {
                 if (e.InnerException is COMException && (uint)((COMException)e.InnerException).ErrorCode == 0x80004005 && retryCount < 10)
                 {
                     Thread.Sleep(1000);
                     retryCount += 1;
                     Debug.WriteLine("Retrying {0}", retryCount);
                     retry = true;
                     continue;
                 }
                 throw;
             }
             catch (Exception e)
             {
                 throw new ScanDriverUnknownException(e);
             }
             if (image != null)
             {
                 yield return(image);
             }
         } while (retry || (!cancel && ScanProfile.PaperSource != ScanSource.Glass));
     }
 }
Beispiel #4
0
 protected override IEnumerable <ScannedImage> ScanInternal()
 {
     using (var eventLoop = new WiaBackgroundEventLoop(ScanProfile, ScanDevice, threadFactory))
     {
         bool supportsFeeder = eventLoop.GetSync(wia => WiaApi.DeviceSupportsFeeder(wia.Device));
         if (ScanProfile.PaperSource != ScanSource.Glass && !supportsFeeder)
         {
             throw new NoFeederSupportException();
         }
         bool supportsDuplex = eventLoop.GetSync(wia => WiaApi.DeviceSupportsDuplex(wia.Device));
         if (ScanProfile.PaperSource == ScanSource.Duplex && !supportsDuplex)
         {
             throw new NoDuplexSupportException();
         }
         int  pageNumber = 1;
         bool cancel;
         do
         {
             ScannedImage image;
             try
             {
                 image = TransferImage(eventLoop, pageNumber++, out cancel);
             }
             catch (ScanDriverException)
             {
                 throw;
             }
             catch (Exception e)
             {
                 throw new ScanDriverUnknownException(e);
             }
             if (image != null)
             {
                 yield return(image);
             }
         } while (!cancel && ScanProfile.PaperSource != ScanSource.Glass);
     }
 }