private EmbeddedResourceVirtualFile GetOrCreateVirtualFile(Url url, bool throwOnError) { // If we're in an application in a folder (i.e. /blog) then remove that part. Url testUrl = new Url(VirtualPathUtility.ToAppRelative(url.Path).TrimStart('~')); // Always deal with lower-case URLs for aspx pages. if (testUrl.Extension == ".aspx") testUrl = testUrl.ToString().ToLower(); // First check if we already have a virtual file cached. if (_files.ContainsKey(testUrl)) return _files[testUrl]; // Grab the first segment of the path. This will be the assembly prefix. string assemblyPathPrefix = testUrl.SegmentAtIndex(0); if (string.IsNullOrEmpty(assemblyPathPrefix)) if (throwOnError) throw new ArgumentException("URL does not contain an assembly path prefix", "url"); else return null; if (!_assemblyPathPrefixes.ContainsKey(assemblyPathPrefix)) if (throwOnError) throw new ArgumentException("URL does not contain a valid assembly path prefix", "url"); else return null; Assembly assembly = _assemblyPathPrefixes[assemblyPathPrefix]; // Now get the rest of the path. This, combined with the assembly prefix, will be the resource path. Url remainingUrl = testUrl.RemoveSegment(0); string resourcePath = remainingUrl.PathWithoutExtension.Replace('/', '.'); if (remainingUrl.Extension == ".aspx") { resourcePath = Regex.Replace(resourcePath, "[^a-zA-Z]([a-z])|^([a-z])", m => m.Captures[0].Value.ToUpper()); resourcePath = Regex.Replace(resourcePath, "-", string.Empty); } // Create a new virtual file. EmbeddedResourceVirtualFile virtualFile = new EmbeddedResourceVirtualFile(url, assembly, assembly.GetName().Name + resourcePath + remainingUrl.Extension); _files.Add(testUrl, virtualFile); // Check that resource actually exists. if (assembly.GetManifestResourceStream(virtualFile.ResourcePath) == null) throw new ArgumentException(string.Format("Cannot find resource in assembly '{0}' matching resource path '{1}'.", assembly, virtualFile.ResourcePath)); return virtualFile; }
protected virtual string GetLanguage(ref Url url) { // Check if start of URL contains a language identifier. string priorityLanguage = null; foreach (Language language in Context.Current.LanguageManager.GetAvailableLanguages()) if (url.Path.Equals("/" + language.Name, StringComparison.InvariantCultureIgnoreCase) || url.Path.StartsWith("/" + language.Name + "/", StringComparison.InvariantCultureIgnoreCase)) { url = url.RemoveSegment(0); priorityLanguage = language.Name; } ContentLanguage.Instance.SetCulture(priorityLanguage); return ContentLanguage.PreferredCulture.Name; }