CompilationAssemblyInstallComponent.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 / Tools / xws_reg / System / ServiceModel / Install / Configuration / CompilationAssemblyInstallComponent.cs / 1 / CompilationAssemblyInstallComponent.cs

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

namespace System.ServiceModel.Install.Configuration 
{
    using System; 
    using System.Collections.Generic; 
    using System.Configuration;
    using System.Text; 
    using System.Web.Configuration;
    using System.Xml;

    internal class CompilationAssemblyInstallComponent : ServiceModelInstallComponent 
    {
        ConfigurationLoader configLoader; 
        string displayString; 

        CompilationAssemblyInstallComponent(ConfigurationLoader configLoader) 
        {
            this.configLoader = configLoader;
        }
 
        internal override string DisplayName
        { 
            get {return this.displayString; } 
        }
 
        protected override string InstallActionMessage
        {
            get
            { 
                StringBuilder message = new StringBuilder();
 
                if (0 < ServiceModelInstallStrings.CompilationAssemblies.Length) 
                {
                    for (int i = 0; i < ServiceModelInstallStrings.CompilationAssemblies.Length; i++) 
                    {
                        string compilationAssembly = ServiceModelInstallStrings.CompilationAssemblies[i];
                        message = message.Append(SR.GetString(SR.CompilationAssemblyInstall, compilationAssembly));
 
                        if (i + 1 < ServiceModelInstallStrings.CompilationAssemblies.Length)
                        { 
                            message = message.Append("\n"); 
                        }
                    } 
                }


                return message.ToString(); 
            }
        } 
 
        internal override string[] InstalledVersions
        { 
            get
            {
                List installedVersions = new List();
 
                if (null != configLoader.SystemWebSectionGroup)
                { 
                    foreach (string compilationAssembly in ServiceModelInstallStrings.CompilationAssemblies) 
                    {
                        AssemblyInfo assemblyInfo = configLoader.SystemWebSectionGroup.Compilation.Assemblies[compilationAssembly]; 
                        if (null != assemblyInfo)
                        {
                            installedVersions.Add(assemblyInfo.Assembly);
                        } 
                    }
                } 
 
                return installedVersions.ToArray();
            } 
        }

        internal override bool IsInstalled
        { 
            get
            { 
                bool isInstalled = false; 

                foreach (string compilationAssembly in ServiceModelInstallStrings.CompilationAssemblies) 
                {
                    isInstalled = this.IsCompilationAssemblyInstalled(compilationAssembly);

                    if (isInstalled) 
                    {
                        break; 
                    } 
                }
 
                return isInstalled;
            }
        }
 
        protected override string ReinstallActionMessage
        { 
            get 
            {
                StringBuilder message = new StringBuilder(); 

                if (0 < ServiceModelInstallStrings.CompilationAssemblies.Length)
                {
                    for (int i = 0; i < ServiceModelInstallStrings.CompilationAssemblies.Length; i++) 
                    {
                        string compilationAssembly = ServiceModelInstallStrings.CompilationAssemblies[i]; 
                        message = message.Append(SR.GetString(SR.CompilationAssemblyReinstall, compilationAssembly)); 

                        if (i + 1 < ServiceModelInstallStrings.CompilationAssemblies.Length) 
                        {
                            message = message.Append("\n");
                        }
                    } 
                }
 
 
                return message.ToString();
            } 
        }

        protected override string UninstallActionMessage
        { 
            get
            { 
                StringBuilder message = new StringBuilder(); 

                if (0 < ServiceModelInstallStrings.CompilationAssemblies.Length) 
                {
                    for (int i = 0; i < ServiceModelInstallStrings.CompilationAssemblies.Length; i++)
                    {
                        string compilationAssembly = ServiceModelInstallStrings.CompilationAssemblies[i]; 
                        message = message.Append(SR.GetString(SR.CompilationAssemblyUninstall, compilationAssembly));
 
                        if (i + 1 < ServiceModelInstallStrings.CompilationAssemblies.Length) 
                        {
                            message = message.Append("\n"); 
                        }
                    }
                }
 

                return message.ToString(); 
            } 
        }
 
        internal static CompilationAssemblyInstallComponent CreateNativeCompilationAssemblyInstallComponent()
        {
            CompilationAssemblyInstallComponent compilationAssembly = new CompilationAssemblyInstallComponent(new NativeConfigurationLoader());
            compilationAssembly.displayString = SR.GetString(SR.CompilationAssemblyName); 
            return compilationAssembly;
        } 
 
        internal static CompilationAssemblyInstallComponent CreateWow64CompilationAssemblyInstallComponent()
        { 
            if (!InstallHelper.Is64BitMachine() || String.IsNullOrEmpty(InstallHelper.Wow64WebConfigFileName))
            {
                throw new ConfigurationLoaderException(SR.GetString(SR.Wow64NotInstalled));
            } 

            CompilationAssemblyInstallComponent compilationAssembly = new CompilationAssemblyInstallComponent(new Wow64ConfigurationLoader()); 
            compilationAssembly.displayString = SR.GetString(SR.CompilationAssemblyNameWow64); 
            return compilationAssembly;
        } 

        internal override void Install(OutputLevel outputLevel)
        {
            if (!this.IsInstalled) 
            {
                if (null != configLoader.SystemWebSectionGroup) 
                { 
                    foreach (string compilationAssembly in ServiceModelInstallStrings.CompilationAssemblies)
                    { 
                        if (!this.IsCompilationAssemblyInstalled(compilationAssembly))
                        {
                            AssemblyInfo assemblyInfo = new AssemblyInfo(compilationAssembly);
                            configLoader.SystemWebSectionGroup.Compilation.Assemblies.Add(assemblyInfo); 
                            configLoader.Save();
                        } 
                        else 
                        {
                            EventLogger.LogWarning(SR.GetString(SR.CompilationAssemblyAlreadyExists, compilationAssembly), (OutputLevel.Verbose == outputLevel)); 
                        }
                    }
                }
                else 
                {
                    throw new InvalidOperationException(SR.GetString(SR.ConfigurationSectionNotInstalled, 
                        configLoader.SystemWebSectionGroupPath, 
                        configLoader.RootWebConfigurationFilePath));
                } 
            }
            else
            {
                EventLogger.LogWarning(SR.GetString(SR.CompilationAssembliesAlreadyExists), (OutputLevel.Verbose == outputLevel)); 
            }
        } 
 
        bool IsCompilationAssemblyInstalled(string compilationInfo)
        { 
            SystemWebSectionGroup systemWebSectionGroup = configLoader.SystemWebSectionGroup;
            if (null != systemWebSectionGroup)
            {
                return (null != systemWebSectionGroup.Compilation.Assemblies[compilationInfo]); 
            }
 
            return false; 
        }
 
        internal override void Uninstall(OutputLevel outputLevel)
        {
            if (this.IsInstalled)
            { 
                foreach (string compilationAssembly in ServiceModelInstallStrings.CompilationAssemblies)
                { 
                    if (this.IsCompilationAssemblyInstalled(compilationAssembly)) 
                    {
                        configLoader.SystemWebSectionGroup.Compilation.Assemblies.Remove(compilationAssembly); 
                        configLoader.Save();
                    }
                    else
                    { 
                        EventLogger.LogWarning(SR.GetString(SR.CompilationAssemblyNotInstalled, compilationAssembly), (OutputLevel.Verbose == outputLevel));
                    } 
                } 
            }
            else 
            {
                EventLogger.LogWarning(SR.GetString(SR.CompilationAssembliesNotInstalled), (OutputLevel.Verbose == outputLevel));
            }
        } 

        internal override InstallationState VerifyInstall() 
        { 
            InstallationState installState = InstallationState.Unknown;
 
            if (this.IsInstalled)
            {
                installState = InstallationState.InstalledDefaults;
 
                foreach (string compilationAssembly in ServiceModelInstallStrings.CompilationAssemblies)
                { 
                    if (!this.IsCompilationAssemblyInstalled(compilationAssembly)) 
                    {
                        installState = InstallationState.InstalledCustom; 
                        break;
                    }
                }
            } 
            else
            { 
                installState = InstallationState.NotInstalled; 
            }
 
            return installState;
        }

    } 
}

// 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