public InteractionResultStatus Handle(string data) { var startsWithSpace = data.StartsWith(" "); data = data.TrimStart(' '); _viewport.Log("> " + data); try { foreach (var interaction in _interactions) { string @alias; string text; if (interaction.WillProcess(data, out @alias, out text)) { if (startsWithSpace) { _viewport.Clear(); } var request = new InteractionRequest(text, CurrentStoryId, data, _viewport.LookupRef, CurrentStoryName); var response = new InteractionResponse(_viewport, (l, s) => { CurrentStoryId = l; CurrentStoryName = s; }, _sender); var context = new InteractionContext(request, _storage, response); var result = interaction.Handle(context); if (result.Status == InteractionResultStatus.Error) { _viewport.Error(result.OptionalError); } return(result.Status); } } } catch (Exception ex) { _viewport.Error("Error: {0}", ex.Message); return(InteractionResultStatus.Error); } _viewport.Error("Unknown command sequence: {0}", data); return(InteractionResultStatus.Error); }
public void Log(string message, params object[] args) { _viewport.Log(message, args); }