Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ // 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
- Unit.cs
- ArrayListCollectionBase.cs
- SamlConstants.cs
- CellParagraph.cs
- PassportPrincipal.cs
- ZipIOLocalFileHeader.cs
- MergablePropertyAttribute.cs
- ClientScriptItemCollection.cs
- FullTextLine.cs
- TemplatePropertyEntry.cs
- DataColumnCollection.cs
- WebServiceClientProxyGenerator.cs
- BoundingRectTracker.cs
- DataPager.cs
- SecurityResources.cs
- FormsAuthenticationCredentials.cs
- ParallelQuery.cs
- Size3D.cs
- QilCloneVisitor.cs
- _NegoState.cs
- Point3DCollectionValueSerializer.cs
- Vars.cs
- DataGridCommandEventArgs.cs
- PersonalizationStateInfo.cs
- WindowsNonControl.cs
- XmlSchemaComplexContent.cs
- sqlnorm.cs
- ObjectCloneHelper.cs
- FormsIdentity.cs
- StateMachineSubscription.cs
- TracedNativeMethods.cs
- Page.cs
- DataControlLinkButton.cs
- xmlfixedPageInfo.cs
- AudioSignalProblemOccurredEventArgs.cs
- XPathChildIterator.cs
- ItemCollection.cs
- unitconverter.cs
- DiscoveryInnerClientAdhoc11.cs
- OutputCache.cs
- _OverlappedAsyncResult.cs
- ListView.cs
- DispatcherHookEventArgs.cs
- MenuItem.cs
- KeyInterop.cs
- OutputWindow.cs
- ValueCollectionParameterReader.cs
- Triplet.cs
- MailSettingsSection.cs
- BookmarkUndoUnit.cs
- PointLightBase.cs
- ControlCachePolicy.cs
- IInstanceContextProvider.cs
- NavigationPropertyEmitter.cs
- ClientScriptManager.cs
- ArgumentOutOfRangeException.cs
- InternalConfigEventArgs.cs
- TextChange.cs
- TextOutput.cs
- DrawingAttributesDefaultValueFactory.cs
- DefaultTraceListener.cs
- NetTcpSection.cs
- TextBlockAutomationPeer.cs
- EndPoint.cs
- BuildProviderUtils.cs
- RepeaterCommandEventArgs.cs
- ReferentialConstraintRoleElement.cs
- TransportChannelListener.cs
- ListViewDataItem.cs
- ToolboxItemAttribute.cs
- Region.cs
- NaturalLanguageHyphenator.cs
- HttpResponseWrapper.cs
- LocalValueEnumerator.cs
- PageStatePersister.cs
- JapaneseCalendar.cs
- shaperfactoryquerycacheentry.cs
- SecurityUtils.cs
- AttributeUsageAttribute.cs
- Operand.cs
- NamedPipeChannelFactory.cs
- InstanceView.cs
- EditorZoneBase.cs
- ResponseStream.cs
- PersonalizationAdministration.cs
- DataGridViewCellFormattingEventArgs.cs
- OleStrCAMarshaler.cs
- Task.cs
- DataGridCellAutomationPeer.cs
- InvalidPipelineStoreException.cs
- PropertyPathWorker.cs
- PrivilegeNotHeldException.cs
- SineEase.cs
- XmlSchemaCompilationSettings.cs
- SqlFlattener.cs
- IndentedTextWriter.cs
- WebScriptMetadataInstanceContextProvider.cs
- ComAdminWrapper.cs
- MissingSatelliteAssemblyException.cs
- WindowsScrollBar.cs