//
        // Helper methods
        //

        internal static CompilerType GetCompilerTypeFromBuildProvider(
            BuildProvider buildProvider)
        {
            HttpContext context = null;

            if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure) && (context = HttpContext.Current) != null)
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_ENTER, context.WorkerRequest);
            }

            try {
                CompilerType compilerType = buildProvider.CodeCompilerType;
                if (compilerType != null)
                {
                    CompilationUtil.CheckCompilerOptionsAllowed(compilerType.CompilerParameters.CompilerOptions,
                                                                false /*config*/, null, 0);
                }
                return(compilerType);
            }
            finally {
                if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure) && context != null)
                {
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_PARSE_LEAVE, context.WorkerRequest);
                }
            }
        }
示例#2
0
        public void AddProvider(BuildProvider bp)
        {
            if (Count == 0)
            {
                // We need to set the name prefix
                if (bp is ApplicationFileBuildProvider)
                {
                    NamePrefix  = "App_global.asax";
                    Application = true;
                }
                else if (bp is ThemeDirectoryBuildProvider)
                {
                    NamePrefix = "App_Theme";
                    Master     = true;
                }
                else
                {
                    NamePrefix = "App_Web";
                }

                CompilerType ct = BuildManager.GetDefaultCompilerTypeForLanguage(bp.LanguageName, null);
                if (ct != null)
                {
                    CompilerType = ct;
                }
            }

            Add(bp);
        }
 internal AssemblyBuilder(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string outputAssemblyName)
 {
     this._compConfig                  = compConfig;
     this._outputAssemblyName          = outputAssemblyName;
     this._initialReferencedAssemblies = AssemblySet.Create(referencedAssemblies);
     this._compilerType                = compilerType.Clone();
     if (BuildManager.PrecompilingWithDebugInfo)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = true;
     }
     else if (BuildManager.PrecompilingForDeployment)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = false;
     }
     else if (DeploymentSection.RetailInternal)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = false;
     }
     else if (this._compConfig.AssemblyPostProcessorTypeInternal != null)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = true;
     }
     this._tempFiles.KeepFiles       = this._compilerType.CompilerParameters.IncludeDebugInformation;
     this._codeProvider              = CompilationUtil.CreateCodeDomProviderNonPublic(this._compilerType.CodeDomProviderType);
     this._maxBatchSize              = this._compConfig.MaxBatchSize;
     this._maxBatchGeneratedFileSize = this._compConfig.MaxBatchGeneratedFileSize * 0x400;
 }
        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);
        }
 internal AssemblyBuilder(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string outputAssemblyName)
 {
     this._compConfig = compConfig;
     this._outputAssemblyName = outputAssemblyName;
     this._initialReferencedAssemblies = AssemblySet.Create(referencedAssemblies);
     this._compilerType = compilerType.Clone();
     if (BuildManager.PrecompilingWithDebugInfo)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = true;
     }
     else if (BuildManager.PrecompilingForDeployment)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = false;
     }
     else if (DeploymentSection.RetailInternal)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = false;
     }
     else if (this._compConfig.AssemblyPostProcessorTypeInternal != null)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = true;
     }
     this._tempFiles.KeepFiles = this._compilerType.CompilerParameters.IncludeDebugInformation;
     this._codeProvider = CompilationUtil.CreateCodeDomProviderNonPublic(this._compilerType.CodeDomProviderType);
     this._maxBatchSize = this._compConfig.MaxBatchSize;
     this._maxBatchGeneratedFileSize = this._compConfig.MaxBatchGeneratedFileSize * 0x400;
 }
        Type GetBuildProviderCodeDomType(BuildProvider bp)
        {
            CompilerType ct = bp.CodeCompilerType;

            if (ct == null)
            {
                string language = bp.LanguageName;

                if (String.IsNullOrEmpty(language))
                {
                    language = CompilationSection.DefaultLanguage;
                }

                ct = BuildManager.GetDefaultCompilerTypeForLanguage(language, CompilationSection, false);
            }

            Type ret = ct != null ? ct.CodeDomProviderType : null;

            if (ret == null)
            {
                throw new HttpException("Unable to determine code compilation language provider for virtual path '" + bp.VirtualPath + "'.");
            }

            return(ret);
        }
 public SimpleRazorBuildProvider()
 {
     this._codeLanguage = new CSharpRazorCodeLanguage();
     this._compilerType = GetDefaultCompilerTypeForLanguage(this._codeLanguage.LanguageName);
     this._host = new SimpleRazorEngineHost(this._codeLanguage);
     this._virtualPathDependencies = null;
     this._typeName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this._host.DefaultNamespace, "Foot");
 }
        public CSharpExtensionBuildProviderShim() {
            OrchardHostContainerRegistry.RegisterShim(this);

            _codeCompilerType = GetDefaultCompilerTypeForLanguage("C#");

            // define a precompilation flag so that module can adapt for older version
            var orchardVersion = typeof (IDependency).Assembly.GetName().Version;
            _codeCompilerType.CompilerParameters.CompilerOptions += string.Format("/define:ORCHARD_{0}_{1}", orchardVersion.Major, orchardVersion.Minor) ;
        }
示例#9
0
        internal static AssemblyBuilder GetDefaultAssemblyBuilder(CompilationSection compConfig,
                                                                  ICollection referencedAssemblies, VirtualPath configPath,
                                                                  string generatedFilesDir, string outputAssemblyName)
        {
            CompilerType ctwp = GetDefaultCompilerTypeWithParams(compConfig, configPath);

            return(ctwp.CreateAssemblyBuilder(compConfig, referencedAssemblies,
                                              generatedFilesDir, outputAssemblyName));
        }
        public override bool Equals(object o)
        {
            CompilerType type = o as CompilerType;

            if (o == null)
            {
                return(false);
            }
            return((((this._codeDomProviderType == type._codeDomProviderType) && (this._compilParams.WarningLevel == type._compilParams.WarningLevel)) && (this._compilParams.IncludeDebugInformation == type._compilParams.IncludeDebugInformation)) && (this._compilParams.CompilerOptions == type._compilParams.CompilerOptions));
        }
        public CSharpExtensionBuildProviderShim() {
            OrchardHostContainerRegistry.RegisterShim(this);

            _codeCompilerType = GetDefaultCompilerTypeForLanguage("C#");

            // NOTE: This code could be used to define a compilation flag with the current Orchar version 
            // but it's not compatible with Medium Trust
            // var orchardVersion = new AssemblyName(typeof(IDependency).Assembly.FullName).Version;
            // _codeCompilerType.CompilerParameters.CompilerOptions += string.Format("/define:ORCHARD_{0}_{1}", orchardVersion.Major, orchardVersion.Minor);
        }
 internal void GenerateSources(out Type codeDomProviderType, out CompilerParameters compilerParameters)
 {
     this.ProcessBuildProviders();
     if (this._assemblyBuilder == null)
     {
         this._assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._configPath, this._generatedFilesDir, null);
     }
     codeDomProviderType = this._assemblyBuilder.CodeDomProviderType;
     compilerParameters  = this._assemblyBuilder.GetCompilerParameters();
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="CSharpRazorBuildProvider"/> class.
		/// </summary>
		public CSharpRazorBuildProvider()
		{
			this.compilerType = this.GetDefaultCompilerTypeForLanguage("C#");

			this.host = new RazorEngineHost(new CSharpRazorCodeLanguage()) {
				DefaultBaseClass = typeof(ViewPageRef).FullName,
				DefaultNamespace = "RazorOutput",
				DefaultClassName = "ViewPage"
			};
		}
示例#14
0
        public override bool Equals(object o)
        {
            if (!(o is CompilerType))
            {
                return(false);
            }

            CompilerType other = (CompilerType)o;

            //FIXME: parameters does NOT have an Equals override
            return(other.type == type && other.parameters == parameters);
        }
示例#15
0
        public override bool Equals(Object o)
        {
            CompilerType other = o as CompilerType;

            if (o == null)
            {
                return(false);
            }

            return(_codeDomProviderType == other._codeDomProviderType &&
                   _compilParams.WarningLevel == other._compilParams.WarningLevel &&
                   _compilParams.IncludeDebugInformation == other._compilParams.IncludeDebugInformation &&
                   _compilParams.CompilerOptions == other._compilParams.CompilerOptions);
        }
 internal CbmCodeGeneratorBuildProviderHost(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string generatedFilesDir, string outputAssemblyName) : base(compConfig, referencedAssemblies, compilerType, outputAssemblyName)
 {
     if (Directory.Exists(generatedFilesDir))
     {
         foreach (FileData data in (IEnumerable) FileEnumerator.Create(generatedFilesDir))
         {
             if (!data.IsDirectory)
             {
                 File.Delete(data.FullName);
             }
         }
     }
     Directory.CreateDirectory(generatedFilesDir);
     this._generatedFilesDir = generatedFilesDir;
 }
示例#17
0
        internal void GenerateSources(out Type codeDomProviderType,
                                      out CompilerParameters compilerParameters)
        {
            ProcessBuildProviders();

            // If we didn't get an AssemblyBuilder (happens when there was nothing to build),
            // get a default one.
            if (_assemblyBuilder == null)
            {
                _assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(
                    CompConfig, _referencedAssemblies, _configPath,
                    _generatedFilesDir, null /*outputAssemblyName*/);
            }

            codeDomProviderType = _assemblyBuilder.CodeDomProviderType;
            compilerParameters  = _assemblyBuilder.GetCompilerParameters();
        }
        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);
        }
示例#19
0
    /*
     * Process a compileFile attribute (aka code besides)
     */
    private void ProcessCodeFile(VirtualPath codeFileVirtualPath) {

        Debug.Assert(_codeFileVirtualPath == null);

        _codeFileVirtualPath = ResolveVirtualPath(codeFileVirtualPath);

        // Get the language for the code beside page
        CompilerType compilerType = CompilationUtil.GetCompilerInfoFromVirtualPath(
            _codeFileVirtualPath);

        // Make sure we don't get conflicting languages
        if (_compilerType != null &&
            _compilerType.CodeDomProviderType != compilerType.CodeDomProviderType) {
            ProcessError(SR.GetString(SR.Inconsistent_CodeFile_Language));

            return;
        }

        // Check if it's trying to go cross app, or points to a special directory.
        // It's important to do this before checkin existence, to avoid revealing information
        // about other apps (VSWhidbey 442957)
        BuildManager.ValidateCodeFileVirtualPath(_codeFileVirtualPath);

        // Make sure the file exists
        Util.CheckVirtualFileExists(_codeFileVirtualPath);

        _compilerType = compilerType;

        // Add the code file to the list of files we depend on
        AddSourceDependency(_codeFileVirtualPath);
    }
示例#20
0
        private void ProcessBuildProviders()
        {
            CompilerType  compilerType = null;
            BuildProvider firstLanguageBuildProvider = null;

            // First, delete all the existing satellite assemblies of the assembly
            // we're about to build (VSWhidbey 87022) (only if it has a fixed name)
            if (OutputAssemblyName != null)
            {
                Debug.Assert(!CbmGenerateOnlyMode);
                StandardDiskBuildResultCache.RemoveSatelliteAssemblies(OutputAssemblyName);
            }

            // List of BuildProvider's that don't ask for a specific language
            ArrayList languageFreeBuildProviders = null;

            foreach (BuildProvider buildProvider in _buildProviders)
            {
                // If it's an InternalBuildProvider, give it the assembly references early on
                buildProvider.SetReferencedAssemblies(_referencedAssemblies);

                // Instruct the internal build providers to continue processing for more parse errors.
                if (!BuildManager.ThrowOnFirstParseError)
                {
                    InternalBuildProvider provider = buildProvider as InternalBuildProvider;
                    if (provider != null)
                    {
                        provider.ThrowOnFirstParseError = false;
                    }
                }

                // Get the language and culture
                CompilerType ctwp = BuildProvider.GetCompilerTypeFromBuildProvider(buildProvider);

                // Only look for a culture if we're supposed to (basically, in the resources directories)
                string cultureName = null;
                if (_supportLocalization)
                {
                    cultureName = buildProvider.GetCultureName();
                }

                // Is it asking for a specific language?
                if (ctwp != null)
                {
                    // If it specifies a language, it can't also have a culture
                    if (cultureName != null)
                    {
                        throw new HttpException(SR.GetString(SR.Both_culture_and_language, BuildProvider.GetDisplayName(buildProvider)));
                    }

                    // Do we already know the language we'll be using
                    if (compilerType != null)
                    {
                        // If it's different from the current one, fail
                        if (!ctwp.Equals(compilerType))
                        {
                            throw new HttpException(SR.GetString(SR.Inconsistent_language,
                                                                 BuildProvider.GetDisplayName(buildProvider),
                                                                 BuildProvider.GetDisplayName(firstLanguageBuildProvider)));
                        }
                    }
                    else
                    {
                        // Keep track of the build provider of error handling purpose
                        firstLanguageBuildProvider = buildProvider;

                        // Keep track of the language
                        compilerType     = ctwp;
                        _assemblyBuilder = compilerType.CreateAssemblyBuilder(
                            CompConfig, _referencedAssemblies, _generatedFilesDir, OutputAssemblyName);
                    }
                }
                else
                {
                    if (cultureName != null)
                    {
                        // Ignore the culture files in generate-only mode
                        if (CbmGenerateOnlyMode)
                        {
                            continue;
                        }

                        if (_satelliteAssemblyBuilders == null)
                        {
                            _satelliteAssemblyBuilders = new Hashtable(
                                StringComparer.OrdinalIgnoreCase);
                        }

                        // Check if we already have an assembly builder for this culture
                        AssemblyBuilder satelliteAssemblyBuilder =
                            (AssemblyBuilder)_satelliteAssemblyBuilders[cultureName];

                        // If not, create one and store it in the hashtable
                        if (satelliteAssemblyBuilder == null)
                        {
                            satelliteAssemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(
                                CompConfig, _referencedAssemblies, _configPath, OutputAssemblyName);
                            satelliteAssemblyBuilder.CultureName    = cultureName;
                            _satelliteAssemblyBuilders[cultureName] = satelliteAssemblyBuilder;
                        }

                        satelliteAssemblyBuilder.AddBuildProvider(buildProvider);
                        continue;
                    }

                    if (_assemblyBuilder == null)
                    {
                        // If this provider doesn't need a specific language, and we don't know
                        // the language yet, just keep track of it
                        if (languageFreeBuildProviders == null)
                        {
                            languageFreeBuildProviders = new ArrayList();
                        }
                        languageFreeBuildProviders.Add(buildProvider);
                        continue;
                    }
                }

                _assemblyBuilder.AddBuildProvider(buildProvider);
            }

            // If we didn't get an AssemblyBuilder, use a default
            if (_assemblyBuilder == null && languageFreeBuildProviders != null)
            {
                _assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(
                    CompConfig, _referencedAssemblies, _configPath,
                    _generatedFilesDir, OutputAssemblyName);
            }

            // Add all the language free providers (if any) to the AssemblyBuilder
            if (_assemblyBuilder != null && languageFreeBuildProviders != null)
            {
                foreach (BuildProvider languageFreeBuildProvider in languageFreeBuildProviders)
                {
                    _assemblyBuilder.AddBuildProvider(languageFreeBuildProvider);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyCSharpRazorBuildProvider"/> class.
        /// </summary>
        public NancyVisualBasicRazorBuildProvider()
        {
            this.compilerType = this.GetDefaultCompilerTypeForLanguage("VB");

            this.host = new NancyRazorEngineHost(new VBRazorCodeLanguage());
        }
示例#22
0
        private bool CompileNonDependentBuildProviders(ICollection buildProviders)
        {
            // Key: CompilerType, Value: AssemblyBuilder
            IDictionary assemblyBuilders = new Hashtable();

            // List of InternalBuildProvider's that don't ask for a specific language
            ArrayList languageFreeBuildProviders = null;

            // AssemblyBuilder used for providers that don't need a specific language
            AssemblyBuilder defaultAssemblyBuilder = null;

            bool hasParserErrors = false;

            foreach (BuildProvider buildProvider in buildProviders)
            {
                if (IsBuildProviderSkipable(buildProvider))
                {
                    continue;
                }

                // Instruct the internal build providers to continue processing for more parse errors.
                if (!BuildManager.ThrowOnFirstParseError)
                {
                    InternalBuildProvider provider = buildProvider as InternalBuildProvider;
                    if (provider != null)
                    {
                        provider.ThrowOnFirstParseError = false;
                    }
                }

                CompilerType compilerType = null;

                // Get the language
                try {
                    compilerType = BuildProvider.GetCompilerTypeFromBuildProvider(
                        buildProvider);
                }
                catch (HttpParseException ex) {
                    // Ignore the error if we are in that mode.
                    if (_ignoreProvidersWithErrors)
                    {
                        continue;
                    }

                    hasParserErrors = true;

                    // Remember the first parse exception
                    if (_firstException == null)
                    {
                        _firstException = ex;
                    }

                    if (_parserErrors == null)
                    {
                        _parserErrors = new ParserErrorCollection();
                    }

                    _parserErrors.AddRange(ex.ParserErrors);

                    continue;
                }
                catch {
                    // Ignore the error if we are in that mode.
                    if (_ignoreProvidersWithErrors)
                    {
                        continue;
                    }

                    throw;
                }

                AssemblyBuilder assemblyBuilder = defaultAssemblyBuilder;
                ICollection     typeNames       = buildProvider.GetGeneratedTypeNames();

                // Is it asking for a specific language?
                if (compilerType == null)
                {
                    // If this provider doesn't need a specific language, and we haven't yet created
                    // a default builder that is capable of building this, just keep track of it
                    if (defaultAssemblyBuilder == null || defaultAssemblyBuilder.IsBatchFull ||
                        defaultAssemblyBuilder.ContainsTypeNames(typeNames))
                    {
                        if (languageFreeBuildProviders == null)
                        {
                            languageFreeBuildProviders = new ArrayList();
                        }

                        languageFreeBuildProviders.Add(buildProvider);
                        continue;
                    }
                }
                else
                {
                    // Check if we already have an assembly builder of the right type
                    assemblyBuilder = (AssemblyBuilder)assemblyBuilders[compilerType];
                }

                // Starts a new assemblyBuilder if the old one already contains another buildprovider
                // that uses the same type name
                if (assemblyBuilder == null || assemblyBuilder.IsBatchFull ||
                    assemblyBuilder.ContainsTypeNames(typeNames))
                {
                    // If the assemblyBuilder is full, compile it.
                    if (assemblyBuilder != null)
                    {
                        CompileAssemblyBuilder(assemblyBuilder);
                    }

                    AssemblyBuilder newBuilder = compilerType.CreateAssemblyBuilder(
                        _compConfig, _referencedAssemblies);

                    assemblyBuilders[compilerType] = newBuilder;

                    // Remember it as the default if we don't already have one,
                    // or if the default is already full, switch the default to the new one.
                    if (defaultAssemblyBuilder == null ||
                        defaultAssemblyBuilder == assemblyBuilder)
                    {
                        defaultAssemblyBuilder = newBuilder;
                    }

                    assemblyBuilder = newBuilder;
                }

                assemblyBuilder.AddTypeNames(typeNames);
                assemblyBuilder.AddBuildProvider(buildProvider);
            }

            // Don't try to compile providers, otherwise compile exceptions will be bubbled up,
            // and we lose the parse errors.
            if (hasParserErrors)
            {
                return(false);
            }

            // Handle all the left over language free providers
            if (languageFreeBuildProviders != null)
            {
                // Indicates whether the default assembly builder is not a language specific builder.
                bool newDefaultAssemblyBuilder = (defaultAssemblyBuilder == null);

                // Add language independent providers to the default assembly builder.
                foreach (BuildProvider languageFreeBuildProvider in languageFreeBuildProviders)
                {
                    ICollection typeNames = languageFreeBuildProvider.GetGeneratedTypeNames();

                    // If we don't have a default language assembly builder, get one or
                    // starts a new assemblyBuilder if the old one already contains another buildprovider
                    // that uses the same type name
                    if (defaultAssemblyBuilder == null || defaultAssemblyBuilder.IsBatchFull ||
                        defaultAssemblyBuilder.ContainsTypeNames(typeNames))
                    {
                        // If the default assemblyBuilder is full, compile it.
                        if (defaultAssemblyBuilder != null)
                        {
                            CompileAssemblyBuilder(defaultAssemblyBuilder);
                        }

                        defaultAssemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(
                            _compConfig, _referencedAssemblies, _vdir.VirtualPathObject /*configPath*/,
                            null /*outputAssemblyName*/);

                        // the default assembly builder needs to be compiled separately.
                        newDefaultAssemblyBuilder = true;
                    }

                    defaultAssemblyBuilder.AddTypeNames(typeNames);
                    defaultAssemblyBuilder.AddBuildProvider(languageFreeBuildProvider);
                }

                // Only compile the default assembly builder if it's not part of language specific
                // assembly builder (which will be compiled separately)
                if (newDefaultAssemblyBuilder)
                {
                    // Compile the default assembly builder.
                    CompileAssemblyBuilder(defaultAssemblyBuilder);
                }
            }

            CompileAssemblyBuilderParallel(assemblyBuilders.Values);

            return(true);
        }
        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);
                }
            }
        }
        private bool CompileNonDependentBuildProviders(ICollection buildProviders)
        {
            IDictionary     dictionary = new Hashtable();
            ArrayList       list       = null;
            AssemblyBuilder builder    = null;
            bool            flag       = false;

            foreach (System.Web.Compilation.BuildProvider provider in buildProviders)
            {
                ICollection is2;
                if (this.IsBuildProviderSkipable(provider))
                {
                    continue;
                }
                if (!BuildManager.ThrowOnFirstParseError)
                {
                    InternalBuildProvider provider2 = provider as InternalBuildProvider;
                    if (provider2 != null)
                    {
                        provider2.ThrowOnFirstParseError = false;
                    }
                }
                CompilerType compilerTypeFromBuildProvider = null;
                try
                {
                    compilerTypeFromBuildProvider = System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(provider);
                }
                catch (HttpParseException exception)
                {
                    if (!this._ignoreProvidersWithErrors)
                    {
                        flag = true;
                        if (this._firstException == null)
                        {
                            this._firstException = exception;
                        }
                        if (this._parserErrors == null)
                        {
                            this._parserErrors = new ParserErrorCollection();
                        }
                        this._parserErrors.AddRange(exception.ParserErrors);
                    }
                    continue;
                }
                catch
                {
                    if (!this._ignoreProvidersWithErrors)
                    {
                        throw;
                    }
                    continue;
                }
                AssemblyBuilder builder2 = builder;
                if (compilerTypeFromBuildProvider == null)
                {
                    if (builder != null)
                    {
                        goto Label_00E6;
                    }
                    if (list == null)
                    {
                        list = new ArrayList();
                    }
                    list.Add(provider);
                    continue;
                }
                builder2 = (AssemblyBuilder)dictionary[compilerTypeFromBuildProvider];
Label_00E6:
                is2 = provider.GetGeneratedTypeNames();
                if (((builder2 == null) || builder2.IsBatchFull) || builder2.ContainsTypeNames(is2))
                {
                    if (builder2 != null)
                    {
                        this.CompileAssemblyBuilder(builder2);
                    }
                    AssemblyBuilder builder3 = compilerTypeFromBuildProvider.CreateAssemblyBuilder(this._compConfig, this._referencedAssemblies);
                    dictionary[compilerTypeFromBuildProvider] = builder3;
                    if ((builder == null) || (builder == builder2))
                    {
                        builder = builder3;
                    }
                    builder2 = builder3;
                }
                builder2.AddTypeNames(is2);
                builder2.AddBuildProvider(provider);
            }
            if (flag)
            {
                return(false);
            }
            if (list != null)
            {
                bool flag2 = builder == null;
                foreach (System.Web.Compilation.BuildProvider provider3 in list)
                {
                    ICollection generatedTypeNames = provider3.GetGeneratedTypeNames();
                    if (((builder == null) || builder.IsBatchFull) || builder.ContainsTypeNames(generatedTypeNames))
                    {
                        if (builder != null)
                        {
                            this.CompileAssemblyBuilder(builder);
                        }
                        builder = CompilerType.GetDefaultAssemblyBuilder(this._compConfig, this._referencedAssemblies, this._vdir.VirtualPathObject, null);
                        flag2   = true;
                    }
                    builder.AddTypeNames(generatedTypeNames);
                    builder.AddBuildProvider(provider3);
                }
                if (flag2)
                {
                    this.CompileAssemblyBuilder(builder);
                }
            }
            foreach (AssemblyBuilder builder4 in dictionary.Values)
            {
                this.CompileAssemblyBuilder(builder4);
            }
            return(true);
        }
示例#25
0
 internal CbmCodeGeneratorBuildProviderHost(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string generatedFilesDir, string outputAssemblyName) : base(compConfig, referencedAssemblies, compilerType, outputAssemblyName)
 {
     if (Directory.Exists(generatedFilesDir))
     {
         foreach (FileData data in (IEnumerable)FileEnumerator.Create(generatedFilesDir))
         {
             if (!data.IsDirectory)
             {
                 File.Delete(data.FullName);
             }
         }
     }
     Directory.CreateDirectory(generatedFilesDir);
     this._generatedFilesDir = generatedFilesDir;
 }
 internal virtual void ProcessDirective(string directiveName, IDictionary directive)
 {
     if (directiveName.Length == 0)
     {
         directiveName = this.DefaultDirectiveName;
     }
     if (this.IsMainDirective(directiveName))
     {
         if (this._fFoundMainDirective && !this.IgnoreParseErrors)
         {
             throw new HttpException(System.Web.SR.GetString("Only_one_directive_allowed", new object[] { this.DefaultDirectiveName }));
         }
         this._fFoundMainDirective = true;
         directive.Remove("description");
         directive.Remove("codebehind");
         string andRemoveNonEmptyAttribute = Util.GetAndRemoveNonEmptyAttribute(directive, "language");
         if (andRemoveNonEmptyAttribute != null)
         {
             this._compilerType = this._buildProvider.GetDefaultCompilerTypeForLanguageInternal(andRemoveNonEmptyAttribute);
         }
         else
         {
             this._compilerType = this._buildProvider.GetDefaultCompilerTypeInternal();
         }
         this._typeName = Util.GetAndRemoveRequiredAttribute(directive, "class");
         if (this._compilerType.CompilerParameters != null)
         {
             ProcessCompilationParams(directive, this._compilerType.CompilerParameters);
         }
     }
     else if (StringUtil.EqualsIgnoreCase(directiveName, "assembly"))
     {
         string      assemblyName = Util.GetAndRemoveNonEmptyAttribute(directive, "name");
         VirtualPath andRemoveVirtualPathAttribute = Util.GetAndRemoveVirtualPathAttribute(directive, "src");
         if (((assemblyName != null) && (andRemoveVirtualPathAttribute != null)) && !this.IgnoreParseErrors)
         {
             throw new HttpException(System.Web.SR.GetString("Attributes_mutually_exclusive", new object[] { "Name", "Src" }));
         }
         if (assemblyName == null)
         {
             if (andRemoveVirtualPathAttribute == null)
             {
                 if (!this.IgnoreParseErrors)
                 {
                     throw new HttpException(System.Web.SR.GetString("Missing_attr", new object[] { "name" }));
                 }
             }
             else
             {
                 this.ImportSourceFile(andRemoveVirtualPathAttribute);
             }
         }
         else
         {
             this.AddAssemblyDependency(assemblyName);
         }
     }
     else if (!this.IgnoreParseErrors)
     {
         throw new HttpException(System.Web.SR.GetString("Unknown_directive", new object[] { directiveName }));
     }
     Util.CheckUnknownDirectiveAttributes(directiveName, directive);
 }
示例#27
0
        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);
        }
示例#28
0
    /*
     * Do what needs to be done before returning after the parsing is complete
     */
    internal virtual void HandlePostParse() {

        // If there was no main directive in the page, process settings that may have come from config
        if (!flags[mainDirectiveHandled]) {
            ProcessMainDirective(_mainDirectiveConfigSettings);
            flags[mainDirectiveHandled] = true;
        }

        // We need to check the PageParserFilter here to handle the case where the base was specified
        // in web.config, and was *not* overridden with an 'inherits' attribute.
        if (_pageParserFilter != null) {
            if (!_pageParserFilter.AllowBaseType(BaseType)) {
                throw new HttpException(
                    SR.GetString(SR.Base_type_not_allowed, BaseType.FullName));
            }
        }

        // If there is more than one builder on the stack, some tag was
        // not correctly closed, which is an error.
        if (BuilderStack.Count > 1) {
            BuilderStackEntry entry = (BuilderStackEntry) _builderStack.Peek();

            string message = SR.GetString(SR.Unexpected_eof_looking_for_tag, entry._tagName);
            ProcessException(new HttpParseException(message, null, entry.VirtualPath, entry._inputText, entry.Line));

            return;
        }

        // If no language was specified in the page
        if (_compilerType == null) {

            if (!FInDesigner) {
                // Get a default from config
                _compilerType = CompilationUtil.GetDefaultLanguageCompilerInfo(
                    _compConfig, CurrentVirtualPath);
            }
            else {
                // Get default from code
                _compilerType = CompilationUtil.GetCodeDefaultLanguageCompilerInfo();
            }
        }

        CompilerParameters compilParams = _compilerType.CompilerParameters;

        // Override certain settings if they were specified on the page
        if (flags[hasDebugAttribute])
            compilParams.IncludeDebugInformation = flags[debug];

        // Debugging requires medium trust level
        if (compilParams.IncludeDebugInformation)
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, SR.Debugging_not_supported_in_low_trust);

        // If warningLevel was specified in the page, use it
        if (_warningLevel >= 0) {
            compilParams.WarningLevel = _warningLevel;
            compilParams.TreatWarningsAsErrors = (_warningLevel>0);
        }
        if (_compilerOptions != null)
            compilParams.CompilerOptions = _compilerOptions;

        // Tell the filter (if any) that the parsing is complete
        if (_pageParserFilter != null)
            _pageParserFilter.ParseComplete(RootBuilder);

        // Tell the ParseRecorders that parsing is complete
        ParseRecorders.ParseComplete(RootBuilder);
    }
        private void ProcessDirective(string directiveName, IDictionary<string, string> attribs, int lineNumber)
        {
            this.lineNumber = lineNumber;

            if (DefaultDirectiveName.Equals(directiveName, StringComparison.OrdinalIgnoreCase))
            {
                if (this.foundDirective)
                {
                    throw new HttpParseException(String.Format(ErrorMultipleDirectives, DefaultDirectiveName), null, base.VirtualPath, this.sourceText, this.lineNumber);
                }
                this.foundDirective = true;

                // determine source language
                string language = attribs.ContainsKey("Language") ? attribs["Language"] : null;
                if (String.IsNullOrEmpty(language))
                {
                    // default to C# because it does not need additional assemblies
                    language = "C#";
                }

                this.compilerType = this.GetDefaultCompilerTypeForLanguage(language);

                // determine backing class
                this.serviceTypeName = attribs.ContainsKey("Class") ? attribs["Class"] : null;
            }
            else if ("Assembly".Equals(directiveName, StringComparison.OrdinalIgnoreCase))
            {
                string name = attribs.ContainsKey("Name") ? attribs["Name"] : null;
                if (String.IsNullOrEmpty(name))
                {
                    throw new HttpParseException(String.Format(ErrorMissingAttrib, "Name"), null, base.VirtualPath, this.sourceText, this.lineNumber);
                }
                this.AddAssemblyDependency(name);
            }
            else
            {
                throw new HttpParseException(String.Format(ErrorUnkownDirective, directiveName), null, base.VirtualPath, this.sourceText, this.lineNumber);
            }
        }
        public CSharpExtensionBuildProviderShim() {
            OrchardHostContainerRegistry.RegisterShim(this);

            _codeCompilerType = GetDefaultCompilerTypeForLanguage("C#");
        }
 internal virtual void ProcessDirective(string directiveName, IDictionary directive)
 {
     if (directiveName.Length == 0)
     {
         directiveName = this.DefaultDirectiveName;
     }
     if (this.IsMainDirective(directiveName))
     {
         if (this._fFoundMainDirective && !this.IgnoreParseErrors)
         {
             throw new HttpException(System.Web.SR.GetString("Only_one_directive_allowed", new object[] { this.DefaultDirectiveName }));
         }
         this._fFoundMainDirective = true;
         directive.Remove("description");
         directive.Remove("codebehind");
         string andRemoveNonEmptyAttribute = Util.GetAndRemoveNonEmptyAttribute(directive, "language");
         if (andRemoveNonEmptyAttribute != null)
         {
             this._compilerType = this._buildProvider.GetDefaultCompilerTypeForLanguageInternal(andRemoveNonEmptyAttribute);
         }
         else
         {
             this._compilerType = this._buildProvider.GetDefaultCompilerTypeInternal();
         }
         this._typeName = Util.GetAndRemoveRequiredAttribute(directive, "class");
         if (this._compilerType.CompilerParameters != null)
         {
             ProcessCompilationParams(directive, this._compilerType.CompilerParameters);
         }
     }
     else if (StringUtil.EqualsIgnoreCase(directiveName, "assembly"))
     {
         string assemblyName = Util.GetAndRemoveNonEmptyAttribute(directive, "name");
         VirtualPath andRemoveVirtualPathAttribute = Util.GetAndRemoveVirtualPathAttribute(directive, "src");
         if (((assemblyName != null) && (andRemoveVirtualPathAttribute != null)) && !this.IgnoreParseErrors)
         {
             throw new HttpException(System.Web.SR.GetString("Attributes_mutually_exclusive", new object[] { "Name", "Src" }));
         }
         if (assemblyName == null)
         {
             if (andRemoveVirtualPathAttribute == null)
             {
                 if (!this.IgnoreParseErrors)
                 {
                     throw new HttpException(System.Web.SR.GetString("Missing_attr", new object[] { "name" }));
                 }
             }
             else
             {
                 this.ImportSourceFile(andRemoveVirtualPathAttribute);
             }
         }
         else
         {
             this.AddAssemblyDependency(assemblyName);
         }
     }
     else if (!this.IgnoreParseErrors)
     {
         throw new HttpException(System.Web.SR.GetString("Unknown_directive", new object[] { directiveName }));
     }
     Util.CheckUnknownDirectiveAttributes(directiveName, directive);
 }
 private void ProcessDirective(string directiveName, IDictionary directive)
 {
     if (directiveName.Length == 0)
     {
         throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderDirectiveNameMissing));
     }
     if (string.Compare(directiveName, "ServiceHost", StringComparison.OrdinalIgnoreCase) == 0)
     {
         if (this.foundMainDirective)
         {
             throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderDuplicateDirective("ServiceHost")));
         }
         this.foundMainDirective = true;
         directive.Remove("codebehind");
         string andRemoveNonEmptyAttribute = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "language");
         if (andRemoveNonEmptyAttribute != null)
         {
             this.compilerType = this.buildProvider.GetDefaultCompilerTypeForLanguageInternal(andRemoveNonEmptyAttribute);
         }
         else
         {
             this.compilerType = this.buildProvider.GetDefaultCompilerTypeInternal();
         }
         if (directive.Contains("Factory"))
         {
             this.factoryAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "Factory");
             this.serviceAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "Service");
         }
         else
         {
             if (!directive.Contains("Service"))
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderMainAttributeMissing));
             }
             this.serviceAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "Service");
         }
         this.ProcessCompilationParams(directive, this.compilerType.CompilerParameters);
     }
     else
     {
         if (string.Compare(directiveName, "assembly", StringComparison.OrdinalIgnoreCase) != 0)
         {
             throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderUnknownDirective(directiveName)));
         }
         if (directive.Contains("name") && directive.Contains("src"))
         {
             throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderMutualExclusiveAttributes("src", "name")));
         }
         if (directive.Contains("name"))
         {
             string assemblyName = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "name");
             if (assemblyName == null)
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderAttributeEmpty("name")));
             }
             this.AddAssemblyDependency(assemblyName);
         }
         else
         {
             if (!directive.Contains("src"))
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderRequiredAttributesMissing("src", "name")));
             }
             string path = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "src");
             if (path == null)
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderAttributeEmpty("src")));
             }
             this.ImportSourceFile(path);
         }
     }
     if (directive.Count > 0)
     {
         throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderUnknownAttribute(ServiceParserUtilities.FirstDictionaryKey(directive))));
     }
 }
 internal CompilerType GetCompilerInfoFromLanguage(string language)
 {
     CompilerType compilerTypeInternal;
     this.EnsureCompilerCacheInit();
     object obj2 = this._compilerLanguages[language];
     Compiler compiler = obj2 as Compiler;
     if (compiler != null)
     {
         compilerTypeInternal = compiler.CompilerTypeInternal;
         this._compilerLanguages[language] = compilerTypeInternal;
     }
     else
     {
         compilerTypeInternal = obj2 as CompilerType;
     }
     if ((compilerTypeInternal == null) && CodeDomProvider.IsDefinedLanguage(language))
     {
         CompilerInfo compilerInfo = CodeDomProvider.GetCompilerInfo(language);
         compilerTypeInternal = new CompilerType(compilerInfo.CodeDomProviderType, compilerInfo.CreateDefaultCompilerParameters());
         this._compilerLanguages[language] = compilerTypeInternal;
     }
     if (compilerTypeInternal == null)
     {
         throw new HttpException(System.Web.SR.GetString("Invalid_lang", new object[] { language }));
     }
     CompilationUtil.CheckCompilerOptionsAllowed(compilerTypeInternal.CompilerParameters.CompilerOptions, true, null, 0);
     compilerTypeInternal = compilerTypeInternal.Clone();
     compilerTypeInternal.CompilerParameters.IncludeDebugInformation = this.Debug;
     return compilerTypeInternal;
 }
示例#34
0
		static CodeDomProvider CreateDomProvider (CompilerType ct)
		{
			if (codeDomProviders == null)
				codeDomProviders = new Dictionary <Type, CodeDomProvider> ();

			Type type = ct.CodeDomProviderType;
			if (type == null) {
				CompilationSection cs = CompilationConfig;
				CompilerType tmp = GetDefaultCompilerTypeForLanguage (cs.DefaultLanguage, cs);
				if (tmp != null)
					type = tmp.CodeDomProviderType;
			}

			if (type == null)
				return null;
			
			CodeDomProvider ret;
			if (codeDomProviders.TryGetValue (type, out ret))
				return ret;

			ret = Activator.CreateInstance (type) as CodeDomProvider;
			if (ret == null)
				return null;

			codeDomProviders.Add (type, ret);
			return ret;
		}		
    internal CbmCodeGeneratorBuildProviderHost(CompilationSection compConfig,
        ICollection referencedAssemblies, CompilerType compilerType,
        string generatedFilesDir, string outputAssemblyName)
        : base(compConfig, referencedAssemblies, compilerType, outputAssemblyName) {

        // Wipe out any existing directory, and recreate it
        // This is where we will put generated source files
        if (Directory.Exists(generatedFilesDir)) {

            // Delete all the files in the directory
            foreach (FileData fileData in FileEnumerator.Create(generatedFilesDir)) {

                // It should only contain files
                Debug.Assert(!fileData.IsDirectory);
                if (fileData.IsDirectory) continue;

                Debug.Trace("CbmCodeGeneratorBuildProviderHost", "Deleting " + fileData.FullName);
                File.Delete(fileData.FullName);
            }
            
        }

        // Create it to make sure it exists
        Directory.CreateDirectory(generatedFilesDir);

        _generatedFilesDir = generatedFilesDir;
    }
示例#36
0
        public void Compile()
        {
            string refsPath = Path.Combine(HttpRuntime.AppDomainAppPath, ResourcesDirName);

            if (!Directory.Exists(refsPath))
            {
                return;
            }

            string[] files = Directory.GetFiles(refsPath, "*.wsdl", SearchOption.AllDirectories);
            if (files == null || files.Length == 0)
            {
                return;
            }

            CompilationSection cs = WebConfigurationManager.GetWebApplicationSection("system.web/compilation") as CompilationSection;

            if (cs == null)
            {
                throw new HttpException("Unable to determine default compilation language.");
            }

            CompilerType    ct = BuildManager.GetDefaultCompilerTypeForLanguage(cs.DefaultLanguage, cs);
            CodeDomProvider codeDomProvider  = null;
            Exception       codeDomException = null;

            try {
                codeDomProvider = Activator.CreateInstance(ct.CodeDomProviderType) as CodeDomProvider;
            } catch (Exception e) {
                codeDomException = e;
            }

            if (codeDomProvider == null)
            {
                throw new HttpException("Unable to instantiate default compilation language provider.", codeDomException);
            }

            AssemblyBuilder ab = new AssemblyBuilder(codeDomProvider, "App_WebReferences_");

            ab.CompilerOptions = ct.CompilerParameters;

            VirtualPath       vp;
            WsdlBuildProvider wbp;

            foreach (string file in files)
            {
                vp = VirtualPath.PhysicalToVirtual(file);
                if (vp == null)
                {
                    continue;
                }

                wbp = new WsdlBuildProvider();
                wbp.SetVirtualPath(vp);
                wbp.GenerateCode(ab);
            }

            CompilerResults results;

            try {
                results = ab.BuildAssembly();
            } catch (CompilationException ex) {
                throw new HttpException("Failed to compile web references.", ex);
            }

            if (results == null)
            {
                return;
            }

            Assembly asm = results.CompiledAssembly;

            BuildManager.TopLevelAssemblies.Add(asm);
        }
    internal AssemblyBuilder(CompilationSection compConfig,
        ICollection referencedAssemblies, CompilerType compilerType, string outputAssemblyName) {

        _compConfig = compConfig;

        _outputAssemblyName = outputAssemblyName;

        // Clone the referenced assemblies
        _initialReferencedAssemblies = AssemblySet.Create(referencedAssemblies);

        // We need to clone it to avoid modifying the original (VSWhidbey 338935)
        _compilerType = compilerType.Clone();

        if (BuildManager.PrecompilingWithDebugInfo) {
            // If the precompile flag indicates force debug, always compile as debug
            _compilerType.CompilerParameters.IncludeDebugInformation = true;
        }
        else if (BuildManager.PrecompilingForDeployment) {
            // If we're precompiling the app, never compile in debug mode (VSWhidbey 178377)
            _compilerType.CompilerParameters.IncludeDebugInformation = false;
        }
        else if (DeploymentSection.RetailInternal) {
            // If we're in retail deployment mode, always turn off debug (DevDiv 36396)
            _compilerType.CompilerParameters.IncludeDebugInformation = false;
        }
        else if (_compConfig.AssemblyPostProcessorTypeInternal != null) {
            // If an IAssemblyPostProcessor is registered always compile as debug
            _compilerType.CompilerParameters.IncludeDebugInformation = true;
        }

        // 
        _tempFiles.KeepFiles = _compilerType.CompilerParameters.IncludeDebugInformation;

        _codeProvider = CompilationUtil.CreateCodeDomProviderNonPublic(
            _compilerType.CodeDomProviderType);

        _maxBatchSize = _compConfig.MaxBatchSize;
        _maxBatchGeneratedFileSize = _compConfig.MaxBatchGeneratedFileSize * 1024;
    }
 private static void SetIncludeDebugInfoFlag(CompilerType compilerType)
 {
     compilerType.CompilerParameters.IncludeDebugInformation = true;
 }
    /*
     * Process a <%@ %> block
     */
    internal virtual void ProcessDirective(string directiveName, IDictionary directive) {

        // Empty means default
        if (directiveName.Length == 0)
            directiveName = DefaultDirectiveName;

        // Check for the main directive
        if (IsMainDirective(directiveName)) {

            // Make sure the main directive was not already specified
            if (_fFoundMainDirective && !IgnoreParseErrors) {
                throw new HttpException(
                    SR.GetString(SR.Only_one_directive_allowed, DefaultDirectiveName));
            }

            _fFoundMainDirective = true;

            // Since description is a no op, just remove it if it's there
            directive.Remove("description");

            // Similarily, ignore 'codebehind' attribute (ASURT 4591)
            directive.Remove("codebehind");

            string language = Util.GetAndRemoveNonEmptyAttribute(directive, "language");

            // Get the compiler for the specified language (if any)
            if (language != null) {
                _compilerType = _buildProvider.GetDefaultCompilerTypeForLanguageInternal(language);
            }
            else {
                // Get a default from config
                _compilerType = _buildProvider.GetDefaultCompilerTypeInternal();
            }

            _typeName = Util.GetAndRemoveRequiredAttribute(directive, "class");

            if (_compilerType.CompilerParameters != null)
                ProcessCompilationParams(directive, _compilerType.CompilerParameters);
        }
        else if (StringUtil.EqualsIgnoreCase(directiveName, "assembly")) {
            // Assembly directive

            // Remove the attributes as we get them from the dictionary
            string assemblyName = Util.GetAndRemoveNonEmptyAttribute(directive, "name");
            VirtualPath src = Util.GetAndRemoveVirtualPathAttribute(directive, "src");

            if (assemblyName != null && src != null && !IgnoreParseErrors) {
                throw new HttpException(
                    SR.GetString(SR.Attributes_mutually_exclusive, "Name", "Src"));
            }

            if (assemblyName != null) {
                AddAssemblyDependency(assemblyName);
            }
            // Is it a source file that needs to be compiled on the fly
            else if (src != null) {
                ImportSourceFile(src);
            }
            else if (!IgnoreParseErrors) {
                throw new HttpException(SR.GetString(SR.Missing_attr, "name"));
            }
        }
        else if (!IgnoreParseErrors) {
            throw new HttpException(
                SR.GetString(SR.Unknown_directive, directiveName));
        }

        // If there are some attributes left, fail
        Util.CheckUnknownDirectiveAttributes(directiveName, directive);
    }
        /// <summary>
        /// Processes a directive block
        /// </summary>
        void ProcessDirective(string directiveName, IDictionary directive)
        {
            // Throw on empy, no directive specified
            //
            if (directiveName.Length == 0)
            {
                throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderDirectiveNameMissing));
            }

            // Check for the main directive
            //
            if (string.Compare(directiveName, ServiceParser.DefaultDirectiveName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Make sure the main directive was not already specified
                //
                if (foundMainDirective)
                {
                    throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderDuplicateDirective(ServiceParser.DefaultDirectiveName)));
                }

                foundMainDirective = true;

                // Ignore 'codebehind' attribute (ASURT 4591)
                //
                directive.Remove("codebehind");

                string language = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "language");

                // Get the compiler for the specified language (if any)
                // or get the one from config
                //
                if (language != null)
                {
                    compilerType = buildProvider.GetDefaultCompilerTypeForLanguageInternal(language);
                }
                else
                {
                    compilerType = buildProvider.GetDefaultCompilerTypeInternal();
                }


                if (directive.Contains(FactoryAttributeName))
                {
                    factoryAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, FactoryAttributeName);
                    serviceAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, ServiceAttributeName);
                }
                else if (directive.Contains(ServiceAttributeName))
                {
                    serviceAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, ServiceAttributeName);
                }
                else
                {
                    throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderMainAttributeMissing));
                }
                // parse the parameters that are related to the compiler
                //
                ProcessCompilationParams(directive, compilerType.CompilerParameters);
            }
            else if (string.Compare(directiveName, "assembly", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (directive.Contains("name") && directive.Contains("src"))
                {
                    throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderMutualExclusiveAttributes("src", "name")));
                }
                else if (directive.Contains("name"))
                {
                    string assemblyName = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "name");
                    if (assemblyName != null)
                    {
                        AddAssemblyDependency(assemblyName);
                    }
                    else
                        throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderAttributeEmpty("name")));
                }
                else if (directive.Contains("src"))
                {
                    string srcPath = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "src");
                    if (srcPath != null)
                    {
                        ImportSourceFile(srcPath);
                    }
                    else
                        throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderAttributeEmpty("src")));
                }
                else
                { // if (!directive.Contains("name") && !directive.Contains("src"))
                    throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderRequiredAttributesMissing("src", "name")));
                }
            }
            else
            {
                throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderUnknownDirective(directiveName)));
            }

            // check if there are any directives that you did not process 
            //
            if (directive.Count > 0)
                throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderUnknownAttribute(ServiceParserUtilities.FirstDictionaryKey(directive))));
        }
示例#41
0
 private void ProcessDirective(string directiveName, IDictionary directive)
 {
     if (directiveName.Length == 0)
     {
         throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderDirectiveNameMissing));
     }
     if (string.Compare(directiveName, "ServiceHost", StringComparison.OrdinalIgnoreCase) == 0)
     {
         if (this.foundMainDirective)
         {
             throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderDuplicateDirective("ServiceHost")));
         }
         this.foundMainDirective = true;
         directive.Remove("codebehind");
         string andRemoveNonEmptyAttribute = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "language");
         if (andRemoveNonEmptyAttribute != null)
         {
             this.compilerType = this.buildProvider.GetDefaultCompilerTypeForLanguageInternal(andRemoveNonEmptyAttribute);
         }
         else
         {
             this.compilerType = this.buildProvider.GetDefaultCompilerTypeInternal();
         }
         if (directive.Contains("Factory"))
         {
             this.factoryAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "Factory");
             this.serviceAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "Service");
         }
         else
         {
             if (!directive.Contains("Service"))
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderMainAttributeMissing));
             }
             this.serviceAttributeValue = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "Service");
         }
         this.ProcessCompilationParams(directive, this.compilerType.CompilerParameters);
     }
     else
     {
         if (string.Compare(directiveName, "assembly", StringComparison.OrdinalIgnoreCase) != 0)
         {
             throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderUnknownDirective(directiveName)));
         }
         if (directive.Contains("name") && directive.Contains("src"))
         {
             throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderMutualExclusiveAttributes("src", "name")));
         }
         if (directive.Contains("name"))
         {
             string assemblyName = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "name");
             if (assemblyName == null)
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderAttributeEmpty("name")));
             }
             this.AddAssemblyDependency(assemblyName);
         }
         else
         {
             if (!directive.Contains("src"))
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderRequiredAttributesMissing("src", "name")));
             }
             string path = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "src");
             if (path == null)
             {
                 throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderAttributeEmpty("src")));
             }
             this.ImportSourceFile(path);
         }
     }
     if (directive.Count > 0)
     {
         throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderUnknownAttribute(ServiceParserUtilities.FirstDictionaryKey(directive))));
     }
 }
示例#42
0
    /*
     * Process a language attribute, as can appear in the Page directive and in
     * <script runat=server> tags.
     */
    private void ProcessLanguageAttribute(string language) {
        if (language == null)
            return;

        // We don't have CompilationConfig at design-time and the language attribute isn't used either.
        if (FInDesigner)
            return;

        CompilerType compilerType = CompilationUtil.GetCompilerInfoFromLanguage(
            CurrentVirtualPath, language);

        // Make sure we don't get conflicting languages
        if (_compilerType != null &&
            _compilerType.CodeDomProviderType != compilerType.CodeDomProviderType) {
            ProcessError(SR.GetString(SR.Mixed_lang_not_supported, language));

            return;
        }

        _compilerType = compilerType;
    }
	    public FakeBuildProvider(Type type)
	    {
			_type = type;
	        _compilerType = GetDefaultCompilerTypeForLanguage("C#");
	    }
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyCSharpRazorBuildProvider"/> class.
        /// </summary>
        public NancyCSharpRazorBuildProvider()
        {
            this.compilerType = this.GetDefaultCompilerTypeForLanguage("C#");

            this.host = new NancyRazorEngineHost(new CSharpRazorCodeLanguage());
        }
 internal CompilerType GetCompilerInfoFromExtension(string extension, bool throwOnFail)
 {
     CompilerType compilerTypeInternal;
     this.EnsureCompilerCacheInit();
     object obj2 = this._compilerExtensions[extension];
     Compiler compiler = obj2 as Compiler;
     if (compiler != null)
     {
         compilerTypeInternal = compiler.CompilerTypeInternal;
         this._compilerExtensions[extension] = compilerTypeInternal;
     }
     else
     {
         compilerTypeInternal = obj2 as CompilerType;
     }
     if ((compilerTypeInternal == null) && CodeDomProvider.IsDefinedExtension(extension))
     {
         CompilerInfo compilerInfo = CodeDomProvider.GetCompilerInfo(CodeDomProvider.GetLanguageFromExtension(extension));
         compilerTypeInternal = new CompilerType(compilerInfo.CodeDomProviderType, compilerInfo.CreateDefaultCompilerParameters());
         this._compilerExtensions[extension] = compilerTypeInternal;
     }
     if (compilerTypeInternal == null)
     {
         if (throwOnFail)
         {
             throw new HttpException(System.Web.SR.GetString("Invalid_lang_extension", new object[] { extension }));
         }
         return null;
     }
     compilerTypeInternal = compilerTypeInternal.Clone();
     compilerTypeInternal.CompilerParameters.IncludeDebugInformation = this.Debug;
     return compilerTypeInternal;
 }