コード例 #1
0
        /// <summary>
        /// Look for a type by name in the assemblies available to this page
        /// </summary>
        Type GetType(string typeName)
        {
            Type type;

            // If it contains an assembly name, just call Type.GetType (ASURT 53589)
            //
            if (ServiceParserUtilities.TypeNameIncludesAssembly(typeName))
            {
                try
                {
                    type = Type.GetType(typeName, true);
                }
                catch (ArgumentException e)
                {
                    Exception parseException = CreateParseException(e, this.sourceString);
                    throw FxTrace.Exception.AsError(
                              new HttpCompileException(parseException.Message, parseException));
                }
                catch (TargetInvocationException e)
                {
                    Exception parseException = CreateParseException(e, this.sourceString);
                    throw FxTrace.Exception.AsError(
                              new HttpCompileException(parseException.Message, parseException));
                }
                catch (TypeLoadException e)
                {
                    Exception parseException = CreateParseException(SR.Hosting_BuildProviderCouldNotCreateType(typeName), e, this.sourceString);
                    throw FxTrace.Exception.AsError(
                              new HttpCompileException(parseException.Message, parseException));
                }

                return(type);
            }

            try
            {
                type = ServiceParserUtilities.GetTypeFromAssemblies(referencedAssemblies, typeName, false /*ignoreCase*/);
                if (type != null)
                {
                    return(type);
                }

                type = ServiceParserUtilities.GetTypeFromAssemblies(AssemblyDependencies, typeName, false /*ignoreCase*/);
                if (type != null)
                {
                    return(type);
                }
            }
            catch (HttpException e)
            {
                Exception parseException = CreateParseException(SR.Hosting_BuildProviderCouldNotCreateType(typeName), e, this.sourceString);
                throw FxTrace.Exception.AsError(
                          new HttpCompileException(parseException.Message, parseException));
            }

            Exception exception = CreateParseException(SR.Hosting_BuildProviderCouldNotCreateType(typeName), this.sourceString);

            throw FxTrace.Exception.AsError(
                      new HttpCompileException(exception.Message, exception));
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
            /// <summary>
            /// Get a string value from a dictionary, and convert it to integer.  Throw an
            /// exception if it's not a valid positive integer string.
            /// However, don't complain about null, which simply means the value is not
            /// in the dictionary.
            /// The value is returned through a REF param (unchanged if null)
            /// </summary>
            /// <returns>True if attrib exists, false otherwise</returns>
            internal static bool GetAndRemoveNonNegativeIntegerAttribute(IDictionary directives, string key, ref int val)
            {
                string s = ServiceParserUtilities.GetAndRemove(directives, key);

                if (s.Length == 0)
                {
                    return(false);
                }

                val = GetNonNegativeIntegerAttribute(key, s);
                return(true);
            }
コード例 #5
0
        private Type GetType(string typeName)
        {
            Type type;

            if (ServiceParserUtilities.TypeNameIncludesAssembly(typeName))
            {
                try
                {
                    type = Type.GetType(typeName, true);
                }
                catch (ArgumentException exception)
                {
                    Exception exception2 = this.CreateParseException(exception, this.sourceString);
                    throw FxTrace.Exception.AsError(new HttpCompileException(exception2.Message, exception2));
                }
                catch (TargetInvocationException exception3)
                {
                    Exception exception4 = this.CreateParseException(exception3, this.sourceString);
                    throw FxTrace.Exception.AsError(new HttpCompileException(exception4.Message, exception4));
                }
                catch (TypeLoadException exception5)
                {
                    Exception exception6 = this.CreateParseException(System.ServiceModel.Activation.SR.Hosting_BuildProviderCouldNotCreateType(typeName), exception5, this.sourceString);
                    throw FxTrace.Exception.AsError(new HttpCompileException(exception6.Message, exception6));
                }
                return(type);
            }
            try
            {
                type = ServiceParserUtilities.GetTypeFromAssemblies(this.referencedAssemblies, typeName, false);
                if (type != null)
                {
                    return(type);
                }
                type = ServiceParserUtilities.GetTypeFromAssemblies(this.AssemblyDependencies, typeName, false);
                if (type != null)
                {
                    return(type);
                }
            }
            catch (HttpException exception7)
            {
                Exception exception8 = this.CreateParseException(System.ServiceModel.Activation.SR.Hosting_BuildProviderCouldNotCreateType(typeName), exception7, this.sourceString);
                throw FxTrace.Exception.AsError(new HttpCompileException(exception8.Message, exception8));
            }
            Exception innerException = this.CreateParseException(System.ServiceModel.Activation.SR.Hosting_BuildProviderCouldNotCreateType(typeName), this.sourceString);

            throw FxTrace.Exception.AsError(new HttpCompileException(innerException.Message, innerException));
        }
コード例 #6
0
            /// <summary>
            /// Get a value from a dictionary, and remove it from the dictionary if
            /// it exists.  Throw an exception if the value is a whitespace string.
            /// However, don't complain about null, which simply means the value is not
            /// in the dictionary.
            /// </summary>
            internal static string GetAndRemoveNonEmptyAttribute(IDictionary directives, string key, bool required)
            {
                string val = ServiceParserUtilities.GetAndRemove(directives, key);

                if (val.Length == 0)
                {
                    if (required)
                    {
                        throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderAttributeMissing(key)));
                    }
                    return(null);
                }

                return(val);
            }
コード例 #7
0
        private void ParseString()
        {
            try
            {
                Match match;
                int   startat = 0;
                this.lineNumber = 1;
                if (this.serviceText.IndexOf('>') == -1)
                {
                    throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderDirectiveEndBracketMissing("ServiceHost")));
                }
Label_0033:
                match = directiveRegex.Match(this.serviceText, startat);
                if (match.Success)
                {
                    this.lineNumber += ServiceParserUtilities.LineCount(this.serviceText, startat, match.Index);
                    startat          = match.Index;
                    IDictionary attribs       = CollectionsUtil.CreateCaseInsensitiveSortedList();
                    string      directiveName = this.ProcessAttributes(match, attribs);
                    this.ProcessDirective(directiveName, attribs);
                    this.lineNumber += ServiceParserUtilities.LineCount(this.serviceText, startat, match.Index + match.Length);
                    startat          = match.Index + match.Length;
                    int num2 = this.serviceText.LastIndexOfAny(newlineChars, startat - 1);
                    this.startColumn = startat - num2;
                    goto Label_0033;
                }
                if (!this.foundMainDirective)
                {
                    throw FxTrace.Exception.AsError(new HttpException(System.ServiceModel.Activation.SR.Hosting_BuildProviderDirectiveMissing("ServiceHost")));
                }
                string s = this.serviceText.Substring(startat);
                if (!ServiceParserUtilities.IsWhiteSpaceString(s))
                {
                    this.sourceString = s;
                }
            }
            catch (HttpException exception)
            {
                Exception innerException = this.CreateParseException(exception, this.serviceText);
                throw FxTrace.Exception.AsError(new HttpCompileException(innerException.Message, innerException));
            }
        }
コード例 #8
0
            /// <summary>
            /// Get a string value from a dictionary, and convert it to bool.  Throw an
            /// exception if it's not a valid bool string.
            /// However, don't complain about null, which simply means the value is not
            /// in the dictionary.
            /// The value is returned through a REF param (unchanged if null)
            /// </summary>
            /// <returns>True if attrib exists, false otherwise</returns>
            internal static bool GetAndRemoveBooleanAttribute(IDictionary directives, string key, ref bool val)
            {
                string s = ServiceParserUtilities.GetAndRemove(directives, key);

                if (s.Length == 0)
                {
                    return(false);
                }

                try
                {
                    val = bool.Parse(s);
                }
                catch (FormatException)
                {
                    throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderInvalidValueForBooleanAttribute(s, key)));
                }

                return(true);
            }
コード例 #9
0
        /// <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))));
            }
        }
コード例 #10
0
        /// <summary>
        /// Parses the content of the svc file for each directive line
        /// </summary>
        void ParseString()
        {
            try
            {
                int   textPos = 0;
                Match match;
                lineNumber = 1;

                // Check for ending bracket first, MB 45013.
                if (this.serviceText.IndexOf('>') == -1)
                {
                    throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderDirectiveEndBracketMissing(ServiceParser.DefaultDirectiveName)));
                }

                // First, parse all the <%@ ... %> directives
                //
                for (;;)
                {
                    match = directiveRegex.Match(this.serviceText, textPos);

                    // Done with the directives?
                    //
                    if (!match.Success)
                    {
                        break;
                    }

                    lineNumber += ServiceParserUtilities.LineCount(this.serviceText, textPos, match.Index);
                    textPos     = match.Index;

                    // Get all the directives into a bag
                    //
                    IDictionary directive     = CollectionsUtil.CreateCaseInsensitiveSortedList();
                    string      directiveName = ProcessAttributes(match, directive);

                    // Understand the directive
                    //
                    ProcessDirective(directiveName, directive);
                    lineNumber += ServiceParserUtilities.LineCount(this.serviceText, textPos, match.Index + match.Length);
                    textPos     = match.Index + match.Length;

                    // Fixup line and column numbers to have meaninglful errors
                    //
                    int newlineIndex = this.serviceText.LastIndexOfAny(newlineChars, textPos - 1);
                    startColumn = textPos - newlineIndex;
                }

                if (!foundMainDirective)
                {
                    throw FxTrace.Exception.AsError(new HttpException(SR.Hosting_BuildProviderDirectiveMissing(ServiceParser.DefaultDirectiveName)));
                }

                // skip the directives chunk
                //
                string remainingText = this.serviceText.Substring(textPos);

                // If there is something else in the file, it needs to be compiled
                //
                if (!ServiceParserUtilities.IsWhiteSpaceString(remainingText))
                {
                    sourceString = remainingText;
                }
            }
            catch (HttpException e)
            {
                // the string is set in the internal exception, no need to set it again.
                //
                Exception parseException = CreateParseException(e, this.serviceText);
                throw FxTrace.Exception.AsError(
                          new HttpCompileException(parseException.Message, parseException));
            }
        }
コード例 #11
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))));
     }
 }