コード例 #1
0
        void AddUser(SPUser user, bool isInstructor, bool isLearner, SlkGroup learnerGroup, List <string> learnerKeys)
        {
            SlkUser slkUser = new SlkUser(user);
            SlkUser slkUser2;
            string  userKey = slkUser.Key;

            if (users.TryGetValue(userKey, out slkUser2))
            {
                slkUser = slkUser2;
            }
            else
            {
                users[userKey] = slkUser;
            }

            if (isInstructor)
            {
                instructors[userKey] = slkUser;
            }

            if (isLearner)
            {
                learners[userKey] = slkUser;

                if (learnerGroup != null)
                {
                    learnerGroup.UserKeys.Add(userKey);
                }

                if (learnerKeys != null)
                {
                    learnerKeys.Add(userKey);
                }
            }
        }
コード例 #2
0
        void IterateWebRoles(SPWeb web, SPRoleDefinition instructorRole, SPRoleDefinition learnerRole, bool instructorsOnly, bool hideDisabledUsers)
        {
            web.AllowUnsafeUpdates = true; // enable web.AllUsers.AddCollection()
            foreach (SPRoleAssignment roleAssignment in web.RoleAssignments)
            {
                // determine if this role assignment refers to an instructor or a learner; skip it if it's neither
                bool isInstructor = false;
                if (instructorRole != null)
                {
                    isInstructor = roleAssignment.RoleDefinitionBindings.Contains(instructorRole);
                }

                bool isLearner = false;
                if (instructorsOnly == false && learnerRole != null)
                {
                    isLearner = roleAssignment.RoleDefinitionBindings.Contains(learnerRole);
                }

                if (isInstructor == false && isLearner == false)
                {
                    continue;
                }

                // process the role assignment
                SPPrincipal member  = roleAssignment.Member;
                SPUser      spUser  = member as SPUser;
                SPGroup     spGroup = member as SPGroup;
                if (spUser != null)
                {
                    AddSPUserAsMember(web, spUser, isInstructor, isLearner, startTime, null, hideDisabledUsers);
                }
                else if (spGroup != null)
                {
                    // role assignment member is a SharePoint group...
                    SlkGroup learnerGroup = null;
                    if (isLearner)
                    {
                        learnerGroup          = new SlkGroup(spGroup, null);
                        learnerGroup.UserKeys = new List <string>();
                    }

                    // add users from the domain group to the collections of instructors, learners, and/or this learner group, as appropriate
                    foreach (SPUser spUserInGroup in spGroup.Users)
                    {
                        AddSPUserAsMember(web, spUserInGroup, isInstructor, isLearner, startTime, learnerGroup, hideDisabledUsers);
                    }

                    if (isLearner)
                    {
                        if (learnerGroup.UserKeys.Count > 0)
                        {
                            learnerGroups.Add(learnerGroup);
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>Enumerates the members of a domain group. </summary>
        /// <param name="spWeb">An <c>SPWeb</c> within the site collection to which users from the domain group will be added as needed.</param>
        /// <param name="domainGroup">The <c>SPUser</c> representing the domain group to enumerate.</param>
        /// <param name="isInstructor"><c>true</c> if this domain group has the "SLK Instructor" permission.</param>
        /// <param name="isLearner"><c>true</c> if this domain group has the "SLK Learner" permission.</param>
        /// <param name="learnerKeys">The SLK "user key" (e.g. SID or login name) of each learner is
        ///     added to this collection, unless <paramref name="learnerKeys"/> is <c>null</c>.</param>
        /// <param name="hideDisabledUsers">Whether to hide disabled users or not.</param>
        /// <returns><c>true</c> if enumeration succeeds, <c>false</c> if not. </returns>
        void EnumerateDomainGroupMembers(SPWeb spWeb, SPUser domainGroup, bool isInstructor, bool isLearner, List <string> learnerKeys, bool hideDisabledUsers)
        {
            // if timeout occurred, output a message to <groupFailureDetailsBuilder>
            TimeSpan timeRemaining = DomainGroupEnumerationTotalTimeout - (DateTime.Now - startTime);

            if (timeRemaining <= TimeSpan.Zero)
            {
                AddGroupFailureDetail(culture.Resources.DomainGroupEnumSkippedDueToTimeout, domainGroup.LoginName);
                return;
            }

            DomainGroupEnumeratorResults results = DomainGroupEnumerator.EnumerateGroup(domainGroup, spWeb, timeRemaining, hideDisabledUsers);

            if (results.Errors.Count > 0)
            {
                groupFailuresList.Add(domainGroup.Name);
                foreach (String error in results.Errors)
                {
                    AddGroupFailureDetail(culture.Resources.DomainGroupError, domainGroup.LoginName, error);
                }

                StringBuilder detailedErrorBuilder = new StringBuilder();
                foreach (Exception e in results.DetailedExceptions)
                {
                    detailedErrorBuilder.Append(e.ToString());
                    detailedErrorBuilder.Append(Environment.NewLine);
                }

                store.LogError(detailedErrorBuilder.ToString());
            }

            // If a learner then create a new learner group and add to the collection of learner groups
            SlkGroup learnerGroup = null;

            if (isLearner && (learnerGroups != null))
            {
                learnerGroup          = new SlkGroup(null, domainGroup);
                learnerGroup.UserKeys = new List <string>(results.Users.Count);
                learnerGroups.Add(learnerGroup);
            }

            // add users from the domain group to the collections of instructors, learners, and/or this learner group, as appropriate
            foreach (SPUser spUserInGroup in results.Users)
            {
                AddUser(spUserInGroup, isInstructor, isLearner, learnerGroup, learnerKeys);
            }

            return;
        }
コード例 #4
0
 void AddSPUserAsMember(SPWeb web, SPUser user, bool isInstructor, bool isLearner, DateTime startTime, SlkGroup learnerGroup, bool hideDisabledUsers)
 {
     if (user.IsDomainGroup)
     {
         // role assignment member is a domain group
         EnumerateDomainGroupMembers(web, user, isInstructor, isLearner, ((learnerGroup != null) ? learnerGroup.UserKeys : null), hideDisabledUsers);
     }
     else
     {
         AddUser(user, isInstructor, isLearner, learnerGroup, null);
     }
 }