public void JoinAllGroups() { this.log.Debug("Groups participation checking started"); IList <VkGroup> allExistingGroups = this.groupRepository.GetGroups(); MembershipProfile groupMembershipStatus = this.vkConnectionBuilder.GetVkDataProvider().GetGroupMembershipStatus(); ICollection <VkGroup> notSubscribedGroups = this.GetNotSubscribedGroups(allExistingGroups, groupMembershipStatus); this.SubscribeToGroups(notSubscribedGroups); this.log.Debug("Groups participation checking finished"); }
private ICollection <VkGroup> GetNotSubscribedGroups(IList <VkGroup> allExistingGroups, MembershipProfile groupMembershipStatus) { IList <VkGroup> notSubscribedGroups = new List <VkGroup>(); foreach (var existingGroup in allExistingGroups) { string groupId = existingGroup.Id.ToString(); if (groupMembershipStatus.group != null && groupMembershipStatus.group.All(g => g.gid != groupId)) { notSubscribedGroups.Add(existingGroup); } } ICollection <string> groupIds = notSubscribedGroups.Select(g => g.Id.ToString()).ToList(); if (groupIds.Count > 0) { this.log.InfoFormat("User is not in groups: {0}", new SeparatedStringBuilder(groupIds).ToString()); } else { this.log.Info("User participates in all groups"); } return(notSubscribedGroups); }