protected void Application_Start()
        {
            //WebApiConfig.Register(GlobalConfiguration.Configuration);
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
            var myScriptResDef = new ScriptResourceDefinition();
            myScriptResDef.Path = "~/Scripts/jquery-2.0.3.min.js";
            myScriptResDef.DebugPath = "~/Scripts/jquery-2.0.3.min.js";
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, myScriptResDef);
            var config = GlobalConfiguration.Configuration;
            config.Formatters.Insert(0, new JsonMediaTypeFormatter());
            FormatterConfig.RegisterFormatters(GlobalConfiguration.Configuration.Formatters);
            //HttpConfiguration.EnsureInitialized();
            //config.Formatters.Remove(config.Formatters.XmlFormatter);

            /*
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
             * */
        }
        public void AddDefinitionIfFound_AddsDefinitionWithVerSupportIfFileFound()
        {
            // Arrange
            var map = new ScriptResourceMapping();
            var sd = new ScriptResourceDefinition
            {
                Path = "~/Scripts/",
                DebugPath = "~/Scripts/",
                CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-{0}.min.js",
                CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-{0}.js",
                CdnSupportsSecureConnection = true
            };
            var vpp = Substitute.For<VirtualPathProvider>();
            var vd = Substitute.For<VirtualDirectory>("~/Scripts/");
            var file = Substitute.For<VirtualFile>("jquery-1.6.2.js");
            file.Name.Returns("jquery-1.6.2.js");
            vd.Files.Returns(new List<VirtualFile> { file });
            vpp.GetDirectory("~/Scripts/").Returns(vd);
            ScriptResourceMappingExtensions.VirtualPathProvider = vpp;

            // Act
            map.AddDefinitionIfFound("jquery", typeof(Page).Assembly, sd,
                @"^jquery-" + ScriptResourceMappingExtensions.VerRegexPattern + @"(?:\.min){0,1}\.js$");

            // Assert
            Assert.IsNotNull(map.GetDefinition("jquery", typeof(Page).Assembly));
        }
Example #3
0
 protected void Application_Start(object sender, EventArgs e) {
     ScriptResourceDefinition myScriptResDef = new ScriptResourceDefinition();
     myScriptResDef.Path = "~/Scripts/jquery-1.4.2.min.js";
     myScriptResDef.DebugPath = "~/Scripts/jquery-1.4.2.js";
     myScriptResDef.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js";
     myScriptResDef.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.js";
     ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, myScriptResDef);
 }
 protected void Application_Start(object sender, EventArgs e)
 {
     ScriptResourceDefinition jQuery = new ScriptResourceDefinition();
     jQuery.Path = "~/scripts/jquery-1.7.2.min.js";
     jQuery.DebugPath = "~/scripts/jquery-1.7.2.js";
     jQuery.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.min.js";
     jQuery.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.js";
     ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
 }
        protected void Application_Start(object sender, EventArgs e)
        {
            var jQuery = new ScriptResourceDefinition {
                Path = "~/Scripts/jquery-2.0.3.min.js",
                DebugPath = "~/Scripts/jquery-2.0.3.js"
            };

            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
        }
Example #6
0
 protected void Application_Start(object sender, EventArgs e)
 {
     Database.SetInitializer<DatabaseContext>(new PastesDatabaseInitializer());
     ScriptResourceDefinition jQuery = new ScriptResourceDefinition();
     jQuery.Path = "~/scripts/jquery-1.7.2.min.js";
     jQuery.DebugPath = "~/scripts/jquery-1.7.2.js";
     jQuery.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.min.js";
     jQuery.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.js";
     ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
 }
Example #7
0
 protected void Application_Start(object sender, EventArgs e)
 {
     var jQuery = new ScriptResourceDefinition
     {
         Path = "~/Scripts/jquery-2.1.4.min.js",
         DebugPath = "jquery-2.1.4.js",
         CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-2.1.4.min.js",
         CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-2.1.4.js"
     };
 }
Example #8
0
 protected void Application_Start(object sender, EventArgs e)
 {
     RouteConfig.RegisterRoute(RouteTable.Routes);
     var jQuery = new ScriptResourceDefinition
     {
         Path = "~/Scripts/jquery-2.1.4.min.js",
         DebugPath = "~/Scripts/jquery-2.1.4.js",
         CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jqiery-2.1.4.min.js",
         CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jqiery-2.1.4.js"
     };
 }
Example #9
0
 protected void Application_Start(object sender, EventArgs e)
 {
     var jQuery = new ScriptResourceDefinition
     {
         Path = "~/Scripts/jquery-2.1.3.min.js",
         DebugPath = "~/Scripts/jquery-2.1.3.js",
         CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-2.1.3.min.js",
         CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-2.1.3.js"
     };
     ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
 }
        protected void Application_Start(object sender, EventArgs e)
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            ScriptResourceDefinition myScriptResDef = new ScriptResourceDefinition();
            myScriptResDef.Path = "~/Scripts/jquery-2.1.0.min.js";
            myScriptResDef.DebugPath = "~/Scripts/jquery-2.1.0.js";
            myScriptResDef.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-2.1.0.min.js";
            myScriptResDef.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-2.1.0.js";
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, myScriptResDef);
        }
        protected void Application_Start(object sender, EventArgs e)
        {
            var jQuery = new ScriptResourceDefinition {
                Path = "~/Scripts/jquery-2.0.3.min.js",
                DebugPath = "~/Scripts/jquery-2.0.3.js"
            };

            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);

            //BundleConfig.RegisterBundles(BundleTable.Bundles);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
Example #12
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();

            ScriptResourceDefinition jQuery = new ScriptResourceDefinition();
            jQuery.Path = "~/scripts/jquery-1.7.1.min.js";
            jQuery.DebugPath = "~/scripts/jquery-1.7.1.js";
            jQuery.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.1.min.js";
            jQuery.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.1.js";

            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
            System.Data.SqlClient.SqlDependency.Start(DBConnectionLayer.DBConnection.GetDBConnection());
        }
        protected void Application_Start(object sender, EventArgs e)
        {
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            BundleTable.EnableOptimizations = true;
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            var jQuery = new ScriptResourceDefinition
            {
                Path = "~/Scripts/jquery-1.9.1.min.js",
                DebugPath = "~/Scripts/jquery-1.9.1.js",
                CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.9.1.min.js",
                CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.9.1.js"
            };
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
        }
Example #14
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            // Use LocalDB for Entity Framework by default
            Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            ScriptResourceDefinition jQuery = new ScriptResourceDefinition();
            jQuery.Path = "~/scripts/jquery-1.7.2.min.js";
            jQuery.DebugPath = "~/scripts/jquery-1.7.2.js";
            jQuery.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.min.js";
            jQuery.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.js";
            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
        }
Example #15
0
        void Application_Start(object sender, EventArgs e)
        {
            // Codice eseguito all'avvio dell'applicazione
            RegisterRoutes(RouteTable.Routes);

            ScriptResourceDefinition jQuery = new ScriptResourceDefinition();

            jQuery.Path = "/js/jquery-1.8.1.min.js";

            //jQuery.DebugPath = "/js/jquery-1.8.1.min.js";

            jQuery.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.8.1.min.js";

            //jQuery.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.8.1.js";

            ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
        }
        public ScriptResourceDefinition GetDefinition(ScriptReference scriptReference)
        {
            if (scriptReference == null)
            {
                throw new ArgumentNullException("scriptReference");
            }
            string   name     = scriptReference.Name;
            Assembly assembly = null;
            ScriptResourceDefinition definition = null;

            if (!String.IsNullOrEmpty(name))
            {
                assembly   = scriptReference.GetAssembly();
                definition = ScriptManager.ScriptResourceMapping.GetDefinition(name, assembly);
            }
            return(definition);
        }
 public void AddDefinition(string name, Assembly assembly, ScriptResourceDefinition definition) {
     // dictionary indexer will update the value if it already exists
     if (String.IsNullOrEmpty(name)) {
         throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
     }
     if (definition == null) {
         throw new ArgumentNullException("definition");
     }
     if (String.IsNullOrEmpty(definition.ResourceName) && String.IsNullOrEmpty(definition.Path)) {
         throw new ArgumentException(AtlasWeb.ScriptResourceDefinition_NameAndPathCannotBeEmpty, "definition");
     }
     EnsureAbsoluteOrAppRelative(definition.Path);
     EnsureAbsoluteOrAppRelative(definition.DebugPath);
     EnsureAbsoluteOrAppRelative(definition.CdnPath);
     EnsureAbsoluteOrAppRelative(definition.CdnDebugPath);
     assembly = NormalizeAssembly(assembly);
     _definitions[new Tuple<String, Assembly>(name, assembly)] = definition;
 }
Example #18
0
            public ScriptEffectiveInfo(ScriptReference scriptReference)
            {
                ScriptResourceDefinition definition =
                    ScriptManager.ScriptResourceMapping.GetDefinition(scriptReference);
                string   name     = scriptReference.Name;
                string   path     = scriptReference.Path;
                Assembly assembly = scriptReference.GetAssembly();

                if (definition != null)
                {
                    if (String.IsNullOrEmpty(path))
                    {
                        // only when the SR has no path, the mapping's path and debug path, if any, apply
                        path       = definition.Path;
                        _debugPath = definition.DebugPath;
                    }
                    name                          = definition.ResourceName;
                    assembly                      = definition.ResourceAssembly;
                    _cdnPath                      = definition.CdnPath;
                    _cdnDebugPath                 = definition.CdnDebugPath;
                    _cdnPathSecureConnection      = definition.CdnPathSecureConnection;
                    _cdnDebugPathSecureConnection = definition.CdnDebugPathSecureConnection;
                    LoadSuccessExpression         = definition.LoadSuccessExpression;
                }
                else if ((assembly == null) && !String.IsNullOrEmpty(name))
                {
                    // name is set and there is no mapping, default to SWE for assembly
                    assembly = AssemblyCache.SystemWebExtensions;
                }
                _resourceName = name;
                _assembly     = assembly;
                _path         = path;

                if (assembly != null && !String.IsNullOrEmpty(name) && String.IsNullOrEmpty(LoadSuccessExpression))
                {
                    var scriptResourceInfo = ScriptResourceInfo.GetInstance(assembly, name);
                    if (scriptResourceInfo != null)
                    {
                        LoadSuccessExpression = scriptResourceInfo.LoadSuccessExpression;
                    }
                }
            }
        protected void Application_Start(object sender, EventArgs e)
        {
            //ValidationSettings.UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
            System.Reflection.Assembly ext = typeof(ScriptManager).Assembly;
            System.Reflection.Assembly web = typeof(HttpApplication).Assembly;

            ScriptResourceDefinition msAjax = new ScriptResourceDefinition();
            msAjax.ResourceName = "MicrosoftAjax.js";
            msAjax.ResourceAssembly = ext;
            msAjax.Path = "~/Scripts/WebForms/MSAjax/MicrosoftAjax.js";
            msAjax.CdnPath = "http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js";
            msAjax.CdnDebugPath = "http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.debug.js";
            msAjax.CdnSupportsSecureConnection = true;
            ScriptManager.ScriptResourceMapping.AddDefinition("msAjax", msAjax);

            ScriptResourceDefinition msAjaxWebForms = new ScriptResourceDefinition();
            msAjaxWebForms.ResourceName = "MicrosoftAjaxWebForms.js";
            msAjaxWebForms.ResourceAssembly = ext;
            msAjaxWebForms.Path = "~/Scripts/WebForms/MSAjax/MicrosoftAjaxWebForms.js";
            msAjaxWebForms.CdnPath = "http://ajax.aspnetcdn.com/ajax/4.5/6/MicrosoftAjaxWebForms.js";
            msAjaxWebForms.CdnPath = "http://ajax.aspnetcdn.com/ajax/4.5/6/MicrosoftAjaxWebForms.debug.js";
            msAjaxWebForms.CdnSupportsSecureConnection = true;
            ScriptManager.ScriptResourceMapping.AddDefinition("msAjaxWebForms", msAjaxWebForms);

            ScriptResourceDefinition webForms = new ScriptResourceDefinition();
            webForms.ResourceName = "WebForms.js";
            webForms.ResourceAssembly = web;
            webForms.Path = "~/Scripts/WebForms/WebForms.js";
            webForms.CdnPath = "http://ajax.aspnetcdn.com/ajax/4.5/6/WebForms.js";
            webForms.CdnSupportsSecureConnection = true;
            ScriptManager.ScriptResourceMapping.AddDefinition("webForms", webForms);

            ScriptResourceDefinition webValidation = new ScriptResourceDefinition();
            webValidation.ResourceName = "WebUIValidation.js";
            webValidation.ResourceAssembly = web;
            webValidation.Path = "~/Scripts/WebForms/WebUIValidation.js";
            webValidation.CdnPath = "http://ajax.aspnetcdn.com/ajax/4.5/6/WebUIValidation.js";
            webForms.CdnSupportsSecureConnection = true;
            ScriptManager.ScriptResourceMapping.AddDefinition("webValidation", webValidation);
        }
 public void AddDefinition(string name, Assembly assembly, ScriptResourceDefinition definition)
 {
     // dictionary indexer will update the value if it already exists
     if (String.IsNullOrEmpty(name))
     {
         throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
     }
     if (definition == null)
     {
         throw new ArgumentNullException("definition");
     }
     if (String.IsNullOrEmpty(definition.ResourceName) && String.IsNullOrEmpty(definition.Path))
     {
         throw new ArgumentException(AtlasWeb.ScriptResourceDefinition_NameAndPathCannotBeEmpty, "definition");
     }
     EnsureAbsoluteOrAppRelative(definition.Path);
     EnsureAbsoluteOrAppRelative(definition.DebugPath);
     EnsureAbsoluteOrAppRelative(definition.CdnPath);
     EnsureAbsoluteOrAppRelative(definition.CdnDebugPath);
     assembly = NormalizeAssembly(assembly);
     _definitions[new Tuple <String, Assembly>(name, assembly)] = definition;
 }
        public void AddDefinitionIfFound_AddsDefinitionWithNoVerSupportIfFileFound()
        {
            // Arrange
            var map = new ScriptResourceMapping();
            var sd = new ScriptResourceDefinition
            {
                Path = "~/Scripts/"
            };
            var vpp = Substitute.For<VirtualPathProvider>();
            var vd = Substitute.For<VirtualDirectory>("~/Scripts/");
            var file = Substitute.For<VirtualFile>("foo.js");
            file.Name.Returns("foo.js");
            vd.Files.Returns(new List<VirtualFile> { file });
            vpp.GetDirectory("~/Scripts/").Returns(vd);
            ScriptResourceMappingExtensions.VirtualPathProvider = vpp;

            // Act
            map.AddDefinitionIfFound("foo", typeof(Page).Assembly, sd, @"^foo.js$");

            // Assert
            Assert.IsNotNull(map.GetDefinition("foo", typeof(Page).Assembly));
        }
 /// <summary>
 ///    Adds a System.Web.UI.ScriptResourceDefinition object to the System.Web.UI.ScriptResourceMapping
 ///    object, but only if a file matching the supplied regex pattern is found. If the pattern includes
 ///    a capture group called "ver", it will be used to determine the highest version found.
 /// </summary>
 /// <param name="map">The ScriptResourceMapping object.</param>
 /// <param name="name">The name of the script resource.</param>
 /// <param name="definition">
 ///     A System.Web.UI.ScriptResourceDefinition object that specifies location support
 ///     for script resources. The Path and optionally DebugPath properties should contain
 ///     the path to the virtual folder containing the script to find, e.g. ~/Scripts/
 /// </param>
 /// <param name="fileNamePattern">
 ///     The regex pattern to match files against. If the pattern includes
 ///     a capture group called "ver", it will be used to determine the highest version found.
 /// </param>
 public static void AddDefinitionIfFound(this ScriptResourceMapping map, string name, ScriptResourceDefinition definition, string fileNamePattern)
 {
     AddDefinitionIfFound(map, name, typeof(ScriptManager).Assembly, definition, fileNamePattern);
 }
Example #23
0
		protected void Application_Start(Object sender, EventArgs e)
		{
            if (WebConfigSettings.EnableVirtualPathProviders)
            {
                try
                {
                    log.Info(Resource.ApplicationStartEventMessage);
                    RegisterVirtualPathProvider();

                }
                catch (MissingMethodException ex)
                {   // this is broken on mono, not implemented 2006-02-04
                    log.Error("Application_Start Could not register VirtualPathProvider, missing method in Mono", ex);

                }
                catch (SecurityException se)
                {
                    // must not be running in full trust
                    log.Error("Application_Start Could not register VirtualPathProvider, this error is expected when running in Medium trust or lower", se);

                }
                catch (UnauthorizedAccessException ae)
                {
                    // must not be running in full trust
                    log.Error("Application_Start Could not register VirtualPathProvider, this error is expected when running in Medium trust or lower", ae);

                }
            }
#if !NET35 && !NET40
            if (WebConfigSettings.EnableRouting)
            {
                AreaRegistration.RegisterAllAreas();
                GlobalConfiguration.Configure(WebApiConfig.Register);
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteRegistrar.RegisterRoutes(RouteTable.Routes);

            }

            BundleConfig.RegisterBundles(BundleTable.Bundles);

#endif

            

            StartOrResumeTasks();
            PurgeOldLogEvents();

//#if !NET35
//            appDomainMonitoringEnabled = WebConfigSettings.AppDomainMonitoringEnabled;
//            firstChanceExceptionMonitoringEnabled = WebConfigSettings.FirstChanceExceptionMonitoringEnabled;
//            try
//            {
//                SetupMonitoring();
//            }
//            catch (MethodAccessException)
//            {
//                log.Info("Failed to setup application monitoring, not allowed under medium trust.");
//                appDomainMonitoringEnabled = false;
//                firstChanceExceptionMonitoringEnabled = false;
//            }

            //#endif

#if!NET35 && !NET40

            if (WebConfigSettings.UnobtrusiveValidationMode == "WebForms")
            {
                if(WebConfigSettings.ForceEmptyJQueryScriptReference)
                {
                    // since we already have jquery loaded
                    // we need to fool scriptmanager by loading a fake version here
                    // to avoid an error http://stackoverflow.com/questions/12065228/asp-net-4-5-web-forms-unobtrusive-validation-jquery-issue
                    ScriptResourceDefinition jQuery = new ScriptResourceDefinition();
                    jQuery.Path = "~/ClientScript/empty.js"; 
                    ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
                }
                
            }
#endif


        }
 public void AddDefinition(string name, ScriptResourceDefinition definition)
 {
     AddDefinition(name, assembly: AssemblyCache.SystemWebExtensions, definition: definition);
 }
 public void AddDefinition(string name, ScriptResourceDefinition definition) {
     AddDefinition(name, assembly: AssemblyCache.SystemWebExtensions, definition: definition);
 }
Example #26
0
 protected void Application_Start(object sender, EventArgs e)
 {
     ScriptResourceDefinition myScriptResDef = new ScriptResourceDefinition();
     myScriptResDef.Path = "~/js/jquery-2.0.3.js";
     ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, myScriptResDef);
 }
        /// <summary>
        ///    Adds a System.Web.UI.ScriptResourceDefinition object to the System.Web.UI.ScriptResourceMapping
        ///    object, but only if a file matching the supplied regex pattern is found. If the pattern includes
        ///    a capture group called "ver", it will be used to determine the highest version found.
        /// </summary>
        /// <param name="map">The ScriptResourceMapping object.</param>
        /// <param name="name">The name of the script resource.</param>
        /// <param name="assembly">A System.Reflection.Assembly object that is used along with the name as the script resource key.</param>
        /// <param name="definition">
        ///     A System.Web.UI.ScriptResourceDefinition object that specifies location support
        ///     for script resources. The Path and optionally DebugPath properties should contain
        ///     the path to the virtual folder containing the script to find, e.g. ~/Scripts/
        /// </param>
        /// <param name="fileNamePattern">
        ///     The regex pattern to match files against. If the pattern includes
        ///     a capture group called "ver", it will be used to determine the highest version found.
        ///     Use ScriptResourceMappingExtensions.VerRegexPattern for a pattern matching standard
        ///     versioning strings, e.g. 1, 1.0, 1.1.2, etc.
        /// </param>
        public static void AddDefinitionIfFound(this ScriptResourceMapping map, string name, Assembly assembly, ScriptResourceDefinition definition, string fileNamePattern)
        {
            var scriptsFolder = VirtualPathProvider.GetDirectory(definition.Path);

            if (scriptsFolder == null)
            {
                return;
            }

            var scripts = scriptsFolder.Files.Cast<VirtualFile>();

            var fileNamePatternRegex = new Regex(fileNamePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);

            var supportVer = fileNamePatternRegex.GroupNumberFromName("ver") >= 0;

            var foundFile = (from file in scripts
                             let match = fileNamePatternRegex.Match(file.Name)
                             where match.Success
                             let fileVer = supportVer ? GetVersion(match) : null
                             orderby fileVer descending
                             select new
                             {
                                 file.Name,
                                 Version = fileVer
                             }).FirstOrDefault();

            if (foundFile != null)
            {
                var ver = foundFile.Version != null
                    ? Regex.Match(foundFile.Name, VerRegexPattern, RegexOptions.IgnoreCase).Groups["ver"].Value
                    : "";
                var isMin = foundFile.Name.EndsWith(".min.js", StringComparison.OrdinalIgnoreCase);

                var fileNamePrefix = foundFile.Name.Substring(0,
                    foundFile.Name.IndexOf(ver + (isMin ? ".min.js" : ".js")));

                var altFile = scripts.SingleOrDefault(f => f.Name.Equals(
                    String.Format(isMin ? "{0}{1}.js" : "{0}{1}.min.js", fileNamePrefix, ver),
                    StringComparison.OrdinalIgnoreCase));

                var hasBoth = altFile != null;

                var minFileName = isMin
                    ? foundFile.Name
                    : hasBoth
                        ? altFile.Name
                        : null;

                var nonMinFileName = !isMin
                    ? foundFile.Name
                    : hasBoth
                        ? altFile.Name
                        : null;

                var minOnly = isMin && !hasBoth;

                var path = minOnly || hasBoth
                    ? minFileName
                    : nonMinFileName;

                var debugPath = hasBoth
                    ? nonMinFileName
                    : null;

                path = path == null ? null : definition.Path + path;

                debugPath = debugPath == null ? null : (definition.DebugPath ?? definition.Path) + debugPath;

                var cdnPath = definition.CdnPath != null
                    ? ver != null
                        ? String.Format(definition.CdnPath, ver)
                        : definition.CdnPath
                    : null;

                var cdnDebugPath = definition.CdnDebugPath != null
                    ? ver != null
                        ? String.Format(definition.CdnDebugPath, ver)
                        : definition.CdnDebugPath
                    : null;

                map.AddDefinition(name, assembly, new ScriptResourceDefinition
                {
                    Path = path,
                    DebugPath = debugPath,
                    CdnPath = cdnPath,
                    CdnDebugPath = cdnDebugPath,
                    CdnSupportsSecureConnection = definition.CdnSupportsSecureConnection
                });
            }
        }