Exemplo n.º 1
0
        private bool HasEnvironment()
        {
            var currentEnvironmentName = HostingEnvironment.EnvironmentName?.Trim();
            bool hasEnvironment = true;

            if (string.IsNullOrEmpty(Include) && string.IsNullOrEmpty(Exclude))
                return hasEnvironment; //by default add the dependency


            if (!string.IsNullOrEmpty(Include))
            {
                var includeTokenizer = new StringTokenizer(Include, NameSeparator);
                hasEnvironment = includeTokenizer.Any(t => t.HasValue && t.Length > 0 && t.Equals(currentEnvironmentName, StringComparison.OrdinalIgnoreCase));

            }

            if (!string.IsNullOrEmpty(Exclude))
            {
                var excludeTokenizer = new StringTokenizer(Exclude, NameSeparator);
                hasEnvironment = excludeTokenizer.Any(t => t.HasValue && t.Length > 0 && !t.Equals(currentEnvironmentName, StringComparison.OrdinalIgnoreCase)); 
            }

            return hasEnvironment;

        }
Exemplo n.º 2
0
        public IDirectoryContents GetDirectoryContents(string path)
        {
            if (path == null)
            {
                return(NotFoundDirectoryContents.Singleton);
            }

            var folder = NormalizePath(path);

            // Under "Modules/**".
            if (folder.StartsWith(_moduleRoot, StringComparison.Ordinal))
            {
                // Check for a "Pages" or a "Views" segment.
                var tokenizer = new StringTokenizer(folder, new char[] { '/' });
                if (tokenizer.Any(s => s == "Pages" || s == "Views"))
                {
                    // Resolve the subpath relative to the application's module root.
                    var folderSubPath = folder.Substring(_moduleRoot.Length);

                    // And serve the contents from the physical application root folder.
                    return(new PhysicalDirectoryContents(_root + folder.Replace("/", "\\")));
                }
            }

            return(NotFoundDirectoryContents.Singleton);
        }
        public IDirectoryContents GetDirectoryContents(string subpath)
        {
            var folder = NormalizePath(subpath);

            if (folder == "")
            {
                return(_fileProvider.GetDirectoryContents(subpath));
            }

            if (folder == Application.ModulesPath)
            {
                return(_fileProvider.GetDirectoryContents(subpath));
            }

            if (folder.StartsWith(Application.ModulesRoot, StringComparison.Ordinal))
            {
                if (folder.Substring(Application.ModulesRoot.Length).IndexOf('/') == -1)
                {
                    return(_fileProvider.GetDirectoryContents(subpath));
                }

                var tokenizer = new StringTokenizer(folder, new char[] { '/' });
                if (tokenizer.Any(s => s == "Pages" || s == "Components"))
                {
                    return(_fileProvider.GetDirectoryContents(subpath));
                }
            }

            return(new NotFoundDirectoryContents());
        }
        public IDirectoryContents GetDirectoryContents(string subpath)
        {
            // 'GetDirectoryContents()' is used to discover shapes templates and build fixed binding tables.
            // So the embedded file provider can always provide the structure under modules "Views" folders.
            // But application's module shapes are not embedded, so we need to serve the application "Views".

            // The razor view engine also uses 'GetDirectoryContents()' to find razor pages (not mvc views).
            // So here, we also need to serve the directory contents under the application "Pages" folder.

            // Note: This provider is also used in production where application views may not be precompiled.

            if (subpath == null)
            {
                return(NotFoundDirectoryContents.Singleton);
            }

            var folder = NormalizePath(subpath);

            // Under "Areas/{ApplicationName}".
            if (folder == Application.ModulePath)
            {
                // Serve the contents from the file system.
                return(new PhysicalDirectoryContents(Application.Path));
            }
            // Under "Areas/{ApplicationName}/**".
            else if (folder.StartsWith(Application.ModuleRoot, StringComparison.Ordinal))
            {
                // Check for a "Pages" or a "Views" segment.
                var tokenizer = new StringTokenizer(folder, new char[] { '/' });
                if (tokenizer.Any(s => s == "Pages" || s == "Views"))
                {
                    // Resolve the subpath relative to the application's module root.
                    var folderSubPath = folder.Substring(Application.ModuleRoot.Length);

                    // And serve the contents from the physical application root folder.
                    return(new PhysicalDirectoryContents(Application.Root + folderSubPath));
                }
            }

            return(NotFoundDirectoryContents.Singleton);
        }
Exemplo n.º 5
0
        public IDirectoryContents GetDirectoryContents(string subpath)
        {
            if (subpath == null)
            {
                return(NotFoundDirectoryContents.Singleton);
            }

            var folder = NormalizePath(subpath);

            var entries = new List <IFileInfo>();

            if (folder == "")
            {
                entries.Add(new EmbeddedDirectoryInfo(Application.ModulesPath));
            }
            else if (folder == Application.ModulesPath)
            {
                entries.AddRange(Application.ModuleNames
                                 .Select(n => new EmbeddedDirectoryInfo(n)));
            }
            else if (folder == Application.ModulePath)
            {
                return(new PhysicalDirectoryContents(Application.Path));
            }
            else if (folder.StartsWith(Application.ModuleRoot, StringComparison.Ordinal))
            {
                var tokenizer = new StringTokenizer(folder, new char[] { '/' });
                if (tokenizer.Any(s => s == "Pages" || s == "Views"))
                {
                    var folderSubPath = folder.Substring(Application.ModuleRoot.Length);
                    return(new PhysicalDirectoryContents(Application.Root + folderSubPath));
                }
            }
            else if (folder.StartsWith(Application.ModulesRoot, StringComparison.Ordinal))
            {
                var path        = folder.Substring(Application.ModulesRoot.Length);
                var index       = path.IndexOf('/');
                var name        = index == -1 ? path : path.Substring(0, index);
                var assetPaths  = _environment.GetModule(name).AssetPaths;
                var folders     = new HashSet <string>(StringComparer.Ordinal);
                var folderSlash = folder + '/';

                foreach (var assetPath in assetPaths.Where(a => a.StartsWith(folderSlash, StringComparison.Ordinal)))
                {
                    var folderPath = assetPath.Substring(folderSlash.Length);
                    var pathIndex  = folderPath.IndexOf('/');
                    var isFilePath = pathIndex == -1;

                    if (isFilePath)
                    {
                        entries.Add(GetFileInfo(assetPath));
                    }
                    else
                    {
                        folders.Add(folderPath.Substring(0, pathIndex));
                    }
                }

                entries.AddRange(folders.Select(f => new EmbeddedDirectoryInfo(f)));
            }

            return(new EmbeddedDirectoryContents(entries));
        }