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
- ResourceManager.cs
- SingleStorage.cs
- ImageClickEventArgs.cs
- AspNetSynchronizationContext.cs
- StylusPlugin.cs
- FontUnit.cs
- HwndSourceKeyboardInputSite.cs
- DelegateOutArgument.cs
- FigureParagraph.cs
- SamlAttributeStatement.cs
- HttpModuleActionCollection.cs
- DataSourceIDConverter.cs
- SynchronizationFilter.cs
- RemoteHelper.cs
- DataRowChangeEvent.cs
- DataContractSerializerSection.cs
- DependencyObjectType.cs
- CompiledQueryCacheKey.cs
- Exceptions.cs
- SqlCacheDependencySection.cs
- SqlDataSourceQueryEditor.cs
- SimpleBitVector32.cs
- PointAnimationUsingKeyFrames.cs
- HttpRequestContext.cs
- ToolStrip.cs
- CodeSubDirectory.cs
- WebPartDisplayMode.cs
- BuildProviderAppliesToAttribute.cs
- NumberFormatInfo.cs
- ListViewCancelEventArgs.cs
- CompositeCollection.cs
- WebEventTraceProvider.cs
- SQLBytesStorage.cs
- XmlSchemaElement.cs
- _emptywebproxy.cs
- Literal.cs
- MapPathBasedVirtualPathProvider.cs
- FileUpload.cs
- Lease.cs
- GridPattern.cs
- DataSourceGeneratorException.cs
- AssemblyCollection.cs
- DbXmlEnabledProviderManifest.cs
- DesignerActionItemCollection.cs
- AssemblyBuilder.cs
- BooleanProjectedSlot.cs
- TextElementCollectionHelper.cs
- IconHelper.cs
- ToolStripMenuItem.cs
- ExpressionConverter.cs
- MessageQueueCriteria.cs
- BroadcastEventHelper.cs
- CompositeFontParser.cs
- ModuleBuilder.cs
- XmlElementAttributes.cs
- XmlElement.cs
- ToolTip.cs
- SchemaCreator.cs
- ScriptingSectionGroup.cs
- HttpVersion.cs
- ReadOnlyDataSourceView.cs
- GridViewColumnHeaderAutomationPeer.cs
- ScriptControlDescriptor.cs
- XmlSerializerVersionAttribute.cs
- ConfigXmlCDataSection.cs
- Transform3D.cs
- Int64Storage.cs
- CancelEventArgs.cs
- EmptyStringExpandableObjectConverter.cs
- StringAnimationBase.cs
- SqlProcedureAttribute.cs
- ReadContentAsBinaryHelper.cs
- ParameterModifier.cs
- ClientFormsAuthenticationMembershipProvider.cs
- FullTrustAssembly.cs
- invalidudtexception.cs
- CompilerScope.Storage.cs
- CounterCreationDataCollection.cs
- ContainerFilterService.cs
- KnownIds.cs
- ShellProvider.cs
- ObjectDataSourceEventArgs.cs
- SqlHelper.cs
- SqlProviderUtilities.cs
- ArgumentValidation.cs
- XmlILOptimizerVisitor.cs
- FixedPageStructure.cs
- TagMapInfo.cs
- DiffuseMaterial.cs
- BoundColumn.cs
- CodeObject.cs
- FixedElement.cs
- ISAPIWorkerRequest.cs
- StrongNameUtility.cs
- LinqToSqlWrapper.cs
- NavigationEventArgs.cs
- DocumentGridPage.cs
- SizeConverter.cs
- Frame.cs
- CodeParameterDeclarationExpression.cs