Exemplo n.º 1
0
        public void Read(TextReader reader)
        {
            int filesToIgnoreCount = int.Parse(reader.ReadLine());

            for (int n = 0; n < filesToIgnoreCount; n++)
            {
                FilesToIgnore.Add(reader.ReadLine());
            }

            CleanGeneratedAddinScanDataFiles = bool.Parse(Console.In.ReadLine());
        }
        private static bool IsCldrJsonFile(string path)
        {
            var fileName = Path.GetFileNameWithoutExtension(path);

            return(FilesToIgnore.Contains(fileName) == false);
        }
        public override bool ProcessContentLinks()
        {
            string fname  = Path.GetFileName(SourceFilePath);
            bool   yml    = string.Equals(fname, "toc.yml", StringComparison.InvariantCultureIgnoreCase);
            bool   result = string.Equals(fname, "toc.md", StringComparison.InvariantCultureIgnoreCase) ||
                            yml ||
                            ContentHasAudienceApplicationUser(_content);

            if (result)
            {
                FoundLink[] links = FindAllLinks(yml, _content);
                Links.AddRange(links.Select(l => l.FullMatch));
                foreach (FoundLink link in links.GroupBy(k => k).Select(k => k.Key))
                {
                    if (String.IsNullOrEmpty(link.Link.Trim()))
                    {
                        continue;
                    }

                    string linkClear = CleanLinkOfQueryAndHash(link.Link);

                    if (linkClear.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) ||
                        linkClear.EndsWith("toc.md", StringComparison.InvariantCultureIgnoreCase) ||
                        linkClear.EndsWith("toc.yml", StringComparison.InvariantCultureIgnoreCase) ||
                        linkClear.StartsWith("mailto", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    try
                    {
                        string href = BuildFullUrl("/" + SourceFilePath, linkClear);
                        ProcessLink(href, link.Link, new ConceptualItemParameter(ref _content, link, href));
                    }
                    catch (Exception ex)
                    {
                        Logger.LogWarning($"Message: \"{ex.Message}\", File: \"{fname}\", Href: \"{link.Link}\"");
                    }
                }

                FoundPicture[] pictures = FindAllPictures(_content);
                Pictures.AddRange(pictures.Select(p => p.FullMatch));
                foreach (FoundPicture picture in pictures)
                {
                    try
                    {
                        string href = BuildFullUrl("/" + SourceFilePath, GetOnlyLink(picture.Link1));
                        ProcessLink(href, picture.Link1, null);

                        if (!String.IsNullOrEmpty(picture.Link2) && !picture.Link1.Equals(picture.Link2))
                        {
                            string link2 = CleanLinkOfQueryAndHash(GetOnlyLink(picture.Link2));
                            href = BuildFullUrl("/" + SourceFilePath, link2);
                            ProcessLink(href, picture.Link2, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogWarning($"Message: \"{ex.Message}\", File: \"{fname}\", Link1: \"{picture.Link1}\", Link2: \"{picture.Link2}\"");
                    }
                }

                FoundLink[] includes = FindIncludedLinks(_content);
                foreach (FoundLink link in includes.GroupBy(k => k).Select(k => k.Key))
                {
                    if (String.IsNullOrEmpty(link.Link.Trim()))
                    {
                        continue;
                    }

                    string linkClear = CleanLinkOfQueryAndHash(link.Link);

                    if (linkClear.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) ||
                        linkClear.EndsWith("toc.md", StringComparison.InvariantCultureIgnoreCase) ||
                        linkClear.EndsWith("toc.yml", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    try
                    {
                        string href = BuildFullUrl("/" + SourceFilePath, linkClear);
                        if (!FilesToIgnore.Contains(href.TrimStart('\\')))
                        {
                            FilesToIgnore.Add(href.TrimStart('\\'));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogWarning($"Message: \"{ex.Message}\", File: \"{fname}\", Href: \"{link.Link}\"");
                    }
                }
                return(HasModified);
            }
            if (!(fname != null && fname.Equals("toc.md", StringComparison.InvariantCultureIgnoreCase)))
            {
                FilesToRemove.Add(SourceFilePath.TrimStart('\\'));
            }
            return(false);
        }