public override bool TryParseArgument(string input, BaseCommandContext context, out Position result) { result = default; var splitted = input.Split(' '); var location = new Position(); int count = 0; var ctx = (ObsidianContext)context; foreach (var text in splitted) { if (double.TryParse(text, out var doubleResult)) { switch (count) { case 0: location.X = doubleResult; break; case 1: location.Y = doubleResult; break; case 2: location.Z = doubleResult; break; default: throw new IndexOutOfRangeException("Count went out of range"); } } else if (text.Equals("~")) { var player = (Player)ctx.Player; switch (count) { case 0: location.X = player.Location.X; break; case 1: location.Y = player.Location.Y; break; case 2: location.Z = player.Location.Z; break; default: throw new IndexOutOfRangeException("Count went out of range"); } } count++; } result = location; return(true); }
} // Unit of work protected TestBase(Fixture fixture) { Services = fixture.ServiceProvider; CommandContext = Services.GetService <BaseCommandContext>(); if (CommandContext != null && CommandContext.Database.EnsureCreated()) { CommandContext.SeedSampleData(); } }
public override async Task <bool> RunChecksAsync(BaseCommandContext ctx) { if (ctx is ObsidianContext c) { var player = c.Player; return(c.Server.Operators.IsOperator(player)); } throw new Exception($"This context ({ctx.ToString()}) is unsupported"); }
public static void SeedSampleData(this BaseCommandContext context) { var company = new Core.Model.Company("Test"); CompanyId = company.Id; context.Company.Add(company); context.SaveChangesAsync().Wait(); }
public static void SeedSampleData(this BaseCommandContext context) { var company = new Core.Model.Company("Test"); CompanyId = company.Id; var user = new User(company, "foo", "bar"); UserId = user.Id; context.Company.Add(company); context.Users.Add(user); context.SaveChangesAsync().Wait(); }
public Fixture() { var path = Environment.CurrentDirectory; var services = new ServiceCollection(); var types = new List <Type>(); var assemblies = AppDomain.CurrentDomain .GetAssemblies(); // Todo Fix explicit adding of Qf.Persistence assembly //assemblies.Push(typeof(AccountsManager).Assembly); //assemblies.Push(typeof(AdminCommandService).Assembly); types.AddRange(AssemblyTypesBuilder.GetCommonExecutingContextTypes(assemblies)); var allTypes = types.ToArray(); var connectionString = Guid.NewGuid().ToString(); // Initialized in memory database services.RegisterCommandQueryDbContext(connectionString, true); // register repositories services.RegisterRepositories(allTypes); // register services services.RegisterCommandsAndQueryServices(allTypes); services.AddSingleton <ILoggerFactory, NullLoggerFactory>(); services.AddSingleton <IHostEnvironment, MockWebHostEnvironment>(); // IOC container services.AddScoped <IHttpContextAccessor, MockHttpContextAccessor>(); services.AddLogging(builder => builder.AddConsole()); ServiceProvider = services.BuildServiceProvider(); CommandContext = ServiceProvider.GetService <BaseCommandContext>(); var hostEnvironment = ServiceProvider.GetService <IHostEnvironment>(); hostEnvironment.SetDefault(); }
public async Task ProcessCommand(BaseCommandContext ctx) { ctx.Commands = this; if (!this._contextType.IsAssignableFrom(ctx.GetType())) { throw new InvalidCommandContextTypeException("Your context does not match the registered context type."); } // split the command message into command and args. if (_commandParser.IsCommandQualified(ctx._message, out string qualified)) { // if string is "command-qualified" we'll try to execute it. var command = _commandParser.SplitQualifiedString(qualified); // first, parse the command // [0] is the command name, all other values are arguments. await executeCommand(command, ctx); } await Task.Yield(); }
public override bool TryParseArgument(string input, BaseCommandContext context, out Player result) { var ctx = (ObsidianContext)context; Player player = null; if (Guid.TryParse(input, out Guid guid)) { // is valid GUID, try find with guid ctx.Server.OnlinePlayers.TryGetValue(guid, out player); } else { // is not valid guid, try find with name player = ctx.Server.OnlinePlayers.FirstOrDefault(x => x.Value.Username == input).Value; } result = player; return(true); }
private async Task executeCommand(string[] command, BaseCommandContext ctx) { Command cmd = null; var args = command; // Search for correct Command class in this._commands. while (_commands.Any(x => x.CheckCommand(args, cmd))) { cmd = _commands.First(x => x.CheckCommand(args, cmd)); args = args.Skip(1).ToArray(); } if (cmd != null) { await cmd.ExecuteAsync(ctx, args); } else { throw new CommandNotFoundException("No such command was found!"); } }
public override bool TryParseArgument(string input, BaseCommandContext ctx, out ulong result) => ulong.TryParse(input, out result);
public override bool TryParseArgument(string input, BaseCommandContext ctx, out sbyte result) => sbyte.TryParse(input, out result);
public override bool TryParseArgument(string input, BaseCommandContext ctx, out decimal result) => decimal.TryParse(input, out result);
public async Task ping(BaseCommandContext ctx, int arg1, string arg2, string arg3) { }
public static void Destroy(BaseCommandContext financeCommandContext) { financeCommandContext.Database.EnsureDeleted(); financeCommandContext.Dispose(); }
public virtual async Task <bool> RunChecksAsync(BaseCommandContext ctx) { throw new Exception($"RunChecksAsync was not implemented for {this.GetType().Name}!"); }
public async Task ping(BaseCommandContext ctx, int arg1, string arg2) { arg1out = arg1; arg2out = arg2; }
public override bool TryParseArgument(string input, BaseCommandContext ctx, out Guid result) { return(Guid.TryParse(input, out result)); }
public override bool TryParseArgument(string input, BaseCommandContext ctx, out string result) { result = input; return(true); }
public async Task ping(BaseCommandContext ctx, int arg1, int arg2) { }