public void AddResourceTest() { var resources = new Resources(); var resource = new Resource { Base = "Base", Identifier = "Identifier" }; ManifestManager.AddResource(resources, resource); var res = resources.ResourcesList.Single(i => i.Base == "Base"); Assert.AreEqual("Identifier", res.Identifier); }
public void AddResourceTest() { IUDICO.CourseManagement.Models.ManifestModels.ResourceModels.Resources resources = new IUDICO.CourseManagement.Models.ManifestModels.ResourceModels.Resources(); Resource resource = new Resource { Base = "Base", Identifier = "Identifier" }; ManifestManager.AddResource(resources, resource); Resource res = resources._Resources.Single(i => i.Base == "Base"); Assert.AreEqual("Identifier", res.Identifier); }
protected Item AddSubItems(Item parentItem, Node parentNode, int courseId, ManifestManager helper, ref Manifest manifest) { var nodes = parentNode == null?GetNodes(courseId) : GetNodes(courseId, parentNode.Id); foreach (var node in nodes) { if (node.IsFolder) { var item = helper.CreateItem(); item.Title = node.Name; if (node.Sequencing != null) { var xml = new XmlSerializer(typeof(Sequencing)); item.Sequencing = (Sequencing)xml.DeserializeXElement(node.Sequencing); } item = AddSubItems(item, node, courseId, helper, ref manifest); parentItem = ManifestManager.AddItem(parentItem, item); } else { var files = new List <ManifestModels.ResourceModels.File>(); files.Add(new ManifestModels.ResourceModels.File(node.Id + ".html")); var resource = helper.CreateResource(ScormType.SCO, files, new[] { _ResourceIdForTemplateFiles }); resource.Href = node.Id + ".html"; manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource); var item = helper.CreateItem(resource.Identifier); item.Title = node.Name; if (node.Sequencing != null) { var xml = new XmlSerializer(typeof(Sequencing)); item.Sequencing = (Sequencing)xml.DeserializeXElement(node.Sequencing); } parentItem = ManifestManager.AddItem(parentItem, item); } } return(parentItem); }
public string Export(int id) { var course = GetCourse(id); var path = 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 = GetNodes(id).ToList(); for (var i = 0; i < nodes.Count; i++) { if (nodes[i].IsFolder == false) { File.Copy(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 = GetCoursePath(id); FileHelper.DirectoryCopy(Path.Combine(coursePath, "Node"), Path.Combine(path, "Node")); foreach (var file in _TemplateFiles) { File.Copy(Path.Combine(coursePath, file), Path.Combine(path, file)); } var helper = new ManifestManager(); var manifest = new Manifest(); var sw = new StreamWriter(Path.Combine(path, SCORM.ImsManifset)); var parentItem = new Item(); parentItem = 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 = _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); return(path + ".zip"); }
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"); }