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
- NullRuntimeConfig.cs
- Unit.cs
- DataGridViewAutoSizeModeEventArgs.cs
- ResXResourceSet.cs
- HtmlInputHidden.cs
- CompiledQuery.cs
- ValueExpressions.cs
- ListSourceHelper.cs
- Int64.cs
- RuntimeWrappedException.cs
- XsltQilFactory.cs
- SqlDataSourceEnumerator.cs
- GraphicsContainer.cs
- StructuredType.cs
- SpeakInfo.cs
- RC2CryptoServiceProvider.cs
- ErrorHandler.cs
- BaseTreeIterator.cs
- ListViewItem.cs
- TcpTransportBindingElement.cs
- CodeBlockBuilder.cs
- HitTestDrawingContextWalker.cs
- OleDbPropertySetGuid.cs
- BuiltInPermissionSets.cs
- SapiGrammar.cs
- PixelFormatConverter.cs
- HttpInputStream.cs
- HtmlInputRadioButton.cs
- ITextView.cs
- StringExpressionSet.cs
- DataGridViewCheckBoxColumn.cs
- MethodCallConverter.cs
- DataGridCell.cs
- InfoCardAsymmetricCrypto.cs
- CounterSample.cs
- StackBuilderSink.cs
- ConfigurationSettings.cs
- FragmentNavigationEventArgs.cs
- Shape.cs
- AppDomainProtocolHandler.cs
- ToolStripDropDown.cs
- IfAction.cs
- Error.cs
- Geometry.cs
- SessionParameter.cs
- NaturalLanguageHyphenator.cs
- DocumentViewerHelper.cs
- CookieProtection.cs
- GeneralTransform3DCollection.cs
- ScrollItemProviderWrapper.cs
- ButtonAutomationPeer.cs
- ServiceDesigner.xaml.cs
- WindowsListViewItemStartMenu.cs
- TextClipboardData.cs
- DataGridViewCellLinkedList.cs
- UpdateException.cs
- SqlDataSourceConfigureSelectPanel.cs
- TabPage.cs
- RichTextBoxConstants.cs
- TimeSpanSecondsConverter.cs
- ContainerUtilities.cs
- DurationConverter.cs
- Function.cs
- DataControlPagerLinkButton.cs
- ValidationEventArgs.cs
- AssemblyCache.cs
- SecurityTokenProvider.cs
- RequestSecurityTokenResponseCollection.cs
- StateManagedCollection.cs
- RandomNumberGenerator.cs
- ToolStripLocationCancelEventArgs.cs
- ResetableIterator.cs
- ConfigXmlAttribute.cs
- GridViewEditEventArgs.cs
- SectionUpdates.cs
- RecommendedAsConfigurableAttribute.cs
- TextBounds.cs
- PerspectiveCamera.cs
- ErrorTableItemStyle.cs
- Properties.cs
- ReliabilityContractAttribute.cs
- DragEvent.cs
- SubclassTypeValidatorAttribute.cs
- WorkflowRuntimeBehavior.cs
- WebPartMovingEventArgs.cs
- CaseStatementSlot.cs
- UriTemplateDispatchFormatter.cs
- RangeValidator.cs
- XslAstAnalyzer.cs
- WindowsBrush.cs
- ObjectMemberMapping.cs
- CompilationRelaxations.cs
- ArrayConverter.cs
- EncodingTable.cs
- StreamDocument.cs
- DataColumnSelectionConverter.cs
- IPAddressCollection.cs
- SecurityElement.cs
- OutputScopeManager.cs
- LineServicesRun.cs