Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Tools / comsvcutil / WasAdminWrapper.cs / 1305376 / WasAdminWrapper.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.Tools.ServiceModel.ComSvcConfig
{
using System;
using System.ServiceModel.Channels;
using System.Diagnostics;
using System.DirectoryServices;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Security;
using System.ServiceModel;
using System.ServiceModel.Configuration;
using Microsoft.Tools.ServiceModel;
using Microsoft.Tools.ServiceModel.SvcUtil;
internal static class WasAdminWrapper
{
const string webService = "IIS://localhost/w3svc";
const string defaultWebServer = "1";
public static string DefaultWebServer
{
get { return webService + "/" + defaultWebServer; }
}
public static bool IsIISInstalled ()
{
try
{
DirectoryEntry webServiceEntry = new DirectoryEntry(webService);
foreach (DirectoryEntry child in webServiceEntry.Children)
return true;
}
catch (COMException)
{
return false;
}
return true;
}
public static string[] GetWebServerNames()
{
if (!IsIISInstalled ())
return null;
try
{
List webServerNames = new List();
DirectoryEntry webServiceEntry = new DirectoryEntry(webService);
foreach (DirectoryEntry child in webServiceEntry.Children)
{
if (child.SchemaClassName.ToUpperInvariant() == "IISWEBSERVER")
{
webServerNames.Add(webService + "/" + child.Name); // Note, child.Name is a number! the "friendly" name is actually child.Description
}
}
return webServerNames.ToArray();
}
catch (COMException ex)
{
// assume a failure here means that no web servers exist
ToolConsole.WriteWarning (SR.GetString(SR.CannotGetWebServersIgnoringWas,
ex.ErrorCode, ex.Message));
return null;
}
}
public static string[] GetWebDirectoryNames(string webServer)
{
if (!IsIISInstalled ())
return null;
try
{
List webDirectoryNames = new List();
DirectoryEntry webServiceEntry = new DirectoryEntry(webServer);
foreach (DirectoryEntry child in webServiceEntry.Children)
{
if (child.SchemaClassName.ToUpperInvariant () == "IISWEBDIRECTORY" || child.SchemaClassName.ToUpperInvariant() == "IISWEBVIRTUALDIR" )
{
webDirectoryNames.Add(child.Name);
// Must special case the "ROOT" vDir, since most actual vDirs are subchildren of the ROOT vdir of a server.
if (child.Name.ToUpperInvariant() == "ROOT")
{
foreach (DirectoryEntry rootChild in child.Children)
{
if (rootChild.SchemaClassName.ToUpperInvariant() == "IISWEBDIRECTORY" || rootChild.SchemaClassName.ToUpperInvariant() == "IISWEBVIRTUALDIR")
{
webDirectoryNames.Add("ROOT" + "/" + rootChild.Name);
}
}
}
}
}
return webDirectoryNames.ToArray();
}
catch (COMException ex)
{
// assume a failure here means that no web directory exist
ToolConsole.WriteWarning (SR.GetString(SR.CannotGetWebDirectoryForServer,
webServer, ex.ErrorCode, ex.Message));
return null;
}
}
public static bool GetWebDirectoryPath(string webServer, string webDirectory, out string webDirectoryPath)
{
webDirectoryPath = null;
if (!IsIISInstalled ())
return false;
if (!webDirectory.ToUpperInvariant().StartsWith("ROOT", StringComparison.Ordinal))
webDirectory = "root/" + webDirectory;
string [] webDirectories = GetWebDirectoryNames (webServer );
if (webDirectories == null)
return false;
bool found = false;
foreach (string webDirectoryName in webDirectories )
if (webDirectoryName.ToUpperInvariant () == webDirectory.ToUpperInvariant())
{
found = true;
break;
}
if (!found ) return false;
DirectoryEntry webDirectoryEntry = new DirectoryEntry(webServer + "/" + webDirectory);
try
{
if (webDirectoryEntry.Properties.Contains("Path"))
{
webDirectoryPath = (string)webDirectoryEntry.Properties["Path"].Value;
return true;
}
else
{
return false;
}
}
catch (COMException ex)
{
// assume a failure here means the dir does not exist
ToolConsole.WriteWarning (SR.GetString(SR.CannotGetWebDirectoryPathOnWebDirOfWebServIgnoring,
webServer, webDirectory, ex.ErrorCode, ex.Message));
return false;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.Tools.ServiceModel.ComSvcConfig
{
using System;
using System.ServiceModel.Channels;
using System.Diagnostics;
using System.DirectoryServices;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Security;
using System.ServiceModel;
using System.ServiceModel.Configuration;
using Microsoft.Tools.ServiceModel;
using Microsoft.Tools.ServiceModel.SvcUtil;
internal static class WasAdminWrapper
{
const string webService = "IIS://localhost/w3svc";
const string defaultWebServer = "1";
public static string DefaultWebServer
{
get { return webService + "/" + defaultWebServer; }
}
public static bool IsIISInstalled ()
{
try
{
DirectoryEntry webServiceEntry = new DirectoryEntry(webService);
foreach (DirectoryEntry child in webServiceEntry.Children)
return true;
}
catch (COMException)
{
return false;
}
return true;
}
public static string[] GetWebServerNames()
{
if (!IsIISInstalled ())
return null;
try
{
List webServerNames = new List();
DirectoryEntry webServiceEntry = new DirectoryEntry(webService);
foreach (DirectoryEntry child in webServiceEntry.Children)
{
if (child.SchemaClassName.ToUpperInvariant() == "IISWEBSERVER")
{
webServerNames.Add(webService + "/" + child.Name); // Note, child.Name is a number! the "friendly" name is actually child.Description
}
}
return webServerNames.ToArray();
}
catch (COMException ex)
{
// assume a failure here means that no web servers exist
ToolConsole.WriteWarning (SR.GetString(SR.CannotGetWebServersIgnoringWas,
ex.ErrorCode, ex.Message));
return null;
}
}
public static string[] GetWebDirectoryNames(string webServer)
{
if (!IsIISInstalled ())
return null;
try
{
List webDirectoryNames = new List();
DirectoryEntry webServiceEntry = new DirectoryEntry(webServer);
foreach (DirectoryEntry child in webServiceEntry.Children)
{
if (child.SchemaClassName.ToUpperInvariant () == "IISWEBDIRECTORY" || child.SchemaClassName.ToUpperInvariant() == "IISWEBVIRTUALDIR" )
{
webDirectoryNames.Add(child.Name);
// Must special case the "ROOT" vDir, since most actual vDirs are subchildren of the ROOT vdir of a server.
if (child.Name.ToUpperInvariant() == "ROOT")
{
foreach (DirectoryEntry rootChild in child.Children)
{
if (rootChild.SchemaClassName.ToUpperInvariant() == "IISWEBDIRECTORY" || rootChild.SchemaClassName.ToUpperInvariant() == "IISWEBVIRTUALDIR")
{
webDirectoryNames.Add("ROOT" + "/" + rootChild.Name);
}
}
}
}
}
return webDirectoryNames.ToArray();
}
catch (COMException ex)
{
// assume a failure here means that no web directory exist
ToolConsole.WriteWarning (SR.GetString(SR.CannotGetWebDirectoryForServer,
webServer, ex.ErrorCode, ex.Message));
return null;
}
}
public static bool GetWebDirectoryPath(string webServer, string webDirectory, out string webDirectoryPath)
{
webDirectoryPath = null;
if (!IsIISInstalled ())
return false;
if (!webDirectory.ToUpperInvariant().StartsWith("ROOT", StringComparison.Ordinal))
webDirectory = "root/" + webDirectory;
string [] webDirectories = GetWebDirectoryNames (webServer );
if (webDirectories == null)
return false;
bool found = false;
foreach (string webDirectoryName in webDirectories )
if (webDirectoryName.ToUpperInvariant () == webDirectory.ToUpperInvariant())
{
found = true;
break;
}
if (!found ) return false;
DirectoryEntry webDirectoryEntry = new DirectoryEntry(webServer + "/" + webDirectory);
try
{
if (webDirectoryEntry.Properties.Contains("Path"))
{
webDirectoryPath = (string)webDirectoryEntry.Properties["Path"].Value;
return true;
}
else
{
return false;
}
}
catch (COMException ex)
{
// assume a failure here means the dir does not exist
ToolConsole.WriteWarning (SR.GetString(SR.CannotGetWebDirectoryPathOnWebDirOfWebServIgnoring,
webServer, webDirectory, ex.ErrorCode, ex.Message));
return false;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListViewGroup.cs
- EditorZoneBase.cs
- RepeaterItemEventArgs.cs
- BaseTemplateCodeDomTreeGenerator.cs
- Aggregates.cs
- webeventbuffer.cs
- TextBoxRenderer.cs
- TextLine.cs
- WebEncodingValidatorAttribute.cs
- X509PeerCertificateAuthenticationElement.cs
- PublisherMembershipCondition.cs
- GridViewSortEventArgs.cs
- InternalTypeHelper.cs
- ReadOnlyCollectionBuilder.cs
- MD5.cs
- PersonalizationStateQuery.cs
- GridViewSortEventArgs.cs
- BindingCompleteEventArgs.cs
- IpcManager.cs
- FunctionMappingTranslator.cs
- DataStorage.cs
- ControlIdConverter.cs
- MetafileHeaderEmf.cs
- Function.cs
- ChineseLunisolarCalendar.cs
- Attribute.cs
- TypeConverter.cs
- SimpleWebHandlerParser.cs
- MexNamedPipeBindingElement.cs
- EmptyQuery.cs
- CancelEventArgs.cs
- VoiceInfo.cs
- RedBlackList.cs
- TemplateControlBuildProvider.cs
- Brush.cs
- HwndAppCommandInputProvider.cs
- GenericsInstances.cs
- ImpersonateTokenRef.cs
- KeyInfo.cs
- ServiceErrorHandler.cs
- StandardBindingElementCollection.cs
- CursorConverter.cs
- NamespaceEmitter.cs
- CompilerGlobalScopeAttribute.cs
- ButtonChrome.cs
- XmlSortKey.cs
- OptimalTextSource.cs
- CachedPathData.cs
- PeerNearMe.cs
- UnknownBitmapDecoder.cs
- DesignerSelectionListAdapter.cs
- ChildTable.cs
- Condition.cs
- RevocationPoint.cs
- SchemaConstraints.cs
- FixedSOMGroup.cs
- DataRecord.cs
- ParallelLoopState.cs
- Module.cs
- ImageCodecInfo.cs
- Hashtable.cs
- CompilationRelaxations.cs
- ProxySimple.cs
- MouseButtonEventArgs.cs
- Bitmap.cs
- AttributeCollection.cs
- DataGridItemAttachedStorage.cs
- CircleEase.cs
- CatalogZoneDesigner.cs
- WebRequestModuleElement.cs
- SoapParser.cs
- XDeferredAxisSource.cs
- RelativeSource.cs
- XmlObjectSerializerReadContextComplex.cs
- ContextQuery.cs
- CultureInfo.cs
- DataGridViewRowCollection.cs
- MembershipSection.cs
- SafeRightsManagementHandle.cs
- SafeThreadHandle.cs
- CompositeScriptReference.cs
- EditorServiceContext.cs
- JsonSerializer.cs
- PathFigureCollection.cs
- HandlerBase.cs
- GridEntry.cs
- SecurityBindingElementImporter.cs
- RectangleHotSpot.cs
- DataGridViewAccessibleObject.cs
- TextOnlyOutput.cs
- ExtentCqlBlock.cs
- SiteMembershipCondition.cs
- SymbolMethod.cs
- Transform3DCollection.cs
- Size3DConverter.cs
- _RequestCacheProtocol.cs
- AsyncPostBackTrigger.cs
- LogReservationCollection.cs
- TimelineGroup.cs
- FrameworkContentElementAutomationPeer.cs