Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Tools / WSATConfig / Configuration / RegistryExceptionHelper.cs / 1305376 / RegistryExceptionHelper.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.Tools.ServiceModel.WsatConfig
{
using Microsoft.Win32;
using System;
class RegistryExceptionHelper
{
string registryKey;
public RegistryExceptionHelper(string registryKey)
{
this.registryKey = registryKey;
EnsureEndsWithSlash(ref this.registryKey);
}
public RegistryExceptionHelper(string machineName, RegistryHive registryHive, string registryKeyRelativeToHive)
: this(RegistryExceptionHelper.GetRegistryKeyBase(machineName, registryHive) + registryKeyRelativeToHive)
{
}
public static void EnsureEndsWithSlash(ref string str)
{
if (!string.IsNullOrEmpty(str))
{
if (!str.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
{
str += '\\';
}
}
}
static string GetRegistryKeyBase(string machineName, RegistryHive registryHive)
{
string registryBase = Utilities.IsLocalMachineName(machineName) ? string.Empty : SR.GetString(SR.RemoteRegistryFormat, machineName);
switch (registryHive)
{
case RegistryHive.ClassesRoot:
registryBase += Registry.ClassesRoot.Name;
break;
case RegistryHive.CurrentUser:
registryBase += Registry.CurrentUser.Name;
break;
case RegistryHive.LocalMachine:
registryBase += Registry.LocalMachine.Name;
break;
default:
// We do not support other values here
System.Diagnostics.Debug.Assert(false, "registryHive is not supported");
break;
}
RegistryExceptionHelper.EnsureEndsWithSlash(ref registryBase);
return registryBase;
}
public WsatAdminException CreateRegistryAccessException(int errorCode)
{
return CreateRegistryAccessException(unchecked((uint)errorCode));
}
public WsatAdminException CreateRegistryAccessException(uint errorCode)
{
return new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.ErrorRegistryAccess, registryKey, errorCode));
}
public WsatAdminException CreateRegistryAccessException(Exception innerException)
{
return DoCreateRegistryAccessException(registryKey, innerException);
}
public WsatAdminException CreateRegistryAccessException(string subRegistryKey, Exception innerException)
{
return DoCreateRegistryAccessException(registryKey + subRegistryKey, innerException);
}
static WsatAdminException DoCreateRegistryAccessException(string regKey, Exception innerException)
{
if (innerException == null)
{
return new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.ErrorRegistryAccessNoErrorCode, regKey));
}
return new WsatAdminException(WsatAdminErrorCode.REGISTRY_ACCESS, SR.GetString(SR.ErrorRegistryAccessNoErrorCode, regKey), innerException);
}
public WsatAdminException CreateRegistryWriteException(Exception innerException)
{
return DoCreateRegistryWriteException(registryKey, innerException);
}
public WsatAdminException CreateRegistryWriteException(string subRegistryKey, Exception innerException)
{
return DoCreateRegistryWriteException(registryKey + subRegistryKey, innerException);
}
static WsatAdminException DoCreateRegistryWriteException(string regKey, Exception innerException)
{
if (innerException == null)
{
return new WsatAdminException(WsatAdminErrorCode.REGISTRY_WRITE, SR.GetString(SR.ErrorRegistryWrite, regKey));
}
return new WsatAdminException(WsatAdminErrorCode.REGISTRY_WRITE, SR.GetString(SR.ErrorRegistryWrite, regKey), innerException);
}
}
}
// 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
- DbMetaDataCollectionNames.cs
- TreeNodeBindingCollection.cs
- PageVisual.cs
- Scene3D.cs
- SafeViewOfFileHandle.cs
- IODescriptionAttribute.cs
- Viewport2DVisual3D.cs
- URLAttribute.cs
- GetLastErrorDetailsRequest.cs
- SparseMemoryStream.cs
- DiscardableAttribute.cs
- InternalDuplexBindingElement.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- LogWriteRestartAreaAsyncResult.cs
- UnsafeNativeMethods.cs
- TextControl.cs
- OleDbParameter.cs
- TabControlCancelEvent.cs
- AttributeEmitter.cs
- SqlInternalConnection.cs
- OpenFileDialog.cs
- Point4DConverter.cs
- securitycriticaldataformultiplegetandset.cs
- BlockUIContainer.cs
- SqlProviderManifest.cs
- StreamInfo.cs
- TextEmbeddedObject.cs
- HashLookup.cs
- OptimalBreakSession.cs
- UnmanagedMemoryStreamWrapper.cs
- ProvidersHelper.cs
- URLBuilder.cs
- WebHttpSecurity.cs
- PictureBox.cs
- ContentDisposition.cs
- HttpGetProtocolReflector.cs
- FieldInfo.cs
- RIPEMD160.cs
- ScrollViewerAutomationPeer.cs
- LocalizableResourceBuilder.cs
- DtdParser.cs
- XmlQueryRuntime.cs
- loginstatus.cs
- DescendantQuery.cs
- dbenumerator.cs
- DesigntimeLicenseContext.cs
- SelectionUIService.cs
- WebPartUtil.cs
- EditableTreeList.cs
- OdbcParameter.cs
- ThaiBuddhistCalendar.cs
- ViewPort3D.cs
- ControlPaint.cs
- InvalidateEvent.cs
- CodeMemberField.cs
- Transform.cs
- WebServiceParameterData.cs
- listitem.cs
- FolderBrowserDialog.cs
- ReadOnlyObservableCollection.cs
- VisualBasicHelper.cs
- MetadataItemCollectionFactory.cs
- MessageProtectionOrder.cs
- XsltContext.cs
- FixedSOMLineCollection.cs
- CompositeScriptReference.cs
- AdministrationHelpers.cs
- DefaultTypeArgumentAttribute.cs
- HiddenField.cs
- SystemParameters.cs
- FormatterServices.cs
- ECDsa.cs
- XmlTypeAttribute.cs
- contentDescriptor.cs
- BaseTreeIterator.cs
- XmlMtomReader.cs
- NodeFunctions.cs
- ErrorWrapper.cs
- Deflater.cs
- DateTime.cs
- BackStopAuthenticationModule.cs
- WebPartAddingEventArgs.cs
- QueryContinueDragEvent.cs
- FixUp.cs
- SpeechSeg.cs
- ConnectionInterfaceCollection.cs
- PKCS1MaskGenerationMethod.cs
- ObjectQueryProvider.cs
- storepermission.cs
- GlobalProxySelection.cs
- Style.cs
- SerialReceived.cs
- RelationshipFixer.cs
- IODescriptionAttribute.cs
- OleDbCommandBuilder.cs
- RowUpdatingEventArgs.cs
- ConnectionManagementSection.cs
- DataGridTablesFactory.cs
- PipelineComponent.cs
- VScrollProperties.cs