Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Tools / xws_reg / System / ServiceModel / Install / Configuration / ListenerAdaptersInstallComponent.cs / 1 / ListenerAdaptersInstallComponent.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Install.Configuration { using WebAdmin = Microsoft.Web.Administration; using System; using System.ServiceModel; using System.Collections.Generic; using System.Configuration; using System.Globalization; using System.Reflection; using System.Security.Principal; using System.Text; using System.Web.Configuration; using System.Runtime.InteropServices; using System.ComponentModel; internal class ListenerAdaptersInstallComponent : ServiceModelInstallComponent { IIS7ConfigurationLoader configLoader; string displayString; string localServiceAccount; string name; ListenerAdaptersInstallComponent(string name, IIS7ConfigurationLoader configLoader) { if (!IisHelper.ShouldInstallWas || !IisHelper.ShouldInstallApplicationHost) { throw new WasNotInstalledException(SR.GetString(SR.WasNotInstalled, SR.GetString(SR.ListenerAdaptersName, name))); } this.name = name; // This account must match the same one in InstallServiceModelOperations.InstallOperations() if (!OSEnvironmentHelper.IsVistaOrGreater) { // this is not localized this.localServiceAccount = ServiceModelInstallStrings.LocalServiceAccountName; } else { // We use the hard-coded service SIDs because we cannot tell when the service is installed here. if (name.Equals(ServiceModelInstallStrings.NetTcp, StringComparison.OrdinalIgnoreCase)) { this.localServiceAccount = ServiceModelInstallStrings.Sid_NetTcpActivator; } else if (name.Equals(ServiceModelInstallStrings.NetPipe, StringComparison.OrdinalIgnoreCase)) { this.localServiceAccount = ServiceModelInstallStrings.Sid_NetPipeActivator; } else // if (name.Equals(ServiceModelInstallStrings.NetMsmq, StringComparison.OrdinalIgnoreCase) || name.Equals(ServiceModelInstallStrings.MsmqFormatName, StringComparison.OrdinalIgnoreCase)) { this.localServiceAccount = ServiceModelInstallStrings.Sid_NetMsmqActivator; } } this.configLoader = configLoader; } internal override string DisplayName { get {return this.displayString; } } protected override string InstallActionMessage { get {return SR.GetString(SR.ListenerAdaptersInstall, this.name); } } internal override string[] InstalledVersions { get { ListinstalledVersions = new List (); WebAdmin.ConfigurationElement listenerAdapter = this.GetListenerAdapterFromCollection(); if (null != listenerAdapter) { string identity = String.Empty; if (null != listenerAdapter.GetAttribute(ServiceModelInstallStrings.Identity)) { identity = (string)listenerAdapter.GetAttribute(ServiceModelInstallStrings.Identity).Value; } installedVersions.Add(SR.GetString(SR.ListenerAdaptersInstalledVersion, identity)); } return installedVersions.ToArray(); } } internal override bool IsInstalled { get { return (null != this.GetListenerAdapterFromCollection()); } } protected override string ReinstallActionMessage { get {return SR.GetString(SR.ListenerAdaptersReinstall, this.name); } } protected override string UninstallActionMessage { get {return SR.GetString(SR.ListenerAdaptersUninstall, this.name); } } internal static ListenerAdaptersInstallComponent CreateNativeListenerAdaptersInstallComponent(string name) { ListenerAdaptersInstallComponent listenerAdapters = new ListenerAdaptersInstallComponent(name, new IIS7ConfigurationLoader(new NativeConfigurationLoader())); listenerAdapters.displayString = SR.GetString(SR.ListenerAdaptersName, name); return listenerAdapters; } WebAdmin.ConfigurationElement GetListenerAdapterFromCollection() { WebAdmin.ConfigurationElement listenerAdapter = null; if (null != this.configLoader.ListenerAdaptersSection) { WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = this.configLoader.ListenerAdaptersSection.GetCollection(); // ListenerAdaptersCollection does not have a unique key, thus need to enumerate collection rather than check for key foreach (WebAdmin.ConfigurationElement element in listenerAdaptersCollection) { if (((string)element.GetAttribute(ServiceModelInstallStrings.Name).Value).Equals(this.name, StringComparison.OrdinalIgnoreCase)) { listenerAdapter = element; break; } } } return listenerAdapter; } internal override void Install(OutputLevel outputLevel) { if (!this.IsInstalled) { if (null != this.configLoader.ListenerAdaptersSection) { WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = this.configLoader.ListenerAdaptersSection.GetCollection(); WebAdmin.ConfigurationElement element = listenerAdaptersCollection.CreateElement(); element.GetAttribute(ServiceModelInstallStrings.Name).Value = this.name; element.GetAttribute(ServiceModelInstallStrings.Identity).Value = this.localServiceAccount; listenerAdaptersCollection.Add(element); configLoader.Save(); } else { throw new InvalidOperationException(SR.GetString(SR.IIS7ConfigurationSectionNotFound, this.configLoader.ListenerAdaptersSectionPath)); } } else { EventLogger.LogWarning(SR.GetString(SR.ListenerAdaptersAlreadyExists, name), OutputLevel.Verbose == outputLevel); } } internal override void Uninstall(OutputLevel outputLevel) { if (this.IsInstalled) { if (null != this.configLoader.ListenerAdaptersSection) { WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = this.configLoader.ListenerAdaptersSection.GetCollection(); // ListenerAdaptersCollection does not have a unique key, thus need to enumerate collection rather than check for key // Also, Microsoft.Web.Administration.ConfigurationElementCollection.Remove(element) does not work here. It // translates (bug?) to RemoveAt(-1) which fails. Instead, get index manually and call RemoveAt(int) directly. for(int i = 0; i < listenerAdaptersCollection.Count; i++) { WebAdmin.ConfigurationElement element = listenerAdaptersCollection[i]; if (((string)element.GetAttribute(ServiceModelInstallStrings.Name).Value).Equals(this.name, StringComparison.OrdinalIgnoreCase)) { listenerAdaptersCollection.RemoveAt(i); configLoader.Save(); break; } } } } else { EventLogger.LogWarning(SR.GetString(SR.ListenerAdaptersNotInstalled, name), OutputLevel.Verbose == outputLevel); } } internal override InstallationState VerifyInstall() { InstallationState installState = InstallationState.Unknown; if (this.IsInstalled) { WebAdmin.ConfigurationElement listenerAdapter = this.GetListenerAdapterFromCollection(); if (null != listenerAdapter.GetAttribute(ServiceModelInstallStrings.Identity) && ((string)listenerAdapter.GetAttribute(ServiceModelInstallStrings.Identity).Value).Equals(this.localServiceAccount, StringComparison.OrdinalIgnoreCase)) { installState = InstallationState.InstalledDefaults; } else { installState = InstallationState.InstalledCustom; } } 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
- DPTypeDescriptorContext.cs
- SourceLineInfo.cs
- PolicyLevel.cs
- MSHTMLHost.cs
- DiscoveryMessageSequence.cs
- NotifyParentPropertyAttribute.cs
- DataBoundLiteralControl.cs
- IDReferencePropertyAttribute.cs
- DeviceOverridableAttribute.cs
- ThicknessKeyFrameCollection.cs
- WindowPattern.cs
- MessageParameterAttribute.cs
- DataGridGeneralPage.cs
- LocalBuilder.cs
- PolyLineSegment.cs
- COM2AboutBoxPropertyDescriptor.cs
- AxisAngleRotation3D.cs
- FilterEventArgs.cs
- VerificationAttribute.cs
- ListViewContainer.cs
- HtmlTableRowCollection.cs
- securitycriticaldata.cs
- BuildResult.cs
- DoubleLink.cs
- NavigationPropertyEmitter.cs
- StylusPointPropertyId.cs
- AssemblyCollection.cs
- RTLAwareMessageBox.cs
- ElapsedEventArgs.cs
- NoClickablePointException.cs
- XmlIncludeAttribute.cs
- HWStack.cs
- XmlSchemaSimpleTypeUnion.cs
- DataGridItemCollection.cs
- InputBindingCollection.cs
- Point3DAnimation.cs
- DesignerCapabilities.cs
- DropDownList.cs
- EntityDataSourceChangedEventArgs.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- RMEnrollmentPage1.cs
- UpWmlMobileTextWriter.cs
- TextRunTypographyProperties.cs
- IgnoreFileBuildProvider.cs
- MessageFault.cs
- NameValuePair.cs
- LogReservationCollection.cs
- ContainerParaClient.cs
- EdmTypeAttribute.cs
- CursorInteropHelper.cs
- TreeBuilderXamlTranslator.cs
- OutputCacheSection.cs
- GridViewDeleteEventArgs.cs
- CodeTypeReferenceCollection.cs
- LinkButton.cs
- TypeDependencyAttribute.cs
- SubMenuStyleCollection.cs
- Message.cs
- ExpressionBuilder.cs
- SessionStateUtil.cs
- StringDictionary.cs
- DebugHandleTracker.cs
- XmlSchemaAnnotation.cs
- ResourcesGenerator.cs
- ProfileService.cs
- FontWeight.cs
- InputLanguageManager.cs
- BaseComponentEditor.cs
- Brushes.cs
- TreeNodeCollection.cs
- XamlWriter.cs
- WindowsHyperlink.cs
- OleAutBinder.cs
- LeafCellTreeNode.cs
- DynamicQueryableWrapper.cs
- ToolStripMenuItem.cs
- Int32Converter.cs
- DataTablePropertyDescriptor.cs
- CustomErrorCollection.cs
- InvokePatternIdentifiers.cs
- UnhandledExceptionEventArgs.cs
- GeneratedContractType.cs
- InfoCardSymmetricCrypto.cs
- CssClassPropertyAttribute.cs
- BitmapEffectInput.cs
- SystemIPv4InterfaceProperties.cs
- WebReferencesBuildProvider.cs
- TreeNodeEventArgs.cs
- QueueProcessor.cs
- PolyLineSegment.cs
- RegistrySecurity.cs
- MILUtilities.cs
- GradientBrush.cs
- ValueTable.cs
- CodeMethodReturnStatement.cs
- TextBoxBaseDesigner.cs
- FrameworkContextData.cs
- UnsafeNativeMethods.cs
- remotingproxy.cs
- AnnotationStore.cs