Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / Util / versioninfo.cs / 2 / versioninfo.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* Support for getting file versions
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.Util {
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Runtime.Serialization.Formatters;
using System.Configuration.Assemblies;
//
// Support for getting file version of relevant files
//
internal class VersionInfo {
static private string _systemWebVersion;
static private string _engineVersion;
static private string _mscoreeVersion;
static private string _exeName;
static private object _lock = new object();
private VersionInfo() {
}
internal static string GetFileVersion(String filename) {
#if !FEATURE_PAL // FEATURE_PAL does not fully support FileVersionInfo
try {
FileVersionInfo ver = FileVersionInfo.GetVersionInfo(filename);
return string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}",
ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart);
}
catch {
return String.Empty;
}
#else // !FEATURE_PAL
// ROTORTODO
return String.Empty;
#endif // !FEATURE_PAL
}
internal static string GetLoadedModuleFileName(string module) {
#if !FEATURE_PAL // FEATURE_PAL does not fully support FileVersionInfo
IntPtr h = UnsafeNativeMethods.GetModuleHandle(module);
if (h == IntPtr.Zero)
return null;
StringBuilder buf = new StringBuilder(256);
if (UnsafeNativeMethods.GetModuleFileName(h, buf, 256) == 0)
return null;
String fileName = buf.ToString();
if (StringUtil.StringStartsWith(fileName, "\\\\?\\")) // on Whistler GetModuleFileName migth return this
fileName = fileName.Substring(4);
return fileName;
#else // !FEATURE_PAL
// ROTORTODO
return String.Empty;
#endif // !FEATURE_PAL
}
internal static string GetLoadedModuleVersion(string module) {
String filename = GetLoadedModuleFileName(module);
if (filename == null)
return null;
return GetFileVersion(filename);
}
internal static string SystemWebVersion {
get {
if (_systemWebVersion == null) {
lock(_lock) {
if (_systemWebVersion == null)
_systemWebVersion = GetFileVersion(typeof(HttpRuntime).Module.FullyQualifiedName);
}
}
return _systemWebVersion;
}
}
internal static string EngineVersion {
#if !FEATURE_PAL // FEATURE_PAL does not enable IIS-based hosting features
get {
if (_engineVersion == null) {
lock(_lock) {
if (_engineVersion == null)
_engineVersion = GetLoadedModuleVersion(ModName.ENGINE_FULL_NAME);
}
}
return _engineVersion;
#else // !FEATURE_PAL
// ROTORTODO
return "1.2.0.0";
#endif // !FEATURE_PAL
}
}
internal static string ClrVersion {
get {
if (_mscoreeVersion == null) {
lock(_lock) {
if (_mscoreeVersion == null)
_mscoreeVersion = GetLoadedModuleVersion("MSCORWKS.DLL");
}
}
return _mscoreeVersion;
}
}
internal static string ExeName {
get {
if (_exeName == null) {
lock(_lock) {
if (_exeName == null) {
String s = GetLoadedModuleFileName(null);
if (s == null)
s = String.Empty;
// strip path
int i = s.LastIndexOf('\\');
if (i >= 0)
s = s.Substring(i+1);
// strip extension
i = s.LastIndexOf('.');
if (i >= 0)
s = s.Substring(0, i);
_exeName = s.ToLower(CultureInfo.InvariantCulture);
}
}
}
return _exeName;
}
}
}
//
// Support for getting OS Flavor
//
internal enum OsFlavor {
Undetermined,
Other,
WebBlade,
StdServer,
AdvServer,
DataCenter,
}
#if UNUSED
internal class OsVersionInfo {
private const UInt32 VER_NT_WORKSTATION = 0x0000001;
private const UInt32 VER_NT_DOMAIN_CONTROLLER = 0x0000002;
private const UInt32 VER_NT_SERVER = 0x0000003;
private const UInt32 VER_SUITE_ENTERPRISE = 0x00000002;
private const UInt32 VER_SUITE_DATACENTER = 0x00000080;
private const UInt32 VER_SUITE_PERSONAL = 0x00000200;
private const UInt32 VER_SUITE_BLADE = 0x00000400;
internal static OsFlavor s_osFlavor = OsFlavor.Undetermined;
private OsVersionInfo() {
}
internal static OsFlavor CurrentOsFlavor {
get {
if (s_osFlavor == OsFlavor.Undetermined) {
#if !FEATURE_PAL // FEATURE_PAL has no defined OS Flavor
UnsafeNativeMethods.OSVERSIONINFOEX x = new UnsafeNativeMethods.OSVERSIONINFOEX();
if (UnsafeNativeMethods.GetVersionEx(x)) {
UInt32 product = (UInt32)x.wProductType;
UInt32 suite = (UInt32)x.wSuiteMask;
if (product == VER_NT_SERVER || product == VER_NT_DOMAIN_CONTROLLER) {
if ((suite&VER_SUITE_BLADE) != 0)
s_osFlavor = OsFlavor.WebBlade;
else if ((suite&VER_SUITE_ENTERPRISE) != 0)
s_osFlavor = OsFlavor.AdvServer;
else if ((suite&VER_SUITE_DATACENTER) != 0)
s_osFlavor = OsFlavor.DataCenter;
else
s_osFlavor = OsFlavor.StdServer;
}
else {
s_osFlavor = OsFlavor.Other;
}
}
#else // !FEATURE_PAL
// ROTORTODO
s_osFlavor = OsFlavor.Other;
#endif // !FEATURE_PAL
}
return s_osFlavor;
}
}
}
#endif
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* Support for getting file versions
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.Util {
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Runtime.Serialization.Formatters;
using System.Configuration.Assemblies;
//
// Support for getting file version of relevant files
//
internal class VersionInfo {
static private string _systemWebVersion;
static private string _engineVersion;
static private string _mscoreeVersion;
static private string _exeName;
static private object _lock = new object();
private VersionInfo() {
}
internal static string GetFileVersion(String filename) {
#if !FEATURE_PAL // FEATURE_PAL does not fully support FileVersionInfo
try {
FileVersionInfo ver = FileVersionInfo.GetVersionInfo(filename);
return string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}",
ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart);
}
catch {
return String.Empty;
}
#else // !FEATURE_PAL
// ROTORTODO
return String.Empty;
#endif // !FEATURE_PAL
}
internal static string GetLoadedModuleFileName(string module) {
#if !FEATURE_PAL // FEATURE_PAL does not fully support FileVersionInfo
IntPtr h = UnsafeNativeMethods.GetModuleHandle(module);
if (h == IntPtr.Zero)
return null;
StringBuilder buf = new StringBuilder(256);
if (UnsafeNativeMethods.GetModuleFileName(h, buf, 256) == 0)
return null;
String fileName = buf.ToString();
if (StringUtil.StringStartsWith(fileName, "\\\\?\\")) // on Whistler GetModuleFileName migth return this
fileName = fileName.Substring(4);
return fileName;
#else // !FEATURE_PAL
// ROTORTODO
return String.Empty;
#endif // !FEATURE_PAL
}
internal static string GetLoadedModuleVersion(string module) {
String filename = GetLoadedModuleFileName(module);
if (filename == null)
return null;
return GetFileVersion(filename);
}
internal static string SystemWebVersion {
get {
if (_systemWebVersion == null) {
lock(_lock) {
if (_systemWebVersion == null)
_systemWebVersion = GetFileVersion(typeof(HttpRuntime).Module.FullyQualifiedName);
}
}
return _systemWebVersion;
}
}
internal static string EngineVersion {
#if !FEATURE_PAL // FEATURE_PAL does not enable IIS-based hosting features
get {
if (_engineVersion == null) {
lock(_lock) {
if (_engineVersion == null)
_engineVersion = GetLoadedModuleVersion(ModName.ENGINE_FULL_NAME);
}
}
return _engineVersion;
#else // !FEATURE_PAL
// ROTORTODO
return "1.2.0.0";
#endif // !FEATURE_PAL
}
}
internal static string ClrVersion {
get {
if (_mscoreeVersion == null) {
lock(_lock) {
if (_mscoreeVersion == null)
_mscoreeVersion = GetLoadedModuleVersion("MSCORWKS.DLL");
}
}
return _mscoreeVersion;
}
}
internal static string ExeName {
get {
if (_exeName == null) {
lock(_lock) {
if (_exeName == null) {
String s = GetLoadedModuleFileName(null);
if (s == null)
s = String.Empty;
// strip path
int i = s.LastIndexOf('\\');
if (i >= 0)
s = s.Substring(i+1);
// strip extension
i = s.LastIndexOf('.');
if (i >= 0)
s = s.Substring(0, i);
_exeName = s.ToLower(CultureInfo.InvariantCulture);
}
}
}
return _exeName;
}
}
}
//
// Support for getting OS Flavor
//
internal enum OsFlavor {
Undetermined,
Other,
WebBlade,
StdServer,
AdvServer,
DataCenter,
}
#if UNUSED
internal class OsVersionInfo {
private const UInt32 VER_NT_WORKSTATION = 0x0000001;
private const UInt32 VER_NT_DOMAIN_CONTROLLER = 0x0000002;
private const UInt32 VER_NT_SERVER = 0x0000003;
private const UInt32 VER_SUITE_ENTERPRISE = 0x00000002;
private const UInt32 VER_SUITE_DATACENTER = 0x00000080;
private const UInt32 VER_SUITE_PERSONAL = 0x00000200;
private const UInt32 VER_SUITE_BLADE = 0x00000400;
internal static OsFlavor s_osFlavor = OsFlavor.Undetermined;
private OsVersionInfo() {
}
internal static OsFlavor CurrentOsFlavor {
get {
if (s_osFlavor == OsFlavor.Undetermined) {
#if !FEATURE_PAL // FEATURE_PAL has no defined OS Flavor
UnsafeNativeMethods.OSVERSIONINFOEX x = new UnsafeNativeMethods.OSVERSIONINFOEX();
if (UnsafeNativeMethods.GetVersionEx(x)) {
UInt32 product = (UInt32)x.wProductType;
UInt32 suite = (UInt32)x.wSuiteMask;
if (product == VER_NT_SERVER || product == VER_NT_DOMAIN_CONTROLLER) {
if ((suite&VER_SUITE_BLADE) != 0)
s_osFlavor = OsFlavor.WebBlade;
else if ((suite&VER_SUITE_ENTERPRISE) != 0)
s_osFlavor = OsFlavor.AdvServer;
else if ((suite&VER_SUITE_DATACENTER) != 0)
s_osFlavor = OsFlavor.DataCenter;
else
s_osFlavor = OsFlavor.StdServer;
}
else {
s_osFlavor = OsFlavor.Other;
}
}
#else // !FEATURE_PAL
// ROTORTODO
s_osFlavor = OsFlavor.Other;
#endif // !FEATURE_PAL
}
return s_osFlavor;
}
}
}
#endif
}
// 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
- CanonicalXml.cs
- ReliabilityContractAttribute.cs
- AccessDataSource.cs
- StaticExtension.cs
- PropertyChangeTracker.cs
- DocumentSchemaValidator.cs
- MetadataPropertyCollection.cs
- Crc32.cs
- ConfigurationManagerHelper.cs
- MultiBinding.cs
- MemberDescriptor.cs
- RuntimeConfigurationRecord.cs
- EnumerableRowCollectionExtensions.cs
- CompositeControl.cs
- WebPartDeleteVerb.cs
- PartialList.cs
- BackgroundFormatInfo.cs
- NumberFunctions.cs
- SocketElement.cs
- TypeHelpers.cs
- IsolatedStorageFilePermission.cs
- BaseInfoTable.cs
- QueryConverter.cs
- XMLDiffLoader.cs
- ErrorTableItemStyle.cs
- SelectedPathEditor.cs
- DependencyObject.cs
- AmbientEnvironment.cs
- ListControlDataBindingHandler.cs
- ConfigXmlCDataSection.cs
- EUCJPEncoding.cs
- PageStatePersister.cs
- PersonalizationState.cs
- SourceItem.cs
- RegexWorker.cs
- ManagedWndProcTracker.cs
- ConfigurationPropertyCollection.cs
- DbProviderSpecificTypePropertyAttribute.cs
- MatrixKeyFrameCollection.cs
- ErrorWebPart.cs
- BitmapImage.cs
- PersonalizationStateInfo.cs
- Divide.cs
- SoapAttributeAttribute.cs
- AppDomainUnloadedException.cs
- PassportPrincipal.cs
- CurrentChangedEventManager.cs
- SystemGatewayIPAddressInformation.cs
- PropertyEmitterBase.cs
- AutomationAttributeInfo.cs
- BitmapSource.cs
- codemethodreferenceexpression.cs
- unsafenativemethodstextservices.cs
- SessionStateItemCollection.cs
- MetadataArtifactLoaderCompositeFile.cs
- ToolStripPanelRow.cs
- CharAnimationBase.cs
- TextElementEditingBehaviorAttribute.cs
- DesigntimeLicenseContext.cs
- XmlDataProvider.cs
- SQlBooleanStorage.cs
- CodeTypeDeclarationCollection.cs
- Knowncolors.cs
- TreeNodeSelectionProcessor.cs
- BaseCollection.cs
- RunWorkerCompletedEventArgs.cs
- WebScriptMetadataFormatter.cs
- PrintControllerWithStatusDialog.cs
- ClientType.cs
- ZoneLinkButton.cs
- XmlTextReaderImpl.cs
- RequestCachingSection.cs
- ExpressionEditorAttribute.cs
- EditingCoordinator.cs
- DataKeyPropertyAttribute.cs
- GifBitmapEncoder.cs
- EdmToObjectNamespaceMap.cs
- ChangeBlockUndoRecord.cs
- MDIClient.cs
- WebControl.cs
- SqlUserDefinedTypeAttribute.cs
- Win32MouseDevice.cs
- PasswordPropertyTextAttribute.cs
- XPathDocument.cs
- CorrelationInitializer.cs
- TabControlAutomationPeer.cs
- ClientData.cs
- IndexerNameAttribute.cs
- NamedPipeWorkerProcess.cs
- OleDbDataReader.cs
- ContextMarshalException.cs
- ObsoleteAttribute.cs
- BaseTemplateCodeDomTreeGenerator.cs
- ImageInfo.cs
- EncryptedPackageFilter.cs
- ExpressionParser.cs
- RenderingBiasValidation.cs
- MsmqIntegrationChannelFactory.cs
- BindingManagerDataErrorEventArgs.cs
- SchemaImporter.cs