// The kludge of using ICodePragmaGenerator for C# and VB code files is bad, but // it's better than allowing for potential DoS while reading a file with arbitrary // size in memory for use with the CodeSnippetCompileUnit class. // Files with extensions other than .cs and .vb use CodeSnippetCompileUnit. internal void AddCodeFile (string path, BuildProvider bp, bool isVirtual) { if (String.IsNullOrEmpty (path)) return; Dictionary <string, bool> codeFiles = CodeFiles; if (codeFiles.ContainsKey (path)) return; codeFiles.Add (path, true); string extension = Path.GetExtension (path); if (extension == null || extension.Length == 0) return; // maybe better to throw an exception here? extension = extension.Substring (1); string filename = GetTempFilePhysicalPath (extension); ICodePragmaGenerator pragmaGenerator; switch (extension.ToLowerInvariant ()) { case "cs": pragmaGenerator = new CSharpCodePragmaGenerator (); break; case "vb": pragmaGenerator = new VBCodePragmaGenerator (); break; default: pragmaGenerator = null; break; } if (isVirtual) { VirtualFile vf = HostingEnvironment.VirtualPathProvider.GetFile (path); if (vf == null) throw new HttpException (404, "Virtual file '" + path + "' does not exist."); if (vf is DefaultVirtualFile) path = HostingEnvironment.MapPath (path); CopyFileWithChecksum (vf.Open (), filename, path, pragmaGenerator); } else CopyFileWithChecksum (path, filename, path, pragmaGenerator); if (pragmaGenerator != null) { if (bp != null) AddPathToBuilderMap (filename, bp); SourceFiles.Add (filename); } }
// The kludge of using ICodePragmaGenerator for C# and VB code files is bad, but // it's better than allowing for potential DoS while reading a file with arbitrary // size in memory for use with the CodeSnippetCompileUnit class. // Files with extensions other than .cs and .vb use CodeSnippetCompileUnit. internal void AddCodeFile(string path, BuildProvider bp, bool isVirtual) { if (String.IsNullOrEmpty(path)) { return; } Dictionary <string, bool> codeFiles = CodeFiles; if (codeFiles.ContainsKey(path)) { return; } codeFiles.Add(path, true); string extension = Path.GetExtension(path); if (extension == null || extension.Length == 0) { return; // maybe better to throw an exception here? } extension = extension.Substring(1); string filename = GetTempFilePhysicalPath(extension); ICodePragmaGenerator pragmaGenerator; switch (extension.ToLowerInvariant()) { case "cs": pragmaGenerator = new CSharpCodePragmaGenerator(); break; case "vb": pragmaGenerator = new VBCodePragmaGenerator(); break; default: pragmaGenerator = null; break; } if (isVirtual) { VirtualFile vf = HostingEnvironment.VirtualPathProvider.GetFile(path); if (vf == null) { throw new HttpException(404, "Virtual file '" + path + "' does not exist."); } if (vf is DefaultVirtualFile) { path = HostingEnvironment.MapPath(path); } CopyFileWithChecksum(vf.Open(), filename, path, pragmaGenerator); } else { CopyFileWithChecksum(path, filename, path, pragmaGenerator); } if (pragmaGenerator != null) { if (bp != null) { AddPathToBuilderMap(filename, bp); } SourceFiles.Add(filename); } }