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
- ContextInformation.cs
- ComponentGuaranteesAttribute.cs
- DataGridToolTip.cs
- Viewport3DAutomationPeer.cs
- UpdateTranslator.cs
- AttributeUsageAttribute.cs
- XmlUnspecifiedAttribute.cs
- RepeaterDataBoundAdapter.cs
- TrustLevel.cs
- ColorConverter.cs
- TextFormatter.cs
- DataGridHelper.cs
- ManagedWndProcTracker.cs
- IEnumerable.cs
- ScriptComponentDescriptor.cs
- Page.cs
- LinqDataSourceContextEventArgs.cs
- BevelBitmapEffect.cs
- SqlMethodTransformer.cs
- UnhandledExceptionEventArgs.cs
- NameTable.cs
- Substitution.cs
- SqlInternalConnection.cs
- HtmlHistory.cs
- Util.cs
- Table.cs
- HttpListenerPrefixCollection.cs
- EncoderParameter.cs
- configsystem.cs
- DependentList.cs
- SoapIncludeAttribute.cs
- FamilyMap.cs
- HtmlInputImage.cs
- KeyedHashAlgorithm.cs
- DataExpression.cs
- LateBoundBitmapDecoder.cs
- VerticalAlignConverter.cs
- PolyQuadraticBezierSegment.cs
- CodeCatchClause.cs
- SoapConverter.cs
- HandleRef.cs
- ToolboxCategory.cs
- SystemIPv6InterfaceProperties.cs
- lengthconverter.cs
- AspCompat.cs
- DataSourceControlBuilder.cs
- ObsoleteAttribute.cs
- ObjectCacheSettings.cs
- documentation.cs
- FixUp.cs
- CreateUserErrorEventArgs.cs
- ModulesEntry.cs
- WebWorkflowRole.cs
- LingerOption.cs
- ServiceInfo.cs
- ColumnHeaderCollectionEditor.cs
- Rect.cs
- PersonalizableTypeEntry.cs
- RefType.cs
- WhitespaceReader.cs
- PasswordRecovery.cs
- WindowsAuthenticationModule.cs
- SpanIndex.cs
- ScriptingWebServicesSectionGroup.cs
- XPathSelectionIterator.cs
- SiteMapHierarchicalDataSourceView.cs
- ResumeStoryboard.cs
- DataMisalignedException.cs
- Animatable.cs
- XmlMemberMapping.cs
- TextEditor.cs
- SettingsProviderCollection.cs
- SqlDataReader.cs
- PersistenceTypeAttribute.cs
- GeneratedView.cs
- UTF8Encoding.cs
- DesignTimeHTMLTextWriter.cs
- EntityDataSourceWizardForm.cs
- WaitForChangedResult.cs
- HttpServerProtocol.cs
- DispatcherOperation.cs
- ListViewDeletedEventArgs.cs
- ClientScriptManagerWrapper.cs
- WebBrowsableAttribute.cs
- ColorConvertedBitmap.cs
- DesignerTransactionCloseEvent.cs
- QueryContinueDragEvent.cs
- SecurityVerifiedMessage.cs
- SerializerProvider.cs
- DispatcherHookEventArgs.cs
- Rectangle.cs
- DoubleLinkList.cs
- JoinQueryOperator.cs
- StrokeCollection.cs
- MethodExpr.cs
- Application.cs
- DataBoundControl.cs
- GeometryGroup.cs
- UiaCoreApi.cs
- LoginView.cs