Exemple #1
0
        void LinkProc(HtmlNode node)
        {
            string link = node.GetAttributeValue("href", null);

            if (link != null)
            {
                link.Trim();
            }
            else
            {
                return;
            }

            //Links Regex
            foreach (string rgx in data.links_regex)
            {
                if (Regex.IsMatch(link, rgx))
                {
                    return;
                }
            }

            URL url_link;

            if (URL.IsRelative(link))
            {
                url_link = new URL(page.final_url.str, link);
            }
            else
            {
                url_link = new URL(link);
            }

            //Its same page?
            if (link == page.final_url.url_main.file)
            {
                node.SetAttributeValue("href", page.filename);
                return;
            }

            //Its internal?
            if (link.StartsWith("#"))
            {
                return;
            }

            //Nav Direction
            URL.NavType nt = url_link.Compare(data.org_links[page.org_link]);

            if (nt == URL.NavType.Same)
            {
                StatusReport sr = data.CheckLink(url_link);
                if (sr.page != null)
                {
                    node.SetAttributeValue("href", sr.page.PathFromRelative(page.final_url));
                }
                return;
            }

            switch (data.nav_direction)
            {
            case NavDirection.In:
                if (nt != URL.NavType.In &&
                    !(data.hnav && nt == URL.NavType.Side))
                {
                    return;
                }
                break;

            case NavDirection.Out:
                if (nt != URL.NavType.Out &&
                    !(data.hnav && nt == URL.NavType.Side))
                {
                    return;
                }
                break;

            case NavDirection.Static:
                if (nt != URL.NavType.Side)
                {
                    return;
                }
                break;

            case NavDirection.Both:
                if (!data.hnav && nt == URL.NavType.Side)
                {
                    break;
                }
                return;
            }

            //Its already dowloaded?
            StatusReport report = data.CheckLink(url_link);

            //FOR DOWNLOAD
            if (report.url_status == UrlStatus.Free)
            {
                data.Log("-->PROC: Link Pending");

                Page link_page = new Page(ref data, url_link, page.org_link);
                link_page.Proccess();

                switch (link_page.result)
                {
                case Result.Ok:
                    string final_link = link_page.PathFromRelative(page.final_url);
                    node.SetAttributeValue("href", final_link);

                    data.UpdateStatus(link_page, UrlStatus.ToDo);
                    break;

                case Result.IsAsset:
                    //TODO Do something
                    break;

                case Result.Fail:
                    data.UpdateStatus(link_page, UrlStatus.Failed);
                    break;
                }

                //DOWNLOADED
            }
            else if (report.url_status != UrlStatus.Failed)
            {
                //TODO
                string final_link = report.page.PathFromRelative(page.final_url);
                node.SetAttributeValue("href", final_link);
            }
        }
Exemple #2
0
        string AssetProc(string src, Type type, string rel = null)
        {
            if (src == null)
            {
                return(null);
            }

            if (rel == null)
            {
                rel = page.final_url.str;
            }

            URL url_src;

            if (URL.IsRelative(src))
            {
                url_src = new URL(rel, src);
            }
            else
            {
                url_src = new URL(src);
            }

            StatusReport report = data.CheckAsset(url_src);

            if (report.url_status == UrlStatus.Iprg || report.url_status == UrlStatus.Saved)
            {
                return(report.asset.final_url.RelativeTo(rel).org_str);
            }
            else if (report.url_status == UrlStatus.Free)
            {
                Asset asset = new Asset(url_src, ref data);

                if (type == Type.css)
                {
                    asset.Process(true);
                }
                else
                {
                    asset.Process();
                }

                if (asset.result == Result.Ok || asset.result == Result.Exists)
                {
                    if (asset.result == Result.Ok)
                    {
                        data.UpdateStatus(asset, UrlStatus.Saved);

                        if (type == Type.css)
                        {
                            css_todo.Add(asset);
                        }
                    }

                    return(asset.final_url.RelativeTo(rel).org_str);
                }
                else if (asset.result == Result.Fail)
                {
                    data.UpdateStatus(asset, UrlStatus.Failed);
                    return(null);
                }
            }
            return(null);
        }