private void TryAction(ActionInfo actionInfo)
 {
     if (actionInfo == null) return;
     var success = false;
     try
     {
         _logger.DebugFormat("Executing action {0}.", actionInfo.Name);
         success = actionInfo.Action(actionInfo.Data);
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("Exception raised when executing action {0}.", actionInfo.Name), ex);
     }
     finally
     {
         if (success)
         {
             _logger.DebugFormat("Executed action {0}.", actionInfo.Name);
             if (actionInfo.Next != null)
             {
                 TryAction(actionInfo.Next);
             }
         }
         else
         {
             _actionQueue.Add(actionInfo);
         }
     }
 }
 /// <summary>Try to execute the given action with the given max retry count.
 /// <remarks>If the action execute still failed within the max retry count, then put the action into the retry queue;</remarks>
 /// </summary>
 /// <param name="actionName"></param>
 /// <param name="action"></param>
 /// <param name="maxRetryCount"></param>
 /// <param name="nextAction"></param>
 public void TryAction(string actionName, Func<bool> action, int maxRetryCount, ActionInfo nextAction)
 {
     if (TryRecursively(actionName, (x, y, z) => action(), 0, maxRetryCount))
     {
         TryAction(nextAction);
     }
     else
     {
         _actionQueue.Add(new ActionInfo(actionName, obj => action(), null, nextAction));
     }
 }
Exemplo n.º 3
0
 /// <summary>Parameterized constructor.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="action"></param>
 /// <param name="data"></param>
 /// <param name="next"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public ActionInfo(string name, Func<object, bool> action, object data, ActionInfo next)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     Name = name;
     Action = action;
     Data = data;
     Next = next;
 }
Exemplo n.º 4
0
 /// <summary>Try to execute the given action with the given max retry count.
 /// <remarks>If the action execute still failed when reached to the max retry count, then put the action into the retry queue.
 /// </remarks>
 /// </summary>
 /// <param name="actionName"></param>
 /// <param name="action"></param>
 /// <param name="maxRetryCount"></param>
 /// <param name="nextAction"></param>
 public void TryAction(string actionName, Func <bool> action, int maxRetryCount, ActionInfo nextAction)
 {
     if (TryWithMaxCount(actionName, (x, y, z) => action(), 0, maxRetryCount))
     {
         ExecuteAction(nextAction);
     }
     else
     {
         _retryQueue.Add(new ActionInfo(actionName, obj => action(), null, nextAction));
     }
 }