Esempio n. 1
0
        public GroupMembership GetMembership(string groupKey)
        {
            GroupMembership membership = new GroupMembership();

            using (PoolItem <DirectoryService> poolService = this.directoryServicePool.Take(NullValueHandling.Ignore))
            {
                string token = null;
                MembersResource.ListRequest request = poolService.Item.Members.List(groupKey);
                request.PrettyPrint = false;
                Trace.WriteLine($"Getting members from group {groupKey}");

                do
                {
                    request.PageToken = token;
                    Members members;

                    try
                    {
                        this.WaitForGate();
                        members = request.ExecuteWithRetry(RetryEvents.Backoff | RetryEvents.Timeout);
                    }
                    finally
                    {
                        this.ReleaseGate();
                    }

                    if (members.MembersValue != null)
                    {
                        foreach (Member member in members.MembersValue)
                        {
                            if (!string.IsNullOrWhiteSpace(member.Email))
                            {
                                membership.AddMember(member);
                            }
                        }
                    }

                    token = members.NextPageToken;
                } while (token != null);
            }

            Trace.WriteLine($"Returned {membership.Count} members from group {groupKey}");

            return(membership);
        }
        /// <summary>
        /// Gets the list of channel memberships.
        /// </summary>
        /// <param name="maxResults">The maximum results to return</param>
        /// <returns>The list of channel memberships</returns>
        public async Task <IEnumerable <Member> > GetChannelMemberships(int maxResults = 1)
        {
            return(await this.YouTubeServiceWrapper(async() =>
            {
                List <Member> results = new List <Member>();
                string pageToken = null;
                do
                {
                    MembersResource.ListRequest request = this.connection.GoogleYouTubeService.Members.List("id,snippet");
                    request.MaxResults = Math.Min(maxResults, 50);
                    request.PageToken = pageToken;

                    MemberListResponse response = await request.ExecuteAsync();
                    results.AddRange(response.Items);
                    maxResults -= response.Items.Count;
                    pageToken = response.NextPageToken;
                } while (maxResults > 0 && !string.IsNullOrEmpty(pageToken));
                return results;
            }));
        }