buunguyen / combres

ASP.NET and MVC performance optimization library ⛺
Other
123 stars 37 forks source link

WebExtensions.CombresLink("resourceSetName") throws System.ArgumentException and WildCard Support #35

Closed rainabba closed 9 years ago

rainabba commented 10 years ago

After hours of head-banging, I realized that resource paths cannot contain wildcards and the "*" in my paths (works with every other minifier/concatonator I've used) was causing the exception. Catching this exception and mentioning the literal path causing the issue in the exception data would make this infinitely easier to address.

Also, what about wildcards? No support using the typical characters; what about including all resources (css or js based on the resourceSet type) in a folder; possible? Would only have to detect that the path is a folder then parse all the files matching the appropriate extension and include them.

Looks like it wouldn't take too much work in API/WebExtensions.cs to accomplish both of these things. I will see if I can do it and submit a pull request unless you reply and say otherwise.

See below for stack trace and example combres.xml that will throw the exception

System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=Illegal characters in path.
  Source=mscorlib
  StackTrace:
       at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
       at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
       at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
       at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
       at System.Web.Hosting.HostingEnvironment.MapPath(VirtualPath virtualPath)
       at Combres.ResourceContentReader.ReadNewContent(Resource resource)
       at Combres.VersionGenerators.HashCodeVersionGenerator.<>c__DisplayClass6.<Generate>b__1(Resource r)
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at Combres.VersionGenerators.HashCodeVersionGenerator.Generate(ResourceSet rs)
       at Combres.ResourceSet.InitializeVersion(XElement xe, Settings parent)
       at Combres.Settings.LoadResourceSets(XContainer xe)
       at Combres.ConfigReader.CreateSettings(XDocument xdoc)
       at Combres.Configuration.ReloadSettings()
       at Combres.Configuration.InitializeConfig()
       at Combres.Configuration.GetSettings()
       at Combres.WebExtensions.CombresLink(String setName, Object htmlAttributes)
       at ASP.ola_master.__Rendercst(HtmlTextWriter __w, Control parameterContainer) in C:\HIGH_SPEED_CONTENT\PROJECTS\AZPREP\GIT\WEB\OLA\OLAWeb\OLA.Master:line 15
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.HtmlControls.HtmlHead.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Page.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

App_Data\combres.xml

<?xml version="1.0" encoding="utf-8" ?>
<combres xmlns='urn:combres'>
  <filters>
    <filter type="Combres.Filters.FixUrlsInCssFilter, Combres" />
  </filters>
  <resourceSets url="~/combres.axd"
                defaultDuration="30"
                defaultVersion="auto"
                defaultDebugEnabled="false"
                defaultIgnorePipelineWhenDebug="true"
                defaultCompressionEnabled ="false"
                localChangeMonitorInterval="30"
                remoteChangeMonitorInterval="60" >

    <resourceSet name="siteCss" type="css">
      <resource path="~/css/custom-theme/*.css" />
    </resourceSet>

  </resourceSets>
</combres>
buunguyen commented 10 years ago

It'd be a nice addition. Go ahead sending me the PR when it's available.

KyleMerritt commented 10 years ago

I actually need this as well. Have you made any progress @rainabba ?

rainabba commented 10 years ago

No. Other issues related to combres brought my site down so I had to pull it in a hurry and just setup a Grunt workflow instead that runs with my build. It was no more work than either of the runtime solutions and is far more efficient. On Aug 22, 2014 8:37 AM, "Kyle Merritt" notifications@github.com wrote:

I actually need this as well. Have you made any progress @rainabba https://github.com/rainabba ?

— Reply to this email directly or view it on GitHub https://github.com/buunguyen/combres/issues/35#issuecomment-53076163.