about virtualPath case sensitive problem in IsPhysicalFileNewer.

Mar 4, 2013 at 3:27 AM
Edited Mar 9, 2013 at 1:28 AM
private bool IsPhysicalFileNewer(string virtualPath)
{
    if (virtualPath.StartsWith(_baseVirtualPath ?? String.Empty, StringComparison.Ordinal))
    ......
}
can change StringComparison.Ordinal to StringComparison.OrdinalIgnoreCase ?

thanks...
Coordinator
Mar 4, 2013 at 3:46 AM
Yes, I would think it could be case insensitive. Pranav?
Mar 4, 2013 at 7:51 AM
Edited Mar 9, 2013 at 1:30 AM
var engine = new PrecompiledMvcEngine(assembly, "~/plugins/passport");

engine.IsPhysicalFileNewer("~/Plugins/passport/Views/login/index.cshtml");
private bool IsPhysicalFileNewer(string virtualPath)
{

    //the _baseVirtualPath value is "~/Plugins/passport/" ( NormalizeBaseVirtualPath("~/Plugins/passport") in constructor )

    if (virtualPath.StartsWith(_baseVirtualPath ?? String.Empty, StringComparison.Ordinal))
    {
        if (!String.IsNullOrEmpty(_baseVirtualPath))
        {
            virtualPath = '~' + virtualPath.Substring(_baseVirtualPath.Length);
            
            // BUG:  the virtualPath value is "~Views/login/index.cshtml"
        }
        ......
    }
    return false;
}
Coordinator
Mar 4, 2013 at 4:30 PM
Confused by that previous entry. What is this code compared to your initial post? Please make sure you format code correctly so it doesn't look so corrupted.
Coordinator
Mar 4, 2013 at 4:44 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Mar 4, 2013 at 4:56 PM
Should be fixed in the 1.5.5 version that I just pushed to NuGet
Mar 5, 2013 at 12:51 AM
Edited Mar 5, 2013 at 12:52 AM
oh.sorry...my english is poor...

that's two problems. the first is virtualPath case sensitive, another is virtualPath value error above sencond post.
Coordinator
Mar 5, 2013 at 12:54 AM
I see. It's usually better to discuss distinct issues separately to make sure they don't get lost. Pranav, I assume your fix is only for the first and not the second?
Coordinator
Mar 5, 2013 at 12:56 AM
Yeah. I'm sorry, I did not see the second issue. I can have a look at it in a bit
Mar 6, 2013 at 3:17 AM
Edited Mar 9, 2013 at 1:34 AM
I have another problem.
[Test]
public void MethodTest()
{
    var engine = new RazorGenerator.Mvc.PrecompiledMvcEngine(Assembly.GetExecutingAssembly(), "~/plugins/passport")
    {
        UsePhysicalViewsIfNewer = true
    };
    engine.CreateInstance("~/plugins/passport/views/user/index.cshtml");  //debug into CreateInstance()
}
debug into CreateInstance():
public object CreateInstance(string virtualPath)
{
    Type type;
    ......

    // the virtualPath value is "~/plugins/passport/views/user/index.cshtml"
    if (UsePhysicalViewsIfNewer && IsPhysicalFileNewer(virtualPath))   //debug into IsPhysicalFileNewer()
    {
        // NOTE: Create WebViewPage instance for the "X:\\appdir\\plugins\\passport\\Views\\login\\index.cshtml" file,
        // but not "X:\\appdir\\Views\\login\\index.cshtml" file.
        var instanceFromVirtualPath = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof (WebViewPage));
        return instanceFromVirtualPath;
    }
    ......
}
debug into IsPhysicalFileNewer():
private bool IsPhysicalFileNewer(string virtualPath)
{
    // the _baseVirtualPath value is "~/plugins/passport"
    if (virtualPath.StartsWith(_baseVirtualPath ?? String.Empty, StringComparison.OrdinalIgnoreCase))
    {
        if (!String.IsNullOrEmpty(_baseVirtualPath))
        {
            virtualPath = '~' + virtualPath.Substring(_baseVirtualPath.Length - 1);
            //Why change the virtualPath value? The virtualPath value is "~/Views/login/index.cshtml" after change it.
        }

        string path = HttpContext.Current.Request.MapPath(virtualPath);

        // NOTE: Determines whether the "X:\\appdir\\Views\\login\\index.cshtml" file exists here.
        return  File.Exists(path) && File.GetLastWriteTimeUtc(path) > _assemblyLastWriteTime.Value;
    }
    return false;
}