コード例 #1
0
        /// <summary>Resets the IsLatest value for all files to false.</summary>
        public void ResetIsLatestFiles(int[] excludes, int currentUser)
        {
            using (new AllowUnsafeUpdates(web))
            {
                foreach (SPFile file in assignmentFolder.Folder.Files)
                {
                    bool isLatestValue = false;
                    foreach (int id in excludes)
                    {
                        if (id == file.Item.ID)
                        {
                            isLatestValue = true;
                            break;
                        }
                    }

                    object currentValue = file.Item[DropBox.ColumnIsLatest];
                    if (currentValue == null || (bool)currentValue != isLatestValue)
                    {
                        DropBoxManager.UnlockFile(file, currentUser);
                        file.Item[DropBox.ColumnIsLatest] = isLatestValue;
                        file.Item.Update();
                    }
                }
            }
        }
コード例 #2
0
        void ExtractAssignmentsFromSharePoint(AssignmentProperties assignmentProperties, string assignmentFolderPath)
        {
            DropBoxManager manager = new DropBoxManager(assignmentProperties);
            Dictionary <string, List <SPFile> > files = manager.AllFiles();

            foreach (string learner in files.Keys)
            {
                string subFolderPath = Path.Combine(assignmentFolderPath, learner);
                Directory.CreateDirectory(subFolderPath);

                foreach (SPFile file in files[learner])
                {
                    object nameValue = file.Item[SPBuiltInFieldId.FileLeafRef];
                    if (nameValue != null)
                    {
                        string name = nameValue.ToString();
                        if (name.Length != 0)
                        {
                            byte[] data = file.OpenBinary();

                            using (FileStream fileStream = new FileStream(Path.Combine(subFolderPath, name), FileMode.CreateNew))
                            {
                                using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
                                {
                                    binaryWriter.Write(data, 0, (int)file.Length);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>Uploads files and submits the assignment.</summary>
        /// <param name="files">The files to upload.</param>
        /// <param name="existingFilesToKeep">Existing files to keep.</param>
        public void UploadFilesAndSubmit(AssignmentUpload[] files, int[] existingFilesToKeep)
        {
            DropBoxManager manager = new DropBoxManager(Assignment);

            manager.UploadFiles(files, existingFilesToKeep);
            Submit();
        }
コード例 #4
0
        void UpdateCachedDropBox()
        {
            StringBuilder errors = new StringBuilder();

            dropBoxManager = new DropBoxManager(properties);
            foreach (DropBoxUpdate update in cachedDropBoxUpdates)
            {
                try
                {
                    UpdateDropBoxPermissionsNow(update.State, update.User);
                }
                catch (Exception e)
                {
                    properties.Store.LogException(e);
                    errors.AppendFormat(SlkCulture.GetResources().ErrorSavingDropBoxPermissions, update.State, update.User.LoginName);
                }
            }

            if (errors.Length > 0)
            {
                throw new SafeToDisplayException(errors.ToString());
            }

            dropBoxManager = null;
        }
コード例 #5
0
        /// <summary>Submits the assignment.</summary>
        public void Submit()
        {
            CheckUserIsLearner();

            // Check the status
            switch (Status)
            {
            case LearnerAssignmentState.NotStarted:
                if (Assignment.IsELearning)
                {
                    throw InvalidTransitionException(LearnerAssignmentState.NotStarted, LearnerAssignmentState.Completed);
                }
                break;

            case LearnerAssignmentState.Active:
                break;

            case LearnerAssignmentState.Completed:
                // Need to transition to Final if auto return assignment
                if (Assignment.AutoReturn != true)
                {
                    return;
                }
                else
                {
                    break;
                }

            case LearnerAssignmentState.Final:
                // Already complete so leave
                return;

            default:
                // New status added
                break;
            }

            CompleteAssignment(null, null);

            if (Assignment.IsNonELearning)
            {
                DropBoxManager dropBoxMgr = new DropBoxManager(Assignment);
                dropBoxMgr.ApplySubmittedPermissions();
            }

            if (Assignment.EmailChanges)
            {
                Assignment.SendSubmitEmail(LearnerName);
            }
        }
コード例 #6
0
        /// <summary>Deletes the assignment.</summary>
        public void Delete(SPWeb web)
        {
            Store.DeleteAssignment(Id);

            if (EmailChanges)
            {
                using (AssignmentEmailer emailer = new AssignmentEmailer(this, Store.Settings.EmailSettings, web))
                {
                    emailer.SendCancelEmail(Learners);
                }
            }

            //Delete corresponding assignment folder from the drop box if exists
            if (IsNonELearning)
            {
                DropBoxManager dropBoxManager = new DropBoxManager(this);
                dropBoxManager.DeleteAssignmentFolder();
            }
        }
コード例 #7
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());
        }
コード例 #8
0
        void SaveNewAssignment(SPWeb web, SlkRole slkRole)
        {
            // Security checks: If assigning as an instructor, fails if user isn't an instructor on
            // the web (implemented by calling EnsureInstructor).  Fails if the user doesn't have access to the package/file
            if (web == null)
            {
                throw new ArgumentNullException("web");
            }

            if (PackageFormat == null && Location == null)
            {
                throw new InvalidOperationException(SlkCulture.GetResources().InvalidNewAssignment);
            }

            SPSiteGuid = web.Site.ID;
            SPWebGuid  = web.ID;

            VerifyRole(web, slkRole);
            Id = Store.CreateAssignment(this);

            if (isSelfAssigned == false)
            {
                //Update the MRU list
                Store.AddToUserWebList(web);
            }

            if (IsNonELearning)
            {
                DropBoxManager dropBoxMgr = new DropBoxManager(this);
                Microsoft.SharePoint.Utilities.SPUtility.ValidateFormDigest();
                dropBoxMgr.CreateAssignmentFolder();
            }

            if (EmailChanges)
            {
                using (AssignmentEmailer emailer = new AssignmentEmailer(this, Store.Settings.EmailSettings, web))
                {
                    emailer.SendNewEmail(Learners);
                }
            }
        }
コード例 #9
0
        void UpdateAssignment(SPWeb web)
        {
            AssignmentProperties oldProperties = Store.LoadAssignmentProperties(Id, SlkRole.Instructor);

            CopyInvariantProperties(oldProperties);

            bool corePropertiesChanged = false;

            if (Title != oldProperties.Title || StartDate != oldProperties.StartDate || DueDate != oldProperties.DueDate || PointsPossible != oldProperties.PointsPossible ||
                Description != oldProperties.Description || AutoReturn != oldProperties.AutoReturn || ShowAnswersToLearners != oldProperties.ShowAnswersToLearners ||
                EmailChanges != oldProperties.EmailChanges)
            {
                corePropertiesChanged = true;
            }

            SlkUserCollectionChanges instructorChanges = new SlkUserCollectionChanges(oldProperties.Instructors, Instructors);
            SlkUserCollectionChanges learnerChanges    = new SlkUserCollectionChanges(oldProperties.Learners, Learners);

            if (corePropertiesChanged || instructorChanges.HasChanges || learnerChanges.HasChanges)
            {
                Store.UpdateAssignment(this, corePropertiesChanged, instructorChanges, learnerChanges);

                if (IsNonELearning)
                {
                    // Update the assignment folder in the Drop Box
                    DropBoxManager dropBoxMgr = new DropBoxManager(this);
                    dropBoxMgr.UpdateAssignment(oldProperties);
                }

                if (EmailChanges)
                {
                    using (AssignmentEmailer emailer = new AssignmentEmailer(this, Store.Settings.EmailSettings, web))
                    {
                        emailer.SendNewEmail(learnerChanges.Additions);
                        emailer.SendCancelEmail(learnerChanges.Removals);
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>Updates the drop box permissions.</summary>
        /// <param name="state">The state the assignment is moving to.</param>
        /// <param name="user">The user.</param>
        void UpdateDropBoxPermissionsNow(LearnerAssignmentState state, SPUser user)
        {
            // If user is null, it's a deleted user so no need to update.
            if (user != null)
            {
                bool createdManager = false;
                if (dropBoxManager == null)
                {
                    dropBoxManager = new DropBoxManager(properties);
                    createdManager = true;
                }

                switch (state)
                {
                case LearnerAssignmentState.Active:
                    // Reactivated
                    dropBoxManager.ApplyReactivateAssignmentPermission(user);
                    break;

                case LearnerAssignmentState.Completed:
                    // Collected
                    dropBoxManager.ApplyCollectAssignmentPermissions(user);
                    break;

                case LearnerAssignmentState.Final:
                    // Return
                    dropBoxManager.ApplyReturnAssignmentPermission(user);
                    break;
                }

                if (createdManager)
                {
                    dropBoxManager = null;
                }
            }
        }