public void Should_CallDiskTableMerger() { for (int i = 0; i < databaseManager.ItemsTreshold + 1; i++) { databaseManager.Add(Item.CreateItem(i.ToString(), i.ToString())); } switch (method) { case MergeMethod.MergeBySize: diskTablesMerger.Received(1).MergeFilesBySize(databaseDirectory); break; case MergeMethod.MergeByLevel: diskTablesMerger.Received(1).MergeFilesByLevel(databaseDirectory); break; } }
private void UsCommandHandler(CommandArgs e) { var player = e.Player; // byDD if (!player.HasPermission("us.color")) { player.SendErrorMessage("You do not have permission to use this command."); return; } // byDD if (e.Parameters.Count < 1) { player.SendErrorMessage($"Invalid syntax! Use {Commands.Specifier}us help for help."); return; } var command = e.Parameters[0]; if (command.Equals("color", StringComparison.CurrentCultureIgnoreCase)) { if (e.Parameters.Count != 3) { player.SendErrorMessage( $"Invalid syntax! Proper syntax: {Commands.Specifier}us color <player name> <rrr,ggg,bbb>"); return; } var username = e.Parameters[1]; var user = TShock.UserAccounts.GetUserAccountByName(username); if (user == null) { player.SendErrorMessage($"Couldn't find any users under the name of '{username}'."); return; } if (user.Name != player.Account?.Name && !e.Player.HasPermission("us.setother")) { e.Player.SendErrorMessage("You do not have permission to modify another user's chat data."); return; } var color = e.Parameters[2].Split(','); var target = _database.Get(user); if (color.Length != 3 || !byte.TryParse(color[0], out byte _) || !byte.TryParse(color[1], out byte _) || !byte.TryParse(color[2], out byte _)) { player.SendErrorMessage("Invalid color format."); return; } if (target == null) { target = new PlayerInfo(user.ID, new ChatData(e.Parameters[2]), new PermissionCollection()); _database.Add(target); } else { target.ChatData.Color = e.Parameters[2]; _database.Update(target); } player.SendSuccessMessage($"Successfully set {user.Name}'s color."); } else if (command.Equals("prefix", StringComparison.CurrentCultureIgnoreCase)) { if (e.Parameters.Count != 3) { player.SendErrorMessage( $"Invalid syntax! Proper syntax: {Commands.Specifier}us prefix <player name> <prefix>"); return; } var username = e.Parameters[1]; var user = TShock.UserAccounts.GetUserAccountByName(username); if (user == null) { player.SendErrorMessage($"Couldn't find any users under the name of '{username}'."); return; } if (user.Name != player.Account?.Name && !e.Player.HasPermission("us.setother")) { e.Player.SendErrorMessage("You do not have permission to modify another user's chat data."); return; } e.Parameters.RemoveRange(0, 2); var prefix = string.Join(" ", e.Parameters); if (prefix.Length > _config.MaximumPrefixLength) { player.SendErrorMessage( $"The prefix cannot contain more than {_config.MaximumPrefixLength} characters."); return; } if (_config.ProhibitedWords.Any(prefix.Contains)) { player.SendErrorMessage( $"The prefix cannot contain the following words: {string.Join(", ", from w in _config.ProhibitedWords where prefix.Contains(w) select w)}"); return; } var target = _database.Get(user); if (target == null) { target = new PlayerInfo(user.ID, new ChatData(prefix: prefix), new PermissionCollection()); _database.Add(target); } else { target.ChatData.Prefix = prefix; _database.Update(target); } player.SendSuccessMessage($"Successfully set {user.Name}'s prefix."); } else if (command.Equals("read", StringComparison.CurrentCultureIgnoreCase)) { if (e.Parameters.Count != 2) { player.SendErrorMessage( $"Invalid syntax! Proper syntax: {Commands.Specifier}us read <player name>"); return; } var username = e.Parameters[1]; var user = TShock.UserAccounts.GetUserAccountByName(username); if (user == null) { player.SendErrorMessage($"Couldn't find any users under the name of '{username}'."); return; } var target = _database.Get(user); if (target == null) { player.SendErrorMessage("This user has no chat data to display."); return; } player.SendInfoMessage($"Username: {user.Name}"); player.SendMessage($" * Prefix: {target.ChatData.Prefix ?? "None"}", Color.LawnGreen); player.SendMessage($" * Suffix: {target.ChatData.Suffix ?? "None"}", Color.LawnGreen); player.SendMessage($" * Chat color: {target.ChatData.Color ?? "None"}", Color.LawnGreen); } else if (command.Equals("remove", StringComparison.CurrentCultureIgnoreCase)) { if (e.Parameters.Count != 3) { player.SendErrorMessage( $"Invalid syntax! Proper syntax: {Commands.Specifier}us remove <player name> <prefix/suffix/color/all>"); return; } var inputOption = e.Parameters[2]; var username = e.Parameters[1]; var user = TShock.UserAccounts.GetUserAccountByName(username); if (user == null) { player.SendErrorMessage($"Couldn't find any users under the name of '{username}'."); return; } if (user.Name != player.Account?.Name && !player.HasPermission("us.setother")) { player.SendErrorMessage("You do not have permission to modify another user's chat data."); return; } var target = _database.Get(user); if (target == null) { player.SendErrorMessage($"No information found for user '{user.Name}'."); return; } switch (inputOption.ToLowerInvariant()) { case "all": if (!player.HasPermission("us.resetall")) { player.SendErrorMessage("You do not have access to this command."); return; } target.ChatData = new ChatData(); player.SendSuccessMessage("Reset successful."); break; case "color": if (!player.HasPermission("us.remove.color")) { player.SendErrorMessage("You do not have access to this command."); return; } target.ChatData.Color = null; player.SendSuccessMessage($"Modified {user.Name}'s chat color successfully."); break; case "prefix": if (!player.HasPermission("us.remove.prefix")) { player.SendErrorMessage("You do not have access to this command."); return; } target.ChatData.Prefix = null; player.SendSuccessMessage($"Modified {user.Name}'s chat prefix successfully."); break; case "suffix": if (!player.HasPermission("us.remove.suffix")) { player.SendErrorMessage("You do not have access to this command."); return; } target.ChatData.Suffix = null; player.SendSuccessMessage($"Modified {user.Name}'s chat suffix successfully."); break; default: player.SendErrorMessage("Invalid option!"); break; } _database.Update(target); } else if (command.Equals("suffix", StringComparison.CurrentCultureIgnoreCase)) { if (e.Parameters.Count != 3) { player.SendErrorMessage( $"Invalid syntax! Proper syntax: {Commands.Specifier}us suffix <player name> <suffix>"); return; } var username = e.Parameters[1]; var user = TShock.UserAccounts.GetUserAccountByName(username); if (user == null) { player.SendErrorMessage($"Couldn't find any users under the name of '{username}'."); return; } if (user.Name != player.Account.Name && !player.HasPermission("us.setother")) { player.SendErrorMessage("You do not have permission to modify another user's chat data."); return; } e.Parameters.RemoveRange(0, 2); var suffix = string.Join(" ", e.Parameters); if (suffix.Length > _config.MaximumSuffixLength) { player.SendErrorMessage( $"The suffix cannot contain more than {_config.MaximumSuffixLength} characters."); return; } if (_config.ProhibitedWords.Any(suffix.Contains)) { player.SendErrorMessage( $"The suffix cannot contain the following words: {string.Join(", ", from w in _config.ProhibitedWords where suffix.Contains(w) select w)}"); return; } var target = _database.Get(user); if (target == null) { target = new PlayerInfo(user.ID, new ChatData(suffix: suffix), new PermissionCollection()); _database.Add(target); } else { target.ChatData.Suffix = suffix; _database.Update(target); } player.SendSuccessMessage($"Successfully set {user.Name}'s suffix."); } else { player.SendInfoMessage("Available commands:"); player.SendInfoMessage($"{Commands.Specifier}us prefix <player name> <prefix>"); player.SendInfoMessage($"{Commands.Specifier}us suffix <player name> <suffix>"); player.SendInfoMessage($"{Commands.Specifier}us color <player name> <color>"); player.SendInfoMessage($"{Commands.Specifier}us read <player name>"); player.SendInfoMessage($"{Commands.Specifier}us remove <player name> <prefix/suffix/color/all>"); } }
/// <summary> /// Insert with generic values based on id /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { databaseManager.Add(nextId++, nextId.ToString(), nextId.ToString() + nextId.ToString() + nextId.ToString()); UpdateDataGrid(); }