private static KmzFile SaveKmlAndLinkedContentIntoAKmzArchive(KmlFile kml, string path) { // All the links in the KML will be relative to the KML file, so // find it's directory so we can add them later string basePath = Path.GetDirectoryName(path); // Create the archive with the KML data KmzFile kmz = KmzFile.Create(kml); // Now find all the linked content in the KML so we can add the // files to the KMZ archive var links = new LinkResolver(kml); // Next gather the local references and add them. foreach (string relativePath in links.GetRelativePaths()) { // Make sure it doesn't point to a directory below the base path if (relativePath.StartsWith("..", StringComparison.Ordinal)) { continue; } // Add it to the archive string fullPath = Path.Combine(basePath, relativePath); using (Stream file = File.OpenRead(fullPath)) { kmz.AddFile(relativePath, file); } } return(kmz); }
public void TestAll() { // Verify that GetLinks finds all kinds of hrefs in a KML file. string[] expected = { "http://example.com/icon.jpg", "itemicon.png", "../more.kml", "go.jpeg", "so.jpeg", "po.jpeg", "#myschema", "model.dae", "style.kml#style" }; using (var stream = SampleData.CreateStream("Engine.Data.Links.kml")) using (var reader = new StreamReader(stream)) { var resolver = new LinkResolver(reader, true); Assert.That(resolver.Links.Count(), Is.EqualTo(expected.Length)); int index = 0; foreach (var uri in resolver.Links) { Assert.That(uri.OriginalString, Is.EqualTo(expected[index++])); } } }
public async Task Resolve_Success(string url, int expectedId) { var resolved = await LinkResolver.ResolveAsync(new Uri(url)); Assert.NotNull(resolved); Assert.AreEqual(expectedId, resolved !.ID); }
public void ResolveHash_Cancellation(string url) { using var tokenSource = new CancellationTokenSource(); tokenSource.CancelAfter(BooruHelper.TaskCancellationDelay); Assert.ThrowsAsync <TaskCanceledException>(() => LinkResolver.ResolveAsync(new Uri(url), tokenSource.Token)); }
public ContentBlocksLinkMapper( IContentTypeService contentTypeService, IDataTypeService dataTypeService, LinkResolver linkResolver) : base(dataTypeService, linkResolver) { this.contentTypeService = contentTypeService; }
public void ShouldFindAllTheLinkTypesInTheKmlFile() { // Verify that GetLinks finds all kinds of hrefs in a KML file. string[] expected = { "http://example.com/icon.jpg", "itemicon.png", "../more.kml", "go.jpeg", "so.jpeg", "po.jpeg", "#myschema", "model.dae", "style.kml#style" }; using (var stream = SampleData.CreateStream("Engine.Data.Links.kml")) using (var reader = new StreamReader(stream)) { var resolver = new LinkResolver(KmlFile.Load(reader)); IEnumerable <string> links = resolver.Links.Select(u => u.OriginalString); Assert.That(links, Is.EquivalentTo(expected)); } }
public void TestRelative() { string[] expected = { "itemicon.png", "../more.kml", "go.jpeg", "so.jpeg", "po.jpeg", "model.dae", "style.kml" }; using (var stream = SampleData.CreateStream("Engine.Data.Links.kml")) using (var reader = new StreamReader(stream)) { var resolver = new LinkResolver(reader, true); Assert.That(resolver.RelativePaths.Count(), Is.EqualTo(expected.Length)); int index = 0; foreach (var path in resolver.RelativePaths) { Assert.That(path, Is.EqualTo(expected[index++])); } } }
//related to Windows.Files public static IEnumerable <string> ResolveAll(this IEnumerable <Link> links) { var resolver = new LinkResolver(); var list = new List <string>(); links.ForEach(i => list.Add(resolver.Resolve(i.Path))); return(list); }
public void ResolvePython2_7Shortcut() { var path = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 2.7\Python (command line).lnk"; if (!File.Exists(path)) { return; } var resolved = LinkResolver.ResolveShortcut(path); Assert.IsFalse(String.IsNullOrEmpty(resolved)); }
public void DuplicateLinksShouldBeIgnored() { const string Kml = "<Folder xmlns='http://www.opengis.net/kml/2.2'>" + "<NetworkLink><Link><href>foo.kml</href></Link></NetworkLink>" + "<NetworkLink><Link><href>foo.kml</href></Link></NetworkLink>" + "</Folder>"; using (var reader = new StringReader(Kml)) { var resolver = new LinkResolver(KmlFile.Load(reader)); Assert.That(resolver.Links.Count, Is.EqualTo(1)); Assert.That(resolver.Links[0].OriginalString, Is.EqualTo("foo.kml")); } }
public void Install(IWindsorContainer container, IConfigurationStore store) { var beerDtoLinkResolver = new LinkResolver <BeerDto>(new List <ILinkResolver <BeerDto> > { new BeerDtoSelfLinkResolver(new Uri("http://localhost:9001")) }); container.Register(Component.For <LinkResolver <BeerDto> >().Instance(beerDtoLinkResolver)); // register all controllers container.Register(Classes .FromThisAssembly() .BasedOn <IHttpController>() .ConfigureFor <ApiController>(c => c.Properties(pi => false)) .LifestyleTransient()); }
public void GetRelativePathsShouldReturnTheNormalizedPath() { string[] expected = { "itemicon.png", "../more.kml", "go.jpeg", "so.jpeg", "po.jpeg", "model.dae", "style.kml" }; using (var stream = SampleData.CreateStream("Engine.Data.Links.kml")) using (var reader = new StreamReader(stream)) { var resolver = new LinkResolver(KmlFile.Load(reader)); IEnumerable <string> relatives = resolver.GetRelativePaths(); Assert.That(relatives, Is.EquivalentTo(expected)); } }
public void TestDuplicates() { const string Kml = "<Folder xmlns='http://www.opengis.net/kml/2.2'>" + "<NetworkLink><Link><href>foo.kml</href></Link></NetworkLink>" + "<NetworkLink><Link><href>foo.kml</href></Link></NetworkLink>" + "</Folder>"; // Test that duplicates are ignored using (var reader = new StringReader(Kml)) { var resolver = new LinkResolver(reader, false); Assert.That(resolver.Links.Count(), Is.EqualTo(1)); Assert.That(resolver.Links.ElementAt(0).OriginalString, Is.EqualTo("foo.kml")); } // Test that everything is read using (var reader = new StringReader(Kml)) { var resolver = new LinkResolver(reader, true); Assert.That(resolver.Links.Count(), Is.EqualTo(2)); } }
public WebResponse getDocument(string link) { var resultado = LinkResolver.GetLinkResponse(link).GetAwaiter().GetResult(); return(resultado); }
static void Main(string[] args) { if (args.Length == 0) { _Help(); return; } var filePerType = args.Any(a => a == _msdnStyleSwitch); Options.UseGitHubPagesLinks = args.Any(a => a == _gitHubPagesSwitch); var wikiPath = args.FirstOrDefault(a => !KnownSwitches.Contains(a)); if (string.IsNullOrWhiteSpace(wikiPath) || !Directory.Exists(wikiPath)) { Console.WriteLine($"Could not find directory '{wikiPath}'"); return; } var assemblyFiles = Directory.GetFiles(wikiPath, "*.dll"); var commentFiles = Directory.GetFiles(wikiPath, "*.xml").ToList(); var assemblies = assemblyFiles.Select(Assembly.LoadFrom).ToList(); var templates = filePerType ? _GetTypeBasedTemplates(wikiPath, assemblies) : _GetTemplatesFromJsonFiles(wikiPath); var comments = commentFiles.SelectMany(XmlProcessor.Load).ToList(); var pages = templates.Select(t => t.Generate(assemblies, comments)).ToList(); LinkResolver.ValidateLinks(); var markdownPages = pages.Select(p => new { Markdown = p.GenerateMarkdown(), File = p.FileName }).OrderBy(p => p.File).ToList(); var fileTemplatePath = Path.Combine(wikiPath, "_autowiki-template.md"); var fileTemplate = File.Exists(fileTemplatePath) ? File.ReadAllText(fileTemplatePath) : null; int order = 1; foreach (var page in markdownPages) { var markdown = page.Markdown.ResolveLinks(); if (fileTemplate != null) { markdown = fileTemplate.Replace("{{content}}", markdown) .Replace("{{filename}}", Path.GetFileNameWithoutExtension(page.File).Replace("`1", "<T>")) .Replace("{{order}}", order.ToString()); } markdown = markdown.EscapeForMarkdown(); File.WriteAllText(page.File, markdown); order++; } }
static Resolvers() { LinkResolver.RegisterResolver(new DanbooruResolver(BooruHelper.Danbooru)); LinkResolver.RegisterResolver(new GelbooruResolver(BooruHelper.Gelbooru)); }
public void ResolveExistingShortcut() { var resolved = LinkResolver.ResolveShortcut("C:\\Users\\laise\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Python 3.8\\IDLE (Python 3.8 32-bit).lnk"); Assert.IsFalse(String.IsNullOrEmpty(resolved)); }