Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Tools / xws_reg / System / ServiceModel / Install / Configuration / WasHttpModulesInstallComponent.cs / 1 / WasHttpModulesInstallComponent.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Install.Configuration
{
using WebAdmin = Microsoft.Web.Administration;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Text;
using System.Web.Configuration;
internal class WasHttpModulesInstallComponent : ServiceModelInstallComponent
{
IIS7ConfigurationLoader configLoader;
string displayString;
WasHttpModulesInstallComponent(IIS7ConfigurationLoader configLoader)
{
if (!IisHelper.ShouldInstallWas || !IisHelper.ShouldInstallApplicationHost)
{
throw new WasNotInstalledException(SR.GetString(SR.WasNotInstalled, SR.GetString(SR.HttpModulesComponentNameWAS)));
}
else if (!IisHelper.ShouldInstallIis)
{
throw new IisNotInstalledException(SR.GetString(SR.IisNotInstalled, SR.GetString(SR.HttpModulesComponentNameWAS)));
}
this.configLoader = configLoader;
}
internal override string DisplayName
{
get {return this.displayString; }
}
protected override string InstallActionMessage
{
get {return SR.GetString(SR.HttpModulesComponentInstall, ServiceModelInstallStrings.ServiceModel); }
}
internal override string[] InstalledVersions
{
get
{
List installedVersions = new List();
WebAdmin.ConfigurationElement httpModule = this.GetHttpModuleFromCollection();
if(null != httpModule)
{
string moduleTypeVersion = String.Empty;
if (null != httpModule.GetAttribute(ServiceModelInstallStrings.Type))
{
moduleTypeVersion = InstallHelper.GetVersionStringFromTypeString(
(string)httpModule.GetAttribute(ServiceModelInstallStrings.Type).Value);
}
string versionString = String.Format(CultureInfo.CurrentCulture,
"{0}{1}{2}",
(string)httpModule.GetAttribute(ServiceModelInstallStrings.Name).Value,
ServiceModelInstallStrings.VersionStringSeparator,
moduleTypeVersion);
if (!installedVersions.Contains(versionString))
{
installedVersions.Add(versionString);
}
}
return installedVersions.ToArray();
}
}
internal override bool IsInstalled
{
get { return (null != this.GetHttpModuleFromCollection()); }
}
protected override string ReinstallActionMessage
{
get {return SR.GetString(SR.HttpModulesComponentReinstall, ServiceModelInstallStrings.ServiceModel); }
}
protected override string UninstallActionMessage
{
get {return SR.GetString(SR.HttpModulesComponentUninstall, ServiceModelInstallStrings.ServiceModel); }
}
internal static WasHttpModulesInstallComponent CreateNativeWasHttpModulesInstallComponent()
{
WasHttpModulesInstallComponent wasHttpModulesComponent = new WasHttpModulesInstallComponent(new IIS7ConfigurationLoader(new NativeConfigurationLoader()));
wasHttpModulesComponent.displayString = SR.GetString(SR.HttpModulesComponentNameWAS);
return wasHttpModulesComponent;
}
WebAdmin.ConfigurationElement GetHttpModuleFromCollection()
{
WebAdmin.ConfigurationElement httpModule = null;
if (null != this.configLoader.HttpModulesSection)
{
WebAdmin.ConfigurationElementCollection modulesCollection = this.configLoader.HttpModulesSection.GetCollection();
// ModulesCollection does not have a unique key, thus need to enumerate collection rather than check for key
foreach (WebAdmin.ConfigurationElement element in modulesCollection)
{
if (((string)element.GetAttribute(ServiceModelInstallStrings.Name).Value).Equals(ServiceModelInstallStrings.ServiceModel, StringComparison.OrdinalIgnoreCase))
{
httpModule = element;
}
}
}
return httpModule;
}
internal override void Install(OutputLevel outputLevel)
{
if (!this.IsInstalled)
{
if (null != this.configLoader.HttpModulesSection)
{
WebAdmin.ConfigurationElementCollection modulesCollection = this.configLoader.HttpModulesSection.GetCollection();
WebAdmin.ConfigurationElement moduleAction = modulesCollection.CreateElement();
moduleAction.GetAttribute(ServiceModelInstallStrings.Name).Value = ServiceModelInstallStrings.ServiceModel;
moduleAction.GetAttribute(ServiceModelInstallStrings.Type).Value = ServiceModelInstallStrings.HttpModulesType;
moduleAction.GetAttribute(ServiceModelInstallStrings.PreCondition).Value = ServiceModelInstallStrings.WasHttpModulesPreCondition;
modulesCollection.Add(moduleAction);
configLoader.Save();
}
else
{
throw new InvalidOperationException(SR.GetString(SR.IIS7ConfigurationSectionNotFound,
this.configLoader.HttpModulesSectionPath));
}
}
else
{
EventLogger.LogWarning(SR.GetString(SR.HttpModulesComponentAlreadyExists, ServiceModelInstallStrings.ServiceModel), (OutputLevel.Verbose == outputLevel));
}
}
internal override void Uninstall(OutputLevel outputLevel)
{
if (this.IsInstalled)
{
WebAdmin.ConfigurationElementCollection modulesCollection = this.configLoader.HttpModulesSection.GetCollection();
// ModulesCollection does not have a unique key, thus need to enumerate collection rather than check for key
// Also, Microsoft.Web.Administration.ConfigurationElementCollection.Remove(element) does not work here. It
// translates (bug?) to RemoveAt(-1) which fails. Instead, get index manually and call RemoveAt(int) directly.
for (int i = 0; i < modulesCollection.Count; i++)
{
WebAdmin.ConfigurationElement element = modulesCollection[i];
if (((string)element.GetAttribute(ServiceModelInstallStrings.Name).Value).Equals(ServiceModelInstallStrings.ServiceModel, StringComparison.OrdinalIgnoreCase))
{
modulesCollection.RemoveAt(i);
configLoader.Save();
break;
}
}
}
else
{
EventLogger.LogWarning(SR.GetString(SR.HttpModulesComponentNotInstalled, ServiceModelInstallStrings.ServiceModel), (OutputLevel.Verbose == outputLevel));
}
}
internal override InstallationState VerifyInstall()
{
InstallationState installState = InstallationState.Unknown;
if (this.IsInstalled)
{
WebAdmin.ConfigurationElement httpModule = this.GetHttpModuleFromCollection();
if (null != httpModule.GetAttribute(ServiceModelInstallStrings.Type) &&
((string)httpModule.GetAttribute(ServiceModelInstallStrings.Type).Value).Equals(ServiceModelInstallStrings.HttpModulesType, StringComparison.OrdinalIgnoreCase) &&
null != httpModule.GetAttribute(ServiceModelInstallStrings.PreCondition) &&
((string)httpModule.GetAttribute(ServiceModelInstallStrings.PreCondition).Value).Equals(ServiceModelInstallStrings.WasHttpModulesPreCondition, StringComparison.OrdinalIgnoreCase))
{
installState = InstallationState.InstalledDefaults;
}
else
{
installState = InstallationState.InstalledCustom;
}
}
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

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HandleTable.cs
- MetadataSerializer.cs
- XmlException.cs
- StorageMappingItemCollection.cs
- IImplicitResourceProvider.cs
- Empty.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- HandlerFactoryCache.cs
- MessageUtil.cs
- ProfilePropertySettings.cs
- PropertyEmitter.cs
- ProjectionPathBuilder.cs
- GridViewCancelEditEventArgs.cs
- OutputScope.cs
- DiffuseMaterial.cs
- ReferencedCollectionType.cs
- CLRBindingWorker.cs
- CoreSwitches.cs
- WriteFileContext.cs
- DataGridViewImageColumn.cs
- sqlcontext.cs
- LocationChangedEventArgs.cs
- DataGridLengthConverter.cs
- VideoDrawing.cs
- ClientTarget.cs
- FixedSOMTableCell.cs
- OleDbTransaction.cs
- CodeExpressionCollection.cs
- RequestCachePolicyConverter.cs
- CdpEqualityComparer.cs
- ObjectComplexPropertyMapping.cs
- RuleSettings.cs
- UndirectedGraph.cs
- BitmapEffect.cs
- PassportAuthenticationEventArgs.cs
- MethodBuilderInstantiation.cs
- GraphicsState.cs
- DeleteIndexBinder.cs
- ListViewAutomationPeer.cs
- TextBoxDesigner.cs
- XmlDocumentFragment.cs
- LowerCaseStringConverter.cs
- ProjectionPlan.cs
- MessageSmuggler.cs
- UIElementPropertyUndoUnit.cs
- PlatformCulture.cs
- XmlEncoding.cs
- RecipientInfo.cs
- ConfigXmlElement.cs
- CacheSection.cs
- DbProviderManifest.cs
- SqlNotificationRequest.cs
- StorageMappingItemCollection.cs
- SmtpReplyReaderFactory.cs
- SelectionProcessor.cs
- DrawingVisual.cs
- ReversePositionQuery.cs
- ListControlConvertEventArgs.cs
- Util.cs
- MethodBody.cs
- PolicyException.cs
- XmlArrayItemAttribute.cs
- XmlDocumentSchema.cs
- ConvertersCollection.cs
- ContractMapping.cs
- ChangePassword.cs
- LogLogRecord.cs
- SafeNativeMethods.cs
- UnknownBitmapDecoder.cs
- WindowAutomationPeer.cs
- AttributeCollection.cs
- SmtpException.cs
- TcpProcessProtocolHandler.cs
- ColorAnimationBase.cs
- AdCreatedEventArgs.cs
- HuffModule.cs
- RegexTree.cs
- ActiveXHost.cs
- CacheMemory.cs
- PlanCompiler.cs
- Parallel.cs
- FieldTemplateFactory.cs
- XPathDescendantIterator.cs
- ComponentFactoryHelpers.cs
- ByteBufferPool.cs
- DatatypeImplementation.cs
- SetStoryboardSpeedRatio.cs
- RSACryptoServiceProvider.cs
- DrawingServices.cs
- EditBehavior.cs
- SourceInterpreter.cs
- OdbcPermission.cs
- InstanceData.cs
- StoryFragments.cs
- elementinformation.cs
- SpellCheck.cs
- KnownTypesProvider.cs
- OracleCommandSet.cs
- GridSplitter.cs
- ControlAdapter.cs