public mojoThemeVirtualDirectory(VirtualDirectory requestedDirectory)
            : base(requestedDirectory.VirtualPath)
        {
            _requestedDirectory = requestedDirectory;

            BuildChildren();
        }
 internal WebDirectoryBatchCompiler(VirtualDirectory vdir)
 {
     this._vdir = vdir;
     this._utcStart = DateTime.UtcNow;
     this._compConfig = MTConfigUtil.GetCompilationConfig(this._vdir.VirtualPath);
     this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this._compConfig);
 }
예제 #3
0
        private static IEnumerable<VirtualFile> SearchFiles( VirtualDirectory directory )
        {
            foreach ( VirtualFile file in directory.Files )
            yield return file;

              foreach ( VirtualDirectory d in directory.Directories )
              {
            foreach ( VirtualFile f in SearchFiles( d ) )
              yield return f;
              }
        }
        private static void TraverseDirectory(
            VirtualDirectory directory,
            ICollection<string> filePaths)
        {
            foreach (var childDirectory in directory
                .Directories
                .Cast<VirtualDirectory>())
            {
               TraverseDirectory(childDirectory, filePaths);
            }

            IncludeFiles(directory, filePaths);
        }
예제 #5
0
        internal VirtualDirectory GetDirectoryWithCheck(string virtualPath)
        {
            VirtualDirectory directory = this.GetDirectory(virtualPath);

            if (directory == null)
            {
                return(null);
            }
            if (!StringUtil.EqualsIgnoreCase(virtualPath, directory.VirtualPath))
            {
                throw new HttpException(System.Web.SR.GetString("Bad_VirtualPath_in_VirtualFileBase", new object[] { "VirtualDirectory", directory.VirtualPath, virtualPath }));
            }
            return(directory);
        }
 private static void IncludeFiles(
     VirtualDirectory directory,
     ICollection<string> filePaths)
 {
     foreach (var file in directory.Files
         .Cast<VirtualFile>()
         .Select(vf => new
             {
                 path = vf.VirtualPath,
                 ext = VirtualPathUtility.GetExtension(vf.VirtualPath)
             })
         .Where(x => ".js".Equals(x.ext, StringComparison.OrdinalIgnoreCase))
         .Select(x => x.path))
     {
         filePaths.Add(file);
     }
 }
예제 #7
0
        internal VirtualDirectory GetDirectoryWithCheck(string virtualPath)
        {
            VirtualDirectory virtualDir = GetDirectory(virtualPath);

            if (virtualDir == null)
            {
                return(null);
            }

            // Make sure the VirtualDirectory's path is the same as what was passed to GetDirectory
            if (!StringUtil.EqualsIgnoreCase(virtualPath, virtualDir.VirtualPath))
            {
                throw new HttpException(SR.GetString(SR.Bad_VirtualPath_in_VirtualFileBase,
                                                     "VirtualDirectory", virtualDir.VirtualPath, virtualPath));
            }

            return(virtualDir);
        }
 private static bool AddBrowserFilesToList(VirtualDirectory directory, IList list, bool doRecurse)
 {
     bool flag = false;
     foreach (VirtualFileBase base2 in directory.Children)
     {
         if (base2.IsDirectory)
         {
             if (doRecurse)
             {
                 AddBrowserFilesToList((VirtualDirectory) base2, list, true);
             }
             flag = true;
         }
         else if (StringUtil.EqualsIgnoreCase(Path.GetExtension(base2.Name), ".browser"))
         {
             list.Add(base2.VirtualPath);
         }
     }
     return flag;
 }
 private static void AddThemeFilesToBuildProvider(VirtualDirectory vdir, PageThemeBuildProvider themeBuildProvider, bool topLevel)
 {
     foreach (VirtualFileBase base2 in vdir.Children)
     {
         if (base2.IsDirectory)
         {
             AddThemeFilesToBuildProvider(base2 as VirtualDirectory, themeBuildProvider, false);
         }
         else
         {
             string extension = Path.GetExtension(base2.Name);
             if (StringUtil.EqualsIgnoreCase(extension, ".skin") && topLevel)
             {
                 themeBuildProvider.AddSkinFile(base2.VirtualPathObject);
             }
             else if (StringUtil.EqualsIgnoreCase(extension, ".css"))
             {
                 themeBuildProvider.AddCssFile(base2.VirtualPathObject);
             }
         }
     }
 }
예제 #10
0
        private void PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, bool topLevel) {

            // Precompile the children directory

            foreach (VirtualDirectory childVdir in vdir.Directories) {

                if (topLevel && _excludedTopLevelDirectories.Contains(childVdir.Name))
                    continue;

                // Exclude the special FrontPage directory (VSWhidbey 116727, 518602)
                if (childVdir.Name == "_vti_cnf")
                    continue;

                // Exclude target directory in precompilation scenarios
                if (SourceDirectoryIsInPrecompilationDestination(childVdir)) {
                    continue;
                }

                if (IsExcludedFromPrecompilation(childVdir)) {
                    continue;
                }

                PrecompileWebDirectoriesRecursive(childVdir, topLevel: false);
            }

            // Precompile this directory
            try {
                // Set a flag to remember that we're in the process of precompiling.  This
                // way, if BatchCompileWebDirectory ends up getting called again recursively
                // via CompileWebFile, we know that we cannot ignore errors.
                _precompilingApp = true;

                if (IsBatchEnabledForDirectory(vdir.VirtualPathObject)) {
                    // batch everything if enabled
                    BatchCompileWebDirectory(vdir, virtualDir: null, ignoreErrors: false);
                }
                else {
                    // if batching is disabled, compile each web file individually.
                    NonBatchDirectoryCompiler dirCompiler = new NonBatchDirectoryCompiler(vdir);
                    dirCompiler.Process();
                }
            }
            finally {
                // Always restore the flag to false when we're done.
                _precompilingApp = false;
            }
        }
예제 #11
0
        /*
         * Recursively copy all the static files from the source directory to the
         * target directory of the precompilation
         */
        private void CopyStaticFilesRecursive(VirtualDirectory sourceVdir, string destPhysicalDir,
            bool topLevel) {

            // Make sure the target physical dir has no relation with the source.  It's important to
            // check at every new directory, because IIS apps can have disconnected virtual sub dirs,
            // making an app root check insufficient (VSWhidbey 426251)
            if (SourceDirectoryIsInPrecompilationDestination(sourceVdir)) {
                return;
            }

            if (IsExcludedFromPrecompilation(sourceVdir)) {
                return;
            }

            bool directoryCreationAttempted = false;

            foreach (VirtualFileBase child in sourceVdir.Children) {

                string destPhysicalSubDir = Path.Combine(destPhysicalDir, child.Name);

                if (child.IsDirectory) {

                    // Skip the special top level directories, since they never contain relevant
                    // static files.  Note that we don't skip Themes, which does contain static files.
                    if (topLevel &&
                        (StringUtil.EqualsIgnoreCase(child.Name, HttpRuntime.CodeDirectoryName) ||
                        StringUtil.EqualsIgnoreCase(child.Name, HttpRuntime.ResourcesDirectoryName) ||
                        StringUtil.EqualsIgnoreCase(child.Name, HttpRuntime.WebRefDirectoryName))) {

                        continue;
                    }

                    // Also, skip the LocalResources directory at any level, except when precompiling
                    // for updatable deployment (in which case, we deploy the local resources file)
                    if (!PrecompilingForUpdatableDeployment && StringUtil.EqualsIgnoreCase(child.Name,
                        HttpRuntime.LocalResourcesDirectoryName)) {
                        continue;
                    }

                    CopyStaticFilesRecursive(child as VirtualDirectory, destPhysicalSubDir, topLevel: false);
                    continue;
                }

                // Create the destination directory if needed
                if (!directoryCreationAttempted) {
                    directoryCreationAttempted = true;
                    Directory.CreateDirectory(destPhysicalDir);
                }

                // Copy the file as appropriate based on its extension
                CopyPrecompiledFile(child as VirtualFile, destPhysicalSubDir);
            }
        }
예제 #12
0
        private bool BatchCompileWebDirectoryInternal(VirtualDirectory vdir, bool ignoreErrors) {

            WebDirectoryBatchCompiler sdc = new WebDirectoryBatchCompiler(vdir);

            // Just ignore build providers that have errors
            if (ignoreErrors) {
                sdc.SetIgnoreErrors();

                // Don't propagate errors that happen during batch compilation
                try {
                    sdc.Process();
                }
                catch {
                    return false;
                }
            }
            else {
                sdc.Process();
            }

            return true;
        }
예제 #13
0
 private bool IsExcludedFromPrecompilation(VirtualDirectory dir) {
     Debug.Assert(dir != null);
     return _excludedCompilationPaths.Any(path => UrlPath.IsEqualOrSubpath(path.VirtualPathString, dir.VirtualPath));
 }
 public VirtualDirectory CreateVirtualDirectory(string virtualPath, VirtualDirectory prev)
 {
     return new AssemblyResourceVirtualDirectory(virtualPath, prev, this);
 }
예제 #15
0
        private bool BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, bool ignoreErrors) {

            // Exactly one of vdir and virtualDir should be non-null.  The idea is to avoid calling
            // VirtualPathProvider.GetDirectory if batching is disabled (VSWhidbey 437549).

            if (virtualDir == null)
                virtualDir = vdir.VirtualPathObject;

            if (vdir == null)
                vdir = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualDir);

            // Then, check if we're already tried batch compiling this directory on this same request

            CaseInsensitiveStringSet directoryBatchCompilerChecker;
            directoryBatchCompilerChecker = CallContext.GetData(BatchCompilationSlotName)
                as CaseInsensitiveStringSet;

            if (directoryBatchCompilerChecker == null) {
                directoryBatchCompilerChecker = new CaseInsensitiveStringSet();

                // Create it and save it in the CallContext
                CallContext.SetData(BatchCompilationSlotName, directoryBatchCompilerChecker);
            }

            // If we've already tried batch compiling this directory, don't do anything
            if (directoryBatchCompilerChecker.Contains(vdir.VirtualPath))
                return false;

            // Add the current virtualDir to the batch compiler checker
            directoryBatchCompilerChecker.Add(vdir.VirtualPath);

            // If we're in the process of precompiling an app, never ignore errors.
            if (_precompilingApp)
                ignoreErrors = false;

            return BatchCompileWebDirectoryInternal(vdir, ignoreErrors);
        }
예제 #16
0
 private static string GetUrl(VirtualDirectory directory)
 {
     return directory.VirtualPath.ToLowerInvariant();
 }
예제 #17
0
 private static string GetTitle(VirtualDirectory dir)
 {
     return Normalize(dir.VirtualPath.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).Last());
 }
    private void ProcessDirectoryRecursive(VirtualDirectory vdir, bool topLevel) {

        // If it's a WebReferences directory, handle it using a single WebReferencesBuildProvider
        // instead of creating a different BuildProvider for each file.
        if (_dirType == CodeDirectoryType.WebReferences) {
            // Create a build provider for the current directory
            BuildProvider buildProvider = new WebReferencesBuildProvider(vdir);
            buildProvider.SetVirtualPath(vdir.VirtualPathObject);
            _buildProviders.Add(buildProvider);

            AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.WebReferences);
        }
        else if (_dirType == CodeDirectoryType.AppResources) {
            AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.GlobalResources);
        }
        else if (_dirType == CodeDirectoryType.LocalResources) {
            AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.LocalResources);
        }
        else if (_dirType == CodeDirectoryType.MainCode || _dirType == CodeDirectoryType.SubCode) {
            AddFolderLevelBuildProviders(vdir, FolderLevelBuildProviderAppliesTo.Code);
        }

        // Go through all the files in the directory
        foreach (VirtualFileBase child in vdir.Children) {

            if (child.IsDirectory) {

                // If we are at the top level of this code directory, and the current
                // subdirectory is in the exclude list, skip it
                if (topLevel && _excludedSubdirectories != null &&
                    _excludedSubdirectories.Contains(child.Name)) {
                    continue;
                }

                // Exclude the special FrontPage directory (VSWhidbey 116727)
                if (child.Name == "_vti_cnf")
                    continue;

                ProcessDirectoryRecursive(child as VirtualDirectory, false /*topLevel*/);
                continue;
            }

            // Don't look at individual files for WebReferences directories
            if (_dirType == CodeDirectoryType.WebReferences)
                continue;

            // Skip neutral files if _onlyBuildLocalizedResources is true
            if (IsResourceCodeDirectoryType(_dirType)) {
                if (_onlyBuildLocalizedResources && System.Web.UI.Util.GetCultureName(child.VirtualPath) == null) {
                    continue;
                }
            }

            BuildProvider buildProvider = BuildManager.CreateBuildProvider(child.VirtualPathObject,
                (IsResourceCodeDirectoryType(_dirType)) ?
                    BuildProviderAppliesTo.Resources : BuildProviderAppliesTo.Code,
                _bpc.CompConfig,
                _bpc.ReferencedAssemblies, false /*failIfUnknown*/);

            // Non-supported file type
            if (buildProvider == null)
                continue;

            // For Page resources, don't generate a strongly typed class
            if (_dirType == CodeDirectoryType.LocalResources && buildProvider is BaseResourcesBuildProvider) {
                ((BaseResourcesBuildProvider)buildProvider).DontGenerateStronglyTypedClass();
            }

            _buildProviders.Add(buildProvider);
        }
    }
    private static void AddThemeFilesToBuildProvider(VirtualDirectory vdir,
        PageThemeBuildProvider themeBuildProvider, bool topLevel) {

        // Go through all the files in the directory
        foreach (VirtualFileBase child in vdir.Children) {

            // Recursive into subdirectories.
            if (child.IsDirectory) {
                AddThemeFilesToBuildProvider(child as VirtualDirectory, themeBuildProvider, false);
                continue;
            }

            // We only process .skin and .css files
            string extension = Path.GetExtension(child.Name);
            if ((StringUtil.EqualsIgnoreCase(extension, skinExtension)) && topLevel) {
                themeBuildProvider.AddSkinFile(child.VirtualPathObject);
                continue;
            }

            if (StringUtil.EqualsIgnoreCase(extension, ".css")) {
                themeBuildProvider.AddCssFile(child.VirtualPathObject);
                continue;
            }
        }
    }
 internal NonBatchDirectoryCompiler(VirtualDirectory vdir) {
     _vdir = vdir;
     _compConfig = MTConfigUtil.GetCompilationConfig(_vdir.VirtualPath);
 }
 public void AddDirectory(VirtualDirectory dir)
 {
     DirectoryMap[NormalizeVirtualPath(dir.VirtualPath, isDirectory: true)] = dir;
 }
 internal WebReferencesBuildProvider(VirtualDirectory vdir) {
     _vdir = vdir;
 }
예제 #23
0
        // Make sure the target physical dir has no relation with the source. Return true if it does.
        private bool SourceDirectoryIsInPrecompilationDestination(VirtualDirectory sourceDir) {
            // Alwasy return false for in-place precompilations or non-precompilation scenarios.
            if (_precompTargetPhysicalDir == null) {
                return false;
            }

            string sourcePhysicalDir = HostingEnvironment.MapPathInternal(sourceDir.VirtualPath);

            // Make sure they're normalized and end with a '\' before comparing (VSWhidbey 452554)
            sourcePhysicalDir = FileUtil.FixUpPhysicalDirectory(sourcePhysicalDir);
            string destPhysicalDir = FileUtil.FixUpPhysicalDirectory(_precompTargetPhysicalDir);

            return StringUtil.StringStartsWithIgnoreCase(sourcePhysicalDir, destPhysicalDir);
        }
예제 #24
0
        private void RenderDirectory(HtmlTextWriter writer, VirtualPathProvider vpp, VirtualDirectory dir)
        {
            RenderCssAttribute(writer, false);
            writer.RenderBeginTag("ul");

            var dirpath = VirtualPathUtility.ToAppRelative(dir.VirtualPath);
            var pagedir = VirtualPathUtility.GetDirectory(Page.AppRelativeVirtualPath);
            var rootpath = VirtualPathUtility.AppendTrailingSlash(RootPath);

            // Render root directory
            foreach (var vf in dir.Children.Cast<VirtualFileBase>().OrderBy(f => f.Name))
            {
                var filepath = VirtualPathUtility.ToAppRelative(vf.VirtualPath);
                var filedir = VirtualPathUtility.GetDirectory(filepath);
                var filename = VirtualPathUtility.GetFileName(filepath);

                var isinpath = pagedir.StartsWith(filepath);

                if (vf.IsDirectory)
                {
                    filepath = VirtualPathUtility.Combine(filepath, "00_index.aspx");

                    if (!vpp.FileExists(filepath))
                    {
                        // Skip directory, if there's no index file
                        continue;
                    }
                }
                else if (comparer.Compare(dirpath, rootpath) != 0 &&
                         comparer.Compare(filename, "00_index.aspx") == 0 ||
                         comparer.Compare(filename, "Default.aspx") == 0 ||
                         comparer.Compare(VirtualPathUtility.GetExtension(filepath), ".aspx") != 0)
                {
                    // Skip index file and default.aspx in root or non aspx files
                    continue;
                }

                var isselected = comparer.Compare(filepath, Page.AppRelativeVirtualPath) == 0;
                var isinroot = comparer.Compare(filedir, rootpath) == 0;
                var title = GetPageTitle(vpp.GetFile(filepath));

                // Apply css to <li>
                RenderCssAttribute(writer, isselected);
                writer.RenderBeginTag("li");

                // Apply css to <a>
                RenderCssAttribute(writer, isselected);
                writer.AddAttribute("href", VirtualPathUtility.MakeRelative(Page.AppRelativeVirtualPath, filepath));
                writer.RenderBeginTag("a");
                writer.Write(title);
                writer.RenderEndTag();

                writer.RenderEndTag();

                // Render children, if
                //      - it is the current page
                //      - the current page is under this directory
                if (vf.IsDirectory && (isselected || isinpath || (isinroot && ExpandRootLevel)))
                {
                    RenderDirectory(writer, vpp, (VirtualDirectory)vf);
                }
            }

            writer.RenderEndTag();
        }
예제 #25
0
        private static IEnumerable<Topic> GetSubTopics(VirtualDirectory directory)
        {
            var directoryMetadata = GetDirectoryMetadata(directory.VirtualPath);
            var files = from file in directory.Files.Cast<VirtualFile>()
                   let subTitle = GetTitle(file)
                   let subMetadata = GetMetadata(subTitle, directoryMetadata)
                   where !subTitle.Equals(MetadataFile, StringComparison.OrdinalIgnoreCase)
                        && DocumentExtensions.Contains(Path.GetExtension(file.Name))
                   select new
                   {
                       Title = subTitle,
                       Url = GetUrl(file),
                       Order = subMetadata.Order
                   };

            var subdirectories = from subdirectory in directory.Directories.Cast<VirtualDirectory>()
                   let subTitle = GetTitle(subdirectory)
                   let subMetadata = GetMetadata(subTitle, directoryMetadata)
                   where subdirectory.Files.Cast<VirtualFile>().Any(x => IndexFiles.Contains(x.Name))
                   select new
                   {
                       Title = subTitle,
                       Url = GetUrl(subdirectory),
                       Order = subMetadata.Order
                   };

            return files.Union(subdirectories)
                .OrderBy(x => x.Order).ThenBy(x => x.Title)
                .Select(x => new Topic() { Title = x.Title, Url = x.Url });
        }
 public ThemeDirectory(VirtualDirectory toFilter) : base(toFilter.VirtualPath)
 {
     _toFilter = toFilter;
     BuildChild();
 }
예제 #27
0
 private static IEnumerable<Topic> GetTopics(VirtualDirectory topicDir)
 {
     var directoryMetadata = GetDirectoryMetadata(topicDir.VirtualPath);
     return from directory in topicDir.Directories.Cast<VirtualDirectory>()
            let title = GetTitle(directory)
            let metadata = GetMetadata(title, directoryMetadata)
            orderby metadata.Order, title
            select new Topic
            {
                Title = title,
                SubTopics = GetSubTopics(directory)
            };
 }
    static void EnumRecursive(HttpResponse response, VirtualDirectory vdir) {
        foreach (VirtualFile vfile in vdir.Files) {
            response.Write("File: " + vfile.VirtualPath + "<br>\r\n");
        }

        foreach (VirtualDirectory childVdir in vdir.Directories) {
            response.Write("Directory: " + childVdir.VirtualPath + "<br>\r\n");
            EnumRecursive(response, childVdir);
        }
    }
 public AssemblyResourceVirtualDirectory(string virtualPath, VirtualDirectory prevDirectory, AssemblyResources assemblyData)
     : base(virtualPath)
 {
     this.prevDirectory = prevDirectory;
      this.assemblyResources = assemblyData;
 }
예제 #30
0
 public EmbeddedVirtualDirectory(string virtualPath, VirtualDirectory filedir)
     : base(virtualPath)
 {
     FileDir = filedir;
 }
		void AddVirtualDir (VirtualDirectory vdir, BuildProviderCollection bpcoll, Dictionary <string, bool> cache)
		{
			if (vdir == null)
				return;
			
			BuildProvider bp;
			IDictionary <string, bool> deps;
			var dirs = new List <string> ();
			string fileVirtualPath;
			
			foreach (VirtualFile file in vdir.Files) {
				fileVirtualPath = file.VirtualPath;
				if (BuildManager.IgnoreVirtualPath (fileVirtualPath))
					continue;
				
				bp = GetBuildProvider (fileVirtualPath, bpcoll);
				if (bp == null)
					continue;
				if (!AddBuildProvider (bp))
					continue;
				
				deps = bp.ExtractDependencies ();
				if (deps == null)
					continue;

				string depDir, s;
				dirs.Clear ();
				foreach (var dep in deps) {
					s = dep.Key;
					depDir = VirtualPathUtility.GetDirectory (s); // dependencies are assumed to contain absolute paths
					if (cache.ContainsKey (depDir))
						continue;
					cache.Add (depDir, true);
					AddVirtualDir (GetVirtualDirectory (s), bpcoll, cache);
				}
			}
		}
        private static bool AddBrowserFilesToList(
            VirtualDirectory directory, IList list, bool doRecurse) {
            bool hasCustomCaps = false;

            foreach (VirtualFileBase fileBase in directory.Children) {

                // Recursive into subdirectories.
                if (fileBase.IsDirectory) {
                    if (doRecurse) {
                        AddBrowserFilesToList((VirtualDirectory)fileBase, list, true);
                    }
                    hasCustomCaps = true;
                    continue;
                }

                string extension = Path.GetExtension(fileBase.Name);
                if (StringUtil.EqualsIgnoreCase(extension, ".browser")) {
                    list.Add(fileBase.VirtualPath);
                }
            }
            return hasCustomCaps;
        }