private async Task CloseChannel(MessageContainer data) { data.AddValue("Close", "BYE. Hope to see you soon again."); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); if (data.Origin is CommunicationComponentBase) { await CloseChannel(data.Origin as CommunicationComponentBase, data.SessionId).ConfigureAwait(false); } }
public static async Task HandleOutput(MessageContainer data) { List <Task> sendTasks = new List <Task>(); foreach (CommunicationComponentBase publisher in communicationComponents) { sendTasks.Add(publisher.Respond(data)); } await Task.WhenAll(sendTasks).ConfigureAwait(false); }
private async Task RemoveTimerItem(MessageContainer data) { if (!Guid.TryParse(data.ResolveParameter("TimerId", 0), out Guid param)) { data.AddValue("Remove", "No valid timer id given"); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); return; } await timerWheel.RemoveTimerItem(param).ConfigureAwait(false); data.AddValue("Remove", $"Task {param} succcessfully removed."); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); }
private async Task SendEcho(MessageContainer data) { if (data.Parameters.Count == 0) { data.AddMultiPartValue("Echo", "Nothing to echo"); } else { foreach (string value in data.Parameters) { data.AddMultiPartValue("Echo", value); } } await ComponentHandler.HandleOutput(data).ConfigureAwait(false); }
protected async Task ComponentHelp(MessageContainer data) { if (null == componentHelp) { componentHelp = new List <Tuple <string, string, string> >(); data.AddValue(constHelp, "Preparing help text."); Task sendWaitMessage = ComponentHandler.HandleOutput(data); BuildHelpCache(); await sendWaitMessage.ConfigureAwait(false); data.ClearValue(constHelp); } foreach (Tuple <string, string, string> helpText in this.componentHelp) { data.AddMultiPartValue(constHelp, $"{componentName} {helpText.Item1} {helpText.Item2}: {helpText.Item3}"); } await ComponentHandler.HandleOutput(data).ConfigureAwait(false); }
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 "); } }
private async Task RegisterTimerTask(MessageContainer data) { int param; TimerItem <Tuple <ComponentActionDelegate, MessageContainer> > timerItem = new TimerItem <Tuple <ComponentActionDelegate, MessageContainer> >(); if (!int.TryParse(data.ResolveParameter("Interval", 0), out param)) { param = 1000; } timerItem.Interval = TimeSpan.FromMilliseconds(param); if (!int.TryParse(data.ResolveParameter("Repetitions", 1), out param)) { param = 0; } timerItem.Repetition = param; string timerAction = data.ResolveParameter("TimerAction", 2); string[] actionParams = timerAction.GetTokens().ToArray(); MessageContainer timerActionData = new MessageContainer(data.SessionId, this, actionParams); ComponentActionDelegate actionDelegate = ComponentHandler.ResolveCommandHandler(timerActionData); if (null == actionDelegate || actionParams == null || actionParams.Length == 0) { data.AddValue("Register", "Could not parse task action. Please check the command provided."); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); return; } timerItem.Data = new Tuple <ComponentActionDelegate, MessageContainer>(actionDelegate, timerActionData); timerItem.TimerAction += TimerAction; await timerWheel.Add(timerItem).ConfigureAwait(false); data.AddValue("Register", $"Task succcessfully registered with ID {timerItem.TimerItemId}"); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); }
public static async Task ExecuteCommand(ComponentActionDelegate actionHandler, MessageContainer data) { try { await(actionHandler?.Invoke(data)).ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine(data.Target, ex.Message + "::" + ex.StackTrace); data.AddValue("Error", ex.Message); data.AddValue("StackTrace", ex.StackTrace); await HandleOutput(data).ConfigureAwait(false); } }
private async Task ClearActiveTimers(MessageContainer data) { await timerWheel.Clear().ConfigureAwait(false); }
protected abstract Task ListContent(MessageContainer data);
protected abstract Task DisconnectStorage(MessageContainer data);
private async Task SendDateTime(MessageContainer data) { data.AddValue("DateTime", DateTime.Now.ToString()); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); }
private async Task SendHello(MessageContainer data) { data.AddMultiPartValue("Hello", "Hello. Great to see you here."); data.AddMultiPartValue("Hello", "Use 'Help + CRLF or Enter' command to get help."); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); }
private async Task ListComponents(MessageContainer data) { data.AddValue("List", await ListComponents().ConfigureAwait(false)); await ComponentHandler.HandleOutput(data).ConfigureAwait(false); }
public abstract Task Respond(MessageContainer data);