StoredLearningSession CreateAttemptIfRequired(bool transitionToComplete) { // NotStarted --> Active or Completed or Final if (Assignment.IsELearning) { // create an attempt for this learner assignment StoredLearningSession learningSession = StoredLearningSession.CreateAttempt(Assignment.Store.PackageStore, LearnerId, LearnerAssignmentId, Assignment.RootActivityId, Assignment.Store.Settings.LoggingOptions); // start the assignment, forcing selection of a first activity learningSession.Start(true); // if NotStarted --> Completed or Final, transition to the Completed state if (transitionToComplete) { // transition to Completed learningSession.Exit(); } // save changes to <learningSession> learningSession.CommitChanges(); return(learningSession); } else { return(null); } }
/// <summary> /// Creates attempt on given organization and returns attempt identifier. /// </summary> /// <param name="orgID">Long integer value represents organization identifier to create attempt on.</param> /// <returns>Long integer value, representing attempt identifier of created attempt.</returns> public long CreateAttempt(long orgID) { ActivityPackageItemIdentifier organizationID = new ActivityPackageItemIdentifier(orgID); StoredLearningSession session = StoredLearningSession.CreateAttempt(this.PStore, this.CurrentUserIdentifier, organizationID, LoggingOptions.LogAll); long attemptID = session.AttemptId.GetKey(); return(attemptID); }
protected void CreateAttemptButton_Click(object sender, EventArgs e) { // the hidden "Create Attempt" button was auto-clicked by script on page load... // prevent script from clicking "Create Attempt" again AutoPostScript.Visible = false; // hide the "please wait" panel PleaseWait.Visible = false; // the OrganizationId hidden form element contains the ID of the organization to attempt -- // try to create a new attempt based on that ID; an organization is a root-level activity, // so OrganizationId is actually an ActivityPackageItemIdentifier try { // set <currentUser> to information about the current user; we // need the current user's UserItemIdentifier LStoreUserInfo currentUser = GetCurrentUserInfo(); // set <organizationId> from the OrganizationId hidden form element as described above ActivityPackageItemIdentifier organizationId = new ActivityPackageItemIdentifier( Convert.ToInt64(OrganizationId.Value, CultureInfo.InvariantCulture)); // create an attempt on <organizationId> StoredLearningSession session = StoredLearningSession.CreateAttempt(PStore, currentUser.Id, organizationId, LoggingOptions.LogAll); // the operation was successful, and there are no messages to display to the user, so // update the AttemptId hidden form element with the ID of the newly-created attempt, // update the parent page, and close the dialog AttemptId.Value = Convert.ToString(session.AttemptId.GetKey(), CultureInfo.InvariantCulture); UpdateParentPageScript.Visible = true; CloseDialogScript.Visible = true; } catch (Exception ex) { // an unexpected error occurred -- display a generic message that // doesn't include the exception message (since that message may // include sensitive information), and write the exception message // to the event log ErrorIntro.Visible = true; ErrorMessage.Visible = true; ErrorMessage.Controls.Add(new System.Web.UI.LiteralControl( Server.HtmlEncode("A serious error occurred. Please contact your system administrator. More information has been written to the server event log."))); LogEvent(System.Diagnostics.EventLogEntryType.Error, "An exception occurred while creating an attempt:\n\n{0}\n\n", ex.ToString()); Buttons.Visible = true; } }
/// <summary> /// Creates attempt on given organization and returns attempt identifier. /// </summary> /// <param name="orgID">Long integer value represents organization identifier to create attempt on.</param> /// <returns>Long integer value, representing attempt identifier of created attempt.</returns> protected AttemptItemIdentifier CreateAttempt(long orgID, int topicId) { ActivityPackageItemIdentifier organizationID = new ActivityPackageItemIdentifier(orgID); StoredLearningSession session = StoredLearningSession.CreateAttempt(this.PStore, this.GetCurrentUserIdentifier(), organizationID, LoggingOptions.LogAll); // TODO: add IudicoTopicRef LearningStoreJob job = LStore.CreateJob(); Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add(Schema.AttemptItem.IudicoThemeRef, topicId); job.UpdateItem(session.AttemptId, dic); job.Execute(); return(session.AttemptId); }
/// <summary> /// Creates attempt on given organization and returns attempt identifier. /// </summary> /// <param name="orgId">Long integer value represents organization identifier to create attempt on.</param> /// <param name="curriculumChapterTopicId">Int32 value representing id of curriculum chapter topic.</param> /// <param name="topicType"><see cref="TopicTypeEnum"/> value defines part of topic.</param> /// <returns>Long integer value, representing attempt identifier of created attempt.</returns> protected AttemptItemIdentifier CreateAttempt(long orgId, int curriculumChapterTopicId, TopicTypeEnum topicType) { var organizationId = new ActivityPackageItemIdentifier(orgId); StoredLearningSession session = StoredLearningSession.CreateAttempt( this.PStore, this.GetCurrentUserIdentifier(), organizationId, LoggingOptions.LogAll); LearningStoreJob job = this.LStore.CreateJob(); var dic = new Dictionary <string, object> { { Schema.AttemptItem.IudicoCurriculumChapterTopicRef, curriculumChapterTopicId }, { Schema.AttemptItem.IudicoTopicType, topicType } }; job.UpdateItem(session.AttemptId, dic); job.Execute(); return(session.AttemptId); }