Exemplo n.º 1
0
        public void Parse(int courseId)
        {
            var db = GetDbContext();
            var course = db.Courses.Single(c => c.Id == courseId);

            if (!course.Locked.Value)
            {
                return;
            }

            var coursePath = GetCoursePath(course.Id);
            var courseTempPath = GetCourseTempPath(course.Id);
            var manifestPath = Path.Combine(courseTempPath, SCORM.ImsManifset);

            Zipper.ExtractZipFile(coursePath + ".zip", courseTempPath);

            var reader = new XmlTextReader(new FileStream(manifestPath, FileMode.Open));
            var manifest = Manifest.Deserialize(reader);
            
            var importer = new Importer(manifest, course, this);

            importer.Import();

            course.Locked = false;

            db.SubmitChanges();
        }
Exemplo n.º 2
0
        public virtual void Parse(int courseId)
        {
            var db = this.GetDbContext();
            var course = db.Courses.Single(c => c.Id == courseId);

            if (!course.Locked.Value)
            {
                return;
            }

            var coursePath = this.GetCoursePath(course.Id);
            var courseTempPath = this.GetCourseTempPath(course.Id);
            var manifestPath = Path.Combine(courseTempPath, SCORM.ImsManifset);

            Zipper.ExtractZipFile(coursePath + ".zip", courseTempPath);

            var manifest = Manifest.Deserialize(manifestPath);

            var importer = new Importer(manifest, course, this);

            importer.Import();

            // QUICK FIX for importing images
            var imagesPath = Path.Combine(courseTempPath, "Node");
            if (Directory.Exists(imagesPath))
            {
                FileHelper.DirectoryCopy(imagesPath, Path.Combine(coursePath, "Node"));
            }

            // QUICK FIX for "Row not found or changed." exception
            db = this.GetDbContext();
            course = db.Courses.Single(c => c.Id == courseId);
            course.Locked = false;

            var xml = new XmlSerializer(typeof(Sequencing));

            // try to apply sequencing from imported course
            try
            {
                var sequencing = manifest.SequencingCollection.Sequencings[0];
                course.Sequencing = xml.SerializeToXElemet(sequencing);
            }
            catch (Exception) // apply default sequencing if any errors occured
            {
                var sequencing = new Sequencing();
                sequencing = SequencingPatternManager.ApplyDefaultChapterSequencing(sequencing);
                course.Sequencing = xml.SerializeToXElemet(sequencing);
            }

            db.SubmitChanges();
        }