protected override IJsonCard GetData() { try { var endpoint = EndpointFactory.Build(EntityRequestType.Card_Read_Refresh, new Dictionary <string, object> { { "_id", Data.Id } }); var newData = JsonRepository.Execute <IJsonCard>(Auth, endpoint); MarkInitialized(); return(newData); } catch (TrelloInteractionException e) { if (!e.IsNotFoundError() || !IsInitialized) { throw; } _deleted = true; return(Data); } }
/// <summary> /// Adds a label to the collection. /// </summary> /// <param name="label">The label to add.</param> public void Add(Label label) { var error = NotNullRule <Label> .Instance.Validate(null, label); if (error != null) { throw new ValidationException <Label>(label, new[] { error }); } var json = TrelloConfiguration.JsonFactory.Create <IJsonParameter>(); json.String = label.Id; var endpoint = EndpointFactory.Build(EntityRequestType.Card_Write_AddLabel, new Dictionary <string, object> { { "_id", OwnerId } }); JsonRepository.Execute(Auth, endpoint, json); Items.Add(label); _context.Expire(); }
protected override async Task <IJsonCheckList> GetData(CancellationToken ct) { try { var endpoint = EndpointFactory.Build(EntityRequestType.CheckList_Read_Refresh, new Dictionary <string, object> { { "_id", Data.Id } }); var newData = await JsonRepository.Execute <IJsonCheckList>(Auth, endpoint, ct, CurrentParameters); MarkInitialized(); return(newData); } catch (TrelloInteractionException e) { if (!e.IsNotFoundError() || !IsInitialized) { throw; } _deleted = true; return(Data); } }
/// <summary> /// Adds a board to the collection of starred boards. /// </summary> /// <param name="board">The board</param> /// <param name="position">The board's position in the starred boards list.</param> /// <param name="ct">(Optional) A cancellation token for async processing.</param> /// <returns>The <see cref="IStarredBoard"/> generated by Trello.</returns> public async Task <IStarredBoard> Add(IBoard board, Position position = null, CancellationToken ct = default(CancellationToken)) { var error = NotNullRule <IBoard> .Instance.Validate(null, board); if (error != null) { throw new ValidationException <IBoard>(board, new[] { error }); } position = position ?? Position.Bottom; var json = TrelloConfiguration.JsonFactory.Create <IJsonStarredBoard>(); json.Board = TrelloConfiguration.JsonFactory.Create <IJsonBoard>(); json.Board.Id = board.Id; json.Pos = Position.GetJson(position); var endpoint = EndpointFactory.Build(EntityRequestType.Member_Write_AddStarredBoard, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute(Auth, endpoint, json, ct); return(new StarredBoard(OwnerId, newData, Auth)); }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { IncorporateLimit(); var allParameters = AdditionalParameters.Concat(BoardContext.CurrentParameters) .ToDictionary(kvp => kvp.Key == "filter" ? kvp.Key : $"boards_{kvp.Key}", kvp => kvp.Value); var endpoint = EndpointFactory.Build(_updateRequestType, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonBoard> >(Auth, endpoint, ct, allParameters); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(jb => { var board = jb.GetFromCache <Board, IJsonBoard>(Auth); board.Json = jb; return(board); })); EventAggregator.Subscribe(this); }
/// <summary> /// Removes a member from a board. /// </summary> /// <param name="member">The member to remove.</param> /// <param name="ct">(Optional) A cancellation token for async processing.</param> public async Task Remove(IMember member, CancellationToken ct = default) { var error = NotNullRule <IMember> .Instance.Validate(null, member); if (error != null) { throw new ValidationException <IMember>(member, new[] { error }); } var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_RemoveMember, new Dictionary <string, object> { { "_id", OwnerId }, { "_memberId", member.Id } }); await JsonRepository.Execute(Auth, endpoint, ct); if (TrelloConfiguration.EnableConsistencyProcessing && member.Boards is ReadOnlyCollection <IBoard> boardCollection) { var board = TrelloConfiguration.Cache.OfType <IBoard>().FirstOrDefault(b => b.Id == OwnerId); if (board != null) { boardCollection.Items.Remove(board); } } }
protected override async Task <IJsonCustomDropDownOption> GetData(CancellationToken ct) { try { var endpoint = EndpointFactory.Build(EntityRequestType.CustomFieldDropDownOption_Read_Refresh, new Dictionary <string, object> { { "_idField", Data.Field.Id }, { "_id", Data.Id } }); var newData = await JsonRepository.Execute <IJsonCustomDropDownOption>(Auth, endpoint, ct); return(newData); } catch (TrelloInteractionException e) { if (!e.IsNotFoundError() || !IsInitialized) { throw; } _deleted = true; return(Data); } }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { IncorporateLimit(); _requestParameters["_id"] = OwnerId; var endpoint = EndpointFactory.Build(_updateRequestType, _requestParameters); var newData = await JsonRepository.Execute <List <IJsonCard> >(Auth, endpoint, ct, AdditionalParameters); var previousItems = new List <ICard>(Items); Items.Clear(); Items.AddRange(newData.Select(jc => { var card = jc.GetFromCache <Card, IJsonCard>(Auth); card.Json = jc; return(card); })); var removedItems = previousItems.Except(Items, CacheableComparer.Get <ICard>()).OfType <Card>().ToList(); foreach (var item in removedItems) { item.Json.List = null; } }