public static IudicoCourseInfo Parse(Course course, ICourseStorage storage) { int id = course.Id; IudicoCourseInfo ci = new IudicoCourseInfo(); ci.Id = id; var nodes = storage.GetNodes(id).ToList(); for (var i = 0; i < nodes.Count; i++) { if (nodes[i].IsFolder == false) { try { ci.NodesInfo.Add(ParseNode(nodes[i], storage)); } catch { } } else { var subNodes = storage.GetNodes(id, nodes[i].Id); nodes.AddRange(subNodes); } } return(ci); }
/// <summary> /// constructor that get all information from Testing System /// </summary> /// <param name="attemptId">id of attempt to show</param> /// <param name="attList">list of attempts from Session Context</param> /// <param name="lmsService">ILmsService for conection to Testing System</param> public TopicTestResultsModel(long attemptId, IEnumerable <AttemptResult> attList, int groupId, ILmsService lmsService) { if (attemptId != -1) { this.group = lmsService.FindService <IUserService>().GetGroup(groupId); // hotfix: added checking of Course id this.attempt = attList.FirstOrDefault( c => c.AttemptId == attemptId && c.CurriculumChapterTopic.Topic.TestCourseRef == c.IudicoCourseRef); if (this.attempt != null) { this.userAnswers = lmsService.FindService <ITestingService>().GetAnswers(this.attempt); this.courseInfo = lmsService.FindService <ICourseService>().GetCourseInfo(this.attempt.IudicoCourseRef); this.hasNoData = this.userAnswers == null; } else { this.hasNoData = true; } } else { this.hasNoData = true; } }
public CurrentTopicTestResultsModel(int curriculumChapterTopicId, TopicTypeEnum topicType, int groupId, ILmsService lmsService) { this.group = lmsService.FindService <IUserService>().GetGroup(groupId); var currenUser = lmsService.FindService <IUserService>().GetCurrentUser(); var curriculumChapterTopic = lmsService.FindService <ICurriculumService>().GetCurriculumChapterTopicById(curriculumChapterTopicId); if (currenUser != null & curriculumChapterTopic != null) { var attemptResults = lmsService.FindService <ITestingService>().GetResults(currenUser, curriculumChapterTopic, topicType).ToList(); if (attemptResults.Any()) { // hotfix: added checking of Course id this.attempt = attemptResults.FirstOrDefault(x => x.CurriculumChapterTopic.Topic.TestCourseRef == x.IudicoCourseRef); if (this.attempt != null) { this.courseInfo = lmsService.FindService <ICourseService>().GetCourseInfo(this.attempt.IudicoCourseRef); this.userAnswers = lmsService.FindService <ITestingService>().GetAnswers(this.attempt); this.hasNoData = this.userAnswers == null; } } else { this.hasNoData = true; } } else { this.hasNoData = true; } }
public int AddCourseInfo(IudicoCourseInfo courseInfo) { var id = this.storage.AddCourseInfo(courseInfo); this.cacheProvider.Invalidate("coursesInfo"); return(id); }
public virtual string Export(int id, bool exportForPlayCourse = false) { var course = this.GetCourse(id); var path = this.GetCoursePath(id); if (course.Locked != null && course.Locked.Value) { return(path + ".zip"); } path = Path.Combine(path, Guid.NewGuid().ToString()); path = Path.Combine(path, course.Name); Directory.CreateDirectory(path); var nodes = this.GetNodes(id).ToList(); for (var i = 0; i < nodes.Count; i++) { if (nodes[i].IsFolder == false) { File.Copy(this.GetNodePath(nodes[i].Id) + ".html", Path.Combine(path, nodes[i].Id + ".html")); } else { var subNodes = GetNodes(id, nodes[i].Id); nodes.AddRange(subNodes); } } var coursePath = this.GetCoursePath(id); FileHelper.DirectoryCopy(Path.Combine(coursePath, "Node"), Path.Combine(path, "Node")); foreach (var file in this.templateFiles) { try { File.Copy(Path.Combine(coursePath, file), Path.Combine(path, file), true); } catch (FileNotFoundException) { continue; } } var helper = new ManifestManager(); var manifest = new Manifest(); var sw = new StreamWriter(Path.Combine(path, SCORM.ImsManifset)); var parentItem = new Item(); parentItem = this.AddSubItems(parentItem, null, id, helper, ref manifest); manifest.Organizations = ManifestManager.AddOrganization(manifest.Organizations, helper.CreateOrganization()); manifest.Organizations.Default = manifest.Organizations[0].Identifier; manifest.Organizations[0].Items = parentItem.Items; manifest.Organizations[0].Title = course.Name; if (course.Sequencing != null) { var xml = new XmlSerializer(typeof(Sequencing)); manifest.Organizations[0].Sequencing = (Sequencing)xml.DeserializeXElement(course.Sequencing); } var resource = new Resource { Identifier = ResourceIdForTemplateFiles, Files = this.templateFiles.Select(file => new ManifestModels.ResourceModels.File(file)).ToList(), ScormType = ScormType.Asset }; manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource); ManifestManager.Serialize(manifest, sw); sw.Close(); Zipper.CreateZip(path + ".zip", path); if (exportForPlayCourse) { try { IudicoCourseInfo ci = CourseParser.Parse(course, this); this.AddCourseInfo(ci); } catch (Exception ex) { log.Error(string.Format("Exception message: {0}\nData: {1}\nHelp Link: {2}\nInner exception: {3}\nSource: {4}\nStack trace: {5}\nTarget site: {6}", ex.Message, ex.Data, ex.HelpLink, ex.InnerException, ex.Source, ex.StackTrace, ex.TargetSite)); } } return(path + ".zip"); }
public IudicoCourseInfo GetCourseInfo(int id) { var db = this.GetDbContext(); var courseInfo = new IudicoCourseInfo { Id = id }; var databaseNodesInfo = db.NodesInfo.Where(n => n.CourseId == id); foreach (var ni in databaseNodesInfo) { var nodeInfo = new IudicoNodeInfo { CourseId = id, Id = ni.NodeId }; var databaseQuestionsInfo = db.QuestionsInfo.Where(q => q.NodeId == ni.NodeId); foreach (var qi in databaseQuestionsInfo) { IudicoQuestionInfo questionInfo = null; switch (qi.Type) { case 1: var simpleQuestion = db.SimpleQuestions.Single(q => q.QuestionId == qi.Id); questionInfo = new IudicoSimpleQuestion { QuestionText = qi.Text, MaxScore = qi.MaxScore, Type = IudicoQuestionType.IudicoSimple, CorrectAnswer = simpleQuestion.CorrectAnswer }; break; case 2: var options = db.ChoiceQuestionsOptions.Where(q => q.QuestionId == qi.Id); var correctChoice = db.ChoiceQuestionsCorrectChoices.Single(q => q.QuestionId == qi.Id); questionInfo = new IudicoChoiceQuestion { QuestionText = qi.Text, MaxScore = qi.MaxScore, Type = IudicoQuestionType.IudicoChoice, CorrectChoice = correctChoice.CorrectChoice, Options = (from o in options select new Tuple <string, string>(o.Option, o.Description)).ToList() }; break; case 3: var compiledTests = db.CompiledTestQuestions.Where(q => q.QuestionId == qi.Id); questionInfo = new IudicoCompiledTest { QuestionText = qi.Text, MaxScore = qi.MaxScore, Type = IudicoQuestionType.IudicoCompile, TestInputs = (from ct in compiledTests select new Tuple <string, string>("testInput" + ct.TestNumber, ct.TestInput)).ToList(), TestOutputs = (from ct in compiledTests select new Tuple <string, string>("testOutput" + ct.TestNumber, ct.TestOutput)).ToList(), }; break; } nodeInfo.QuestionsInfo.Add(questionInfo); } courseInfo.NodesInfo.Add(nodeInfo); } return(courseInfo); }
public virtual int AddCourseInfo(IudicoCourseInfo courseInfo) { var db = this.GetDbContext(); CoursesInfo ci = new CoursesInfo { CourseId = courseInfo.Id, OverallMaxScore = (float)courseInfo.OverallMaxScore }; db.CoursesInfo.InsertOnSubmit(ci); db.SubmitChanges(); foreach (IudicoNodeInfo nodeInfo in courseInfo.NodesInfo) { NodesInfo ni = new NodesInfo { CourseId = courseInfo.Id, NodeId = nodeInfo.Id, MaxScore = (float)nodeInfo.MaxScore }; db.NodesInfo.InsertOnSubmit(ni); db.SubmitChanges(); foreach (IudicoQuestionInfo questionInfo in nodeInfo.QuestionsInfo) { QuestionsInfo qi = new QuestionsInfo { NodeId = nodeInfo.Id, Text = questionInfo.QuestionText, MaxScore = (float)questionInfo.MaxScore }; switch (questionInfo.Type) { case IudicoQuestionType.IudicoSimple: qi.Type = 1; break; case IudicoQuestionType.IudicoChoice: qi.Type = 2; break; case IudicoQuestionType.IudicoCompile: qi.Type = 3; break; } db.QuestionsInfo.InsertOnSubmit(qi); db.SubmitChanges(); switch (questionInfo.Type) { case IudicoQuestionType.IudicoSimple: SimpleQuestion sq = new SimpleQuestion { QuestionId = qi.Id, CorrectAnswer = (questionInfo as IudicoSimpleQuestion).CorrectAnswer }; db.SimpleQuestions.InsertOnSubmit(sq); db.SubmitChanges(); break; case IudicoQuestionType.IudicoChoice: ChoiceQuestionsCorrectChoice cqcc = new ChoiceQuestionsCorrectChoice { QuestionId = qi.Id, CorrectChoice = (questionInfo as IudicoChoiceQuestion).CorrectChoice }; db.ChoiceQuestionsCorrectChoices.InsertOnSubmit(cqcc); db.SubmitChanges(); foreach (var option in (questionInfo as IudicoChoiceQuestion).Options) { ChoiceQuestionsOption cqo = new ChoiceQuestionsOption { QuestionId = qi.Id, Option = option.Item1, Description = option.Item2 }; db.ChoiceQuestionsOptions.InsertOnSubmit(cqo); db.SubmitChanges(); } break; case IudicoQuestionType.IudicoCompile: for (int i = 0; i < (questionInfo as IudicoCompiledTest).NumberOfTests; ++i) { CompiledTestQuestion ctq = new CompiledTestQuestion { QuestionId = qi.Id, TestNumber = i, TestInput = (questionInfo as IudicoCompiledTest).TestInputs[i].Item2, TestOutput = (questionInfo as IudicoCompiledTest).TestOutputs[i].Item2 }; db.CompiledTestQuestions.InsertOnSubmit(ctq); db.SubmitChanges(); } break; } } } return(courseInfo.Id); }