سؤال

I am able to get the list of actions for a card. However, the action card has only the limited information so how do I get to the actual content of the action?

var actionList = trello.Actions.ForCard(card);
foreach (TrelloNet.Action action in actionList)

as I go through each action in the list, I can only see the member who originated the action, date, member and action type (e.g. TrelloNet.UpdateCardAction). How can I get to the actual context of the action, e.g. had transfered this card to board ?

If this is not the right way to get to the actual Action information, please point me to the right logical path.

Thanks,

Chi

هل كانت مفيدة؟

المحلول

Each type of action is a sub class of the Action class. The subclasses have a property called Data which contains specific information for that type of action.

As an example, if you want print all create card actions for a board you could do it like this:

var board = trello.Boards.WithId("a board id");
foreach (var action in trello.Actions.ForBoard(board).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " " + action.Data.Card.Name);
}

That will fetch all board actions from trello and then filter in memory. For performance reasons you can tell Trello.NET to only ask for specific action types by passing an additional parameter like this:

foreach (var action in trello.Actions.ForBoard(board, 
    new[] { ActionType.CreateCard }).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " - " + action.Data.Card.Name);
}

Since there can be a lot of actions trello uses paging. You can pass a Paging parameter to tell trello the page index and the page size. The following means that each page is 100 actions and you want the first page (0).

foreach (var action in trello.Actions.ForBoard(board, 
    new[] { ActionType.CreateCard }, 
    paging: new Paging(100, 0)).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " - " + action.Data.Card.Name);
}

There is an extension method called AutoPaged() that will help with the paging. Add a using statement...

using TrelloNet.Extensions;

...and use AutoPaged(). Trello.NET will automatically fetch new pages as needed.

foreach (var action in trello.Actions.AutoPaged().ForBoard(board, 
    new[] { ActionType.CreateCard }).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " - " + action.Data.Card.Name);
}

Note: There has been a while since new action types were added to Trello.NET so there might be new ones that are not recognized...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top