Пример #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();
        }
Пример #2
0
 static void Main(string[] args)
 {
     using (var instream = File.OpenRead("test.zip"))
     {
         Zipper.ExtractZipFile(instream, "./extract");
     }
 }
Пример #3
0
        public void ExportTest()
        {
            // creating discipline
            var controller    = this.GetController <DisciplineController>();
            var disciplineIds = this.DataPreparer.CreateDisciplinesSet1();

            //exporting into .zip file
            var path = controller.Export(disciplineIds[0]);

            // exctracting into temp folder
            Zipper.ExtractZipFile(path.FileName, Path.GetTempPath());

            // deserializing
            var        reader                 = new FileStream(Path.GetTempPath() + "\\" + this.DisciplineStorage.GetDiscipline(disciplineIds[0]).Name + ".disc", FileMode.Open);
            var        serializer             = new XmlSerializer(typeof(DisciplineDto));
            var        deserializedDiscipline = (DisciplineDto)serializer.Deserialize(reader);
            Discipline excpectedDiscipline    = this.DisciplineStorage.GetDiscipline(disciplineIds[0]);

            // checking if created discipline is similar to exported one
            Assert.AreEqual(deserializedDiscipline.Name, excpectedDiscipline.Name);
            Assert.AreEqual(deserializedDiscipline.Chapters.Count, excpectedDiscipline.Chapters.Count);
            for (int i = 0; i < excpectedDiscipline.Chapters.Count; i++)
            {
                Assert.AreEqual(excpectedDiscipline.Chapters[i], deserializedDiscipline.Chapters[i]);
            }
        }
Пример #4
0
        /// <summary>
        /// Open zip package that contains course's files
        /// </summary>
        /// <param name="fileName">If course is opened return true</param>
        public static bool OpenZipPackage([NotNull] string fileName)
        {
            FFDebug.EnterMethod(Cattegory.Course, string.Format("fileName:'{0}'", fileName));
            var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Zipper.ExtractZipFile(fileName, path);
            bool res = Open(path);

            if (res)
            {
                var lc = Settings.Default.LastCoursesXml;
                if (!lc.Contains(fileName))
                {
                    lc.Add(fileName);
                    if (lc.Count > 9)
                    {
                        lc.RemoveAt(0);
                    }
                    Settings.Default.LastCoursesXml = lc;
                }
            }

            FFDebug.LeaveMethod(Cattegory.Course, MethodBase.GetCurrentMethod());

            return(res);
        }
Пример #5
0
        public void ImportButton_Click()
        {
            if (CourseUpload.HasFile)
            {
                try
                {
                    projectPaths.Initialize(CourseUpload.FileName);
                    CourseUpload.SaveAs(projectPaths.PathToCourseZipFile);
                    Zipper.ExtractZipFile(projectPaths.PathToCourseZipFile, projectPaths.PathToTempCourseFolder);

                    string     courseName = CourseName.Value == "" ? Path.GetFileNameWithoutExtension(CourseUpload.FileName) : CourseName.Value;
                    int        courseId   = CourseManager.Import(projectPaths, courseName, CourseDescription.Value);
                    TblCourses course     = ServerModel.DB.Load <TblCourses>(courseId);

                    //grant permissions for this course
                    PermissionsManager.Grand(course, FxCourseOperations.Use, ServerModel.User.Current.ID, null, DateTimeInterval.Full);
                    PermissionsManager.Grand(course, FxCourseOperations.Modify, ServerModel.User.Current.ID, null, DateTimeInterval.Full);

                    //Update course tree
                    CourseTree.DataSource = GetCourses();
                }
                catch (Exception e)
                {
                    //Message.Value = e.ToString();
                    Message.Value = e.Message;
                    //Message.Value = uploadError;
                }
            }
            else
            {
                Message.Value = fileNotFound;
            }
        }
Пример #6
0
        public bool Validate(HttpPostedFileBase file)
        {
            var fileName = GetImportFileName(Path.GetFileNameWithoutExtension(file.FileName));
            var path     = Path.Combine(GetFolderPath(), fileName);

            Directory.CreateDirectory(GetFolderPath());
            file.SaveAs(path);
            var pathToExtract = Path.Combine(GetFolderPath(), Guid.NewGuid().ToString());

            Zipper.ExtractZipFile(path, pathToExtract);

            if (Directory.GetFiles(pathToExtract, "*.disc").Count() == 0)
            {
                Directory.Delete(pathToExtract, true);
                return(false);
            }

            foreach (var courseFile in Directory.GetFiles(pathToExtract, "*.zip"))
            {
                if (!PackageValidator.Validate(courseFile).Contains("Package is valid."))
                {
                    Directory.Delete(pathToExtract, true);
                    return(false);
                }
            }

            Directory.Delete(pathToExtract, true);
            return(true);
        }
Пример #7
0
        public List <string> Validate(string path, ref int countCourses, ref int countValidCourses, ref int countInvalidCourses)
        {
            List <string> messages = new List <string>();

            var pathToExtract = Path.Combine(GetFolderPath(), Guid.NewGuid().ToString());

            Zipper.ExtractZipFile(path, pathToExtract);

            if (Directory.GetFiles(pathToExtract, "*.disc").Count() == 0)
            {
                messages.Add("Archive doesn't contain file with .disc extension");
            }

            string[] files = Directory.GetFiles(pathToExtract, "*.zip");
            countCourses = files.Count();

            foreach (var courseFile in files)
            {
                List <string> courseMessages = PackageValidator.Validate(courseFile);
                messages.AddRange(courseMessages.AsEnumerable());

                if (courseMessages.Contains("Package is valid."))
                {
                    countValidCourses++;
                }
                else
                {
                    countInvalidCourses++;
                }
            }

            Directory.Delete(pathToExtract, true);

            return(messages);
        }
Пример #8
0
        public void Import(string path)
        {
            var pathToExtract = Path.Combine(GetFolderPath(), Guid.NewGuid().ToString());

            Zipper.ExtractZipFile(path, pathToExtract);
            this.Deserialize(pathToExtract);
            Directory.Delete(pathToExtract, true);
        }
Пример #9
0
        public void ExtractZipFileTest()
        {
            var folder = Path.Combine(this.root, @"Zipped Folder");

            var zip = Path.Combine(this.root, @"Zipped Folder.zip");

            Zipper.ExtractZipFile(zip, folder);

            Assert.IsTrue(Directory.Exists(folder));
        }
Пример #10
0
        public void ExtractZipFileTest()
        {
            // creating the folder
            var folder = Path.Combine(this.root, @"Zipped Folder");
            // creating zip file from which we extract
            var zip = Path.Combine(this.root, @"Zipped Folder.zip");

            //extracting into folder
            Zipper.ExtractZipFile(zip, folder);

            Assert.IsTrue(Directory.Exists(folder));
        }
Пример #11
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();
        }
Пример #12
0
        public void Import(HttpPostedFileBase file)
        {
            var fileName = GetImportFileName(Path.GetFileNameWithoutExtension(file.FileName));
            var path     = Path.Combine(GetFolderPath(), fileName);

            Directory.CreateDirectory(GetFolderPath());
            file.SaveAs(path);

            var pathToExtract = Path.Combine(GetFolderPath(), Guid.NewGuid().ToString());

            Zipper.ExtractZipFile(path, pathToExtract);
            this.Deserialize(pathToExtract);
            Directory.Delete(pathToExtract, true);
        }
Пример #13
0
        public bool Validate(string path)
        {
            var pathToExtract = Path.Combine(GetFolderPath(), Guid.NewGuid().ToString());

            Zipper.ExtractZipFile(path, pathToExtract);

            if (Directory.GetFiles(pathToExtract, "*.disc").Count() == 0)
            {
                Directory.Delete(pathToExtract, true);
                return(false);
            }

            foreach (var courseFile in Directory.GetFiles(pathToExtract, "*.zip"))
            {
                if (!PackageValidator.Validate(courseFile).Contains("Package is valid."))
                {
                    Directory.Delete(pathToExtract, true);
                    return(false);
                }
            }

            Directory.Delete(pathToExtract, true);
            return(true);
        }
Пример #14
0
 private void PrepareCourse()
 {
     InitializePaths(CourseUpload.FileName);
     CourseUpload.SaveAs(projectPaths.PathToCourseZipFile);
     Zipper.ExtractZipFile(projectPaths.PathToCourseZipFile, projectPaths.PathToTempCourseFolder);
 }
Пример #15
0
        private void SaveWorld(WorldModel world, byte[] data)
        {
            MemoryStream inStream = new MemoryStream(data);

            Zipper.ExtractZipFile(inStream, SavesPath + world.Title);
        }
Пример #16
0
 public static void ExtractZipFile(ProjectPaths projectPaths)
 {
     Zipper.ExtractZipFile(projectPaths.PathToCourseZipFile, projectPaths.PathToTempCourseFolder);
 }