Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Tools / xws_reg / System / ServiceModel / Install / Configuration / HttpHandlersInstallComponent.cs / 1 / HttpHandlersInstallComponent.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Install.Configuration
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Text;
using System.Web.Configuration;
internal class HttpHandlersInstallComponent : ServiceModelInstallComponent
{
ConfigurationLoader configLoader;
string displayString;
HttpHandlersInstallComponent(ConfigurationLoader configLoader)
{
this.configLoader = configLoader;
}
internal override string DisplayName
{
get {return this.displayString; }
}
protected override string InstallActionMessage
{
get {return SR.GetString(SR.HttpHandlersComponentInstall, ServiceModelInstallStrings.HttpHandlersPath); }
}
internal override string[] InstalledVersions
{
get
{
List installedVersions = new List();
if (null != configLoader.SystemWebSectionGroup)
{
// Foreach needed here since HttpHandlerActionCollection does not have an accessor that takes a string
foreach (HttpHandlerAction handler in configLoader.SystemWebSectionGroup.HttpHandlers.Handlers)
{
if (handler.Path.Equals(ServiceModelInstallStrings.HttpHandlersPath, StringComparison.OrdinalIgnoreCase))
{
Type type = GetHandlerType(handler.Type);
string versionString = null;
if (type != null)
{
versionString = handler.Path + ServiceModelInstallStrings.VersionStringSeparator + InstallHelper.GetVersionStringFromTypeString(type.AssemblyQualifiedName);
}
else
{
versionString = handler.Path + ServiceModelInstallStrings.VersionStringSeparator + handler.Type;
}
installedVersions.Add(versionString);
}
}
}
return installedVersions.ToArray();
}
}
internal override bool IsInstalled
{
get
{
if (null != configLoader.SystemWebSectionGroup)
{
Type forbiddenHandlerType = GetHandlerType(ServiceModelInstallStrings.HttpForbiddenHandlerType);
// Foreach needed here since HttpHandlerActionCollection does not have an accessor that takes a string
foreach (HttpHandlerAction installedHandler in configLoader.SystemWebSectionGroup.HttpHandlers.Handlers)
{
if (installedHandler.Path.Equals(ServiceModelInstallStrings.HttpHandlersPath, StringComparison.OrdinalIgnoreCase))
{
Type type = GetHandlerType(installedHandler.Type);
// Only if the type is Forbidden we assume it's installed.
if (type == null || !type.Equals(forbiddenHandlerType))
{
return true;
}
}
}
}
return false;
}
}
protected override string ReinstallActionMessage
{
get {return SR.GetString(SR.HttpHandlersComponentReinstall, ServiceModelInstallStrings.HttpHandlersPath); }
}
protected override string UninstallActionMessage
{
get {return SR.GetString(SR.HttpHandlersComponentUninstall, ServiceModelInstallStrings.HttpHandlersPath); }
}
internal static HttpHandlersInstallComponent CreateNativeHttpHandlersInstallComponent()
{
HttpHandlersInstallComponent httpHandlersComponent = new HttpHandlersInstallComponent(new NativeConfigurationLoader());
httpHandlersComponent.displayString = SR.GetString(SR.HttpHandlersComponentName);
return httpHandlersComponent;
}
internal static HttpHandlersInstallComponent CreateWow64HttpHandlersInstallComponent()
{
if (!InstallHelper.Is64BitMachine() || String.IsNullOrEmpty(InstallHelper.Wow64WebConfigFileName))
{
throw new ConfigurationLoaderException(SR.GetString(SR.Wow64NotInstalled));
}
HttpHandlersInstallComponent httpHandlersComponent = new HttpHandlersInstallComponent(new Wow64ConfigurationLoader());
httpHandlersComponent.displayString = SR.GetString(SR.HttpHandlersComponentNameWow64);
return httpHandlersComponent;
}
internal static Type GetHandlerType(string typeName)
{
Type type = Type.GetType(typeName, false);
if (type == null)
{
// Try System.Web
type = typeof(System.Web.IHttpHandler).Assembly.GetType(typeName, false);
}
return type;
}
internal override void Install(OutputLevel outputLevel)
{
if (!this.IsInstalled)
{
if (null != configLoader.SystemWebSectionGroup)
{
List handlerList = new List();
HttpHandlerActionCollection handlers = configLoader.SystemWebSectionGroup.HttpHandlers.Handlers;
// Foreach needed here since HttpHandlerActionCollection does not have an accessor that takes a string
foreach (HttpHandlerAction handler in handlers)
{
if (string.CompareOrdinal(handler.Path, ServiceModelInstallStrings.WildCardHttpHandlerPath) == 0)
{
handlerList.Add(handler);
}
}
// Adding Indigo handler
handlers.Add(new HttpHandlerAction(ServiceModelInstallStrings.HttpHandlersPath, ServiceModelInstallStrings.HttpHandlersType, ServiceModelInstallStrings.HttpHandlersVerb, false));
for (int i = 0; i < handlerList.Count; i++)
{
handlers.Remove(handlerList[i]);
}
configLoader.Save();
// Move wildcard handlers to the end of the collection:
// need to refresh our config objects, or the old config/section will retain information on their original position
handlers = configLoader.SystemWebSectionGroup.HttpHandlers.Handlers;
for (int i = 0; i < handlerList.Count; i++)
{
handlers.Add(handlerList[i]);
}
configLoader.Save();
}
else
{
throw new InvalidOperationException(SR.GetString(SR.ConfigurationSectionNotInstalled,
configLoader.SystemWebSectionGroupPath,
configLoader.RootWebConfigurationFilePath));
}
}
else
{
EventLogger.LogWarning(SR.GetString(SR.HttpHandlersComponentAlreadyExists, ServiceModelInstallStrings.HttpHandlersPath), (OutputLevel.Verbose == outputLevel));
}
}
internal override void Uninstall(OutputLevel outputLevel)
{
if (this.IsInstalled)
{
// Remove the httpHandlers node
// Foreach needed here since HttpHandlerActionCollection does not have an accessor that takes a string
foreach (HttpHandlerAction installedHandler in configLoader.SystemWebSectionGroup.HttpHandlers.Handlers)
{
if (installedHandler.Path.Equals(ServiceModelInstallStrings.HttpHandlersPath, StringComparison.OrdinalIgnoreCase))
{
installedHandler.Type = ServiceModelInstallStrings.HttpForbiddenHandlerType;
installedHandler.Validate = true;
}
}
configLoader.Save();
}
else
{
EventLogger.LogWarning(SR.GetString(SR.HttpHandlersComponentNotInstalled, ServiceModelInstallStrings.HttpHandlersPath), (OutputLevel.Verbose == outputLevel));
}
}
internal override InstallationState VerifyInstall()
{
InstallationState installState = InstallationState.Unknown;
if (this.IsInstalled)
{
if (null != configLoader.SystemWebSectionGroup)
{
HttpHandlerAction handler = new HttpHandlerAction(ServiceModelInstallStrings.HttpHandlersPath, ServiceModelInstallStrings.HttpHandlersType, ServiceModelInstallStrings.HttpHandlersVerb, false);
// Foreach needed here since HttpHandlerActionCollection does not have an accessor that takes a string
foreach (HttpHandlerAction installedHandler in configLoader.SystemWebSectionGroup.HttpHandlers.Handlers)
{
if (handler.Path.Equals(installedHandler.Path, StringComparison.OrdinalIgnoreCase))
{
if (installedHandler.Equals(handler))
{
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
- SafeArrayTypeMismatchException.cs
- ToolStripRenderEventArgs.cs
- ExtensionQuery.cs
- WindowsToolbarAsMenu.cs
- ObjectListSelectEventArgs.cs
- X509Certificate2Collection.cs
- SqlFileStream.cs
- StylusSystemGestureEventArgs.cs
- DefaultParameterValueAttribute.cs
- ListBoxItemAutomationPeer.cs
- DbModificationClause.cs
- OrCondition.cs
- ProvidePropertyAttribute.cs
- TextWriterTraceListener.cs
- SID.cs
- UserControl.cs
- ApplicationServiceHelper.cs
- WebPartConnection.cs
- DeviceContext.cs
- Triangle.cs
- BmpBitmapDecoder.cs
- NativeBuffer.cs
- MenuScrollingVisibilityConverter.cs
- UnknownMessageReceivedEventArgs.cs
- InvalidWMPVersionException.cs
- HttpVersion.cs
- DataBindingHandlerAttribute.cs
- UnsafeNativeMethodsPenimc.cs
- TransactionScope.cs
- StateManager.cs
- XmlWrappingWriter.cs
- XamlHostingConfiguration.cs
- PostBackTrigger.cs
- _TransmitFileOverlappedAsyncResult.cs
- ScriptComponentDescriptor.cs
- ExecutionContext.cs
- TemplateContent.cs
- CollectionTraceRecord.cs
- KeyNotFoundException.cs
- RequestCacheManager.cs
- CreateDataSourceDialog.cs
- TokenizerHelper.cs
- SchemaCollectionCompiler.cs
- XmlObjectSerializer.cs
- RichListBox.cs
- XmlPreloadedResolver.cs
- TableCell.cs
- ProtocolsConfiguration.cs
- SafeCoTaskMem.cs
- SecurityKeyIdentifierClause.cs
- ClientSponsor.cs
- PasswordRecoveryAutoFormat.cs
- GradientStopCollection.cs
- RegexStringValidator.cs
- SmtpReplyReaderFactory.cs
- XmlSchemaDocumentation.cs
- GenericEnumerator.cs
- CommandID.cs
- LocatorManager.cs
- Point4D.cs
- DesignerRegionCollection.cs
- OpenFileDialog.cs
- MD5CryptoServiceProvider.cs
- SyndicationSerializer.cs
- EncodingTable.cs
- Geometry.cs
- ProfileEventArgs.cs
- ImportContext.cs
- NativeMethodsOther.cs
- ActivationServices.cs
- InfoCardKeyedHashAlgorithm.cs
- InvalidDocumentContentsException.cs
- DrawingContextFlattener.cs
- BmpBitmapDecoder.cs
- TextFormatterImp.cs
- DataServiceExpressionVisitor.cs
- CancellationHandlerDesigner.cs
- URL.cs
- ReadWriteObjectLock.cs
- WarningException.cs
- _UriSyntax.cs
- InfoCardAsymmetricCrypto.cs
- MediaSystem.cs
- FileLogRecordEnumerator.cs
- _Win32.cs
- WebProxyScriptElement.cs
- PreDigestedSignedInfo.cs
- XamlFigureLengthSerializer.cs
- XmlNode.cs
- AnnotationComponentManager.cs
- BounceEase.cs
- SplitterPanel.cs
- BitmapCache.cs
- TextLineBreak.cs
- HandlerFactoryWrapper.cs
- QilPatternVisitor.cs
- XmlAttributeOverrides.cs
- TypeToTreeConverter.cs
- DefaultHttpHandler.cs
- ContentTextAutomationPeer.cs