Beispiel #1
0
        /// <summary>
        /// Updates a community to the Episerver Social Framework.
        /// </summary>
        /// <param name="community">The community to update.</param>
        /// <returns>The updated community.</returns>
        public Community Update(Community community)
        {
            Composite <Group, GroupExtensionData> updatedGroup = null;

            try
            {
                var group     = new Group(GroupId.Create(community.Id), community.Name, community.Description);
                var extension = new GroupExtensionData(community.PageLink);
                updatedGroup = this.groupService.Update <GroupExtensionData>(group, extension);
                if (updatedGroup == null)
                {
                    throw new SocialRepositoryException("The new community could not be added. Please try again");
                }
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.", ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException("The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }

            return(new Community(updatedGroup.Data.Id.Id, updatedGroup.Data.Name, updatedGroup.Data.Description, updatedGroup.Extension.PageLink));
        }
        /// <summary>
        /// Build the appropriate CompositeCriteria based the provided CommunityMemberFilter.
        /// The member filter will either contain a group id or a logged in user id. If neitheris provided an exception is thrown.
        /// </summary>
        /// <param name="communityMemberFilter">The provided member filter</param>
        /// <returns>A composite criteria of type MemberFilter and MemberExtensionData</returns>
        private CompositeCriteria <MemberFilter, MemberExtensionData> BuildCriteria(CommunityMemberFilter communityMemberFilter)
        {
            var pageInfo = new PageInfo {
                PageSize = communityMemberFilter.PageSize
            };
            var orderBy = new List <SortInfo> {
                new SortInfo(MemberSortFields.Id, false)
            };
            var compositeCriteria = new CompositeCriteria <MemberFilter, MemberExtensionData>()
            {
                PageInfo = pageInfo,
                OrderBy  = orderBy
            };

            if (!string.IsNullOrEmpty(communityMemberFilter.CommunityId) && (string.IsNullOrEmpty(communityMemberFilter.UserId)))
            {
                compositeCriteria.Filter = new MemberFilter {
                    Group = GroupId.Create(communityMemberFilter.CommunityId)
                };
            }
            else if ((!string.IsNullOrEmpty(communityMemberFilter.UserId) && (string.IsNullOrEmpty(communityMemberFilter.CommunityId))))
            {
                compositeCriteria.Filter = new MemberFilter {
                    User = Reference.Create(communityMemberFilter.UserId)
                };
            }
            else
            {
                throw new SocialException("This implementation of a CommunityMemberFilter should only contain either a CommunityId or a UserReference.");
            }

            return(compositeCriteria);
        }
Beispiel #3
0
        /// <summary>
        /// Retrieves a community based on a list of community ids that are provided.
        /// </summary>
        /// <param name="communityIds">The groups ids that are to be retrieved from the underlying data store.</param>
        /// <returns>The requested groups.</returns>
        public List <Community> Get(List <string> communityIds)
        {
            List <Community> socialGroups = new List <Community>();

            try
            {
                var groupIdList = communityIds.Select(x => GroupId.Create(x)).ToList();
                var groupCount  = groupIdList.Count();
                var criteria    = new CompositeCriteria <GroupFilter, GroupExtensionData>
                {
                    Filter = new GroupFilter {
                        GroupIds = groupIdList
                    },
                    PageInfo = new PageInfo {
                        PageSize = groupCount
                    },
                    OrderBy = new List <SortInfo> {
                        new SortInfo(GroupSortFields.Name, true)
                    }
                };
                var returnedGroups = this.groupService.Get(criteria);
                socialGroups = returnedGroups.Results.Select(x => new Community(x.Data.Id.Id, x.Data.Name, x.Data.Description, x.Extension.PageLink)).ToList();
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.", ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException("The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }
            catch (GroupDoesNotExistException ex)
            {
                throw new SocialRepositoryException("Episerver Social could not find the community requested.", ex);
            }


            return(socialGroups);
        }
        /// <summary>
        ///     Adds a member to the Episerver Social Framework.
        /// </summary>
        /// <param name="communityMember">The member to add.</param>
        /// <returns>The added member.</returns>
        public CommunityMember Add(CommunityMember communityMember)
        {
            CommunityMember addedSocialMember = null;

            try
            {
                var userReference        = Reference.Create(communityMember.User);
                var groupId              = GroupId.Create(communityMember.GroupId);
                var member               = new Member(userReference, groupId);
                var extensionData        = new MemberExtensionData(communityMember.Email, communityMember.Company);
                var addedCompositeMember = _memberService.Add(member, extensionData);
                addedSocialMember =
                    _communityMemberAdapter.Adapt(addedCompositeMember.Data, addedCompositeMember.Extension);

                if (addedSocialMember == null)
                {
                    throw new SocialRepositoryException("The new member could not be added. Please try again");
                }
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.",
                                                    ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException(
                          "The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }

            return(addedSocialMember);
        }