Exemplo n.º 1
0
        private static ResourceBase CreateResource(string resourceName, CultureInfo culture, string resourceLocation)
        {
            Func <string, string> fixResourceName = c => resourceName + ((c != null) ? "." + c : string.Empty) + ".resx";

            IVirtualPathProvider vpp = DI.Current.Resolve <IVirtualPathProvider>();

            // First try the file path Resource.fr-CA.resx
            string fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.ToString()));
            bool   exists           = vpp.FileExists(fullResourcePath);

            // If not found, try Resource.fr.resx
            if (!exists)
            {
                fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.TwoLetterISOLanguageName));
                exists           = vpp.FileExists(fullResourcePath);
            }

            // If nothing is found try Resource.resx
            if (!exists)
            {
                fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(null));
                exists           = vpp.FileExists(fullResourcePath);
            }

            ResourceBase resource = exists ?
                                    new ResXResource(DI.Current.Resolve <IPathResolver>().Resolve(fullResourcePath)) :
                                    new EmbeddedResource(resourceName, culture) as ResourceBase;

            return(resource);
        }
Exemplo n.º 2
0
        private string NormalizePath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(pathProvider.ToAbsolute(ContentPath));
            }

            return(pathProvider.CombinePaths(pathProvider.ToAbsolute(ContentPath), path));
        }
Exemplo n.º 3
0
        private bool TryPath(string path, string modifier, out string result)
        {
            var directory   = virtualPathProvider.GetDirectory(path);
            var fileName    = virtualPathProvider.GetFile(path);
            var pathToProbe = modifier.HasValue() ? virtualPathProvider.CombinePaths(directory, modifier) + Path.AltDirectorySeparatorChar + fileName : path;

            result = virtualPathProvider.FileExists(pathToProbe) ? pathToProbe : null;

            return(result != null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the path to the script.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <param name="version">The version.</param>
        /// <param name="extensions">The collection of extensions.</param>
        /// <returns>The path.</returns>
        private string ProbePath(string virtualPath, string version, IEnumerable <string> extensions)
        {
            string result = null;

            Func <string, string> fixPath = path =>
            {
                string directory = _virtualPathProvider.GetDirectory(path);
                string fileName  = _virtualPathProvider.GetFile(path);

                if (!directory.EndsWith(version + Path.AltDirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
                {
                    string newDirectory = _virtualPathProvider.CombinePaths(directory, version);
                    string newPath      = newDirectory + Path.AltDirectorySeparatorChar + fileName;

                    if (_virtualPathProvider.FileExists(newPath))
                    {
                        return(newPath);
                    }
                }

                return(path);
            };

            foreach (string extension in extensions)
            {
                string changedPath    = Path.ChangeExtension(virtualPath, extension);
                string newVirtualPath = string.IsNullOrEmpty(version) ? changedPath : fixPath(changedPath);

                if (_virtualPathProvider.FileExists(newVirtualPath))
                {
                    result = newVirtualPath;
                    break;
                }
            }

            if (string.IsNullOrEmpty(result))
            {
                result = virtualPath;

                if (!_virtualPathProvider.FileExists(result))
                {
                    throw new FileNotFoundException("The specified file does not exist : '" + result + "'");
                }
            }

            // Return the virtual file.
            return(result);
        }
        public string Filter(string basePath, string content)
        {
            content = urlRegex.Replace(content, match =>
            {
                string url = match.Groups["url"].Value.Trim("'\"".ToCharArray());

                if (url.HasValue() &&
                    !url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
                    !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) &&
                    !url.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
                {
                    url = provider.CombinePaths(basePath, url);

                    return("url('{0}')".FormatWith(resolver.Resolve(url)));
                }

                return("url('{0}')".FormatWith(url));
            });

            return(content);
        }