mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 15:26:55 +03:00
Remove ScanController.ScanError event
This always happens in concert with the ScanEnd event so merging them is a simplification.
This commit is contained in:
parent
21a9cabe95
commit
84ee5380db
@ -65,18 +65,16 @@ internal class ScanPerformer : IScanPerformer
|
||||
_scanBridgeFactory);
|
||||
var op = new ScanOperation(options);
|
||||
|
||||
Exception? error = null;
|
||||
controller.PageStart += (sender, args) => op.NextPage(args.PageNumber);
|
||||
controller.ScanEnd += (sender, args) =>
|
||||
{
|
||||
// Close the progress window before showing the error dialog
|
||||
op.Completed();
|
||||
if (error != null)
|
||||
if (args.Error != null)
|
||||
{
|
||||
HandleError(error);
|
||||
HandleError(args.Error);
|
||||
}
|
||||
};
|
||||
controller.ScanError += (sender, args) => error = args.Exception;
|
||||
controller.PropagateErrors = false;
|
||||
TranslateProgress(controller, op);
|
||||
|
||||
|
@ -20,23 +20,21 @@ internal class ScanJob : IEsclScanJob
|
||||
private readonly TaskCompletionSource<bool> _completedTcs = new();
|
||||
private readonly List<ProcessedImage> _pdfImages = [];
|
||||
private Action<StatusTransition>? _callback;
|
||||
private bool _hasError;
|
||||
|
||||
public ScanJob(ScanningContext scanningContext, ScanController controller, ScanDevice device,
|
||||
EsclScanSettings settings)
|
||||
{
|
||||
_scanningContext = scanningContext;
|
||||
_controller = controller;
|
||||
_controller.ScanEnd += (_, _) =>
|
||||
_controller.ScanEnd += (_, args) =>
|
||||
{
|
||||
_callback?.Invoke(StatusTransition.DeviceIdle);
|
||||
if (_hasError)
|
||||
if (args.HasError)
|
||||
{
|
||||
_callback?.Invoke(StatusTransition.AbortJob);
|
||||
}
|
||||
_completedTcs.TrySetResult(!_hasError);
|
||||
_completedTcs.TrySetResult(!args.HasError);
|
||||
};
|
||||
_controller.ScanError += (_, _) => { _hasError = true; };
|
||||
var options = new ScanOptions
|
||||
{
|
||||
Device = device,
|
||||
|
@ -130,9 +130,9 @@ public class ScanController
|
||||
options = _scanOptionsValidator.ValidateAll(options, _scanningContext, true);
|
||||
int pageNumber = 0;
|
||||
|
||||
Exception? scanError = null;
|
||||
void ScanStartCallback() => ScanStart?.Invoke(this, EventArgs.Empty);
|
||||
void ScanEndCallback() => ScanEnd?.Invoke(this, EventArgs.Empty);
|
||||
void ScanErrorCallback(Exception ex) => ScanError?.Invoke(this, new ScanErrorEventArgs(ex));
|
||||
void ScanEndCallback() => ScanEnd?.Invoke(this, new ScanEndEventArgs(scanError));
|
||||
void PageStartCallback() => PageStart?.Invoke(this, new PageStartEventArgs(++pageNumber));
|
||||
|
||||
void PageProgressCallback(double progress) =>
|
||||
@ -156,7 +156,7 @@ public class ScanController
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ScanErrorCallback(ex);
|
||||
scanError = ex;
|
||||
if (PropagateErrors)
|
||||
{
|
||||
throw;
|
||||
@ -181,15 +181,10 @@ public class ScanController
|
||||
public event EventHandler? ScanStart;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a Scan operation has completed.
|
||||
/// Occurs when a Scan operation has completed. If the scan ends due to an error, the Error property will be set on
|
||||
/// the event args. For more detailed diagnostics, set ScanningContext.Logger.
|
||||
/// </summary>
|
||||
public event EventHandler? ScanEnd;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a fatal error happens during a Scan operation. For more detailed diagnostics, set
|
||||
/// ScanningContext.Logger.
|
||||
/// </summary>
|
||||
public event EventHandler<ScanErrorEventArgs>? ScanError;
|
||||
public event EventHandler<ScanEndEventArgs>? ScanEnd;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when scanning starts for a page. This can be called multiple times during a single Scan operation if it
|
||||
|
16
NAPS2.Sdk/Scan/ScanEndEventArgs.cs
Normal file
16
NAPS2.Sdk/Scan/ScanEndEventArgs.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace NAPS2.Scan;
|
||||
|
||||
public class ScanEndEventArgs : EventArgs
|
||||
{
|
||||
public ScanEndEventArgs(Exception? error = null)
|
||||
{
|
||||
Error = error;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the exception that ended the scan, if any.
|
||||
/// </summary>
|
||||
public Exception? Error { get; }
|
||||
|
||||
public bool HasError => Error != null;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
namespace NAPS2.Scan;
|
||||
|
||||
public class ScanErrorEventArgs : EventArgs
|
||||
{
|
||||
public ScanErrorEventArgs(Exception exception)
|
||||
{
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the exception that occurred.
|
||||
/// </summary>
|
||||
public Exception Exception { get; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user