Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Tools / xws_reg / System / ServiceModel / Install / WebHostScriptMappingsInstallComponent.cs / 2 / WebHostScriptMappingsInstallComponent.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Install { using System; using System.Collections.Generic; using System.DirectoryServices; using System.Globalization; using System.Runtime.InteropServices; using System.Text; internal class WebHostScriptMappingsInstallComponent : ServiceModelInstallComponent { const string IISRoot = WebHostScriptMappingsInstallComponent.LocalHost + "W3SVC"; const string LocalHost = "IIS://localhost/"; bool recursive; DirectoryEntry rootPath; const string ScriptMapOptions = @",1,GET,HEAD,POST,DEBUG"; bool updateExisting; bool isReinstalling; QueuereinstallPaths; private WebHostScriptMappingsInstallComponent() : this(WebHostScriptMappingsInstallComponent.IISRoot, true, true) { } internal WebHostScriptMappingsInstallComponent(string rootPath, bool recursive, bool updateExisting) { if (!IisHelper.ShouldInstallIis) { throw new IisNotInstalledException(SR.GetString(SR.IisNotInstalled, SR.GetString(SR.WebHostScriptMappingsName))); } else { if (!String.IsNullOrEmpty(rootPath)) { if (rootPath.StartsWith("/LM/", StringComparison.OrdinalIgnoreCase)) { // Replace "/LM/" with "IIS://localhost/" to accept // root paths like "/LM/W3SVC/1/root" rootPath = WebHostScriptMappingsInstallComponent.LocalHost + rootPath.Substring(4); } if (!rootPath.StartsWith(WebHostScriptMappingsInstallComponent.LocalHost, StringComparison.OrdinalIgnoreCase)) { rootPath = WebHostScriptMappingsInstallComponent.LocalHost + rootPath; } if (rootPath.EndsWith("/", StringComparison.OrdinalIgnoreCase)) { rootPath = rootPath.Remove(rootPath.LastIndexOf('/'), 1); } try { // No need to call ValidateDirectoryEntry here because DirectoryEntry.Exists forces a bind // We won't get the retry logic of ValidateDirectoryEntry, but that's okay because this code path is not used in the MSI install if (!DirectoryEntry.Exists(rootPath)) { throw new ApplicationException(SR.GetString(SR.WebHostScriptMappingsInvalidScriptMapPath, rootPath)); } else { this.rootPath = new DirectoryEntry(rootPath); } } catch (COMException e) { switch (e.ErrorCode) { case (COMErrors.E_ADS_BAD_PATHNAME): case (COMErrors.E_UNSPECIFIED_ERRROR): throw new ApplicationException(SR.GetString(SR.WebHostScriptMappingsInvalidScriptMapPath, rootPath), e); default: throw IisHelper.WrapIisError(e); } } } else { try { this.rootPath = new DirectoryEntry(WebHostScriptMappingsInstallComponent.IISRoot); IisHelper.ValidateDirectoryEntry(this.rootPath); } catch (COMException e) { throw IisHelper.WrapIisError(e); } } this.recursive = recursive; this.updateExisting = updateExisting; } } internal override string DisplayName { get { return SR.GetString(SR.WebHostScriptMappingsName); } } string ExtensionValuesDisplay { get { StringBuilder extensionValuesDisplay = new StringBuilder(); for (int i = 0; i < ServiceModelInstallStrings.IISExtensionValues.Length; i++) { string extensionValue = ServiceModelInstallStrings.IISExtensionValues[i]; extensionValuesDisplay = extensionValuesDisplay.Append(extensionValue); if (i + 1 < ServiceModelInstallStrings.IISExtensionValues.Length) { extensionValuesDisplay = extensionValuesDisplay.Append(", "); } } return extensionValuesDisplay.ToString(); } } string GenerateScriptMapping(string extensionValue, string isapiFilter) { return String.Format(CultureInfo.CurrentCulture, "{0},{1}{2}", extensionValue, isapiFilter, WebHostScriptMappingsInstallComponent.ScriptMapOptions); } protected override string InstallActionMessage { get { if (!this.IsInstalled) { return SR.GetString(SR.WebHostScriptMappingsInstall, this.ExtensionValuesDisplay); } else { return SR.GetString(SR.WebHostScriptMappingsUpdate, this.ExtensionValuesDisplay); } } } internal string[] InstalledPaths { get { List installedPaths = BuildInstalledPathsRecursive(this.rootPath); return installedPaths.ToArray(); } } internal override string[] InstalledVersions { get { List installedVersions = new List (); PropertyValueCollection scriptMapCollection = this.rootPath.Properties[ServiceModelInstallStrings.ScriptMaps]; foreach (string scriptMap in scriptMapCollection) { string lowerScriptMap = scriptMap.ToLower(CultureInfo.InvariantCulture); foreach (string extensionValue in ServiceModelInstallStrings.IISExtensionValues) { if (lowerScriptMap.Contains(extensionValue.ToLower(CultureInfo.InvariantCulture))) { installedVersions.Add(scriptMap); break; } } } return installedVersions.ToArray(); } } internal override bool IsInstalled { get { return IsInstalledAtPath(this.rootPath); } } protected override string ReinstallActionMessage { get { return SR.GetString(SR.WebHostScriptMappingsReinstall, this.ExtensionValuesDisplay); } } protected override string UninstallActionMessage { get { return SR.GetString(SR.WebHostScriptMappingsUninstall, this.ExtensionValuesDisplay); } } List BuildInstalledPathsRecursive(DirectoryEntry webSite) { List installedPaths = new List (); if (IsInstalledAtPath(webSite)) { installedPaths.Add(webSite.Path); PropertyValueCollection scriptMapCollection = webSite.Properties[ServiceModelInstallStrings.ScriptMaps]; foreach (string scriptMap in scriptMapCollection) { foreach (string extensionValue in ServiceModelInstallStrings.IISExtensionValues) { if (scriptMap.ToLower(CultureInfo.InvariantCulture).Contains(extensionValue.ToLower(CultureInfo.InvariantCulture))) { installedPaths.Add("\t" + scriptMap); break; } } } } foreach (DirectoryEntry child in webSite.Children) { installedPaths.AddRange(BuildInstalledPathsRecursive(child)); } return installedPaths; } List CurrentInstalledScriptMaps(DirectoryEntry path) { List installedScriptMaps = new List (); PropertyValueCollection scriptMapCollection = path.Properties[ServiceModelInstallStrings.ScriptMaps]; foreach (string scriptMap in scriptMapCollection) { foreach (string extensionValue in ServiceModelInstallStrings.IISExtensionValues) { if (scriptMap.StartsWith(extensionValue, StringComparison.OrdinalIgnoreCase)) { installedScriptMaps.Add(scriptMap); break; } } } return installedScriptMaps; } internal override void Install(OutputLevel outputLevel) { if (!IisHelper.ShouldInstallScriptMaps) { EventLogger.LogWarning(SR.GetString(SR.AspNetNotInstalled, SR.GetString(SR.WebHostScriptMappingsName)), (OutputLevel.Verbose == outputLevel)); } else { int numberScriptMapsInstalled = InstallScriptMapToPath(this.rootPath, outputLevel); if (this.isReinstalling && !this.recursive) { while (this.reinstallPaths.Count > 0) { DirectoryEntry path = this.reinstallPaths.Dequeue(); if (path != this.rootPath) { numberScriptMapsInstalled += InstallScriptMapToPath(path, outputLevel); } } } if (0 == numberScriptMapsInstalled) { EventLogger.LogWarning(SR.GetString(SR.WebHostScriptMappingsAlreadyExists, this.ExtensionValuesDisplay), (OutputLevel.Verbose == outputLevel)); } } } internal override void Reinstall(OutputLevel outputLevel) { isReinstalling = true; this.reinstallPaths = new Queue (); base.Reinstall(outputLevel); isReinstalling = false; } int InstallScriptMapToPath(DirectoryEntry path, OutputLevel outputLevel) { int numberScriptMapsInstalled = 0; if (PathContainsScriptMaps(path)) { PropertyValueCollection scriptMapCollection = path.Properties[ServiceModelInstallStrings.ScriptMaps]; if (IsInstalledAtPath(path) && this.updateExisting) { foreach (string scriptMap in this.CurrentInstalledScriptMaps(path)) { scriptMapCollection.Remove(scriptMap); } } if (!IsInstalledAtPath(path)) { if (OutputLevel.Verbose == outputLevel) { EventLogger.WriteMsiStyleLogEntry(SR.GetString(SR.WebHostScriptMappingsAddMap, path.Path)); EventLogger.LogToConsole(SR.GetString(SR.WebHostScriptMappingsAddMap, path.Path)); } foreach (string extensionValue in ServiceModelInstallStrings.IISExtensionValues) { scriptMapCollection.Add(this.GenerateScriptMapping(extensionValue, InstallHelper.IsapiFilter)); } path.CommitChanges(); numberScriptMapsInstalled++; } } if (this.recursive) { foreach (DirectoryEntry childPath in path.Children) { numberScriptMapsInstalled += InstallScriptMapToPath(childPath, outputLevel); } } return numberScriptMapsInstalled; } bool IsInstalledAtPath(DirectoryEntry path) { bool isInstalled = false; if (PathContainsScriptMaps(path)) { PropertyValueCollection scriptMapCollection = path.Properties[ServiceModelInstallStrings.ScriptMaps]; foreach (string scriptMap in scriptMapCollection) { string lowerScriptMap = scriptMap.ToLower(CultureInfo.InvariantCulture); foreach (string extensionValue in ServiceModelInstallStrings.IISExtensionValues) { if (lowerScriptMap.Contains(extensionValue.ToLower(CultureInfo.InvariantCulture))) { isInstalled = true; break; } } if (isInstalled) { break; } } } return isInstalled; } bool PathContainsScriptMaps(DirectoryEntry path) { bool containsScriptMaps = false; try { if (path.Properties.Contains(ServiceModelInstallStrings.ScriptMaps)) { containsScriptMaps = true; } } catch (COMException e) { if (COMErrors.E_ADS_PROPERTY_NOT_SUPPORTED == e.ErrorCode || COMErrors.MD_ERROR_DATA_NOT_FOUND == e.ErrorCode || COMErrors.COR_E_DIRECTORYNOTFOUND == e.ErrorCode) { containsScriptMaps = false; } else { Environment.ExitCode = e.ErrorCode; throw IisHelper.WrapIisError(e); } } return containsScriptMaps; } int IndexOfScriptMap(PropertyValueCollection scriptMapCollection, string entry) { int scriptMapIndex = scriptMapCollection.IndexOf(entry); if (-1 == scriptMapIndex) { for (int i = 0; i < scriptMapCollection.Count; i++) { string scriptMap = (string)scriptMapCollection[i]; if (scriptMap.Equals(entry, StringComparison.OrdinalIgnoreCase)) { scriptMapIndex = i; break; } } } return scriptMapIndex; } internal override void Uninstall(OutputLevel outputLevel) { if (this.IsInstalled) { UninstallScriptMapFromPath(this.rootPath, outputLevel); } else { EventLogger.LogWarning(SR.GetString(SR.WebHostScriptMappingsNotInstalled, this.ExtensionValuesDisplay), (OutputLevel.Verbose == outputLevel)); } } void UninstallScriptMapFromPath(DirectoryEntry path, OutputLevel outputLevel) { if (PathContainsScriptMaps(path)) { bool displayedUninstallMessage = false; PropertyValueCollection scriptMapCollection = path.Properties[ServiceModelInstallStrings.ScriptMaps]; if (this.updateExisting) { string newIsapiFilter = null; string otherIndigoVersionDirectory = InstallHelper.GetHighestOtherWcfRuntimeInstallPath(); if (!String.IsNullOrEmpty(otherIndigoVersionDirectory)) { newIsapiFilter = InstallHelper.IsapiFilter.Replace(InstallHelper.GetWcfRuntimeInstallPath(), otherIndigoVersionDirectory); } foreach (string extensionValue in ServiceModelInstallStrings.IISExtensionValues) { int scriptMapIndex = this.IndexOfScriptMap(scriptMapCollection, this.GenerateScriptMapping(extensionValue, InstallHelper.IsapiFilter)); if (-1 != scriptMapIndex) { if (!displayedUninstallMessage) { if (OutputLevel.Verbose == outputLevel) { EventLogger.WriteMsiStyleLogEntry(SR.GetString(SR.WebHostScriptMappingsRemoveMap, path.Path)); EventLogger.LogToConsole(SR.GetString(SR.WebHostScriptMappingsRemoveMap, path.Path)); } displayedUninstallMessage = true; } if (this.isReinstalling && !this.recursive) { // This path has the script map explicitly set, which means that it won't inherit // script maps from its parent. So on reinstall, we need to explicit re-add it. this.reinstallPaths.Enqueue(path); } scriptMapCollection.RemoveAt(scriptMapIndex); if (!String.IsNullOrEmpty(newIsapiFilter)) { scriptMapCollection.Add(this.GenerateScriptMapping(extensionValue, newIsapiFilter)); } } } } else { foreach (string scriptMap in this.CurrentInstalledScriptMaps(path)) { if (!displayedUninstallMessage) { if (OutputLevel.Verbose == outputLevel) { EventLogger.WriteMsiStyleLogEntry(SR.GetString(SR.WebHostScriptMappingsRemoveMap, path.Path)); EventLogger.LogToConsole(SR.GetString(SR.WebHostScriptMappingsRemoveMap, path.Path)); } displayedUninstallMessage = true; } scriptMapCollection.Remove(scriptMap); } } path.CommitChanges(); } if (this.recursive || this.isReinstalling) { foreach (DirectoryEntry childPath in path.Children) { UninstallScriptMapFromPath(childPath, outputLevel); } } } internal override InstallationState VerifyInstall() { InstallationState installState = InstallationState.Unknown; if (this.IsInstalled) { installState = InstallationState.InstalledDefaults; } 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
- TextComposition.cs
- DelegateBodyWriter.cs
- ApplicationServicesHostFactory.cs
- TextFragmentEngine.cs
- PhonemeEventArgs.cs
- XmlSchemaCollection.cs
- InternalConfigHost.cs
- ParserOptions.cs
- AdRotatorDesigner.cs
- DataColumnPropertyDescriptor.cs
- FixedDocumentPaginator.cs
- DecodeHelper.cs
- SectionInformation.cs
- RepeatBehaviorConverter.cs
- FileDialog.cs
- BadImageFormatException.cs
- TypeInitializationException.cs
- HuffmanTree.cs
- Zone.cs
- XsltLoader.cs
- ScriptHandlerFactory.cs
- SimpleType.cs
- HtmlImage.cs
- CryptoHelper.cs
- ExpressionBindings.cs
- HandlerBase.cs
- ForeignConstraint.cs
- VisualTreeHelper.cs
- DataGridViewCellConverter.cs
- CancellationTokenRegistration.cs
- Stack.cs
- SqlException.cs
- Html32TextWriter.cs
- Size.cs
- ServicesUtilities.cs
- ConfigXmlWhitespace.cs
- TransformerInfo.cs
- XmlEncoding.cs
- BrowserCapabilitiesFactoryBase.cs
- ObjectIDGenerator.cs
- ClientScriptManagerWrapper.cs
- ElementMarkupObject.cs
- StyleModeStack.cs
- ScriptMethodAttribute.cs
- DiscoveryInnerClientAdhocCD1.cs
- TransformFinalBlockRequest.cs
- EndpointAddressMessageFilter.cs
- ExpanderAutomationPeer.cs
- PointHitTestResult.cs
- Visual3D.cs
- CurrencyManager.cs
- MyContact.cs
- Thread.cs
- AttributeQuery.cs
- ServiceInfo.cs
- DiscardableAttribute.cs
- FigureParaClient.cs
- MediaEntryAttribute.cs
- DataGridViewRowStateChangedEventArgs.cs
- Vector3DKeyFrameCollection.cs
- XmlReturnWriter.cs
- FixUpCollection.cs
- PeerNameResolver.cs
- DataReceivedEventArgs.cs
- LineGeometry.cs
- AesCryptoServiceProvider.cs
- MemoryFailPoint.cs
- _StreamFramer.cs
- WindowsAuthenticationModule.cs
- RijndaelManagedTransform.cs
- SecureConversationSecurityTokenParameters.cs
- RayMeshGeometry3DHitTestResult.cs
- AutomationElementCollection.cs
- ImageMapEventArgs.cs
- RequiredFieldValidator.cs
- SetUserPreferenceRequest.cs
- SiteMapDesignerDataSourceView.cs
- BasePropertyDescriptor.cs
- ListDependantCardsRequest.cs
- SizeChangedEventArgs.cs
- WindowsStatusBar.cs
- SmtpClient.cs
- Tokenizer.cs
- ToolStripDropDownItemDesigner.cs
- ClientSponsor.cs
- AutoGeneratedFieldProperties.cs
- SingletonChannelAcceptor.cs
- MetadataSource.cs
- Attributes.cs
- ClientEventManager.cs
- DataRecordObjectView.cs
- OracleTransaction.cs
- SetIterators.cs
- SafePointer.cs
- GenericIdentity.cs
- SamlAttribute.cs
- ConfigurationConverterBase.cs
- Not.cs
- DataGridViewMethods.cs
- ChameleonKey.cs