예제 #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="Board"/> object.
        /// </summary>
        /// <param name="id">The board's ID.</param>
        /// <param name="auth">(Optional) Custom authorization parameters. When not provided,
        /// <see cref="TrelloAuthorization.Default"/> will be used.</param>
        public Board(string id, TrelloAuthorization auth = null)
        {
            Auth     = auth;
            _context = new BoardContext(id, auth);
            _context.Synchronized += Synchronized;
            Id = id;

            Actions      = new ReadOnlyActionCollection(typeof(Board), () => Id, auth);
            Cards        = new ReadOnlyCardCollection(typeof(Board), () => Id, auth);
            _description = new Field <string>(_context, nameof(Description));
            _isClosed    = new Field <bool?>(_context, nameof(IsClosed));
            _isClosed.AddRule(NullableHasValueRule <bool> .Instance);
            _isSubscribed = new Field <bool?>(_context, nameof(IsSubscribed));
            _isSubscribed.AddRule(NullableHasValueRule <bool> .Instance);
            Labels      = new BoardLabelCollection(() => Id, auth);
            Lists       = new ListCollection(() => Id, auth);
            Members     = new ReadOnlyMemberCollection(EntityRequestType.Board_Read_Members, () => Id, auth);
            Memberships = new BoardMembershipCollection(() => Id, auth);
            _name       = new Field <string>(_context, nameof(Name));
            _name.AddRule(NotNullOrWhiteSpaceRule.Instance);
            _organization       = new Field <Organization>(_context, nameof(Organization));
            PowerUps            = new ReadOnlyPowerUpCollection(() => Id, auth);
            PowerUpData         = new ReadOnlyPowerUpDataCollection(EntityRequestType.Board_Read_PowerUpData, () => Id, auth);
            Preferences         = new BoardPreferences(_context.BoardPreferencesContext);
            PersonalPreferences = new BoardPersonalPreferences(Id, auth);
            _url = new Field <string>(_context, nameof(Url));

            TrelloConfiguration.Cache.Add(this);
        }
예제 #2
0
        internal Member(string id, bool isMe, TrelloAuthorization auth)
        {
            Auth     = auth;
            Id       = id;
            _context = new MemberContext(id, auth);
            _context.Synchronized += Synchronized;

            Actions       = new ReadOnlyActionCollection(typeof(Member), () => Id, auth);
            _avatarSource = new Field <AvatarSource?>(_context, nameof(AvatarSource));
            _avatarSource.AddRule(NullableHasValueRule <AvatarSource> .Instance);
            _avatarSource.AddRule(EnumerationRule <AvatarSource?> .Instance);
            _avatarUrl = new Field <string>(_context, nameof(AvatarUrl));
            _bio       = new Field <string>(_context, nameof(Bio));
            Boards     = isMe ? new BoardCollection(typeof(Member), () => Id, auth) : new ReadOnlyBoardCollection(typeof(Member), () => Id, auth);
            _fullName  = new Field <string>(_context, nameof(FullName));
            _fullName.AddRule(MemberFullNameRule.Instance);
            _initials = new Field <string>(_context, nameof(Initials));
            _initials.AddRule(MemberInitialsRule.Instance);
            _isConfirmed  = new Field <bool?>(_context, nameof(IsConfirmed));
            Organizations = isMe ? new OrganizationCollection(() => Id, auth) : new ReadOnlyOrganizationCollection(() => Id, auth);
            _status       = new Field <MemberStatus?>(_context, nameof(Status));
            _trophies     = new Field <IEnumerable <string> >(_context, nameof(Trophies));
            _url          = new Field <string>(_context, nameof(Url));
            _userName     = new Field <string>(_context, nameof(UserName));
            _userName.AddRule(UsernameRule.Instance);

            TrelloConfiguration.Cache.Add(this);
        }
예제 #3
0
        /// <summary>
        /// Creates a new instance of the <see cref="Card"/> object.
        /// </summary>
        /// <param name="id">The card's ID.</param>
        /// <param name="auth">(Optional) Custom authorization parameters. When not provided, <see cref="TrelloAuthorization.Default"/> will be used.</param>
        /// <remarks>
        /// The supplied ID can be either the full or short ID.
        /// </remarks>
        public Card(string id, TrelloAuthorization auth = null)
        {
            Id       = id;
            _context = new CardContext(id, auth);
            _context.Synchronized += Synchronized;

            Actions = new ReadOnlyActionCollection(typeof(Card), () => id, auth);
            Badges  = new Badges(_context.BadgesContext);
            _board  = new Field <Board>(_context, nameof(Board));
            _board.AddRule(NotNullRule <Board> .Instance);
            _description = new Field <string>(_context, nameof(Description));
            _dueDate     = new Field <DateTime?>(_context, nameof(DueDate));
            _isComplete  = new Field <bool?>(_context, nameof(IsComplete));
            _isArchived  = new Field <bool?>(_context, nameof(IsArchived));
            _isArchived.AddRule(NullableHasValueRule <bool> .Instance);
            _isSubscribed = new Field <bool?>(_context, nameof(IsSubscribed));
            _isSubscribed.AddRule(NullableHasValueRule <bool> .Instance);
            _lastActivity = new Field <DateTime?>(_context, nameof(LastActivity));
            _list         = new Field <List>(_context, nameof(List));
            _list.AddRule(NotNullRule <IList> .Instance);
            _name = new Field <string>(_context, nameof(Name));
            _name.AddRule(NotNullOrWhiteSpaceRule.Instance);
            _position = new Field <Position>(_context, nameof(Position));
            _position.AddRule(PositionRule.Instance);
            _shortId  = new Field <int?>(_context, nameof(ShortId));
            _shortUrl = new Field <string>(_context, nameof(ShortUrl));
            _url      = new Field <string>(_context, nameof(Url));

            if (_context.HasValidId && auth != TrelloAuthorization.Null)
            {
                TrelloConfiguration.Cache.Add(this);
            }
        }
예제 #4
0
 internal ReadOnlyActionCollection(ReadOnlyActionCollection source, TrelloAuthorization auth)
     : base(() => source.OwnerId, auth)
 {
     _updateRequestType = source._updateRequestType;
     if (source._additionalParameters != null)
     {
         _additionalParameters = new Dictionary <string, object>(source._additionalParameters);
     }
 }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="actions">The <see cref="ReadOnlyActionCollection"/></param>
        /// <param name="start">The desired start date.</param>
        /// <param name="end">The desired end date.</param>
        /// <exception cref="ArgumentException">Thrown when <see cref="ActionType.Unknown"/> is included in the filter.</exception>
        /// <returns>The filtered collection.</returns>
        public static ReadOnlyActionCollection Filter(this ReadOnlyActionCollection actions, DateTime?start = null, DateTime?end = null)
        {
            if (!start.HasValue && !end.HasValue)
            {
                throw new ArgumentException("Must pass a start and/or end date.");
            }

            var collection = new ReadOnlyActionCollection(actions, actions.Auth);

            collection.AddFilter(start, end);
            return(collection);
        }
예제 #6
0
        /// <summary>
        /// Filters a <see cref="ReadOnlyActionCollection"/> for a given <see cref="ActionType"/>s.
        /// </summary>
        /// <param name="actions">The <see cref="ReadOnlyActionCollection"/></param>
        /// <param name="filters">The new <see cref="ActionType"/>s by which to filter.</param>
        /// <returns>The filtered collection.</returns>
        /// <exception cref="ArgumentException">Thrown when <see cref="ActionType.Unknown"/> is included in the filter.</exception>
        /// <remarks>The new filter parameters will function as OR parameters.</remarks>
        public static ReadOnlyActionCollection Filter(this ReadOnlyActionCollection actions, IEnumerable <ActionType> filters)
        {
            if (filters.Any(f => f == ActionType.Unknown))
            {
                throw new ArgumentException($"Action type '{ActionType.Unknown}' is not recognized by the Trello API.  Please remove it from the filters.", nameof(filters));
            }

            var collection = new ReadOnlyActionCollection(actions, actions.Auth);

            collection.AddFilter(filters);
            return(collection);
        }
예제 #7
0
        /// <summary>
        /// Limits a <see cref="ReadOnlyActionCollection"/> to a specified count of items.
        /// </summary>
        /// <param name="actions">The <see cref="ReadOnlyActionCollection"/></param>
        /// <param name="limit">The limit.</param>
        /// <returns>The limited collection.</returns>
        public static ReadOnlyActionCollection Limit(this ReadOnlyActionCollection actions, int limit)
        {
            if (limit <= 0)
            {
                throw new ArgumentException("limit");
            }

            return(new ReadOnlyActionCollection(actions, actions.Auth)
            {
                Limit = limit
            });
        }
예제 #8
0
        /// <summary>
        /// Filters a <see cref="ReadOnlyActionCollection"/> for a given <see cref="ActionType"/>.
        /// </summary>
        /// <param name="actions">The <see cref="ReadOnlyActionCollection"/></param>
        /// <param name="filter">The new <see cref="ActionType"/> by which to filter.  Can be combined using the bitwise OR operator.</param>
        /// <returns>The filtered collection.</returns>
        /// <exception cref="ArgumentException">Thrown when <see cref="ActionType.Unknown"/> is included in the filter.</exception>
        /// <remarks>The new filter parameter will function as an OR parameter.</remarks>
        public static ReadOnlyActionCollection Filter(this ReadOnlyActionCollection actions, ActionType filter)
        {
            if (filter == ActionType.Unknown)
            {
                throw new ArgumentException($"Action type '{ActionType.Unknown}' is not recognized by the Trello API.  Please indicate a different filter.", nameof(filter));
            }

            var collection = new ReadOnlyActionCollection(actions, actions.Auth);

            collection.AddFilter(new[] { filter });
            return(collection);
        }
예제 #9
0
        /// <summary>
        /// Creates a new instance of the <see cref="List"/> object.
        /// </summary>
        /// <param name="id">The list's ID.</param>
        /// <param name="auth">(Optional) Custom authorization parameters. When not provided,
        /// <see cref="TrelloAuthorization.Default"/> will be used.</param>
        public List(string id, TrelloAuthorization auth = null)
        {
            Id       = id;
            _context = new ListContext(id, auth);
            _context.Synchronized += Synchronized;

            Actions = new ReadOnlyActionCollection(typeof(List), () => Id, auth);
            _board  = new Field <Board>(_context, nameof(Board));
            _board.AddRule(NotNullRule <Board> .Instance);
            Cards       = new CardCollection(() => Id, auth);
            _isArchived = new Field <bool?>(_context, nameof(IsArchived));
            _isArchived.AddRule(NullableHasValueRule <bool> .Instance);
            _isSubscribed = new Field <bool?>(_context, nameof(IsSubscribed));
            _isSubscribed.AddRule(NullableHasValueRule <bool> .Instance);
            _name = new Field <string>(_context, nameof(Name));
            _name.AddRule(NotNullOrWhiteSpaceRule.Instance);
            _position = new Field <Position>(_context, nameof(Position));
            _position.AddRule(NotNullRule <Position> .Instance);
            _position.AddRule(PositionRule.Instance);

            TrelloConfiguration.Cache.Add(this);
        }
예제 #10
0
        /// <summary>
        /// Creates a new instance of the <see cref="Organization"/> object.
        /// </summary>
        /// <param name="id">The organization's ID.</param>
        /// <param name="auth">(Optional) Custom authorization parameters. When not provided,
        /// <see cref="TrelloAuthorization.Default"/> will be used.</param>
        /// <remarks>
        /// The supplied ID can be either the full ID or the organization's name.
        /// </remarks>
        public Organization(string id, TrelloAuthorization auth = null)
        {
            Id       = id;
            _context = new OrganizationContext(id, auth);
            _context.Synchronized += Synchronized;

            Actions          = new ReadOnlyActionCollection(typeof(Organization), () => Id, auth);
            Boards           = new BoardCollection(typeof(Organization), () => Id, auth);
            _description     = new Field <string>(_context, nameof(Description));
            _displayName     = new Field <string>(_context, nameof(DisplayName));
            _isBusinessClass = new Field <bool>(_context, nameof(IsBusinessClass));
            Members          = new ReadOnlyMemberCollection(EntityRequestType.Organization_Read_Members, () => Id, auth);
            Memberships      = new OrganizationMembershipCollection(() => Id, auth);
            _name            = new Field <string>(_context, nameof(Name));
            _name.AddRule(OrganizationNameRule.Instance);
            Preferences = new OrganizationPreferences(_context.OrganizationPreferencesContext);
            _url        = new Field <string>(_context, nameof(Url));
            _website    = new Field <string>(_context, nameof(Website));
            _website.AddRule(UriRule.Instance);

            TrelloConfiguration.Cache.Add(this);
        }
예제 #11
0
        /// <summary>
        /// Creates a new instance of the <see cref="Card"/> object.
        /// </summary>
        /// <param name="id">The card's ID.</param>
        /// <param name="auth">(Optional) Custom authorization parameters. When not provided,
        /// <see cref="TrelloAuthorization.Default"/> will be used.</param>
        /// <remarks>
        /// The supplied ID can be either the full or short ID.
        /// </remarks>
        public Card(string id, TrelloAuthorization auth = null)
        {
            Id       = id;
            _context = new CardContext(id, auth);
            _context.Synchronized += Synchronized;

            Actions     = new ReadOnlyActionCollection(typeof(Card), () => id, auth);
            Attachments = new AttachmentCollection(() => Id, auth);
            Badges      = new Badges(_context.BadgesContext);
            _board      = new Field <Board>(_context, nameof(Board));
            _board.AddRule(NotNullRule <Board> .Instance);
            CheckLists   = new CheckListCollection(this, auth);
            Comments     = new CommentCollection(() => Id, auth);
            _description = new Field <string>(_context, nameof(Description));
            _dueDate     = new Field <DateTime?>(_context, nameof(DueDate));
            _isComplete  = new Field <bool?>(_context, nameof(IsComplete));
            _isArchived  = new Field <bool?>(_context, nameof(IsArchived));
            _isArchived.AddRule(NullableHasValueRule <bool> .Instance);
            _isSubscribed = new Field <bool?>(_context, nameof(IsSubscribed));
            _isSubscribed.AddRule(NullableHasValueRule <bool> .Instance);
            Labels        = new CardLabelCollection(_context, auth);
            _lastActivity = new Field <DateTime?>(_context, nameof(LastActivity));
            _list         = new Field <List>(_context, nameof(List));
            _list.AddRule(NotNullRule <List> .Instance);
            Members = new MemberCollection(EntityRequestType.Card_Read_Members, () => Id, auth);
            _name   = new Field <string>(_context, nameof(Name));
            _name.AddRule(NotNullOrWhiteSpaceRule.Instance);
            _position = new Field <Position>(_context, nameof(Position));
            _position.AddRule(PositionRule.Instance);
            PowerUpData   = new ReadOnlyPowerUpDataCollection(EntityRequestType.Card_Read_PowerUpData, () => Id, auth);
            _shortId      = new Field <int?>(_context, nameof(ShortId));
            _shortUrl     = new Field <string>(_context, nameof(ShortUrl));
            Stickers      = new CardStickerCollection(() => Id, auth);
            _url          = new Field <string>(_context, nameof(Url));
            VotingMembers = new ReadOnlyMemberCollection(EntityRequestType.Card_Read_MembersVoted, () => Id, auth);

            TrelloConfiguration.Cache.Add(this);
        }