void ProcessCompilationParams(IDictionary directive, CompilerParameters compilParams) { bool debug = false; if (ServiceParserUtilities.GetAndRemoveBooleanAttribute(directive, "debug", ref debug)) { compilParams.IncludeDebugInformation = debug; } int warningLevel = 0; if (ServiceParserUtilities.GetAndRemoveNonNegativeIntegerAttribute(directive, "warninglevel", ref warningLevel)) { compilParams.WarningLevel = warningLevel; if (warningLevel > 0) { compilParams.TreatWarningsAsErrors = true; } } string compilerOptions = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "compileroptions"); if (compilerOptions != null) { compilParams.CompilerOptions = compilerOptions; } }
private void ProcessCompilationParams(IDictionary directive, CompilerParameters compilParams) { bool val = false; if (ServiceParserUtilities.GetAndRemoveBooleanAttribute(directive, "debug", ref val)) { compilParams.IncludeDebugInformation = val; } int num = 0; if (ServiceParserUtilities.GetAndRemoveNonNegativeIntegerAttribute(directive, "warninglevel", ref num)) { compilParams.WarningLevel = num; if (num > 0) { compilParams.TreatWarningsAsErrors = true; } } string andRemoveNonEmptyAttribute = ServiceParserUtilities.GetAndRemoveNonEmptyAttribute(directive, "compileroptions"); if (andRemoveNonEmptyAttribute != null) { compilParams.CompilerOptions = andRemoveNonEmptyAttribute; } }
/// <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)))); } }
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)))); } }