Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Tools / xws_reg / System / ServiceModel / Install / Configuration / WasHttpHandlersInstallComponent.cs / 1 / WasHttpHandlersInstallComponent.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 WasHttpHandlersInstallComponent : ServiceModelInstallComponent { IIS7ConfigurationLoader configLoader; string displayString; ConfigElementInfo integratedHttpHandler; ListisapiHttpHandlers; WasHttpHandlersInstallComponent(IIS7ConfigurationLoader configLoader) { if (!IisHelper.ShouldInstallWas || !IisHelper.ShouldInstallApplicationHost) { throw new WasNotInstalledException(SR.GetString(SR.WasNotInstalled, SR.GetString(SR.HttpHandlersComponentNameWAS))); } else if (!IisHelper.ShouldInstallIis) { throw new IisNotInstalledException(SR.GetString(SR.IisNotInstalled, SR.GetString(SR.HttpHandlersComponentNameWAS))); } this.configLoader = configLoader; CreateDefaultHttpHandlers(); } void CreateDefaultHttpHandlers() { // Integrated HTTP Handler this.integratedHttpHandler = new ConfigElementInfo(); this.integratedHttpHandler.RawAttributes.Add(ServiceModelInstallStrings.Name, ServiceModelInstallStrings.IIS7IntegratedHttpHandlerName); this.integratedHttpHandler.RawAttributes.Add(ServiceModelInstallStrings.Path, ServiceModelInstallStrings.HttpHandlersPath); this.integratedHttpHandler.RawAttributes.Add(ServiceModelInstallStrings.Verb, ServiceModelInstallStrings.HttpHandlersVerb); this.integratedHttpHandler.RawAttributes.Add(ServiceModelInstallStrings.Type, ServiceModelInstallStrings.HttpHandlersType); this.integratedHttpHandler.RawAttributes.Add(ServiceModelInstallStrings.PreCondition, ServiceModelInstallStrings.IIS7IntegratedMode); // ISAPI HTTP Handlers this.isapiHttpHandlers = new List (); // ISAPI 32-bit Handler ConfigElementInfo handler = new ConfigElementInfo(); handler.RawAttributes.Add(ServiceModelInstallStrings.Name, ServiceModelInstallStrings.IIS7IsapiHttpHandlerName); handler.RawAttributes.Add(ServiceModelInstallStrings.Path, ServiceModelInstallStrings.HttpHandlersPath); handler.RawAttributes.Add(ServiceModelInstallStrings.Verb, ServiceModelInstallStrings.HttpHandlersVerb); handler.RawAttributes.Add(ServiceModelInstallStrings.Modules, ServiceModelInstallStrings.IIS7IsapiModule); if (!InstallHelper.Is64BitMachine()) { handler.RawAttributes.Add(ServiceModelInstallStrings.ScriptProcessor, InstallHelper.GetNativeIsapiFilter(true)); } else { handler.RawAttributes.Add(ServiceModelInstallStrings.ScriptProcessor, InstallHelper.GetWow64IsapiFilter(true)); } handler.RawAttributes.Add(ServiceModelInstallStrings.PreCondition, ServiceModelInstallStrings.IIS7ClassicModePreCondition); this.isapiHttpHandlers.Add(handler); // ISAPI 64-bit Handler if (InstallHelper.Is64BitMachine()) { handler = new ConfigElementInfo(); handler.RawAttributes.Add(ServiceModelInstallStrings.Name, ServiceModelInstallStrings.IIS7Isapi64HttpHandlerName); handler.RawAttributes.Add(ServiceModelInstallStrings.Path, ServiceModelInstallStrings.HttpHandlersPath); handler.RawAttributes.Add(ServiceModelInstallStrings.Verb, ServiceModelInstallStrings.HttpHandlersVerb); handler.RawAttributes.Add(ServiceModelInstallStrings.Modules, ServiceModelInstallStrings.IIS7IsapiModule); handler.RawAttributes.Add(ServiceModelInstallStrings.ScriptProcessor, InstallHelper.GetNativeIsapiFilter(true)); handler.RawAttributes.Add(ServiceModelInstallStrings.PreCondition, ServiceModelInstallStrings.IIS7ClassicMode64PreCondition); this.isapiHttpHandlers.Add(handler); } } internal override string DisplayName { get {return this.displayString; } } protected override string InstallActionMessage { get {return SR.GetString(SR.HttpHandlersComponentInstall, ServiceModelInstallStrings.IIS7IntegratedHttpHandlerName); } } internal override string[] InstalledVersions { get { List installedVersions = new List (); if (null != this.configLoader.HttpHandlersSection) { WebAdmin.ConfigurationElement httpHandler = this.GetHttpHandlerFromCollection(); Type type = HttpHandlersInstallComponent.GetHandlerType((string)httpHandler.GetAttribute(ServiceModelInstallStrings.Type).Value); string versionString = null; if (type != null) { versionString = InstallHelper.GetVersionStringFromTypeString(type.AssemblyQualifiedName); } else { versionString = (string)httpHandler.GetAttribute(ServiceModelInstallStrings.Type).Value; } string preCondition = String.Empty; if(null != httpHandler.GetAttribute(ServiceModelInstallStrings.PreCondition)) { preCondition = (string)httpHandler.GetAttribute(ServiceModelInstallStrings.PreCondition).Value; } versionString = string.Format(CultureInfo.InvariantCulture, "{0} : {1} ({2})", (string)httpHandler.GetAttribute(ServiceModelInstallStrings.Path).Value, versionString, preCondition); if (!installedVersions.Contains(versionString)) { installedVersions.Add(versionString); } } return installedVersions.ToArray(); } } internal override bool IsInstalled { get { bool isInstalled = false; WebAdmin.ConfigurationElement httpHandler = this.GetHttpHandlerFromCollection(); if (null != httpHandler && null != httpHandler.GetAttribute(ServiceModelInstallStrings.Type) && !((string)httpHandler.GetAttribute(ServiceModelInstallStrings.Type).Value).StartsWith(ServiceModelInstallStrings.HttpForbiddenHandlerType, StringComparison.OrdinalIgnoreCase) && !((string)httpHandler.GetAttribute(ServiceModelInstallStrings.Type).Value).StartsWith(ServiceModelInstallStrings.HttpNotFoundHandlerType, StringComparison.OrdinalIgnoreCase)) { isInstalled = true; } return isInstalled; } } protected override string ReinstallActionMessage { get {return SR.GetString(SR.HttpHandlersComponentReinstall, ServiceModelInstallStrings.IIS7IntegratedHttpHandlerName); } } protected override string UninstallActionMessage { get {return SR.GetString(SR.HttpHandlersComponentUninstall, ServiceModelInstallStrings.IIS7IntegratedHttpHandlerName); } } internal static WasHttpHandlersInstallComponent CreateNativeWasHttpHandlersInstallComponent() { WasHttpHandlersInstallComponent wasHttpHandlersInstallComponent = new WasHttpHandlersInstallComponent(new IIS7ConfigurationLoader(new NativeConfigurationLoader())); wasHttpHandlersInstallComponent.displayString = SR.GetString(SR.HttpHandlersComponentNameWAS); return wasHttpHandlersInstallComponent; } WebAdmin.ConfigurationElement GetHttpHandlerFromCollection() { WebAdmin.ConfigurationElement httpHandler = null; if (null != this.configLoader.HttpHandlersSection) { WebAdmin.ConfigurationElementCollection httpHandlersCollection = this.configLoader.HttpHandlersSection.GetCollection(); // HttpHandlersCollection does not have a unique key, thus need to enumerate collection rather than check for key foreach (WebAdmin.ConfigurationElement element in httpHandlersCollection) { if (((string)element.GetAttribute(ServiceModelInstallStrings.Name).Value).Equals(ServiceModelInstallStrings.IIS7IntegratedHttpHandlerName, StringComparison.OrdinalIgnoreCase)) { httpHandler = element; break; } } } return httpHandler; } internal override void Install(OutputLevel outputLevel) { if (!this.IsInstalled) { if (null != this.configLoader.HttpHandlersSection) { AddSvcHandlers(); configLoader.Save(); } else { throw new InvalidOperationException(SR.GetString(SR.IIS7ConfigurationSectionNotFound, this.configLoader.HttpHandlersSectionPath)); } } else { EventLogger.LogWarning(SR.GetString(SR.HttpHandlersComponentAlreadyExists, ServiceModelInstallStrings.IIS7IntegratedHttpHandlerName), (OutputLevel.Verbose == outputLevel)); } } void CopyHandlerAttributes(WebAdmin.ConfigurationElement element, IDictionary attributes) { foreach (KeyValuePair attribute in attributes) { element.GetAttribute(attribute.Key).Value = attribute.Value; } } void AddSvcHandlers() { WebAdmin.ConfigurationElementCollection httpHandlersCollection = this.configLoader.HttpHandlersSection.GetCollection(); List oldSvcHandlers = new List (); for (int i = 0; i < httpHandlersCollection.Count; i++) { if (string.Compare((string)httpHandlersCollection[i].GetAttribute(ServiceModelInstallStrings.Path).Value, ServiceModelInstallStrings.HttpHandlersPath, StringComparison.OrdinalIgnoreCase) == 0) { oldSvcHandlers.Add(httpHandlersCollection[i]); } } // Remove existing svc handlers for (int i = 0; i < oldSvcHandlers.Count; i++) { httpHandlersCollection.Remove(oldSvcHandlers[i]); } // Add our handler before the first wildcard handler WebAdmin.ConfigurationElement newHandlerAction = httpHandlersCollection.CreateElement(); CopyHandlerAttributes(newHandlerAction, integratedHttpHandler.RawAttributes); // Always install to the top of the config so that we are before wildcard "*" handlers. httpHandlersCollection.AddAt(0, newHandlerAction); for (int i = 0; i < isapiHttpHandlers.Count; i++) { newHandlerAction = httpHandlersCollection.CreateElement(); CopyHandlerAttributes(newHandlerAction, isapiHttpHandlers[i].RawAttributes); httpHandlersCollection.AddAt(i + 1, newHandlerAction); } } internal override void Uninstall(OutputLevel outputLevel) { if (this.IsInstalled) { // Remove the httpHandlers node WebAdmin.ConfigurationElement httpHandler = this.GetHttpHandlerFromCollection(); httpHandler.GetAttribute(ServiceModelInstallStrings.Type).Value = ServiceModelInstallStrings.HttpForbiddenHandlerType; configLoader.Save(); } else { EventLogger.LogWarning(SR.GetString(SR.HttpHandlersComponentNotInstalled, ServiceModelInstallStrings.IIS7IntegratedHttpHandlerName), (OutputLevel.Verbose == outputLevel)); } } internal override InstallationState VerifyInstall() { InstallationState installState = InstallationState.Unknown; if (this.IsInstalled) { WebAdmin.ConfigurationElement httpHandler = this.GetHttpHandlerFromCollection(); if (((string)httpHandler.GetAttribute(ServiceModelInstallStrings.Path).Value).Equals(ServiceModelInstallStrings.HttpHandlersPath, StringComparison.OrdinalIgnoreCase) && ((string)httpHandler.GetAttribute(ServiceModelInstallStrings.Verb).Value).Equals(ServiceModelInstallStrings.HttpHandlersVerb, StringComparison.OrdinalIgnoreCase) && ((string)httpHandler.GetAttribute(ServiceModelInstallStrings.Type).Value).Equals(ServiceModelInstallStrings.HttpHandlersType, StringComparison.OrdinalIgnoreCase) && null != httpHandler.GetAttribute(ServiceModelInstallStrings.PreCondition) && ((string)httpHandler.GetAttribute(ServiceModelInstallStrings.PreCondition).Value).Equals(ServiceModelInstallStrings.IIS7IntegratedMode, StringComparison.OrdinalIgnoreCase)) { installState = InstallationState.InstalledDefaults; } else { installState = InstallationState.InstalledCustom; } } else { installState = InstallationState.NotInstalled; } return installState; } class ConfigElementInfo { IDictionary rawAttributes; public ConfigElementInfo() { rawAttributes = new Dictionary (); } public IDictionary RawAttributes { get { return this.rawAttributes; } } } } } // 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
- HttpHandlersSection.cs
- Rfc2898DeriveBytes.cs
- ScriptControl.cs
- ModifierKeysConverter.cs
- XmlSchemaSubstitutionGroup.cs
- ContentPlaceHolder.cs
- WindowsFormsHelpers.cs
- RectangleGeometry.cs
- DriveNotFoundException.cs
- SchemaTypeEmitter.cs
- OdbcParameterCollection.cs
- IisTraceWebEventProvider.cs
- DbFunctionCommandTree.cs
- QueryStringParameter.cs
- EventListenerClientSide.cs
- RSAOAEPKeyExchangeFormatter.cs
- SerializationEventsCache.cs
- DataBoundControlAdapter.cs
- TextSelectionProcessor.cs
- GroupBoxAutomationPeer.cs
- MouseActionConverter.cs
- EntityProxyFactory.cs
- DebugTraceHelper.cs
- WebPartConnectionsDisconnectVerb.cs
- AsyncPostBackErrorEventArgs.cs
- FactoryRecord.cs
- Stack.cs
- MaterialGroup.cs
- EtwProvider.cs
- RangeValueProviderWrapper.cs
- DataMemberFieldConverter.cs
- ListViewGroupConverter.cs
- TreeWalkHelper.cs
- XamlStream.cs
- SqlCacheDependencySection.cs
- CharAnimationUsingKeyFrames.cs
- OpenTypeLayout.cs
- GACMembershipCondition.cs
- ProcessModelSection.cs
- MouseCaptureWithinProperty.cs
- ParallelEnumerable.cs
- BitmapImage.cs
- ByteStorage.cs
- WorkflowRuntimeServicesBehavior.cs
- FontWeights.cs
- TargetPerspective.cs
- IFlowDocumentViewer.cs
- ReaderWriterLock.cs
- Encoder.cs
- MessageDecoder.cs
- ZipIOLocalFileBlock.cs
- CngProperty.cs
- Dictionary.cs
- SqlUtil.cs
- StatusInfoItem.cs
- ConfigErrorGlyph.cs
- Int32Collection.cs
- QilStrConcatenator.cs
- sortedlist.cs
- MissingMethodException.cs
- XmlSecureResolver.cs
- TemplateBindingExtensionConverter.cs
- MetaTableHelper.cs
- IPEndPoint.cs
- InstanceKeyCollisionException.cs
- QuaternionConverter.cs
- DefaultTraceListener.cs
- PackageDigitalSignature.cs
- WhitespaceReader.cs
- UserNameSecurityTokenParameters.cs
- Freezable.cs
- EditingCoordinator.cs
- AnnotationAdorner.cs
- SqlMethods.cs
- filewebresponse.cs
- X509Certificate2.cs
- UrlAuthorizationModule.cs
- UrlMappingsSection.cs
- TypeUsageBuilder.cs
- ClonableStack.cs
- XmlStringTable.cs
- SessionStateModule.cs
- CmsUtils.cs
- EditorZoneAutoFormat.cs
- DtrList.cs
- LabelLiteral.cs
- InstancePersistenceException.cs
- RadioButtonAutomationPeer.cs
- PingOptions.cs
- OpCopier.cs
- CommentEmitter.cs
- ManagedIStream.cs
- RouteData.cs
- TableRowGroupCollection.cs
- AssemblyHash.cs
- IntSecurity.cs
- NamespaceDisplay.xaml.cs
- FixedTextView.cs
- StringOutput.cs
- IPHostEntry.cs