Exemplo n.º 1
0
        public string Export(int disciplineId)
        {
            var discname   = this.storage.GetDiscipline(disciplineId).Name;
            var pathToDisc = Path.Combine(GetFolderPath(), Guid.NewGuid().ToString());
            var tempPath   = Path.Combine(pathToDisc, discname);

            Directory.CreateDirectory(tempPath);


            foreach (var chapter in this.storage.GetChapters(x => x.DisciplineRef == disciplineId))
            {
                foreach (var topic in this.storage.GetTopics(x => x.ChapterRef == chapter.Id))
                {
                    if (topic.TheoryCourseRef != null)
                    {
                        File.Copy(this.storage.Export((int)topic.TheoryCourseRef), Path.Combine(tempPath, string.Format("{0}-Theory_{1}.zip", this.storage.GetCourse((int)topic.TheoryCourseRef).Name, (int)topic.TheoryCourseRef)));
                    }
                    if (topic.TestCourseRef != null)
                    {
                        File.Copy(this.storage.Export((int)topic.TestCourseRef), Path.Combine(tempPath, string.Format("{0}-Test_{1}.zip", this.storage.GetCourse((int)topic.TestCourseRef).Name, (int)topic.TestCourseRef)));
                    }
                }
            }

            this.Serialize(Path.Combine(tempPath, string.Format("{0}.disc", discname)), disciplineId);
            Zipper.CreateZip(Path.Combine(pathToDisc, discname + ".zip"), tempPath);

            return(Path.Combine(pathToDisc, discname + ".zip"));
        }
Exemplo n.º 2
0
        public void CreateZipTest()
        {
            string filename = "D:\\Tests";
            string folder   = "D:\\Tests\\1";

            Zipper.CreateZip(filename, folder);
        }
Exemplo n.º 3
0
        public void CreateZipTest()
        {
            var folder = Path.Combine(this.root, @"New Folder");
            var zip    = Path.Combine(this.root, @"1.zip");

            Zipper.CreateZip(zip, folder);

            Assert.IsTrue(File.Exists(zip));
        }
Exemplo n.º 4
0
        public void CreateZipTest()
        {
            // creating the folder
            var folder = Path.Combine(this.root, @"New Folder");
            // creating zip file
            var zip = Path.Combine(this.root, @"1.zip");

            // push folder into zip
            Zipper.CreateZip(zip, folder);

            Assert.IsTrue(File.Exists(zip));
        }
Exemplo n.º 5
0
        public void CreateZipTest()
        {
            string filename = "1.zip";
            string folder   = Path.Combine(ConfigurationManager.AppSettings.Get("PathToIUDICO.UnitTests"),
                                           @"IUDICO.UnitTests\bin\Debug\Site\Data\");


            Zipper.CreateZip(filename, folder);

            Assert.IsTrue(
                File.Exists(Path.Combine(ConfigurationManager.AppSettings.Get("PathToIUDICO.UnitTests"),
                                         @"IUDICO.UnitTests\bin\Debug\1.zip")));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Save current course to zip package
        /// </summary>
        /// <param name="fileName">File name of zip package. If file not exists it will be created</param>
        public static bool SaveToZipPackage([NotNull] string fileName)
        {
            FFDebug.EnterMethod(Cattegory.Course, string.Format("fileName:'{0}'", fileName));

            if (Save() != true)
            {
                return(false);
            }

            Zipper.CreateZip(fileName, __FullPath);
            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(true);
        }
Exemplo n.º 7
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");
        }
Exemplo n.º 8
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");
        }