Пример #1
0
 public Section(IHeader header = null, ICourseLink parentCourse = null)
 {
     Header = header != null
         ? new Header(header.Name, header.Order, header.AnchorId, this)
         : new Header(parentSection: this);
     ParentCourse = parentCourse;
     Links        = new List <IDownloadableLink>();
 }
Пример #2
0
        public static string CourseLink(this HtmlHelper helper, ICourseLink course)
        {
            if (course == null)
            {
                return(null);
            }
            if (course.IsTrack.GetValueOrDefault())
            {
                return(HtmlControls.Anchor("/track/" + course.UrlName,
                                           course.GetName()).ToString());
            }

            return(helper.CourseLink(course.UrlName, course.GetName()));
        }
Пример #3
0
        public static string CourseLinkShortName(this HtmlHelper helper, ICourseLink course)
        {
            if (course == null)
            {
                return(null);
            }
            if (course.WebShortName.IsEmpty())
            {
                return(helper.CourseLink(course));
            }
            if (course.IsTrack.GetValueOrDefault())
            {
                return(helper.ActionLink <TrackController>(
                           tc => tc.Details(course.UrlName), course.WebShortName).ToString());
            }

            return(helper.CourseLink(course.UrlName, course.WebShortName));
        }
Пример #4
0
 public static string GetShortName(this ICourseLink courseLink)
 {
     return(courseLink.WebShortName.IsEmpty()
         ? courseLink.GetName()
         : courseLink.WebShortName);
 }
Пример #5
0
 public static string GetName(this ICourseLink courseLink)
 {
     return(courseLink.WebName.IsEmpty()
         ? courseLink.Name
         : courseLink.WebName);
 }
        public static async Task <List <ISection> > ExtractSectionsForCourse(ICourseLink courseLink)
        {
            await CoursesClient.LazyRefresh();

            var coursePageText = await CoursesClient.SessionClient.GetStringAsyncHttp(courseLink.Url);

            CoursesClient.FindSessKey(coursePageText);
            var doc = new HtmlDocument();

            doc.LoadHtml(coursePageText);
            var headersLinks = doc.DocumentNode.SelectNodes(XPathFilterLinksHeadersFolders);

            SharedVars.Sections = new List <ISection>();
            var currentSection = new Section();

            SharedVars.Sections.Add(currentSection);

            foreach (var headerLink in headersLinks)
            {
                var itemType = TryGetItemType(headerLink);

                string innerText = null;
                string href      = null;

                if (itemType != ItemType.Header)
                {
                    innerText = headerLink.Descendants().First(d => d.Name == "#text").InnerText.DecodeHtml();
                    href      = headerLink.Attributes.First(l => l.Name == "href").Value;
                }

                switch (itemType)
                {
                case ItemType.Header:
                    var headerName = headerLink.InnerText.DecodeHtml();
                    var headerTag  = headerLink.OriginalName;
                    var headerId   = FindIdFromAncestors(headerLink);
                    currentSection = new Section(new Header(headerName, headerTag, headerId), courseLink);
                    SharedVars.Sections.Add(currentSection);
                    break;

                case ItemType.File:
                    currentSection.Links.Add(new FileLink(innerText, href, currentSection));
                    break;

                case ItemType.Folder:
                    currentSection.Links.Add(new FolderLink(innerText, href, currentSection));
                    break;

                case ItemType.Url:
                    currentSection.Links.Add(new ExternalLink(innerText, href, currentSection));
                    break;

                case ItemType.Page:
                    currentSection.Links.Add(new PageLink(innerText, href, currentSection));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            SharedVars.Sections = SharedVars.Sections.Where(s => s.Links.Any()).ToList();

            return(SharedVars.Sections);
        }