public async void DoAction(IActionFactory actionFactory) { if (ReadyForAction) { ReadyForAction = false; var action = actionFactory.CreateAction(this); if (action != null) { await Task.Delay(action.Apply(MapDirection)); } else { "Invalid action. => null".Dump(); } "Action available.".Dump(); ReadyForAction = true; } }
private int Process(IEnumerable <ActionQueueRecord> records, Action <Exception> onError = null, Action <string> onSuccess = null) { var recordCounter = 0; try { foreach (var actionQueueRecord in records) { try { onSuccess(string.Format("actionQueueRecord.Id {0}, actionQueueRecord.ActionTypeId {1}", actionQueueRecord.Id, actionQueueRecord.ActionTypeId)); if (actionQueueRecord != null) { IAction action = _actionFactory.CreateAction(actionQueueRecord.ActionTypeId); action.Execute(actionQueueRecord.Id); recordCounter++; if (onSuccess != null) { onSuccess(string.Format("[Action {0}]: OK", actionQueueRecord.Id)); } GC.Collect(); } } catch (Exception ex) { if (onError != null) { onError(ex); } } } } catch (Exception ex) { if (onError != null) { onError(ex); } } return(recordCounter); }
public static IAction CreateAction <T>(this IActionFactory factory, params object[] args) where T : IAction { return(factory.CreateAction <T>(args)); }
public virtual string Use(IActionFactory actionFactory, int itemPos, User user, string channel) { return(actionFactory.CreateAction(ActionId)(itemPos, user, channel)); }