/// <summary> /// Perform several API calls and provide default handling of exceptions. /// </summary> /// <param name="op">Operation with API calls.</param> public static void HandleApiExceptions(SaveApiCall op) { Stopwatch watch = new Stopwatch(); watch.Start(); EventArgsOperationResult eventArgs = new EventArgsOperationResult(); try { op(); eventArgs.Result = new PsaException(Result.Success, ""); } catch (PsaException ex) { eventArgs.Result = ex; } catch (Desko.Mrz.MrzException ex) { eventArgs.Result = new PsaException(Result.Fail, "MRZ error (" + ex.Result.ToString() + "):" + ex.Message); } watch.Stop(); eventArgs.ElapsedMilliseconds = watch.ElapsedMilliseconds; if (OnOperationResultAvailable != null) { OnOperationResultAvailable(null, eventArgs); } }
public void onOperationResult(object sender, EventArgsOperationResult eventArgs) { if (eventArgs.Result.Result == Result.Success) { stateLabelLastResult.State = LabelState.Good; labelLastResultMessage.Text = null; } else { stateLabelLastResult.State = LabelState.Bad; stateLabelLastResult.Text = eventArgs.Result.Result.ToString(); labelLastResultMessage.Text = eventArgs.Result.Message; logTextControl.AppendTicksLine("Operation failed: " + eventArgs.Result.Result.ToString() + " " + eventArgs.Result.Message); } }