Esempio n. 1
0
        /// <summary>
        /// Parses xml nodes with user info into CS4User objects and returns them ina collection
        /// </summary>
        /// <param name="usersElements">user xml nodes</param>
        /// <returns>CS4UserCollection with the data from the xml</returns>
        private CS4UserCollection GetUsersFromXml(XmlNodeList usersElements)
        {
            CS4UserCollection users = new CS4UserCollection();

            for (int curElementIndex = 0; curElementIndex < usersElements.Count; curElementIndex++)
            {
                string userLogin    = usersElements[curElementIndex].Attributes["LoginName"].InnerText;
                string userDomain   = usersElements[curElementIndex].Attributes["LoginNameDomain"].InnerText;
                string userName     = usersElements[curElementIndex].Attributes["UserName"].InnerText;
                string userEmail    = usersElements[curElementIndex].Attributes["Email"].InnerText;
                string userRole     = usersElements[curElementIndex].Attributes["Role"].InnerText;
                bool   userTransfer = (usersElements[curElementIndex].Attributes["Transfer"].InnerText == "1" ? true : false);
                int    userId       = 0;
                Int32.TryParse(usersElements[curElementIndex].Attributes["Id"].InnerText, out userId);
                CS4User user = new CS4User(
                    userId,
                    userDomain,
                    userLogin,
                    userName,
                    userEmail,
                    userTransfer,
                    IsUserInTeacherRole(userRole));
                users.Add(user);
            }
            return(users);
        }
Esempio n. 2
0
        /// <summary>
        /// Does the actual work of creating an SLK site with groups and users.
        /// </summary>
        /// <param name="classData">Class to be created</param>
        /// <param name="processingLog">Method returns log of actions performed</param>
        private void ProcessClass(CS4Class classData, ref string processingLog)
        {
            string       log    = System.String.Empty;
            SharePointV3 SLKweb = new SharePointV3();

            CS4UserCollection classUsers = new CS4UserCollection();
            CS4UserCollection groupUsers = new CS4UserCollection();
            bool    classAdded           = false;
            string  classURL             = String.Empty;
            string  classCreateResult    = String.Empty;
            CS4User groupsOwner          = null;

            log += System.Environment.NewLine + TextResources.ProcessingClass + classData.ClassName + System.Environment.NewLine;

            if (classData.Transfer)
            {
                classAdded = SLKweb.CreateSite(
                    SiteBuilder.Default.SLKSchoolWeb,
                    classData.ClassWeb,
                    classData.ClassName,
                    String.Empty,
                    classData.ClassLCID,
                    classData.Overwrite,
                    ref classURL,
                    ref classCreateResult);
                log += classCreateResult;
                if (classAdded)
                {
                    //adding site users
                    for (int classUserIndex = 0; classUserIndex < classData.Users.Count; classUserIndex++)
                    {
                        CS4User user = classData.Users.Item(classUserIndex);
                        if (user.Transfer)
                        {
                            user.UserRoles = this.DefineUserRoles(user.IsTeacher, classURL);
                            classUsers.Add(user);
                            //if the user is teacher, set it as group owner
                            //we only take first teacher to be groups owner as we only need one
                            if ((groupsOwner == null) && (user.IsTeacher))
                            {
                                groupsOwner = user;
                            }
                        }
                        else
                        {
                            log += string.Format(TextResources.UserNotForTransfer, user.UserLoginWithDomain) + System.Environment.NewLine;
                        }
                    }
                    string addUsersLog = String.Empty;
                    SLKweb.AssignUsersToSite(classURL, classUsers, ref addUsersLog);
                    log += addUsersLog;
                    //adding groups
                    for (int groupIndex = 0; groupIndex < classData.Groups.Count; groupIndex++)
                    {
                        log += string.Format(TextResources.ProcessingGroup, classData.Groups.Item(groupIndex).WebName) + System.Environment.NewLine;
                        if (classData.Groups.Item(groupIndex).Transfer)
                        {
                            //processing group users
                            groupUsers = new CS4UserCollection();
                            for (int groupUserIndex = 0; groupUserIndex < classData.Groups.Item(groupIndex).GroupUsers.Count; groupUserIndex++)
                            {
                                CS4User groupUser = classData.Groups.Item(groupIndex).GroupUsers.Item(groupUserIndex);
                                if (groupUser.Transfer)
                                {
                                    groupUser.UserRoles = this.DefineUserRoles(groupUser.IsTeacher, classURL);
                                    groupUsers.Add(groupUser);
                                }
                                else
                                {
                                    log += string.Format(TextResources.GroupUserNotForTransfer, groupUser.UserLoginWithDomain) + System.Environment.NewLine;
                                }
                            }
                            //adding group
                            //only if we have a group owner and at least one group user
                            if ((groupUsers.Count > 0) && (groupsOwner != null))
                            {
                                //taking first user as default user
                                bool   groupAdded        = false;
                                string groupCreateResult = string.Empty;
                                groupAdded = SLKweb.CreateUsersGroup(
                                    classURL,
                                    classData.Groups.Item(groupIndex).WebName,
                                    groupsOwner,
                                    classData.Groups.Item(groupIndex).GroupUsers.Item(0),
                                    classData.Groups.Item(groupIndex).Overwrite,
                                    ref groupCreateResult);
                                //adding group users
                                log += groupCreateResult;
                                if (groupAdded)
                                {
                                    string addGroupUsersLog = String.Empty;
                                    SLKweb.AssignUsersToGroup(classURL, classData.Groups.Item(groupIndex).WebName, groupUsers, ref addGroupUsersLog);
                                    log += addGroupUsersLog;
                                }
                            }
                            else
                            {
                                //not transferring this group
                                log += TextResources.GroupOwnerOrDefaultUserProblem + System.Environment.NewLine;
                            }
                        }
                        else
                        {
                            log += TextResources.GroupNotForTransfer + System.Environment.NewLine;
                        }
                    }
                }
            }
            else
            {
                log += TextResources.ClassNotForTransfer + System.Environment.NewLine;
            }
            log          += String.Format(TextResources.FinishedProcessingClass, classData.ClassName) + System.Environment.NewLine;
            processingLog = log;
        }