public static ComponentActionDelegate ResolveCommandHandler(MessageContainer data) { string component = data.ResolveParameter(nameof(MessageContainer.FixedPropertyNames.Target), 0); if (string.IsNullOrEmpty(component)) { Debug.WriteLine("No target component specified. Assuming malicous packet. Exiting request pipeline."); throw new ArgumentNullException("No target component specified."); } ComponentBase instance = GetByName(component); if (null == instance) { data.PushParameters(); //push all parameters back, as this is starting right with the action component = "Root"; instance = GetByName(component); } if (null != instance) { string action = data.ResolveParameter(nameof(MessageContainer.FixedPropertyNames.Action), 1).ToUpperInvariant(); ComponentActionDelegate actionHandler; if (instance.commandHandlers.TryGetValue(action, out actionHandler)) { return(actionHandler); } else { Debug.WriteLine($"{component} :: No handler found do for '{action}'"); return(null); } } Debug.WriteLine($"{component} :: Component not found "); return(null); }
public static async Task HandleInput(MessageContainer data) { string component = data.ResolveParameter(nameof(MessageContainer.FixedPropertyNames.Target), 0); if (string.IsNullOrEmpty(component)) { throw new ArgumentNullException("No target component specified."); } ComponentBase instance = GetByName(component); if (null == instance) { data.PushParameters(); //push all parameters back, as this is starting right with the action component = "Root"; instance = GetByName(component); } if (null != instance) { string action = data.ResolveParameter(nameof(MessageContainer.FixedPropertyNames.Action), 1).ToUpperInvariant(); ComponentActionDelegate actionHandler; if (instance.commandHandlers.TryGetValue(action, out actionHandler)) { try { await(actionHandler?.Invoke(data)).ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine(data.Target, ex.Message + "::" + ex.StackTrace); data.AddValue("Error", ex.Message); await HandleOutput(data).ConfigureAwait(false); } } else { Debug.WriteLine($"{component} :: No handler found do for '{action}'"); } } else { Debug.WriteLine($"{component} :: Component not found "); } }