Exemple #1
0
 /// <summary>Sends an email to a group of users.</summary>
 /// <param name="user">The user to send to.</param>
 /// <param name="subject">The email subject.</param>
 /// <param name="body">The email body.</param>
 public void SendEmail(SlkUser user, string subject, string body)
 {
     if (user.SPUser != null && string.IsNullOrEmpty(user.SPUser.Email) == false)
     {
         emailSender.SendEmail(user.SPUser.Email, subject, UserEmailText(body, user));
     }
 }
        /// <summary>Gets the result for a learner.</summary>
        /// <param name="learner">The learner to get the result for.</param>
        public LearnerAssignmentProperties ResultForLearner(SlkUser learner)
        {
            LearnerAssignmentProperties result = null;

            userResults.TryGetValue(learner.UserId.GetKey(), out result);
            return(result);
        }
        /// <summary>Saves a file in the folder.</summary>
        /// <param name="fileName">The name of the file.</param>
        /// <param name="fileStream">The contents of the file.</param>
        /// <param name="learner">The learner the file is for.</param>
        /// <returns>The saved file.</returns>
        public AssignmentFile SaveFile(string fileName, Stream fileStream, SlkUser learner)
        {
            SPFolder folder  = assignmentFolder.Folder;
            string   fileUrl = folder.Url + '/' + fileName;

            SPFile file = null;

            try
            {
                file = folder.Files.Add(fileUrl, fileStream, true);
            }
            catch (SPException)
            {
                // Seen cases of SPFileLockException - Locked for shared use by learner & SPException - Save Conflict. Your changes conflict with those made concurrently by another user.
                // In those cases it looks like File must already exist. So check for that and if so continue.
                file = folder.ParentWeb.GetFile(fileUrl);
                if (file.Exists == false)
                {
                    // Doesn't exist. Let calling code clean up.
                    throw;
                }
            }

            try
            {
                SaveProperties(file, learner);
            }
            // Don't worry too much about the properties, at least the file is present
            catch (SPException) { }

            return(new AssignmentFile(file.Item.ID, file.Name, file.ServerRelativeUrl, (string)file.Item["PermMask"]));
        }
Exemple #4
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);
                }
            }
        }
Exemple #5
0
 /// <summary>Sends an email when an assignment is returned.</summary>
 /// <param name="learner">The learner being returned.</param>
 /// <param name="learnerAssignment">The learner assignment properties.</param>
 public void SendReturnEmail(SlkUser learner, LearnerAssignmentProperties learnerAssignment)
 {
     if (properties.EmailChanges)
     {
         emailSender.SendReturnEmail(learner, learnerAssignment);
     }
 }
Exemple #6
0
 /// <summary>Sends an email when an assignment is collected.</summary>
 /// <param name="learner">The learner being collected.</param>
 public void SendCollectEmail(SlkUser learner)
 {
     if (properties.EmailChanges)
     {
         emailSender.SendCollectEmail(learner);
     }
 }
Exemple #7
0
 /// <summary>Sends an email when an assignment is reactivated.</summary>
 /// <param name="learner">The learner being reactivated.</param>
 public void SendReactivateEmail(SlkUser learner)
 {
     if (properties.EmailChanges)
     {
         emailSender.SendReactivateEmail(learner);
     }
 }
 private void SaveProperties(SPFile file, SlkUser learner)
 {
     file.Item[DropBox.ColumnAssignmentDate] = properties.StartDate;
     file.Item[DropBox.ColumnAssignmentName] = properties.Title.Trim();
     file.Item[DropBox.ColumnAssignmentId]   = properties.Id.GetKey();
     file.Item[DropBox.ColumnLearnerId]      = learner.Key;
     file.Item[DropBox.ColumnLearner]        = learner.SPUser;
     file.Item[DropBox.ColumnIsLatest]       = true;
     file.Item.Update();
 }
Exemple #9
0
 /// <summary>Updates the drop box permissions.</summary>
 /// <param name="state">The state the assignment is moving to.</param>
 /// <param name="user">The SLK user.</param>
 public void UpdateDropBoxPermissions(LearnerAssignmentState state, SlkUser user)
 {
     if (properties.IsNonELearning)
     {
         if (store != null)
         {
             cachedDropBoxUpdates.Add(new DropBoxUpdate(state, user.SPUser));
         }
         else
         {
             UpdateDropBoxPermissionsNow(state, user.SPUser);
         }
     }
 }
Exemple #10
0
        /// <summary>Returns the SlkUser for the given key.</summary>
        public SlkUser this[long key]
        {
            get
            {
                if (usersById.Count == 0)
                {
                    foreach (SlkUser user in users.Values)
                    {
                        usersById.Add(user.UserId.GetKey(), user);
                    }
                }

                SlkUser toReturn = null;
                usersById.TryGetValue(key, out toReturn);
                return(toReturn);
            }
        }
Exemple #11
0
        /// <summary>Uploads files to the learner's drop box.</summary>
        /// <param name="files">The files to upload.</param>
        /// <param name="existingFilesToKeep">Existing files to keep.</param>
        public void UploadFiles(AssignmentUpload[] files, int[] existingFilesToKeep)
        {
            SPUser currentUser = CurrentUser;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    spSite.CatchAccessDeniedException = false;
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);
                        AssignmentFolder assignmentFolder = dropBox.GetOrCreateAssignmentFolder(assignmentProperties);
                        assignmentFolder.ApplyPermission(currentUser, SPRoleType.Reader);

                        AssignmentFolder learnerSubFolder = assignmentFolder.FindLearnerFolder(currentUser);

                        if (learnerSubFolder == null)
                        {
                            learnerSubFolder = assignmentFolder.CreateLearnerAssignmentFolder(currentUser);
                        }
                        else
                        {
                            learnerSubFolder.ResetIsLatestFiles(existingFilesToKeep, currentUser.ID);
                        }

                        CheckExtensions(spSite, files);

                        using (new AllowUnsafeUpdates(spWeb))
                        {
                            SlkUser currentSlkUser = new SlkUser(currentUser);
                            foreach (AssignmentUpload upload in files)
                            {
                                learnerSubFolder.SaveFile(upload.Name, upload.Stream, currentSlkUser);
                            }
                        }

                        ApplySubmittedPermissions(spWeb);
                    }
                }
            });
        }
Exemple #12
0
        /// <summary>The last submitted files of a user.</summary>
        /// <param name="user">The user to get the files for.</param>
        /// <param name="assignmentKey">The key of the assignment.</param>
        /// <param name="forceUnlock">Force unlocking of all the files.</param>
        /// <param name="currentUser">The current user id.</param>
        /// <returns>The last submitted files.</returns>
        public AssignmentFile[] LastSubmittedFiles(SlkUser user, long assignmentKey, bool forceUnlock, int currentUser)
        {
            if (user == null)
            {
                throw new ArgumentNullException();
            }

            string queryXml = @"<Where>
                                <And>
                                    <Eq><FieldRef Name='{0}'/><Value Type='Text'>{1}</Value></Eq>
                                    <Eq><FieldRef Name='{2}'/><Value Type='Text'>{3}</Value></Eq>
                                </And>
                             </Where>";

            queryXml = string.Format(CultureInfo.InvariantCulture, queryXml, ColumnAssignmentId, assignmentKey, ColumnLearnerId, user.Key);
            SPQuery query = new SPQuery();

            query.ViewAttributes = "Scope=\"Recursive\"";
            query.Query          = queryXml;
            SPListItemCollection items = DropBoxList.GetItems(query);

            List <AssignmentFile> files = new List <AssignmentFile>();


            foreach (SPListItem item in items)
            {
                if (item[ColumnIsLatest] != null)
                {
                    if ((bool)item[ColumnIsLatest])
                    {
                        SPFile file = item.File;
                        if (forceUnlock)
                        {
                            DropBoxManager.UnlockFile(file, currentUser);
                        }

                        files.Add(new AssignmentFile(item.ID, file.Name, file.ServerRelativeUrl, (string)file.Item["PermMask"]));
                    }
                }
            }
            return(files.ToArray());
        }
Exemple #13
0
        private string UserEmailText(string baseText, SlkUser user)
        {
            string text = baseText;

            if (text.Contains("%url%"))
            {
                string url = "{0}{1}Lobby.aspx?LearnerAssignmentId={2}";
                url  = string.Format(CultureInfo.InvariantCulture, url, web.Url, Constants.SlkUrlPath, user.AssignmentUserGuidId);
                text = text.Replace("%url%", url);
            }

            if (text.Contains("%gradingUrl%"))
            {
                string url = "{0}{1}grading.aspx?AssignmentId={2}";
                url  = string.Format(CultureInfo.InvariantCulture, url, web.Url, Constants.SlkUrlPath, assignment.Id.GetKey());
                text = text.Replace("%gradingUrl%", url);
            }

            return(text);
        }
Exemple #14
0
 /// <summary>Sends an email when an assignment is reactivated.</summary>
 /// <param name="learner">The learner being reactivated.</param>
 public void SendReactivateEmail(SlkUser learner)
 {
     SendEmail(learner, ReactivateSubjectText(), ReactivateBodyText());
 }
Exemple #15
0
 /// <summary>Sends an email when an assignment is returned.</summary>
 /// <param name="learner">The learner being returned.</param>
 /// <param name="learnerAssignment">The learner assignment properties.</param>
 public void SendReturnEmail(SlkUser learner, LearnerAssignmentProperties learnerAssignment)
 {
     this.learnerAssignment = learnerAssignment;
     SendEmail(learner, ReturnSubjectText(), ReturnBodyText());
 }
Exemple #16
0
 /// <summary>
 /// Adds a user to <c>Users</c>.
 /// </summary>
 ///
 /// <param name="slkUser">The user to add.</param>
 ///
 internal void AddUser(SlkUser slkUser)
 {
     m_users.Add(slkUser);
 }
Exemple #17
0
 /// <summary>Sends an email when an assignment is collected.</summary>
 /// <param name="learner">The learner being collected.</param>
 public void SendCollectEmail(SlkUser learner)
 {
     SendEmail(learner, CollectSubjectText(), CollectBodyText());
 }