Пример #1
0
        private IEnumerable <View> FindViews(string root, string areaName)
        {
            var viewsPath = Path.Combine(root, "Views");

            if (_fileLocator.DirectoryExists(viewsPath))
            {
                foreach (var controllerPath in _fileLocator.GetDirectories(viewsPath))
                {
                    var controllerName = Path.GetFileName(controllerPath);
                    foreach (var file in _fileLocator.GetFiles(Path.Combine(viewsPath, controllerName), "*.cshtml"))
                    {
                        var relativePath = !string.IsNullOrEmpty(areaName)
                            ? $"~/Areas/{areaName}/Views/{controllerName}/{Path.GetFileName(file)}"
                            : $"~/Views/{controllerName}/{Path.GetFileName(file)}";
                        yield return(GetView(file, controllerName, areaName));
                    }

                    foreach (var directory in _fileLocator.GetDirectories(controllerPath))
                    {
                        foreach (var file in _fileLocator.GetFiles(directory, "*.cshtml"))
                        {
                            yield return(GetView(file, controllerName, areaName, Path.GetFileName(directory)));
                        }
                    }
                }
            }
        }
Пример #2
0
        public IEnumerable <StaticFile> Find(string staticPathRoot)
        {
            var files = _fileLocator.GetFiles(staticPathRoot, "*", recurse: true).AsEnumerable();

            if (_settings.ExcludedStaticFileExtensions?.Length > 0)
            {
                files = files.Where(f => !_settings.ExcludedStaticFileExtensions.Any(e => f.EndsWith(e)));
            }
            if (!staticPathRoot.EndsWith("/"))
            {
                staticPathRoot += "/";
            }
            var rootUri = new Uri(staticPathRoot);

            return(files.Select(f => new StaticFile(rootUri.MakeRelativeUri(new Uri(f)))));
        }