コード例 #1
0
        private static ConnectOperationResult Try(Action action)
        {
            try
            {
                var resilient = new Resilient();
                resilient.ExecuteWithRetry(action);

                return(new ConnectOperationResult());
            }
            catch (CommunicationException communicationException)
            {
                FaultException fe  = null;
                Exception      tmp = communicationException;

                while (tmp != null)
                {
                    fe = tmp as FaultException;
                    if (fe != null)
                    {
                        break;
                    }
                    tmp = tmp.InnerException;
                }

                if (fe != null)
                {
                    return(new ConnectOperationResult(fe, string.Format(Resources.TXT_SERVER_SENT_A_FAULT, fe.CreateMessageFault().Reason.GetMatchingTranslation().Text)));
                }

                return(new ConnectOperationResult(communicationException, string.Format(Resources.TXT_REQUEST_FAIlED_WITH_EXCEPTION, communicationException)));
            }
            catch (TimeoutException timeoutException)
            {
                return(new ConnectOperationResult(timeoutException, Resources.TXT_REQUEST_TIMED_OUT));
            }
            catch (MaxAttemptsReachedException maxAttemptsException)
            {
                return(new ConnectOperationResult(maxAttemptsException.InnerException, string.Format(Resources.TXT_REQUEST_FAILED_WITH_UNEXPECTED_EXCEPTION, maxAttemptsException.InnerException)));
            }
            catch (Exception ex)
            {
                return(new ConnectOperationResult(ex, string.Format(Resources.TXT_REQUEST_FAILED_WITH_UNEXPECTED_EXCEPTION, ex)));
            }
        }
コード例 #2
0
 private void SafelyWithRetry(SmartCardReadOperation operation, Action action)
 {
     try
     {
         Task.Factory.StartNew(() =>
         {
             var resilient = new Resilient(OnProgress);
             resilient.ExecuteWithRetry(action);
         })
         .ContinueWith(t =>
         {
             if (t.IsFaulted)
             {
                 HandleException(operation, t.Exception);
             }
         });
     }
     catch (Exception ex)
     {
         HandleException(operation, ex);
     }
 }