Пример #1
0
        protected void ProcessResource(Node node, Resource resource)
        {
            var nodePath = this.courseStorage.GetNodePath(node.Id);
            var coursePath = this.courseStorage.GetCoursePath(node.CourseId);

            File.Copy(Path.Combine(this.courseTempPath, resource.Href), nodePath + ".html", true);

            foreach (var file in resource.Files)
            {

                if (file.Href != resource.Href)
                {
                   var path = Path.Combine(coursePath, file.Href);
                   if (!Directory.GetParent(path).Exists)
                   {
                      Directory.CreateDirectory(Directory.GetParent(path).ToString());
                   }

                   File.Copy(Path.Combine(this.courseTempPath, file.Href), Path.Combine(coursePath, file.Href));
                }
            }

            foreach (var dependency in resource.Dependencies)
            {
                var depResource = this.manifest.Resources.ResourcesList.Where(r => r.Identifier == dependency.IdentifierRef).FirstOrDefault();

                if (depResource != null)
                {
                    this.manifest.Resources.ResourcesList.Remove(depResource);

                    this.ProcessDependencyResource(node, depResource);
                }
            }
        }
Пример #2
0
        protected void ProcessResource(Node node, Resource resource)
        {
            var nodePath = _CourseStorage.GetNodePath(node.Id);
            var coursePath = _CourseStorage.GetCoursePath(node.CourseId);

            File.Copy(Path.Combine(_CourseTempPath, resource.Href), nodePath + ".html", true);

            foreach (var file in resource.Files)
            {
                if (file.Href != resource.Href)
                {
                    File.Copy(Path.Combine(_CourseTempPath, file.Href), Path.Combine(coursePath, file.Href));
                }
            }

            foreach (var dependency in resource.Dependencies)
            {
                var depResource = _Manifest.Resources._Resources.Where(r => r.Identifier == dependency.IdentifierRef).FirstOrDefault();

                if (depResource != null)
                {
                    _Manifest.Resources._Resources.Remove(depResource);

                    ProcessDependencyResource(node, depResource);
                }
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        public Resource CreateResource(ScormType type, List<File> files = null, IEnumerable<string> dependOnResourcesIds = null)
        {
            var resource = new Resource()
                               {
                                   Identifier = ConstantStrings.ResourceIdPrefix + _ResourcesCount++,
                                   ScormType = type
                               };
            if(files != null)
            {
                resource.Files = files;
            }

            if (dependOnResourcesIds != null)
            {
                foreach (var resId in dependOnResourcesIds)
                {
                    resource.Dependencies.Add(new Dependency(resId));
                }
            }

            return resource;
        }
Пример #6
0
        protected void ProcessDependencyResource(Node node, Resource resource)
        {
            foreach (var file in resource.Files)
            {
                if (!File.Exists(Path.Combine(_CoursePath, file.Href)))
                {
                    File.Copy(Path.Combine(_CourseTempPath, file.Href), Path.Combine(_CoursePath, file.Href));
                }
            }

            foreach (var dependency in resource.Dependencies)
            {
                var depResource = _Manifest.Resources._Resources.Where(r => r.Identifier == dependency.IdentifierRef).FirstOrDefault();

                if (depResource != null)
                {
                    _Manifest.Resources._Resources.Remove(depResource);

                    ProcessDependencyResource(node, depResource);
                }
            }
        }
Пример #7
0
        public void ResourceTest()
        {
            var resource = new Resource();
            resource.Base = "base";
            resource.Dependencies.Add(new Dependency("ref"));
            resource.Files.Add(
                new IUDICO.CourseManagement.Models.ManifestModels.ResourceModels.File("href")
                    {
                       Metadata = new Metadata() 
                    });
            resource.Href = "href";
            resource.Metadata = new Metadata();
            resource.ScormType = ScormType.SCO;
            resource.Type = "web";

            var manifest = new Manifest();
            manifest.Resources.ResourcesList.Add(resource);

            var path = Path.Combine(this.root, "resource.xml");
            manifest.Serialize(new StreamWriter(path));
            Assert.IsTrue(File.Exists(path));
        }
Пример #8
0
        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";
        }
Пример #9
0
 public static Resources AddResource(Resources resources, Resource resource)
 {
     resources._Resources.Add(resource);
     return resources;
 }
Пример #10
0
        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";
        }