Example #1
0
        /*
         * Return a CompilerType that a extension maps to.
         */
        private static CompilerType GetCompilerInfoFromExtension(VirtualPath configPath, string extension)
        {
            // Get the <compilation> config object
            CompilationSection config = MTConfigUtil.GetCompilationConfig(configPath);

            return(config.GetCompilerInfoFromExtension(extension, true /*throwOnFail*/));
        }
        internal string[] GetTopLevelAssemblyReferences(VirtualPath virtualPath)
        {
            this.AddPendingCall();
            List <Assembly> fromList = new List <Assembly>();

            try
            {
                virtualPath.CombineWithAppRoot();
                foreach (AssemblyInfo info in MTConfigUtil.GetCompilationConfig(virtualPath).Assemblies)
                {
                    Assembly[] assemblyInternal = info.AssemblyInternal;
                    for (int i = 0; i < assemblyInternal.Length; i++)
                    {
                        if (assemblyInternal[i] != null)
                        {
                            fromList.Add(assemblyInternal[i]);
                        }
                    }
                }
            }
            finally
            {
                this.RemovePendingCall();
            }
            StringCollection toList = new StringCollection();

            Util.AddAssembliesToStringCollection(fromList, toList);
            string[] array = new string[toList.Count];
            toList.CopyTo(array, 0);
            return(array);
        }
 internal WebDirectoryBatchCompiler(VirtualDirectory vdir)
 {
     this._vdir                 = vdir;
     this._utcStart             = DateTime.UtcNow;
     this._compConfig           = MTConfigUtil.GetCompilationConfig(this._vdir.VirtualPath);
     this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this._compConfig);
 }
Example #4
0
        /*
         * Return a CompilerType that a language maps to.
         */
        internal static CompilerType GetCompilerInfoFromLanguage(VirtualPath configPath, string language)
        {
            // Get the <compilation> config object
            CompilationSection config = MTConfigUtil.GetCompilationConfig(configPath);

            return(config.GetCompilerInfoFromLanguage(language));
        }
        /*
         * Returns an array of the assemblies defined in the bin and assembly reference config section
         */
        internal String[] GetTopLevelAssemblyReferences(VirtualPath virtualPath)
        {
            // Add a pending call to make sure our thread doesn't get killed
            AddPendingCall();

            List <Assembly> assemblyList = new List <Assembly>();

            try {
                // Treat it as relative to the app root
                virtualPath.CombineWithAppRoot();

                CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath);

                // Add all the config assemblies to the list
                foreach (AssemblyInfo assemblyInfo in compConfig.Assemblies)
                {
                    Assembly[] assemblies = assemblyInfo.AssemblyInternal;
                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        if (assemblies[i] != null)
                        {
                            assemblyList.Add(assemblies[i]);
                        }
                    }
                }
            } finally {
                RemovePendingCall();
            }
            StringCollection paths = new StringCollection();

            Util.AddAssembliesToStringCollection(assemblyList, paths);
            string[] references = new string[paths.Count];
            paths.CopyTo(references, 0);
            return(references);
        }
Example #6
0
        // Add the referenced assemblies into the compileParameters. Notice that buildProviders do not have
        // the correct referenced assemblies and we don't cache them since the assemblies could change
        // between appdomains. (removing assemblies from bin, etc)
        private void FixupReferencedAssemblies(VirtualPath virtualPath, CompilerParameters compilerParameters)
        {
            CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath);

            ICollection referencedAssemblies = BuildManager.GetReferencedAssemblies(compConfig);
            Util.AddAssembliesToStringCollection(referencedAssemblies, compilerParameters.ReferencedAssemblies);
        }
Example #7
0
        protected override void ComputeHashCode(HashCodeCombiner hashCodeCombiner)
        {
            base.ComputeHashCode(hashCodeCombiner);
            CompilationSection compilationConfig = MTConfigUtil.GetCompilationConfig(base.VirtualPath);

            hashCodeCombiner.AddObject(compilationConfig.RecompilationHash);
        }
 internal BuildProvidersCompiler(VirtualPath configPath, bool supportLocalization, string outputAssemblyName)
 {
     this._configPath           = configPath;
     this._supportLocalization  = supportLocalization;
     this._compConfig           = MTConfigUtil.GetCompilationConfig(this._configPath);
     this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this.CompConfig);
     this._outputAssemblyName   = outputAssemblyName;
 }
Example #9
0
        /*
         * Return a file provider Type that an extension maps to.
         */
        internal static Type GetBuildProviderTypeFromExtension(VirtualPath configPath, string extension,
                                                               BuildProviderAppliesTo neededFor, bool failIfUnknown)
        {
            // Get the <compilation> config object
            CompilationSection config = MTConfigUtil.GetCompilationConfig(configPath);

            return(GetBuildProviderTypeFromExtension(config, extension, neededFor, failIfUnknown));
        }
 internal BuildProvidersCompiler(VirtualPath configPath, bool supportLocalization, string generatedFilesDir, int index)
 {
     this._configPath           = configPath;
     this._supportLocalization  = supportLocalization;
     this._compConfig           = MTConfigUtil.GetCompilationConfig(this._configPath);
     this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this.CompConfig, index);
     this._generatedFilesDir    = generatedFilesDir;
 }
Example #11
0
 internal static CompilerType GetDefaultLanguageCompilerInfo(CompilationSection compConfig, VirtualPath configPath)
 {
     if (compConfig == null)
     {
         compConfig = MTConfigUtil.GetCompilationConfig(configPath);
     }
     if (compConfig.DefaultLanguage == null)
     {
         return(GetCodeDefaultLanguageCompilerInfo());
     }
     return(compConfig.GetCompilerInfoFromLanguage(compConfig.DefaultLanguage));
 }
Example #12
0
 internal static CompilerType GetCSharpCompilerInfo(CompilationSection compConfig, VirtualPath configPath)
 {
     if (compConfig == null)
     {
         compConfig = MTConfigUtil.GetCompilationConfig(configPath);
     }
     if (compConfig.DefaultLanguage == null)
     {
         return(new CompilerType(typeof(CSharpCodeProvider), null));
     }
     return(compConfig.GetCompilerInfoFromLanguage("c#"));
 }
Example #13
0
        internal static System.Web.Compilation.ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host)
        {
            if (expressionPrefix.Length == 0)
            {
                if (dataBindingExpressionBuilder == null)
                {
                    dataBindingExpressionBuilder = new DataBindingExpressionBuilder();
                }
                return(dataBindingExpressionBuilder);
            }
            CompilationSection compilationConfig = null;

            if (host != null)
            {
                IWebApplication application = (IWebApplication)host.GetService(typeof(IWebApplication));
                if (application != null)
                {
                    compilationConfig = application.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection;
                }
            }
            if (compilationConfig == null)
            {
                compilationConfig = MTConfigUtil.GetCompilationConfig(virtualPath);
            }
            System.Web.Configuration.ExpressionBuilder builder = compilationConfig.ExpressionBuilders[expressionPrefix];
            if (builder == null)
            {
                throw new HttpParseException(System.Web.SR.GetString("InvalidExpressionPrefix", new object[] { expressionPrefix }));
            }
            Type c = null;

            if (host != null)
            {
                ITypeResolutionService service = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
                if (service != null)
                {
                    c = service.GetType(builder.Type);
                }
            }
            if (c == null)
            {
                c = builder.TypeInternal;
            }
            if (!typeof(System.Web.Compilation.ExpressionBuilder).IsAssignableFrom(c))
            {
                throw new HttpParseException(System.Web.SR.GetString("ExpressionBuilder_InvalidType", new object[] { c.FullName }));
            }
            return((System.Web.Compilation.ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(c));
        }
Example #14
0
        internal static CompilerType GetDefaultLanguageCompilerInfo(CompilationSection compConfig, VirtualPath configPath)
        {
            if (compConfig == null)
            {
                // Get the <compilation> config object
                compConfig = MTConfigUtil.GetCompilationConfig(configPath);
            }

            // If no default language was specified in config, use VB
            if (compConfig.DefaultLanguage == null)
            {
                return(GetCodeDefaultLanguageCompilerInfo());
            }
            else
            {
                return(compConfig.GetCompilerInfoFromLanguage(compConfig.DefaultLanguage));
            }
        }
Example #15
0
        internal static bool NeedToCopyFile(VirtualPath virtualPath, bool updatable, out bool createStub)
        {
            createStub = false;
            CompilationSection compilationConfig = MTConfigUtil.GetCompilationConfig(virtualPath);
            string             extension         = virtualPath.Extension;
            BuildProviderInfo  buildProviderInfo = System.Web.Compilation.BuildProvider.GetBuildProviderInfo(compilationConfig, extension);

            if (buildProviderInfo != null)
            {
                if ((BuildProviderAppliesTo.Web & buildProviderInfo.AppliesTo) == 0)
                {
                    return(true);
                }
                if (buildProviderInfo.Type == typeof(ForceCopyBuildProvider))
                {
                    return(true);
                }
                if ((buildProviderInfo.Type != typeof(IgnoreFileBuildProvider)) && BuildManager.PrecompilingForUpdatableDeployment)
                {
                    return(true);
                }
                createStub = true;
                if (((buildProviderInfo.Type == typeof(UserControlBuildProvider)) || (buildProviderInfo.Type == typeof(MasterPageBuildProvider))) || (buildProviderInfo.Type == typeof(IgnoreFileBuildProvider)))
                {
                    createStub = false;
                }
                return(false);
            }
            if (compilationConfig.GetCompilerInfoFromExtension(extension, false) != null)
            {
                return(false);
            }
            if (System.Web.Util.StringUtil.EqualsIgnoreCase(extension, ".asax"))
            {
                return(false);
            }
            if (!updatable && System.Web.Util.StringUtil.EqualsIgnoreCase(extension, ".skin"))
            {
                return(false);
            }
            return(true);
        }
        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);
        }
Example #17
0
        internal static ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host)
        {
            // If there is no expressionPrefix, it's a v1 style databinding expression
            if (expressionPrefix.Length == 0)
            {
                if (dataBindingExpressionBuilder == null)
                {
                    dataBindingExpressionBuilder = new DataBindingExpressionBuilder();
                }
                return(dataBindingExpressionBuilder);
            }

            CompilationSection config = null;

            // If we are in the designer, we need to access IWebApplication config instead
#if !FEATURE_PAL // FEATURE_PAL does not support designer-based features
            if (host != null)
            {
                IWebApplication webapp = (IWebApplication)host.GetService(typeof(IWebApplication));
                if (webapp != null)
                {
                    config = webapp.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection;
                }
            }
#endif // !FEATURE_PAL

            // If we failed to get config from the designer, fall back on runtime config always
            if (config == null)
            {
                config = MTConfigUtil.GetCompilationConfig(virtualPath);
            }

            System.Web.Configuration.ExpressionBuilder builder = config.ExpressionBuilders[expressionPrefix];
            if (builder == null)
            {
                throw new HttpParseException(SR.GetString(SR.InvalidExpressionPrefix, expressionPrefix));
            }

            Type expressionBuilderType = null;
            if (host != null)
            {
                // If we are in the designer, we have to use the type resolution service
                ITypeResolutionService ts = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
                if (ts != null)
                {
                    expressionBuilderType = ts.GetType(builder.Type);
                }
            }
            if (expressionBuilderType == null)
            {
                expressionBuilderType = builder.TypeInternal;
            }
            Debug.Assert(expressionBuilderType != null, "expressionBuilderType should not be null");

            if (!typeof(ExpressionBuilder).IsAssignableFrom(expressionBuilderType))
            {
                throw new HttpParseException(SR.GetString(SR.ExpressionBuilder_InvalidType, expressionBuilderType.FullName));
            }
            ExpressionBuilder expressionBuilder = (ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(expressionBuilderType);

            return(expressionBuilder);
        }
        private BuildProvider GetCompilerParamsAndBuildProvider(VirtualPath virtualPath,
                                                                out Type codeDomProviderType, out CompilerParameters compilerParameters)
        {
            virtualPath.CombineWithAppRoot();

            CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath);

            ICollection referencedAssemblies = BuildManager.GetReferencedAssemblies(compConfig);

            // Create the buildprovider for the passed in virtualPath
            BuildProvider buildProvider = null;

            // Special case global asax build provider here since we do not want to compile every files with ".asax" extension.
            if (StringUtil.EqualsIgnoreCase(virtualPath.VirtualPathString, BuildManager.GlobalAsaxVirtualPath.VirtualPathString))
            {
                ApplicationBuildProvider provider = new ApplicationBuildProvider();
                provider.SetVirtualPath(virtualPath);
                provider.SetReferencedAssemblies(referencedAssemblies);
                buildProvider = provider;
            }
            else
            {
                buildProvider = BuildManager.CreateBuildProvider(virtualPath, compConfig,
                                                                 referencedAssemblies, true /*failIfUnknown*/);
            }

            // DevDiv 69017
            // The methods restricted to internalBuildProvider have been moved up to BuildProvider
            // to allow WCFBuildProvider to support .svc syntax highlighting.

            // Ignore parse errors, since they should not break the designer
            buildProvider.IgnoreParseErrors = true;

            // Ignore all control properties, since we do not generate code for the properties
            buildProvider.IgnoreControlProperties = true;

            // Process as many errors as possible, do not rethrow on first error
            buildProvider.ThrowOnFirstParseError = false;

            // Get the language (causes the file to be parsed)
            CompilerType compilerType = buildProvider.CodeCompilerType;

            // compilerType could be null in the no-compile case (VSWhidbey 221749)
            if (compilerType == null)
            {
                codeDomProviderType = null;
                compilerParameters  = null;
                return(null);
            }

            // Return the provider type and compiler params
            codeDomProviderType = compilerType.CodeDomProviderType;
            compilerParameters  = compilerType.CompilerParameters;

            IAssemblyDependencyParser parser = buildProvider.AssemblyDependencyParser;

            // Add all the assemblies that the page depends on (e.g. user controls)
            if (parser != null && parser.AssemblyDependencies != null)
            {
                Util.AddAssembliesToStringCollection(parser.AssemblyDependencies,
                                                     compilerParameters.ReferencedAssemblies);
            }

            // Make any fix up adjustments to the CompilerParameters to work around some issues
            AssemblyBuilder.FixUpCompilerParameters(compConfig, codeDomProviderType, compilerParameters);

            return(buildProvider);
        }
 internal NonBatchDirectoryCompiler(VirtualDirectory vdir)
 {
     _vdir       = vdir;
     _compConfig = MTConfigUtil.GetCompilationConfig(_vdir.VirtualPath);
 }
Example #20
0
 internal static bool IsBatchingEnabled(string configPath)
 {
     return(MTConfigUtil.GetCompilationConfig(configPath).Batch);
 }
 private void FixupReferencedAssemblies(VirtualPath virtualPath, CompilerParameters compilerParameters)
 {
     Util.AddAssembliesToStringCollection(BuildManager.GetReferencedAssemblies(MTConfigUtil.GetCompilationConfig(virtualPath)), compilerParameters.ReferencedAssemblies);
 }
Example #22
0
        internal static bool IsBatchingEnabled(string configPath)
        {
            CompilationSection config = MTConfigUtil.GetCompilationConfig(configPath);

            return(config.Batch);
        }
Example #23
0
        // This is used to determine what files need to be copied, and what stub files
        // need to be created during deployment precompilation.
        // Note: createStub only applies if the method returns false.
        internal static bool NeedToCopyFile(VirtualPath virtualPath, bool updatable, out bool createStub)
        {
            createStub = false;

            // Get the <compilation> config object
            CompilationSection config = MTConfigUtil.GetCompilationConfig(virtualPath);

            string extension = virtualPath.Extension;

            BuildProviderInfo providerInfo = BuildProvider.GetBuildProviderInfo(config, extension);

            if (providerInfo != null)
            {
                // We only care about 'web' providers.  Everything else we treat as static
                if ((BuildProviderAppliesTo.Web & providerInfo.AppliesTo) == 0)
                {
                    return(true);
                }

                // If the provider is a ForceCopyBuildProvider, treat as static
                if (providerInfo.Type == typeof(ForceCopyBuildProvider))
                {
                    return(true);
                }

                // During updatable precomp, everything needs to be copied over.  However,
                // aspx files that use code beside will later be overwritten by modified
                // versions (see TemplateParser.CreateModifiedMainDirectiveFileIfNeeded)
                if (providerInfo.Type != typeof(IgnoreFileBuildProvider) &&
                    BuildManager.PrecompilingForUpdatableDeployment)
                {
                    return(true);
                }

                // There is a real provider, so don't copy the file.  We also need to determine whether
                // a stub file needs to be created.

                createStub = true;

                // Skip the stub file for some non-requestable types
                if (providerInfo.Type == typeof(UserControlBuildProvider) ||
                    providerInfo.Type == typeof(MasterPageBuildProvider) ||
                    providerInfo.Type == typeof(IgnoreFileBuildProvider))
                {
                    createStub = false;
                }

                return(false);
            }

            // If the extension is registered as a compiler extension, don't copy
            if (config.GetCompilerInfoFromExtension(extension, false /*throwOnFail*/) != null)
            {
                return(false);
            }

            // Skip the copying for asax and skin files, which are not static even though they
            // don't have a registered BuildProvider (but don't skip .skin files during
            // updatable precomp).
            //
            if (StringUtil.EqualsIgnoreCase(extension, ".asax"))
            {
                return(false);
            }
            if (!updatable && StringUtil.EqualsIgnoreCase(extension, ThemeDirectoryCompiler.skinExtension))
            {
                return(false);
            }

            //
            // If there is no BuildProvider registered, it's a static file, and should be copied
            //

            return(true);
        }
Example #24
0
        internal static bool IsDebuggingEnabled(HttpContext context)
        {
            CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(context);

            return(compConfig.Debug);
        }
Example #25
0
 internal static bool IsDebuggingEnabled(HttpContext context)
 {
     return(MTConfigUtil.GetCompilationConfig(context).Debug);
 }
Example #26
0
 internal static CompilerType GetCompilerInfoFromLanguage(VirtualPath configPath, string language)
 {
     return(MTConfigUtil.GetCompilationConfig(configPath).GetCompilerInfoFromLanguage(language));
 }
Example #27
0
 internal static Type GetBuildProviderTypeFromExtension(VirtualPath configPath, string extension, BuildProviderAppliesTo neededFor, bool failIfUnknown)
 {
     return(GetBuildProviderTypeFromExtension(MTConfigUtil.GetCompilationConfig(configPath), extension, neededFor, failIfUnknown));
 }
Example #28
0
 private static CompilerType GetCompilerInfoFromExtension(VirtualPath configPath, string extension)
 {
     return(MTConfigUtil.GetCompilationConfig(configPath).GetCompilerInfoFromExtension(extension, true));
 }