private void AddBuildProviders(bool retryIfDeletionHappens)
 {
     DiskBuildResultCache.ResetAssemblyDeleted();
     foreach (VirtualFile file in this._vdir.Files)
     {
         BuildResult vPathBuildResultFromCache = null;
         try
         {
             vPathBuildResultFromCache = BuildManager.GetVPathBuildResultFromCache(file.VirtualPathObject);
         }
         catch
         {
             if (!BuildManager.PerformingPrecompilation)
             {
                 continue;
             }
         }
         if (vPathBuildResultFromCache == null)
         {
             System.Web.Compilation.BuildProvider provider = BuildManager.CreateBuildProvider(file.VirtualPathObject, this._compConfig, this._referencedAssemblies, false);
             if (provider != null)
             {
                 this._buildProviders[file.VirtualPath] = provider;
             }
         }
     }
     if ((DiskBuildResultCache.InUseAssemblyWasDeleted && retryIfDeletionHappens) && BuildManager.PerformingPrecompilation)
     {
         this.AddBuildProviders(false);
     }
 }
        public void AddCodeCompileUnit(System.Web.Compilation.BuildProvider buildProvider, CodeCompileUnit compileUnit)
        {
            string str;

            this.AddChecksumPragma(buildProvider, compileUnit);
            Util.AddAssembliesToStringCollection(this._initialReferencedAssemblies, compileUnit.ReferencedAssemblies);
            Util.AddAssembliesToStringCollection(this._additionalReferencedAssemblies, compileUnit.ReferencedAssemblies);
            using (new ProcessImpersonationContext())
            {
                TextWriter writer = this.CreateCodeFile(buildProvider, out str);
                try
                {
                    this._codeProvider.GenerateCodeFromCompileUnit(compileUnit, writer, null);
                }
                finally
                {
                    writer.Flush();
                    writer.Close();
                }
            }
            if (str != null)
            {
                this._totalFileLength += this.GetFileLengthWithAssert(str);
            }
        }
示例#3
0
 internal override void AddBuildProvider(System.Web.Compilation.BuildProvider buildProvider)
 {
     if (!(buildProvider is SourceFileBuildProvider))
     {
         base.AddBuildProvider(buildProvider);
     }
 }
        internal static CompilerType GetCompilerTypeFromBuildProvider(System.Web.Compilation.BuildProvider buildProvider)
        {
            HttpContext  context = null;
            CompilerType type2;

            if (EtwTrace.IsTraceEnabled(5, 1) && ((context = HttpContext.Current) != null))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_ENTER, context.WorkerRequest);
            }
            try
            {
                CompilerType codeCompilerType = buildProvider.CodeCompilerType;
                if (codeCompilerType != null)
                {
                    CompilationUtil.CheckCompilerOptionsAllowed(codeCompilerType.CompilerParameters.CompilerOptions, false, null, 0);
                }
                type2 = codeCompilerType;
            }
            finally
            {
                if (EtwTrace.IsTraceEnabled(5, 1) && (context != null))
                {
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_LEAVE, context.WorkerRequest);
                }
            }
            return(type2);
        }
 private void AddChecksumPragma(System.Web.Compilation.BuildProvider buildProvider, CodeCompileUnit compileUnit)
 {
     if (((buildProvider != null) && (buildProvider.VirtualPath != null)) && this._compilerType.CompilerParameters.IncludeDebugInformation)
     {
         string path = HostingEnvironment.MapPathInternal(buildProvider.VirtualPath);
         if (File.Exists(path))
         {
             if (!s_hashMD5Guid.HasValue)
             {
                 s_hashMD5Guid = new Guid(0x406ea660, 0x64cf, 0x4c82, 0xb6, 240, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99);
             }
             CodeChecksumPragma pragma = new CodeChecksumPragma();
             if (this._compConfig.UrlLinePragmas)
             {
                 pragma.FileName = ErrorFormatter.MakeHttpLinePragma(buildProvider.VirtualPathObject.VirtualPathString);
             }
             else
             {
                 pragma.FileName = path;
             }
             pragma.ChecksumAlgorithmId = s_hashMD5Guid.Value;
             using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
             {
                 pragma.ChecksumData = this.ComputeHash(stream);
             }
             compileUnit.StartDirectives.Add(pragma);
         }
     }
 }
 private void CacheCompileErrors(AssemblyBuilder assemblyBuilder, CompilerResults results)
 {
     System.Web.Compilation.BuildProvider provider = null;
     foreach (CompilerError error in results.Errors)
     {
         if (!error.IsWarning)
         {
             System.Web.Compilation.BuildProvider buildProviderFromLinePragma = assemblyBuilder.GetBuildProviderFromLinePragma(error.FileName);
             if (((buildProviderFromLinePragma != null) && (buildProviderFromLinePragma is BaseTemplateBuildProvider)) && (buildProviderFromLinePragma != provider))
             {
                 provider = buildProviderFromLinePragma;
                 CompilerResults results2 = new CompilerResults(null);
                 foreach (string str in results.Output)
                 {
                     results2.Output.Add(str);
                 }
                 results2.PathToAssembly            = results.PathToAssembly;
                 results2.NativeCompilerReturnValue = results.NativeCompilerReturnValue;
                 results2.Errors.Add(error);
                 HttpCompileException compileException = new HttpCompileException(results2, assemblyBuilder.GetGeneratedSourceFromBuildProvider(buildProviderFromLinePragma));
                 BuildResult          result           = new BuildResultCompileError(buildProviderFromLinePragma.VirtualPathObject, compileException);
                 buildProviderFromLinePragma.SetBuildResultDependencies(result);
                 BuildManager.CacheVPathBuildResult(buildProviderFromLinePragma.VirtualPathObject, result, this._utcStart);
             }
         }
     }
 }
 private bool IsBuildProviderSkipable(System.Web.Compilation.BuildProvider buildProvider)
 {
     if (buildProvider.IsDependedOn)
     {
         return(false);
     }
     return((buildProvider is SourceFileBuildProvider) || (buildProvider is ResXBuildProvider));
 }
 internal static string GetDisplayName(System.Web.Compilation.BuildProvider buildProvider)
 {
     if (buildProvider.VirtualPath != null)
     {
         return(buildProvider.VirtualPath);
     }
     return(buildProvider.GetType().Name);
 }
示例#9
0
        internal override TextWriter CreateCodeFile(System.Web.Compilation.BuildProvider buildProvider, out string filename)
        {
            string cacheKeyFromVirtualPath = BuildManager.GetCacheKeyFromVirtualPath(buildProvider.VirtualPathObject);

            cacheKeyFromVirtualPath = FileUtil.TruncatePathIfNeeded(Path.Combine(this._generatedFilesDir, cacheKeyFromVirtualPath), 10) + "." + base._codeProvider.FileExtension;
            filename = cacheKeyFromVirtualPath;
            BuildManager.GenerateFileTable[buildProvider.VirtualPathObject.VirtualPathStringNoTrailingSlash] = cacheKeyFromVirtualPath;
            return(new StreamWriter(new FileStream(cacheKeyFromVirtualPath, FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8));
        }
 internal void AddBuildProviderDependency(System.Web.Compilation.BuildProvider dependentBuildProvider)
 {
     if (this._buildProviderDependencies == null)
     {
         this._buildProviderDependencies = new BuildProviderSet();
     }
     this._buildProviderDependencies.Add(dependentBuildProvider);
     dependentBuildProvider.flags[1] = true;
 }
        internal System.Web.Compilation.BuildProvider GetBuildProviderFromLinePragma(string linePragma)
        {
            System.Web.Compilation.BuildProvider buildProviderFromLinePragmaInternal = this.GetBuildProviderFromLinePragmaInternal(linePragma);
            SourceFileBuildProvider provider2 = buildProviderFromLinePragmaInternal as SourceFileBuildProvider;

            if (provider2 != null)
            {
                buildProviderFromLinePragmaInternal = provider2.OwningBuildProvider;
            }
            return(buildProviderFromLinePragmaInternal);
        }
        private void AddCompileWithBuildProvider(VirtualPath virtualPath, System.Web.Compilation.BuildProvider owningBuildProvider)
        {
            System.Web.Compilation.BuildProvider buildProvider = BuildManager.CreateBuildProvider(virtualPath, this._compConfig, this._initialReferencedAssemblies, true);
            buildProvider.SetNoBuildResult();
            SourceFileBuildProvider provider2 = buildProvider as SourceFileBuildProvider;

            if (provider2 != null)
            {
                provider2.OwningBuildProvider = owningBuildProvider;
            }
            this.AddBuildProvider(buildProvider);
        }
        internal virtual void AddBuildProvider(System.Web.Compilation.BuildProvider buildProvider)
        {
            object key  = buildProvider;
            bool   flag = false;

            if (this._compConfig.FolderLevelBuildProviders != null)
            {
                Type t = buildProvider.GetType();
                flag = this._compConfig.FolderLevelBuildProviders.IsFolderLevelBuildProvider(t);
            }
            if ((buildProvider.VirtualPath != null) && !flag)
            {
                key = buildProvider.VirtualPath;
                if (this._buildProviders.ContainsKey(key))
                {
                    return;
                }
            }
            this._buildProviders[key] = buildProvider;
            try
            {
                buildProvider.GenerateCode(this);
            }
            catch (XmlException exception)
            {
                throw new HttpParseException(exception.Message, null, buildProvider.VirtualPath, null, exception.LineNumber);
            }
            catch (XmlSchemaException exception2)
            {
                throw new HttpParseException(exception2.Message, null, buildProvider.VirtualPath, null, exception2.LineNumber);
            }
            catch (Exception exception3)
            {
                throw new HttpParseException(exception3.Message, exception3, buildProvider.VirtualPath, null, 1);
            }
            InternalBuildProvider owningBuildProvider = buildProvider as InternalBuildProvider;

            if (owningBuildProvider != null)
            {
                ICollection compileWithDependencies = owningBuildProvider.GetCompileWithDependencies();
                if (compileWithDependencies != null)
                {
                    foreach (VirtualPath path in compileWithDependencies)
                    {
                        if (!this._buildProviders.ContainsKey(path.VirtualPathString))
                        {
                            this.AddCompileWithBuildProvider(path, owningBuildProvider);
                        }
                    }
                }
            }
        }
        private string GetErrorSourceFileContents(CompilerResults results)
        {
            if (!results.Errors.HasErrors)
            {
                return(null);
            }
            string fileName = results.Errors[0].FileName;

            System.Web.Compilation.BuildProvider buildProviderFromLinePragma = this.GetBuildProviderFromLinePragma(fileName);
            if (buildProviderFromLinePragma != null)
            {
                return(this.GetGeneratedSourceFromBuildProvider(buildProviderFromLinePragma));
            }
            return(Util.StringFromFileIfExists(fileName));
        }
        internal virtual TextWriter CreateCodeFile(System.Web.Compilation.BuildProvider buildProvider, out string filename)
        {
            string tempFilePhysicalPathWithAssert = this.GetTempFilePhysicalPathWithAssert(this._codeProvider.FileExtension);

            filename = tempFilePhysicalPathWithAssert;
            if (buildProvider != null)
            {
                if (this._buildProviderToSourceFileMap == null)
                {
                    this._buildProviderToSourceFileMap = new Hashtable();
                }
                this._buildProviderToSourceFileMap[buildProvider] = tempFilePhysicalPathWithAssert;
                buildProvider.SetContributedCode();
            }
            this._sourceFiles.Add(tempFilePhysicalPathWithAssert);
            return(this.CreateCodeFileWithAssert(tempFilePhysicalPathWithAssert));
        }
 private void GetBuildResultDependencies()
 {
     foreach (System.Web.Compilation.BuildProvider provider in this._buildProviders.Values)
     {
         ICollection buildResultVirtualPathDependencies = provider.GetBuildResultVirtualPathDependencies();
         if (buildResultVirtualPathDependencies != null)
         {
             foreach (string str in buildResultVirtualPathDependencies)
             {
                 System.Web.Compilation.BuildProvider dependentBuildProvider = (System.Web.Compilation.BuildProvider) this._buildProviders[str];
                 if (dependentBuildProvider != null)
                 {
                     provider.AddBuildProviderDependency(dependentBuildProvider);
                 }
             }
         }
     }
 }
        public Stream CreateEmbeddedResource(System.Web.Compilation.BuildProvider buildProvider, string name)
        {
            if (!Util.IsValidFileName(name))
            {
                throw new ArgumentException(null, name);
            }
            string codegenResourceDir = BuildManager.CodegenResourceDir;
            string fileName           = Path.Combine(codegenResourceDir, name);

            this.CreateTempResourceDirectoryIfNecessary();
            this._tempFiles.AddFile(fileName, this._tempFiles.KeepFiles);
            if (this._embeddedResourceFiles == null)
            {
                this._embeddedResourceFiles = new StringSet();
            }
            this._embeddedResourceFiles.Add(fileName);
            InternalSecurityPermissions.FileWriteAccess(codegenResourceDir).Assert();
            return(File.OpenWrite(fileName));
        }
        private System.Web.Compilation.BuildProvider GetCompilerParamsAndBuildProvider(VirtualPath virtualPath, out Type codeDomProviderType, out CompilerParameters compilerParameters)
        {
            virtualPath.CombineWithAppRoot();
            CompilationSection compilationConfig    = MTConfigUtil.GetCompilationConfig(virtualPath);
            ICollection        referencedAssemblies = BuildManager.GetReferencedAssemblies(compilationConfig);

            System.Web.Compilation.BuildProvider provider = null;
            if (StringUtil.EqualsIgnoreCase(virtualPath.VirtualPathString, BuildManager.GlobalAsaxVirtualPath.VirtualPathString))
            {
                ApplicationBuildProvider provider2 = new ApplicationBuildProvider();
                provider2.SetVirtualPath(virtualPath);
                provider2.SetReferencedAssemblies(referencedAssemblies);
                provider = provider2;
            }
            else
            {
                provider = BuildManager.CreateBuildProvider(virtualPath, compilationConfig, referencedAssemblies, true);
            }
            provider.IgnoreParseErrors       = true;
            provider.IgnoreControlProperties = true;
            provider.ThrowOnFirstParseError  = false;
            CompilerType codeCompilerType = provider.CodeCompilerType;

            if (codeCompilerType == null)
            {
                codeDomProviderType = null;
                compilerParameters  = null;
                return(null);
            }
            codeDomProviderType = codeCompilerType.CodeDomProviderType;
            compilerParameters  = codeCompilerType.CompilerParameters;
            IAssemblyDependencyParser assemblyDependencyParser = provider.AssemblyDependencyParser;

            if ((assemblyDependencyParser != null) && (assemblyDependencyParser.AssemblyDependencies != null))
            {
                Util.AddAssembliesToStringCollection(assemblyDependencyParser.AssemblyDependencies, compilerParameters.ReferencedAssemblies);
            }
            AssemblyBuilder.FixUpCompilerParameters(codeDomProviderType, compilerParameters);
            return(provider);
        }
        private void ProcessBuildProviders()
        {
            CompilerType type = null;

            System.Web.Compilation.BuildProvider buildProvider = null;
            if (this.OutputAssemblyName != null)
            {
                StandardDiskBuildResultCache.RemoveSatelliteAssemblies(this.OutputAssemblyName);
            }
            ArrayList list = null;

            foreach (System.Web.Compilation.BuildProvider provider2 in this._buildProviders)
            {
                provider2.SetReferencedAssemblies(this._referencedAssemblies);
                if (!BuildManager.ThrowOnFirstParseError)
                {
                    InternalBuildProvider provider3 = provider2 as InternalBuildProvider;
                    if (provider3 != null)
                    {
                        provider3.ThrowOnFirstParseError = false;
                    }
                }
                CompilerType compilerTypeFromBuildProvider = System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(provider2);
                string       cultureName = null;
                if (this._supportLocalization)
                {
                    cultureName = provider2.GetCultureName();
                }
                if (compilerTypeFromBuildProvider != null)
                {
                    if (cultureName != null)
                    {
                        throw new HttpException(System.Web.SR.GetString("Both_culture_and_language", new object[] { System.Web.Compilation.BuildProvider.GetDisplayName(provider2) }));
                    }
                    if (type != null)
                    {
                        if (!compilerTypeFromBuildProvider.Equals(type))
                        {
                            throw new HttpException(System.Web.SR.GetString("Inconsistent_language", new object[] { System.Web.Compilation.BuildProvider.GetDisplayName(provider2), System.Web.Compilation.BuildProvider.GetDisplayName(buildProvider) }));
                        }
                    }
                    else
                    {
                        buildProvider         = provider2;
                        this._assemblyBuilder = compilerTypeFromBuildProvider.CreateAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._generatedFilesDir, this.OutputAssemblyName);
                    }
                }
                else
                {
                    if (cultureName != null)
                    {
                        if (!this.CbmGenerateOnlyMode)
                        {
                            if (this._satelliteAssemblyBuilders == null)
                            {
                                this._satelliteAssemblyBuilders = new Hashtable(StringComparer.OrdinalIgnoreCase);
                            }
                            AssemblyBuilder builder = (AssemblyBuilder)this._satelliteAssemblyBuilders[cultureName];
                            if (builder == null)
                            {
                                builder             = CompilerType.GetDefaultAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._configPath, this.OutputAssemblyName);
                                builder.CultureName = cultureName;
                                this._satelliteAssemblyBuilders[cultureName] = builder;
                            }
                            builder.AddBuildProvider(provider2);
                        }
                        continue;
                    }
                    if (this._assemblyBuilder == null)
                    {
                        if (list == null)
                        {
                            list = new ArrayList();
                        }
                        list.Add(provider2);
                        continue;
                    }
                }
                this._assemblyBuilder.AddBuildProvider(provider2);
            }
            if ((this._assemblyBuilder == null) && (list != null))
            {
                this._assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._configPath, this._generatedFilesDir, this.OutputAssemblyName);
            }
            if ((this._assemblyBuilder != null) && (list != null))
            {
                foreach (System.Web.Compilation.BuildProvider provider4 in list)
                {
                    this._assemblyBuilder.AddBuildProvider(provider4);
                }
            }
        }
        public TextWriter CreateCodeFile(System.Web.Compilation.BuildProvider buildProvider)
        {
            string str;

            return(this.CreateCodeFile(buildProvider, out str));
        }
        private void ProcessDependencies()
        {
            int       num       = 0;
            Hashtable hashtable = new Hashtable();
            Stack     stack     = new Stack();

            foreach (System.Web.Compilation.BuildProvider provider in this._buildProviders.Values)
            {
                stack.Push(provider);
                while (stack.Count > 0)
                {
                    System.Web.Compilation.BuildProvider provider2 = (System.Web.Compilation.BuildProvider)stack.Peek();
                    bool flag = false;
                    int  num2 = 0;
                    if (provider2.BuildProviderDependencies != null)
                    {
                        foreach (System.Web.Compilation.BuildProvider provider3 in (IEnumerable)provider2.BuildProviderDependencies)
                        {
                            if (hashtable.ContainsKey(provider3))
                            {
                                if (num2 > ((int)hashtable[provider3]))
                                {
                                    if (((int)hashtable[provider3]) == -1)
                                    {
                                        throw new HttpException(System.Web.SR.GetString("File_Circular_Reference", new object[] { provider3.VirtualPath }));
                                    }
                                }
                                else
                                {
                                    num2 = ((int)hashtable[provider3]) + 1;
                                }
                            }
                            else
                            {
                                flag = true;
                                stack.Push(provider3);
                            }
                        }
                    }
                    if (flag)
                    {
                        hashtable[provider2] = -1;
                    }
                    else
                    {
                        stack.Pop();
                        hashtable[provider2] = num2;
                        if (num <= num2)
                        {
                            num = num2 + 1;
                        }
                    }
                }
            }
            this._nonDependentBuckets = new ArrayList[num];
            IDictionaryEnumerator enumerator = hashtable.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int index = (int)enumerator.Value;
                if (this._nonDependentBuckets[index] == null)
                {
                    this._nonDependentBuckets[index] = new ArrayList();
                }
                this._nonDependentBuckets[index].Add(enumerator.Key);
            }
        }
 internal ApplicationBrowserCapabilitiesCodeGenerator(System.Web.Compilation.BuildProvider buildProvider)
 {
     this._buildProvider = buildProvider;
 }
 internal ApplicationBrowserCapabilitiesCodeGenerator(System.Web.Compilation.BuildProvider buildProvider)
 {
     this._buildProvider = buildProvider;
 }
        internal string GetGeneratedSourceFromBuildProvider(System.Web.Compilation.BuildProvider buildProvider)
        {
            string path = (string)this._buildProviderToSourceFileMap[buildProvider];

            return(Util.StringFromFileIfExists(path));
        }
        internal CodeCompileUnit GenerateCodeCompileUnit(VirtualPath virtualPath, string virtualFileString, out Type codeDomProviderType, out CompilerParameters compilerParameters, out IDictionary linePragmasTable)
        {
            CodeCompileUnit codeCompileUnit;

            this.AddPendingCall();
            try
            {
                BuildManager.SkipTopLevelCompilationExceptions = true;
                this._buildManager.EnsureTopLevelFilesCompiled();
                if (virtualFileString == null)
                {
                    using (Stream stream = virtualPath.OpenFile())
                    {
                        virtualFileString = Util.ReaderFromStream(stream, virtualPath).ReadToEnd();
                    }
                }
                this._virtualPathProvider.RegisterVirtualFile(virtualPath, virtualFileString);
                string cacheKey = BuildManager.GetCacheKeyFromVirtualPath(virtualPath) + "_CBMResult";
                BuildResultCodeCompileUnit buildResultFromCache = (BuildResultCodeCompileUnit)BuildManager.GetBuildResultFromCache(cacheKey, virtualPath);
                if (buildResultFromCache == null)
                {
                    lock (this._lock)
                    {
                        DateTime utcNow = DateTime.UtcNow;
                        System.Web.Compilation.BuildProvider provider = this.GetCompilerParamsAndBuildProvider(virtualPath, out codeDomProviderType, out compilerParameters);
                        if (provider == null)
                        {
                            linePragmasTable = null;
                            return(null);
                        }
                        CodeCompileUnit unit2 = provider.GetCodeCompileUnit(out linePragmasTable);
                        buildResultFromCache = new BuildResultCodeCompileUnit(codeDomProviderType, unit2, compilerParameters, linePragmasTable)
                        {
                            VirtualPath = virtualPath
                        };
                        buildResultFromCache.SetCacheKey(cacheKey);
                        this.FixupReferencedAssemblies(virtualPath, compilerParameters);
                        if (unit2 != null)
                        {
                            foreach (string str2 in compilerParameters.ReferencedAssemblies)
                            {
                                unit2.ReferencedAssemblies.Add(str2);
                            }
                        }
                        ICollection virtualPathDependencies = provider.VirtualPathDependencies;
                        if (virtualPathDependencies != null)
                        {
                            buildResultFromCache.AddVirtualPathDependencies(virtualPathDependencies);
                        }
                        BuildManager.CacheBuildResult(cacheKey, buildResultFromCache, utcNow);
                        return(unit2);
                    }
                }
                codeDomProviderType = buildResultFromCache.CodeDomProviderType;
                compilerParameters  = buildResultFromCache.CompilerParameters;
                linePragmasTable    = buildResultFromCache.LinePragmasTable;
                this.FixupReferencedAssemblies(virtualPath, compilerParameters);
                codeCompileUnit = buildResultFromCache.CodeCompileUnit;
            }
            finally
            {
                if (virtualFileString != null)
                {
                    this._virtualPathProvider.RevertVirtualFile(virtualPath);
                }
                BuildManager.SkipTopLevelCompilationExceptions = false;
                this.RemovePendingCall();
            }
            return(codeCompileUnit);
        }