Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Fixed #70
Browse files Browse the repository at this point in the history
  • Loading branch information
kipusoep committed May 1, 2015
1 parent af237f2 commit 32145f9
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions Providers/EmbeddedResourcesVirtualPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,57 @@

namespace InfoCaster.Umbraco.UrlTracker.Providers
{
public class EmbeddedResourcesVirtualPathProvider : VirtualPathProvider
{
public EmbeddedResourcesVirtualPathProvider()
{
}
public class EmbeddedResourcesVirtualPathProvider : VirtualPathProvider
{
public EmbeddedResourcesVirtualPathProvider()
{
}

private bool IsEmbeddedResourcePath(string virtualPath)
{
var checkPath = VirtualPathUtility.ToAppRelative(virtualPath);
return checkPath.StartsWith("~/Umbraco/UrlTracker/", StringComparison.InvariantCultureIgnoreCase);
}
private bool IsEmbeddedResourcePath(string virtualPath)
{
var checkPath = VirtualPathUtility.ToAppRelative(virtualPath);
return checkPath.StartsWith("~/Umbraco/UrlTracker/", StringComparison.InvariantCultureIgnoreCase);
}

public override bool FileExists(string virtualPath)
{
return IsEmbeddedResourcePath(virtualPath) || base.FileExists(virtualPath);
}
public override bool FileExists(string virtualPath)
{
return IsEmbeddedResourcePath(virtualPath) || base.FileExists(virtualPath);
}

public override VirtualFile GetFile(string virtualPath)
{
if (IsEmbeddedResourcePath(virtualPath))
return new EmbeddedResourceVirtualFile(virtualPath);
return base.GetFile(virtualPath);
}
public override VirtualFile GetFile(string virtualPath)
{
if (IsEmbeddedResourcePath(virtualPath))
return new EmbeddedResourceVirtualFile(virtualPath);
return base.GetFile(virtualPath);
}

public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
{
if (IsEmbeddedResourcePath(virtualPath))
return null;
return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
}
public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
{
if (IsEmbeddedResourcePath(virtualPath))
return null;
return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
}

public class EmbeddedResourceVirtualFile : VirtualFile
{
string _path;
public class EmbeddedResourceVirtualFile : VirtualFile
{
readonly string _path;

public EmbeddedResourceVirtualFile(string virtualPath)
: base(virtualPath)
{
_path = VirtualPathUtility.ToAppRelative(virtualPath);
}
public EmbeddedResourceVirtualFile(string virtualPath)
: base(virtualPath)
{
_path = VirtualPathUtility.ToAppRelative(virtualPath);
}

public override Stream Open()
{
var resourceName = _path.Split('/').Last();
var assembly = GetType().Assembly;
if (assembly != null)
return assembly.GetManifestResourceStream(resourceName);
return null;
}
}
public override Stream Open()
{
var resourceName = _path.Split('/').Last();
var assembly = GetType().Assembly;
resourceName = assembly.GetManifestResourceNames()
.SingleOrDefault(x => x.Equals(resourceName, StringComparison.OrdinalIgnoreCase));
if (string.IsNullOrEmpty(resourceName))
return null;
return assembly.GetManifestResourceStream(resourceName);
}
}
}

0 comments on commit 32145f9

Please sign in to comment.