/// <summary> /// Retrieves attempt identifier for specified organization id and Iudico topic id. /// </summary> /// <param name="orgId"><c>ActivityPackageItemIdentifier</c> value representing Organization ID.</param> /// <param name="curriculumChapterTopicId">Integer value - IUDICO curriculum chapter topic id.</param> /// <param name="topicType"><see cref="TopicTypeEnum"/> value.</param> /// <returns><c>AttemptItemIdentifier</c> value representing Attempt Identifier.</returns> protected AttemptItemIdentifier GetAttemptIdentifier( ActivityPackageItemIdentifier orgId, int curriculumChapterTopicId, TopicTypeEnum topicType) { AttemptItemIdentifier result = null; LearningStoreJob job = this.LStore.CreateJob(); LearningStoreQuery query = this.LStore.CreateQuery(Schema.MyAttemptIds.ViewName); query.AddColumn(Schema.MyAttemptIds.AttemptId); query.SetParameter(Schema.MyAttemptIds.CurriculumChapterTopicId, curriculumChapterTopicId); query.SetParameter(Schema.MyAttemptIds.OrganizationId, orgId); query.SetParameter(Schema.MyAttemptIds.TopicType, topicType); job.PerformQuery(query); ReadOnlyCollection <object> resultList = job.Execute(); var dataTable = (DataTable)resultList[0]; if (dataTable.Rows.Count > 0) { // get last result LStoreHelper.Cast(dataTable.Rows[dataTable.Rows.Count - 1][Schema.MyAttemptIds.AttemptId], out result); } return(result); }
public IEnumerable <AttemptResult> GetAllAttempts() { List <AttemptResult> result = new List <AttemptResult>(); LearningStoreJob job = LStore.CreateJob(); RequestAllAttempts(job); DataTable dataTable = job.Execute <DataTable>(); foreach (DataRow dataRow in dataTable.AsEnumerable()) { AttemptItemIdentifier attemptItemId; LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.AttemptId], out attemptItemId); long attemptId = attemptItemId.GetKey(); String userKey; LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.UserItemKey], out userKey); User user = UserService.GetUsers().Single(curr => curr.Id.ToString() == userKey); if (user == null) { throw new NoNullAllowedException("Error while getting user with id = " + userKey); } Int32 topicId; LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.ThemeId], out topicId); Topic topic = DisciplineService.GetTopic(topicId); if (topic == null) { throw new NoNullAllowedException("Error while getting topic with id = " + topicId); } Microsoft.LearningComponents.CompletionStatus completionStatus; LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.CompletionStatus], out completionStatus); IUDICO.Common.Models.Shared.Statistics.CompletionStatus iudicoCompletionStatus = (IUDICO.Common.Models.Shared.Statistics.CompletionStatus)completionStatus; Microsoft.LearningComponents.AttemptStatus attemptStatus; LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.AttemptStatus], out attemptStatus); IUDICO.Common.Models.Shared.Statistics.AttemptStatus iudicoAttemptStatus = (IUDICO.Common.Models.Shared.Statistics.AttemptStatus)attemptStatus; Microsoft.LearningComponents.SuccessStatus successStatus; LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.SuccessStatus], out successStatus); IUDICO.Common.Models.Shared.Statistics.SuccessStatus iudicoSuccessStatus = (IUDICO.Common.Models.Shared.Statistics.SuccessStatus)successStatus; DateTime?startTime; LStoreHelper.Cast(dataRow[Schema.AllAttemptsResults.StartedTimestamp], out startTime); DateTime?finishTime; LStoreHelper.Cast(dataRow[Schema.AllAttemptsResults.FinishedTimestamp], out finishTime); float?scaledScore; LStoreHelper.Cast <float>(dataRow[Schema.AllAttemptsResults.Score], out scaledScore); // Create AttemptResult object AttemptResult attemptResult = new AttemptResult(attemptId, user, topic, iudicoCompletionStatus, iudicoAttemptStatus, iudicoSuccessStatus, startTime, finishTime, scaledScore); result.Add(attemptResult); } return(result); }
public IEnumerable <AttemptResult> GetResults(User user, Topic topic) { List <AttemptResult> result = new List <AttemptResult>(); LearningStoreJob job = LStore.CreateJob(); RequestAttemptsByTopicAndUser(job, user.Id.ToString(), topic.Id); DataTable dataTable = job.Execute <DataTable>(); foreach (DataRow dataRow in dataTable.AsEnumerable()) { AttemptItemIdentifier attemptItemId; LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.AttemptId], out attemptItemId); long attemptId = attemptItemId.GetKey(); Microsoft.LearningComponents.CompletionStatus completionStatus; LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.CompletionStatus], out completionStatus); IUDICO.Common.Models.Shared.Statistics.CompletionStatus iudicoCompletionStatus = (IUDICO.Common.Models.Shared.Statistics.CompletionStatus)completionStatus; Microsoft.LearningComponents.AttemptStatus attemptStatus; LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.AttemptStatus], out attemptStatus); IUDICO.Common.Models.Shared.Statistics.AttemptStatus iudicoAttemptStatus = (IUDICO.Common.Models.Shared.Statistics.AttemptStatus)attemptStatus; Microsoft.LearningComponents.SuccessStatus successStatus; LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.SuccessStatus], out successStatus); IUDICO.Common.Models.Shared.Statistics.SuccessStatus iudicoSuccessStatus = (IUDICO.Common.Models.Shared.Statistics.SuccessStatus)successStatus; DateTime?startTime; LStoreHelper.Cast(dataRow[Schema.AttemptsResultsByThemeAndUser.StartedTimestamp], out startTime); DateTime?finishTime; LStoreHelper.Cast(dataRow[Schema.AllAttemptsResults.FinishedTimestamp], out finishTime); float?score; LStoreHelper.Cast <float>(dataRow[Schema.AttemptsResultsByThemeAndUser.Score], out score); float?scaledScore = null; if (score != null) { scaledScore = score / 100; } // Create AttemptResult object AttemptResult attemptResult = new AttemptResult(attemptId, user, topic, iudicoCompletionStatus, iudicoAttemptStatus, iudicoSuccessStatus, startTime, finishTime, scaledScore); result.Add(attemptResult); } return(result); }
/// <summary> /// Retrieves package id by specified IUDICO course. /// </summary> /// <param name="course">Course object represents iudico course entity.</param> /// <returns>PackageItemIdentifier value representing corresponding MLC Package ID.</returns> protected PackageItemIdentifier GetPackageIdentifier(int courseId) { PackageItemIdentifier result = null; LearningStoreJob job = LStore.CreateJob(); LearningStoreQuery query = LStore.CreateQuery(Schema.PackageIdByCourse.ViewName); query.AddColumn(Schema.PackageIdByCourse.PackageId); query.SetParameter(Schema.PackageIdByCourse.IudicoCourseRef, courseId); job.PerformQuery(query); ReadOnlyCollection <object> resultList = job.Execute(); DataTable dataTable = (DataTable)resultList[0]; if (dataTable.Rows.Count > 0) { LStoreHelper.Cast(dataTable.Rows[0][Schema.PackageIdByCourse.PackageId], out result); } return(result); }
/// <summary> /// Retrieves Organization Id by specified package oidentifier. /// </summary> /// <param name="packageId"><c>PackageItemIdentifier</c> value representing package id, organization is being searched by.</param> /// <returns><c>ActivityPackageItemIdentifier</c> value, which represents organization identifier of specified package.</returns> protected ActivityPackageItemIdentifier GetOrganizationIdentifier(PackageItemIdentifier packageId) { ActivityPackageItemIdentifier result = null; LearningStoreJob job = LStore.CreateJob(); LearningStoreQuery query = LStore.CreateQuery(Schema.RootActivityByPackage.ViewName); query.AddColumn(Schema.RootActivityByPackage.RootActivity); query.SetParameter(Schema.RootActivityByPackage.PackageId, packageId); job.PerformQuery(query); var resultList = job.Execute(); DataTable dataTable = (DataTable)resultList[0]; if (dataTable.Rows.Count > 0) { LStoreHelper.Cast(dataTable.Rows[0][Schema.RootActivityByPackage.RootActivity], out result); } return(result); }
/// <summary> /// Retrieves attempt identifier for specified organization id and Iudico topic id. /// </summary> /// <param name="orgId"><c>ActivityPackageItemIdentifier</c> value representing Organization ID.</param> /// <param name="topicId">Integer value - IUDICO topic id.</param> /// <returns><c>AttemptItemIdentifier</c> value representing Attempt Identifier.</returns> protected AttemptItemIdentifier GetAttemptIdentifier(ActivityPackageItemIdentifier orgId, int topicId) { AttemptItemIdentifier result = null; LearningStoreJob job = LStore.CreateJob(); LearningStoreQuery query = LStore.CreateQuery(Schema.MyAttempts.ViewName); query.AddColumn(Schema.MyAttempts.AttemptId); query.AddCondition(Schema.MyAttempts.OrganizationId, LearningStoreConditionOperator.Equal, orgId); query.AddCondition(Schema.MyAttempts.ThemeId, LearningStoreConditionOperator.Equal, topicId); job.PerformQuery(query); ReadOnlyCollection <object> resultList = job.Execute(); DataTable dataTable = (DataTable)resultList[0]; if (dataTable.Rows.Count > 0) { // get last result LStoreHelper.Cast(dataTable.Rows[dataTable.Rows.Count - 1][Schema.MyAttempts.AttemptId], out result); } return(result); }
public IEnumerable <AnswerResult> GetAnswers(AttemptResult attemptResult) { List <AnswerResult> result = new List <AnswerResult>(); LearningStoreJob job = LStore.CreateJob(); AttemptItemIdentifier attemptId = new AttemptItemIdentifier(attemptResult.AttemptId); RequestInteractionResultsByAttempt(job, attemptId); DataTable dataTable = job.Execute <DataTable>(); foreach (DataRow dataRow in dataTable.AsEnumerable()) { ActivityAttemptItemIdentifier activityAttemptItemId; LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.ActivityAttemptId], out activityAttemptItemId); long activityAttemptId = activityAttemptItemId.GetKey(); ActivityPackageItemIdentifier activityPackageItemId; LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.ActivityPackageId], out activityPackageItemId); long activityPackageId = activityPackageItemId.GetKey(); String activityTitle; LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.ActivityTitle], out activityTitle); InteractionItemIdentifier interactionItemId; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.InteractionId], out interactionItemId); long?interactionId = null; if (interactionItemId != null) { interactionId = interactionItemId.GetKey(); } Microsoft.LearningComponents.CompletionStatus completionStatus; LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.CompletionStatus], out completionStatus); IUDICO.Common.Models.Shared.Statistics.CompletionStatus iudicoCompletionStatus = (IUDICO.Common.Models.Shared.Statistics.CompletionStatus)completionStatus; Microsoft.LearningComponents.SuccessStatus?successStatus; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.SuccessStatus], out successStatus); IUDICO.Common.Models.Shared.Statistics.SuccessStatus?iudicoSuccessStatus = (IUDICO.Common.Models.Shared.Statistics.SuccessStatus?)successStatus; bool?learnerResponseBool = null; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.LearnerResponseBool], out learnerResponseBool); string learnerResponseString = null; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.LearnerResponseString], out learnerResponseString); double?learnerResponseNumeric = null; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.LearnerResponseNumeric], out learnerResponseNumeric); object learnerResponse = null; if (learnerResponseBool != null) { learnerResponse = learnerResponseBool; } if (learnerResponseString != null) { learnerResponse = learnerResponseString; } if (learnerResponseNumeric != null) { learnerResponse = learnerResponseNumeric; } string correctResponse; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.CorrectResponse], out correctResponse); Microsoft.LearningComponents.InteractionType?interactionType = null; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.InteractionType], out interactionType); IUDICO.Common.Models.Shared.Statistics.InteractionType?learnerResponseType = null; if (interactionType != null) { learnerResponseType = (IUDICO.Common.Models.Shared.Statistics.InteractionType)interactionType; } float?scaledScore; LStoreHelper.Cast <float>(dataRow[Schema.InteractionResultsByAttempt.ScaledScore], out scaledScore); // Create AnswerResult object AnswerResult answerResult = new AnswerResult(activityAttemptId, activityPackageId, activityTitle, interactionId, iudicoCompletionStatus, iudicoSuccessStatus, attemptResult, learnerResponse, correctResponse, learnerResponseType, scaledScore); result.Add(answerResult); } return(result); }
public Training(DataRow dataRow) { // extract information from <dataRow> into local variables PackageItemIdentifier packageId; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.PackageId], out packageId); long?pID; if (packageId == null) { pID = null; } else { pID = packageId.GetKey(); } string packageFileName; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.PackageFileName], out packageFileName); ActivityPackageItemIdentifier organizationId; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.OrganizationId], out organizationId); long?orgID; if (organizationId == null) { orgID = null; } else { orgID = organizationId.GetKey(); } string organizationTitle; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.OrganizationTitle], out organizationTitle); AttemptItemIdentifier attemptId; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.AttemptId], out attemptId); long?attID; if (attemptId == null) { attID = null; } else { attID = attemptId.GetKey(); } DateTime?uploadDateTime; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.UploadDateTime], out uploadDateTime); AttemptStatus?attemptStatus; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.AttemptStatus], out attemptStatus); float?score; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.TotalPoints], out score); this.PackageID = pID; this.PackageFileName = packageFileName; this.OrganizationID = orgID; this.OrganizationTitle = organizationTitle; this.AttemptID = attID; this.UploadDateTime = uploadDateTime; this.AttemptStatusProp = attemptStatus; this.TotalPoints = score; }
/// <summary> /// Performs mapping and setting appropriate fields of <paramref name="attemptResult"/> with given values. /// </summary> /// <param name="rawValue"><see cref="object"/> representing raw value retrieved from LearningStore (DB).</param> /// <param name="fieldName"><see cref="string"/> value representing name of the field (column).</param> /// <param name="attemptResult"><see cref="AttemptResult"/> value passed by reference. Parsed value is being assigned to it's corresponding property.</param> protected void ParseAttemptResultField(object rawValue, string fieldName, ref AttemptResult attemptResult) { switch (fieldName) { case Schema.AllAttemptsResults.AttemptId: AttemptItemIdentifier attemptItemId; LStoreHelper.CastNonNull(rawValue, out attemptItemId); attemptResult.AttemptId = attemptItemId.GetKey(); break; case Schema.AllAttemptsResults.AttemptStatus: AttemptStatus attemptStatus; LStoreHelper.CastNonNull(rawValue, out attemptStatus); attemptResult.AttemptStatus = (Common.Models.Shared.Statistics.AttemptStatus)attemptStatus; break; case Schema.AllAttemptsResults.CompletionStatus: CompletionStatus completionStatus; LStoreHelper.CastNonNull(rawValue, out completionStatus); attemptResult.CompletionStatus = (Common.Models.Shared.Statistics.CompletionStatus)completionStatus; break; case Schema.AllAttemptsResults.CurriculumChapterTopicId: int curriculumChapterTopicId; LStoreHelper.CastNonNull(rawValue, out curriculumChapterTopicId); var curriculumChapterTopic = this.CurriculumService.GetCurriculumChapterTopicById(curriculumChapterTopicId); if (curriculumChapterTopic == null) { throw new NoNullAllowedException( "Error while getting curriculum-chapter-topic with id = " + curriculumChapterTopicId); } attemptResult.CurriculumChapterTopic = curriculumChapterTopic; break; case Schema.AllAttemptsResults.IudicoCourseRef: int courseId; LStoreHelper.CastNonNull(rawValue, out courseId); var course = this.CourseService.GetCourse(courseId); if (course == null) { throw new NoNullAllowedException( "Error while getting course with id = " + courseId); } attemptResult.IudicoCourseRef = courseId; break; case Schema.AllAttemptsResults.MinScore: { float?score; LStoreHelper.Cast(rawValue, out score); attemptResult.Score.MinScore = score; } break; case Schema.AllAttemptsResults.MaxScore: { float?score; LStoreHelper.Cast(rawValue, out score); attemptResult.Score.MaxScore = score; } break; case Schema.AllAttemptsResults.RawScore: { float?score; LStoreHelper.Cast(rawValue, out score); attemptResult.Score.RawScore = score; } break; case Schema.AllAttemptsResults.Score: { float?score; LStoreHelper.Cast(rawValue, out score); float?scaledScore = null; if (score != null) { scaledScore = score / 100; } attemptResult.Score.ScaledScore = scaledScore; } break; case Schema.AllAttemptsResults.StartedTimestamp: DateTime?startTime; LStoreHelper.Cast(rawValue, out startTime); attemptResult.StartTime = startTime; break; case Schema.AllAttemptsResults.FinishedTimestamp: DateTime?finishTime; LStoreHelper.Cast(rawValue, out finishTime); attemptResult.FinishTime = finishTime; break; case Schema.AllAttemptsResults.SuccessStatus: SuccessStatus successStatus; LStoreHelper.CastNonNull(rawValue, out successStatus); attemptResult.SuccessStatus = (Common.Models.Shared.Statistics.SuccessStatus)successStatus; break; case Schema.AllAttemptsResults.TopicType: int rawTopicType; LStoreHelper.CastNonNull(rawValue, out rawTopicType); attemptResult.TopicType = (TopicTypeEnum)rawTopicType; break; case Schema.AllAttemptsResults.UserItemKey: string userKey; LStoreHelper.CastNonNull(rawValue, out userKey); var user = this.UserService.GetUsers().SingleOrDefault(curr => curr.Id.ToString() == userKey); if (user == null) { throw new NoNullAllowedException("Error while getting user with id = " + userKey); } attemptResult.User = user; break; } }
public IEnumerable <AnswerResult> GetAnswers(AttemptResult attemptResult) { LearningStoreJob job = this.LStore.CreateJob(); var attemptId = new AttemptItemIdentifier(attemptResult.AttemptId); this.RequestInteractionResultsByAttempt(job, attemptId); var dataTable = job.Execute <DataTable>(); foreach (DataRow dataRow in dataTable.AsEnumerable()) { ActivityAttemptItemIdentifier activityAttemptItemId; LStoreHelper.CastNonNull( dataRow[Schema.InteractionResultsByAttempt.ActivityAttemptId], out activityAttemptItemId); long activityAttemptId = activityAttemptItemId.GetKey(); ActivityPackageItemIdentifier activityPackageItemId; LStoreHelper.CastNonNull( dataRow[Schema.InteractionResultsByAttempt.ActivityPackageId], out activityPackageItemId); long activityPackageId = activityPackageItemId.GetKey(); string activityTitle; LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.ActivityTitle], out activityTitle); InteractionItemIdentifier interactionItemId; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.InteractionId], out interactionItemId); long?interactionId = null; if (interactionItemId != null) { interactionId = interactionItemId.GetKey(); } CompletionStatus completionStatus; LStoreHelper.CastNonNull( dataRow[Schema.InteractionResultsByAttempt.CompletionStatus], out completionStatus); var iudicoCompletionStatus = (Common.Models.Shared.Statistics.CompletionStatus)completionStatus; SuccessStatus?successStatus; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.SuccessStatus], out successStatus); var iudicoSuccessStatus = (Common.Models.Shared.Statistics.SuccessStatus?)successStatus; bool?learnerResponseBool; LStoreHelper.Cast( dataRow[Schema.InteractionResultsByAttempt.LearnerResponseBool], out learnerResponseBool); string learnerResponseString; LStoreHelper.Cast( dataRow[Schema.InteractionResultsByAttempt.LearnerResponseString], out learnerResponseString); double?learnerResponseNumeric; LStoreHelper.Cast( dataRow[Schema.InteractionResultsByAttempt.LearnerResponseNumeric], out learnerResponseNumeric); object learnerResponse = null; if (learnerResponseBool != null) { learnerResponse = learnerResponseBool; } if (learnerResponseString != null) { learnerResponse = learnerResponseString; } if (learnerResponseNumeric != null) { learnerResponse = learnerResponseNumeric; } string correctResponse; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.CorrectResponse], out correctResponse); InteractionType?interactionType; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.InteractionType], out interactionType); Common.Models.Shared.Statistics.InteractionType?learnerResponseType = null; if (interactionType != null) { learnerResponseType = (Common.Models.Shared.Statistics.InteractionType)interactionType; } float?minScore; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.MinScore], out minScore); float?maxScore; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.MaxScore], out maxScore); float?rawScore; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.RawScore], out rawScore); float?scaledScore; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.ScaledScore], out scaledScore); string primaryResourceFromManifest; LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.PrimaryResourceFromManifest], out primaryResourceFromManifest); // Create AnswerResult object var answerResult = new AnswerResult( activityAttemptId, activityPackageId, activityTitle, interactionId, iudicoCompletionStatus, iudicoSuccessStatus, attemptResult, learnerResponse, correctResponse, learnerResponseType, minScore, maxScore, rawScore, scaledScore, primaryResourceFromManifest); yield return(answerResult); } }
protected void Page_Load(object sender, EventArgs e) { // set <attemptId> to the ID of this attempt AttemptItemIdentifier attemptId = new AttemptItemIdentifier( Convert.ToInt64(Request.QueryString["AttemptId"], CultureInfo.InvariantCulture)); // set <previousEntryId> to the ID of the sequencing log entry that we most recently // displayed; newer entries than that will be highlighted long previousEntryId; string value = Request.QueryString["PreviousEntryId"]; if (value == null) { previousEntryId = long.MaxValue; } else { previousEntryId = Convert.ToInt64(value, CultureInfo.InvariantCulture); } try { // create a job to execute two queries LearningStoreJob job = LStore.CreateJob(); // first query: get the package name and organization title of this attempt LearningStoreQuery query = LStore.CreateQuery(Schema.MyAttemptsAndPackages.ViewName); query.AddColumn(Schema.MyAttemptsAndPackages.PackageFileName); query.AddColumn(Schema.MyAttemptsAndPackages.OrganizationTitle); query.AddCondition(Schema.MyAttemptsAndPackages.AttemptId, LearningStoreConditionOperator.Equal, attemptId); job.PerformQuery(query); // second query: get the contents of the sequencing log for this attempt query = LStore.CreateQuery(Schema.SequencingLog.ViewName); query.AddColumn(Schema.SequencingLog.Id); query.AddColumn(Schema.SequencingLog.Timestamp); query.AddColumn(Schema.SequencingLog.EventType); query.AddColumn(Schema.SequencingLog.NavigationCommand); query.AddColumn(Schema.SequencingLog.Message); query.SetParameter(Schema.SequencingLog.AttemptId, attemptId); query.AddSort(Schema.SequencingLog.Id, LearningStoreSortDirection.Descending); job.PerformQuery(query); // execute the job ReadOnlyCollection <object> results = job.Execute(); DataTable attemptInfoDataTable = (DataTable)results[0]; DataTable sequencingLogDataTable = (DataTable)results[1]; // extract information from the first query into local variables DataRow attemptInfo = attemptInfoDataTable.Rows[0]; string packageFileName; LStoreHelper.CastNonNull(attemptInfo[Schema.MyAttemptsAndPackages.PackageFileName], out packageFileName); string organizationTitle; LStoreHelper.CastNonNull(attemptInfo[Schema.MyAttemptsAndPackages.OrganizationTitle], out organizationTitle); // set <trainingName> to the name to use for this attempt string trainingName; if (organizationTitle.Length == 0) { trainingName = packageFileName; } else { trainingName = String.Format("{0} - {1}", packageFileName, organizationTitle); } // copy <trainingName> to the UI TrainingName.Text = Server.HtmlEncode(trainingName); // set <maxLogEntryId> to the highest-numbered log entry ID -- which is the first one, // since they're sorted by descending entry ID SequencingLogEntryItemIdentifier maxLogEntryId; if (sequencingLogDataTable.Rows.Count > 0) { DataRow dataRow = sequencingLogDataTable.Rows[0]; LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Id], out maxLogEntryId); } else { maxLogEntryId = new SequencingLogEntryItemIdentifier(-1); } // loop once for each item in the sequencing log foreach (DataRow dataRow in sequencingLogDataTable.Rows) { // extract information from <dataRow> into local variables SequencingLogEntryItemIdentifier logEntryId; LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Id], out logEntryId); DateTime?time; LStoreHelper.Cast(dataRow[Schema.SequencingLog.Timestamp], out time); SequencingEventType?eventType; LStoreHelper.Cast(dataRow[Schema.SequencingLog.EventType], out eventType); NavigationCommand?navigationCommand; LStoreHelper.Cast(dataRow[Schema.SequencingLog.NavigationCommand], out navigationCommand); string message; LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Message], out message); // begin the HTML table row TableRow htmlRow = new TableRow(); // highlight this row if it's new since the last refresh if (logEntryId.GetKey() > previousEntryId) { htmlRow.CssClass = "Highlight"; } // add the "ID" HTML cell TableCell htmlCell = new TableCell(); htmlCell.CssClass = "Id_"; htmlCell.Wrap = false; htmlCell.Text = NoBr(Server.HtmlEncode(logEntryId.GetKey().ToString())); htmlRow.Cells.Add(htmlCell); // add the "Time" HTML cell htmlCell = new TableCell(); htmlCell.CssClass = "Time_"; htmlCell.Wrap = false; htmlCell.Text = NoBr(Server.HtmlEncode(String.Format("{0:d} {0:t}", time))); htmlRow.Cells.Add(htmlCell); // add the "EventType" HTML cell htmlCell = new TableCell(); htmlCell.CssClass = "EventType_"; htmlCell.Wrap = false; htmlCell.Text = NoBr(Server.HtmlEncode(eventType.ToString())); htmlRow.Cells.Add(htmlCell); // add the "NavigationCommand" HTML cell htmlCell = new TableCell(); htmlCell.CssClass = "NavigationCommand_"; htmlCell.Wrap = false; htmlCell.Text = NoBr(Server.HtmlEncode(navigationCommand.ToString())); htmlRow.Cells.Add(htmlCell); // add the "Message" HTML cell htmlCell = new TableCell(); htmlCell.CssClass = "Message_"; htmlCell.Wrap = false; htmlCell.Text = Server.HtmlEncode(message); htmlRow.Cells.Add(htmlCell); // end the table HTML row; add it to the HTML table LogGrid.Rows.Add(htmlRow); } // update <RefreshLink> RefreshLink.NavigateUrl = String.Format("?AttemptId={0}&PreviousEntryId={1}", attemptId.GetKey(), maxLogEntryId.GetKey()); } 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 LogTitle.Visible = false; LogContents.Visible = false; 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 accessing the sequencing log for attempt #{0}:\n\n{1}\n\n", attemptId.GetKey(), ex.ToString()); } }
public Training(DataRow dataRow) { // extract information from <dataRow> into local variables PackageItemIdentifier packageId; LStoreHelper.CastNonNull(dataRow[Schema.MyAttempts.PackageId], out packageId); long?pId; if (packageId == null) { pId = null; } else { pId = packageId.GetKey(); } ActivityPackageItemIdentifier organizationId; LStoreHelper.CastNonNull(dataRow[Schema.MyAttempts.OrganizationId], out organizationId); long?orgId; if (organizationId == null) { orgId = null; } else { orgId = organizationId.GetKey(); } AttemptItemIdentifier attemptId; LStoreHelper.Cast(dataRow[Schema.MyAttempts.AttemptId], out attemptId); long?attId; if (attemptId == null) { attId = null; } else { attId = attemptId.GetKey(); } AttemptStatus?attemptStatus; LStoreHelper.Cast(dataRow[Schema.MyAttempts.AttemptStatus], out attemptStatus); float?score; LStoreHelper.Cast(dataRow[Schema.MyAttempts.TotalPoints], out score); PackageId = pId; OrganizationId = orgId; AttemptId = attId; AttemptStatusProp = attemptStatus; TotalPoints = score; }
/// <summary> /// Reads a <c>DataTable</c>, returned by <c>Job.Execute</c>, containing the results requested /// by a previous call to <c>RequestMyTraining</c>. Converts the results to HTML rows, added /// to a given HTML table. /// </summary> /// /// <param name="dataTable">A <c>DataTable</c> returned from <c>Job.Execute</c>.</param> /// /// <param name="htmlTable">The HTML table to write to.</param> /// protected void GetMyTrainingResultsToHtml(DataTable dataTable, Table htmlTable) { // loop once for each organization of each package PackageItemIdentifier previousPackageId = null; foreach (DataRow dataRow in dataTable.Rows) { // extract information from <dataRow> into local variables PackageItemIdentifier packageId; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.PackageId], out packageId); string packageFileName; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.PackageFileName], out packageFileName); ActivityPackageItemIdentifier organizationId; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.OrganizationId], out organizationId); string organizationTitle; LStoreHelper.CastNonNull(dataRow[Schema.MyAttemptsAndPackages.OrganizationTitle], out organizationTitle); AttemptItemIdentifier attemptId; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.AttemptId], out attemptId); DateTime?uploadDateTime; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.UploadDateTime], out uploadDateTime); AttemptStatus?attemptStatus; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.AttemptStatus], out attemptStatus); float?score; LStoreHelper.Cast(dataRow[Schema.MyAttemptsAndPackages.TotalPoints], out score); // if this <dataRow> is another organization (basically another "table of contents") // within the same package as the previous <dataRow>, set <samePackage> to true bool samePackage = ((previousPackageId != null) && (packageId.GetKey() == previousPackageId.GetKey())); // begin the HTML table row TableRow htmlRow = new TableRow(); htmlRow.ID = "Package" + packageId.GetKey().ToString(); // set <trainingName> to a name to use for this row (i.e. one // organization of one package) string trainingName; if (organizationTitle.Length == 0) { trainingName = packageFileName; } else { trainingName = String.Format("{0} - {1}", packageFileName, organizationTitle); } // add the "Select" HTML cell, unless this row is for the same // package as the previous row TableCell htmlCell = new TableCell(); if (samePackage) { htmlCell.CssClass = "Select_ SamePackage_"; } else { htmlCell.CssClass = "Select_ NewPackage_"; CheckBox checkBox = new CheckBox(); checkBox.ID = "Select" + packageId.GetKey().ToString(); checkBox.Attributes.Add("onclick", "OnSelectionChanged()"); checkBox.ToolTip = "Select"; htmlCell.Controls.Add(checkBox); } htmlRow.Cells.Add(htmlCell); // add the "Name" HTML cell htmlCell = new TableCell(); htmlCell.CssClass = "Name_"; HtmlAnchor anchor = new HtmlAnchor(); if (attemptId == null) { // attempt has not yet been created for this training -- create an URL that begins // with "Org:", indicating that the ID is an OrganizationId which identifies // which organization of which package to launch anchor.HRef = String.Format("javascript:OpenTraining('Org:{0}')", organizationId.GetKey()); // give this anchor an ID that allows client-side script to update its URL once // training has been launched anchor.ID = String.Format("Org_{0}", organizationId.GetKey()); // provide a tooltip anchor.Attributes.Add("title", "Begin training"); } else { // attempt was already created -- include its ID in the URL anchor.HRef = String.Format("javascript:OpenTraining('Att:{0}')", attemptId.GetKey()); // provide a tooltip anchor.Attributes.Add("title", "Continue training"); } anchor.InnerText = trainingName; htmlCell.Controls.Add(anchor); htmlRow.Cells.Add(htmlCell); // add the "Uploaded" HTML cell htmlCell = new TableCell(); htmlCell.CssClass = "Uploaded_"; htmlCell.Wrap = false; htmlCell.Text = NoBr(Server.HtmlEncode( String.Format("{0:d} {0:t}", uploadDateTime))); htmlRow.Cells.Add(htmlCell); // add the "Status" HTML cell string attemptStatusString; if (attemptStatus == null) { attemptStatusString = "Not Started"; } else { attemptStatusString = attemptStatus.ToString(); } htmlCell = new TableCell(); htmlCell.CssClass = "Status_"; htmlCell.Wrap = false; if (attemptId != null) { anchor = new HtmlAnchor(); anchor.HRef = String.Format("javascript:ShowLog({0})", attemptId.GetKey()); anchor.InnerHtml = NoBr(Server.HtmlEncode(attemptStatusString)); anchor.Attributes.Add("title", "Show Log"); htmlCell.Controls.Add(anchor); } else { htmlCell.Text = NoBr(Server.HtmlEncode(attemptStatusString)); } htmlRow.Cells.Add(htmlCell); // add the "Score" HTML cell string scoreString; if (score == null) { scoreString = ""; } else { scoreString = String.Format("{0:0}%", Math.Round(score.Value)); } htmlCell = new TableCell(); htmlCell.CssClass = "Score_"; htmlCell.Wrap = false; htmlCell.Text = NoBr(Server.HtmlEncode(scoreString)); htmlRow.Cells.Add(htmlCell); // end the table HTML row; add it to the HTML table htmlTable.Rows.Add(htmlRow); previousPackageId = packageId; } }