Example #1
0
        public bool TryFindCommand1(IEvent e, IVersaCommand <CommandContext> command, out string commandMatchString)
        {
            bool x = testDictionary.TryGetValue(command, out commandMatchString);

            testDictionary.GetOrAdd(command, commandMatchString);
            return(x);
        }
Example #2
0
        private bool TryFindCommand(object e, IVersaCommand <CommandContext> command, string v)
        {
            bool x = testDictionary.TryGetValue(command, out v);

            testDictionary.GetOrAdd(command, v);
            return(x);
        }
Example #3
0
 public void addCommand(IVersaCommand <CommandContext> command, string commandMatchString)
 {
     if (!testDictionary.TryGetValue(command, out commandMatchString))
     {
         testDictionary.TryAdd(command, commandMatchString);
     }
 }
Example #4
0
        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);
        }
Example #5
0
 public void Add(IVersaCommand command)
 {
     if (TryAdd(command) == false)
     {
         throw new ArgumentException("Duplicate command already present in system.", nameof(command));
     }
 }
Example #6
0
 public void updateCommand(IVersaCommand <CommandContext> command, string commandMatchString,
                           string newCommandMatchString)
 {
     if (testDictionary.TryGetValue(command, out commandMatchString))
     {
         testDictionary.TryUpdate(command, commandMatchString, newCommandMatchString);
     }
 }
Example #7
0
 public CommandRunStateEventArgs(IEvent @event, IVersaCommand command, ICommandContext context,
                                 ECommandState state, Exception commandException = default)
 {
     Event            = @event;
     Command          = command;
     Context          = context;
     State            = state;
     CommandException = commandException;
 }
Example #8
0
 private bool removeCommand(IVersaCommand <CommandContext> command, string v)
 {
     if (testDictionary.TryGetValue(command, out v))
     {
         testDictionary.TryRemove(command, out v);
         return(true);
     }
     return(false);
 }
Example #9
0
 public bool TryAdd(IVersaCommand command)
 {
     if (_commands.ContainsKey(command.CommandLine))
     {
         return(false);
     }
     _commands.Add(command.CommandLine, command);
     return(true);
 }
Example #10
0
        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);
 }
Example #12
0
 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);
 }
Example #13
0
        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);
            }
        }
Example #14
0
 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)
Example #15
0
 public bool TryRemove(IVersaCommand command) => _commands.Remove(command.CommandLine);