示例#1
0
        public static void ParseResource(ProjectPaths projectPaths, int courseID, XmlNode resource)
        {
            string identifier = resource.Attributes["identifier"].Value;
            string type = resource.Attributes["adlcp:scormType"].Value;

            if (resources.ContainsKey(identifier))
            {
                return;
            }

            if (resource.Attributes["href"] != null)
            {
                string resourseHref = resource.Attributes["href"].Value;
                int ID = Store(identifier, type, resourseHref, courseID);
                resources[identifier] = ID;

                HashSet<string> dependencyFiles = GetDependencyFiles(resource);
                XmlNodeList fileNodes = XmlUtility.GetNodes(resource, "ns:file");

                foreach (XmlNode node in fileNodes)
                {
                    string href = node.Attributes["href"].Value;

                    StoreFile(href, projectPaths, courseID);
                }

                foreach (string file in dependencyFiles)
                {
                    StoreFile(file, projectPaths, courseID);
                }

                resources[identifier] = ID;
            }
        }
示例#2
0
        public static void Import(XmlNode node, int themeId, ProjectPaths projectPaths)
        {
            string fileName  = Path.Combine(projectPaths.PathToTempCourseFolder, XmlUtility.GetIdentifierRef(node) + FileExtentions.Html);

            byte[] file = File.ReadAllBytes(fileName);
            int id = Store(themeId, XmlUtility.GetIdentifier(node), file);
            FilesManager.StoreAllPageFiles(id, fileName);
        }
示例#3
0
        private static int ImportTestCourse(string path)
        {
            var projectPath = new ProjectPaths();
            projectPath.Initialize(path);
            CourseManager.ExtractZipFile(projectPath);

            return CourseManager.Import(projectPath, Path.GetFileNameWithoutExtension(path), "[UNITTESTS]");
        }
示例#4
0
        private static XmlNode GetAnswerNode(string pageName, ProjectPaths projectPaths)
        {
            var answers = new XmlDocument();
            answers.Load(projectPaths.PathToAnswerXml);
            if (answers.DocumentElement != null)
                return FindItem(answers.DocumentElement.FirstChild, pageName);

            return null;
        }
示例#5
0
 private static void SearchThemes(XmlNode document, int courseId, ProjectPaths projectPaths)
 {
     foreach (XmlNode node in document.ChildNodes)
     {
         if (XmlUtility.IsItem(node))
         {
             ThemeManager.Import(node, courseId, projectPaths);
         }
     }
 }
示例#6
0
        public static int Import(ProjectPaths projectPaths, string name, string description)
        {
            projectPaths.PathToAnswerXml = Path.Combine(projectPaths.PathToTempCourseFolder, "answers.xml");

            int id = Store(name, description);

            ManageThemes(id, projectPaths);

            return id;
        }
示例#7
0
        private static void ManageThemes(int courseId, ProjectPaths projectPaths)
        {
            XmlDocument imsmanifest = GetImsmanifest(projectPaths.PathToTempCourseFolder);

            if (imsmanifest.DocumentElement != null)
            {
                XmlNode document = imsmanifest.DocumentElement.FirstChild;

                foreach (XmlNode node in document)
                    SearchThemes(node, courseId, projectPaths);
            }
        }
示例#8
0
        public static void Import(XmlNode node, int themeRef, ProjectPaths projectPaths)
        {
            XmlNode answerNode = GetAnswerNode(XmlUtility.GetIdentifier(node), projectPaths);

            int rank = GetPageRank(answerNode);

            string tempFileName = Path.Combine(projectPaths.PathToTempCourseFolder, XmlUtility.GetIdentifierRef(node) + FileExtentions.Html);

            var pageTable = StorePageWithoutPageFile(themeRef, XmlUtility.GetIdentifier(node), rank);

            int fileID = SearchForResources(node, pageTable.ID, projectPaths.PathToTempCourseFolder);

            AddPageFileToPage(pageTable, fileID);
        }
示例#9
0
        public static void Import(XmlNode node, int themeRef, ProjectPaths projectPaths)
        {
            XmlNode answerNode = GetAnswerNode(XmlUtility.GetIdentifier(node), projectPaths);

            int rank = GetPageRank(answerNode);

            string tempFileName = Path.Combine(projectPaths.PathToTempCourseFolder, XmlUtility.GetIdentifierRef(node) + FileExtentions.Html);

            var pageTable = StorePageWithoutPageFile(themeRef, XmlUtility.GetIdentifier(node), rank);

            WebPage webPage = CreateAspControl(tempFileName, pageTable.ID,
                answerNode, projectPaths.PathToTempCourseFolder);

            AddPageFileToPage(pageTable, webPage.BinaryRepresentation);
        }
示例#10
0
 private static void SearchPages(XmlNode theme, int themeId, ProjectPaths projectPaths)
 {
     foreach (XmlNode node in theme.ChildNodes)
     {
         if (node != null && XmlUtility.IsItem(node))
         {
             if (XmlUtility.IsPage(node))
             {
                     if (XmlUtility.IsPractice(node))
                     {
                         PracticeManager.Import(node, themeId, projectPaths);
                     }
                     if (XmlUtility.IsTheory(node))
                     {
                         TheoryManager.Import(node, themeId, projectPaths);
                     }
             }
             else if (XmlUtility.IsChapter(node))
             {
                 SearchPages(node, themeId, projectPaths);
             }
         }
     }
 }
示例#11
0
        private static void StoreFile(string href, ProjectPaths projectPaths, int courseID)
        {
            string FilePath = Path.Combine(projectPaths.PathToTempCourseFolder, href);

            if (File.Exists(FilePath))
            {
                string AssetFilePath = Path.Combine(CourseManager.GetCoursePath(courseID), href);

                string AssetDirectoryPath = Directory.GetParent(AssetFilePath).ToString();
                RecursiveCreateDirectory(AssetDirectoryPath);

                if (!File.Exists(AssetFilePath))
                {
                    CopyFile(FilePath, AssetFilePath);
                }
            }
        }
示例#12
0
        public static void Import(XmlNode theme, int courseId, ProjectPaths projectPaths)
        {
            int id = Store(courseId, XmlUtility.GetIdentifier(theme), XmlUtility.IsControlChapter(theme));

            SearchPages(theme, id, projectPaths);
        }
示例#13
0
        public static int Import(ProjectPaths projectPaths, string name, string description)
        {
            ResourceManager.Resources.Clear();
            ResourceManager.Dependencies.Clear();

            if (!File.Exists(projectPaths.PathToManifestXml))
            {
                throw new Exception(Translations.CourseManager_Import_No_imsmanifest_xml_file_found);
            }
            if(!File.Exists(projectPaths.PathToAnswerXml))
            {
                throw new Exception(Translations.CourseManager_Import_No_answers_xml_file_found);
            }

            // load manifest
            XmlDocument imsmanifest = new XmlDocument();
            imsmanifest.Load(projectPaths.PathToManifestXml);
            // load answers
            XmlDocument answers = new XmlDocument();
            answers.Load(projectPaths.PathToAnswerXml);

            // store the course in db
            int courseID = Store(name, description);

            string CoursePath = GetCoursePath(courseID);

            if (!Directory.Exists(CoursePath))
            {
                Directory.CreateDirectory(CoursePath);
            }

            string ManifestPath = Path.Combine(CoursePath, "imsmanifest.xml");
            string AnswersPath = Path.Combine(CoursePath, "answers.xml");

            if (!File.Exists(ManifestPath))
            {
                File.Copy(projectPaths.PathToManifestXml, ManifestPath);
            }
            if (!File.Exists(AnswersPath))
            {
              File.Copy(projectPaths.PathToAnswerXml, AnswersPath);
            }

            XmlNodeList resources = XmlUtility.GetNodes(imsmanifest.DocumentElement, "/ns:manifest/ns:resources/ns:resource");
            
            foreach (XmlNode resource in resources)
            {
                ResourceManager.ParseResource(projectPaths, courseID, resource);
            }

            // import list of <organization> elements in imsmanifest.xml
            XmlNodeList organizationList = XmlUtility.GetNodes(imsmanifest.DocumentElement, "/ns:manifest/ns:organizations/ns:organization");
            // import list of <organization> elements in answers.xml
            XmlNodeList answerList = XmlUtility.GetNodes(answers.DocumentElement, "/answers/organization");

            foreach (XmlNode node in organizationList)
            {
                OrganizationManager.Import(node, XmlUtility.GetNodeById(answerList, XmlUtility.GetIdentifier(node)), courseID);
            }

            return courseID;
        }
示例#14
0
 public static void ExtractZipFile(ProjectPaths projectPaths)
 {
     Zipper.ExtractZipFile(projectPaths.PathToCourseZipFile, projectPaths.PathToTempCourseFolder);
 }