ServiceBuildProvider.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Activation / ServiceBuildProvider.cs / 1 / ServiceBuildProvider.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.ServiceModel.Activation 
{
    using System; 
    using System.CodeDom; 
    using System.CodeDom.Compiler;
    using System.Collections; 
    using System.Diagnostics;
    using System.IO;
    using System.Reflection;
    using System.Web.Compilation; 
    using System.Security;
    using System.Web; 
    using System.Security.Permissions; 
    using System.Threading;
 
    /// 
    /// Critical - entry-point from asp.net, called outside PermitOnly context
    ///            also needs to elevate in order to inherit from BuildProvider and call methods on the base class
    ///  
    [SecurityCritical(SecurityCriticalScope.Everything)]
    [BuildProviderAppliesTo(BuildProviderAppliesTo.Web)] 
    [ServiceActivationBuildProvider] 
    class ServiceBuildProvider : BuildProvider
    { 
        ServiceParser parser;

        public override CompilerType CodeCompilerType
        { 
            get
            { 
                return GetCodeCompilerType(); 
            }
        } 

        CompilerType GetCodeCompilerType()
        {
            EnsureParsed(); 
            return parser.CompilerType;
        } 
 
        protected override CodeCompileUnit GetCodeCompileUnit(out IDictionary linePragmasTable)
        { 
            CodeSnippetCompileUnit ccu = parser.GetCodeModel() as CodeSnippetCompileUnit;
            linePragmasTable = parser.GetLinePragmasTable();
            return ccu;
        } 

        void EnsureParsed() 
        { 
            if (parser == null)
            { 
                parser = new ServiceParser(VirtualPath, this);
                parser.Parse(ReferencedAssemblies);
            }
        } 

        public override BuildProviderResultFlags GetResultFlags(CompilerResults results) 
        { 
            return BuildProviderResultFlags.ShutdownAppDomainOnChange;
        } 

        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            GenerateCodeCore(assemblyBuilder); 
        }
 
        void GenerateCodeCore(AssemblyBuilder assemblyBuilder) 
        {
            if (assemblyBuilder == null) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assemblyBuilder");
            }
 
            CodeCompileUnit codeCompileUnit = parser.GetCodeModel();
 
            // Bail if we have nothing we need to compile 
            //
            if (codeCompileUnit == null) 
                return;

            // Add the code unit and then add all the assemblies
            // 
            assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
            if (parser.AssemblyDependencies != null) 
            { 
                foreach (Assembly assembly in parser.AssemblyDependencies)
                { 
                    assemblyBuilder.AddAssemblyReference(assembly);
                }
            }
        } 

        public override string GetCustomString(CompilerResults results) 
        { 
            return GetCustomStringCore(results);
       } 

        string GetCustomStringCore(CompilerResults results)
        {
            return parser.CreateParseString((results == null) ? null : results.CompiledAssembly); 
        }
 
        public override System.Collections.ICollection VirtualPathDependencies 
        {
            get 
            {
                return parser.SourceDependencies;
            }
        } 

        internal CompilerType GetDefaultCompilerTypeForLanguageInternal(string language) 
        { 
            return GetDefaultCompilerTypeForLanguage(language);
        } 

        internal CompilerType GetDefaultCompilerTypeInternal()
        {
            return GetDefaultCompilerType(); 
        }
 
        internal TextReader OpenReaderInternal() 
        {
            return OpenReader(); 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK