public bool TryFindCommand1(IEvent e, IVersaCommand <CommandContext> command, out string commandMatchString) { bool x = testDictionary.TryGetValue(command, out commandMatchString); testDictionary.GetOrAdd(command, commandMatchString); return(x); }
private bool TryFindCommand(object e, IVersaCommand <CommandContext> command, string v) { bool x = testDictionary.TryGetValue(command, out v); testDictionary.GetOrAdd(command, v); return(x); }
public void addCommand(IVersaCommand <CommandContext> command, string commandMatchString) { if (!testDictionary.TryGetValue(command, out commandMatchString)) { testDictionary.TryAdd(command, commandMatchString); } }
public bool TryFindCommand(string externalPrefix, IMessageEvent e, out IVersaCommand command, out string commandMatchString) { string finalPrefix; if (!string.IsNullOrWhiteSpace(Prefix)) { finalPrefix = (externalPrefix + Prefix).Trim() + " "; } else { finalPrefix = externalPrefix; } foreach (var item in _commands) { if (!e.FullMessage.StartsWith(finalPrefix + item.Key)) { continue; } commandMatchString = finalPrefix + item.Key; command = item.Value; return(true); } commandMatchString = default; command = default; return(false); }
public void Add(IVersaCommand command) { if (TryAdd(command) == false) { throw new ArgumentException("Duplicate command already present in system.", nameof(command)); } }
public void updateCommand(IVersaCommand <CommandContext> command, string commandMatchString, string newCommandMatchString) { if (testDictionary.TryGetValue(command, out commandMatchString)) { testDictionary.TryUpdate(command, commandMatchString, newCommandMatchString); } }
public CommandRunStateEventArgs(IEvent @event, IVersaCommand command, ICommandContext context, ECommandState state, Exception commandException = default) { Event = @event; Command = command; Context = context; State = state; CommandException = commandException; }
private bool removeCommand(IVersaCommand <CommandContext> command, string v) { if (testDictionary.TryGetValue(command, out v)) { testDictionary.TryRemove(command, out v); return(true); } return(false); }
public bool TryAdd(IVersaCommand command) { if (_commands.ContainsKey(command.CommandLine)) { return(false); } _commands.Add(command.CommandLine, command); return(true); }
public bool removeCommand1(IVersaCommand <CommandContext> command, string commandMatchString) { if (testDictionary.TryGetValue(command, out commandMatchString)) { testDictionary.TryRemove(command, out commandMatchString); return(true); } return(false); }
internal void AHoop(IVersaCommand <ICommandContext> command) { command.Run(new CommandContext.Builder().Build(), default(IServiceProvider)).Wait(); Assert.True(iRan); iRan = false; DoImplicitConversion(VersaCommandBase <CommandContext> .GetFromInterface(command).casted); Assert.True(iRan); iRan = false; DoubleCastCrais((VersaCommand)VersaCommandBase <CommandContext> .GetFromInterface(command).casted); Assert.True(iRan); }
public virtual bool TryFindCommand(IMessageEvent e, out IVersaCommand command, out string matchedCommandText) { foreach (var comG in e.EventSpecificCommands.Concat(Groups)) { if (!comG.TryFindCommand(GlobalPrefix, e, out command, out matchedCommandText)) { continue; } RunStateArgs.OnNext(new CommandRunStateEventArgs(e, command, null, ECommandState.FoundCommand)); return(true); } command = default; matchedCommandText = default; return(false); }
public virtual async Task <(bool, Task <(bool, IConditionalRule, string)>)> RunSupportedCommand( IMessageEvent @event, IVersaCommand command, string matchedCommandLine) { switch (command) { case IVersaCommand <CommandContext> basicCommand: RunStateArgs.OnNext(new CommandRunStateEventArgs(@event, command, null, ECommandState.BeforeContextConstruction)); var factory = @event.Services .GetRequiredService <ICommandContextFactory <CommandContext> >(); var(context, additionalConditionFuncs) = await factory.ConfigureContextAsync(@event, basicCommand, matchedCommandLine).ConfigureAwait(false); return(true, RunCommand(@event, context, basicCommand, @event.Services, additionalConditionFuncs)); default: return(false, default); } }
public async Task <(bool, IConditionalRule, string)> RunCommand(IEvent e, CommandContext context, IVersaCommand <CommandContext> command, IServiceProvider provider, params Func <Task <(bool passed, IConditionalRule rule, string failureReason)> >[] additionalChecks)
public bool TryRemove(IVersaCommand command) => _commands.Remove(command.CommandLine);