public async Task <bool> RemoveCommand(string command) { DeleteResult deleteOneAsync = await Collection.DeleteOneAsync(c => c.Command == command); CommandRemoved?.Invoke(this, command); return(deleteOneAsync.DeletedCount > 0); }
public async Task <ResponseCommand> UpsertCommand(string command, string response) { ResponseCommand newCommand = new(command, response); ResponseCommand?oldCommand = await Collection.FindOneAndReplaceAsync( Builders <ResponseCommand> .Filter.Eq(c => c.Command, command), newCommand, new FindOneAndReplaceOptions <ResponseCommand> { IsUpsert = true, ReturnDocument = ReturnDocument.Before }); if (oldCommand != null) { CommandRemoved?.Invoke(this, oldCommand.Command); } CommandInserted?.Invoke(this, newCommand); return(newCommand); }
/// <summary> /// Unregisters a command for a command client</summary> /// <param name="command">ICommandItem for command</param> /// <param name="client">Client that handles the command</param> public void UnregisterCommand(ICommandItem command, ICommandClient client) { if (command.CommandTag is StandardCommand) { return; } if (client == null) { m_commandClients.Remove(command.CommandTag); } else { m_commandClients.Remove(command.CommandTag, client); } if (!m_commandClients.TryGetFirst(command.CommandTag, out client)) { m_commandsLookup.Remove(command.CommandTag); int index = m_commands.IndexOf(command); m_commands.Remove(command); CommandRemoved.Raise <ItemRemovedEventArgs <ICommandItem> >(this, new ItemRemovedEventArgs <ICommandItem>(index, command)); } }
private void OnCommandRemoved(object sender, EditorCommand editorCommand) { CommandRemoved?.Invoke(this, editorCommand); }