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
- ParsedAttributeCollection.cs
- SingletonInstanceContextProvider.cs
- ImmutablePropertyDescriptorGridEntry.cs
- FormCollection.cs
- CustomPopupPlacement.cs
- ConsoleCancelEventArgs.cs
- DeflateEmulationStream.cs
- MarkerProperties.cs
- ClientRequest.cs
- FixedDocumentPaginator.cs
- EdmMember.cs
- IndexedGlyphRun.cs
- ContextStack.cs
- SoapDocumentServiceAttribute.cs
- StaticFileHandler.cs
- RepeaterCommandEventArgs.cs
- PathStreamGeometryContext.cs
- MultiView.cs
- FaultCode.cs
- RecognizerInfo.cs
- RectAnimationBase.cs
- LookupBindingPropertiesAttribute.cs
- ResourceProperty.cs
- dbdatarecord.cs
- AsyncPostBackErrorEventArgs.cs
- codemethodreferenceexpression.cs
- WebServiceMethodData.cs
- FileDialogCustomPlacesCollection.cs
- RotateTransform.cs
- DataGridPagerStyle.cs
- XmlMemberMapping.cs
- SolidBrush.cs
- ThreadPool.cs
- bindurihelper.cs
- SystemColorTracker.cs
- TextContainerChangeEventArgs.cs
- ImageMap.cs
- FlagsAttribute.cs
- UIPermission.cs
- AssociationProvider.cs
- SecurityKeyUsage.cs
- BaseParser.cs
- MaskDescriptors.cs
- PngBitmapDecoder.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- IdnMapping.cs
- SectionUpdates.cs
- ReachSerializerAsync.cs
- XPathBinder.cs
- LocalizationParserHooks.cs
- TransformerInfo.cs
- TextCollapsingProperties.cs
- GeometryValueSerializer.cs
- SlotInfo.cs
- AppDomainProtocolHandler.cs
- LambdaCompiler.Binary.cs
- ScriptHandlerFactory.cs
- AnimationTimeline.cs
- TextEmbeddedObject.cs
- __FastResourceComparer.cs
- NGCPageContentCollectionSerializerAsync.cs
- FixedPageStructure.cs
- EventManager.cs
- ListParaClient.cs
- DropShadowBitmapEffect.cs
- DataRecordInfo.cs
- DataSourceXmlClassAttribute.cs
- ExpressionList.cs
- SettingsProviderCollection.cs
- OdbcFactory.cs
- SRGSCompiler.cs
- XmlAutoDetectWriter.cs
- UnsafeMethods.cs
- ListenerElementsCollection.cs
- WinFormsSpinner.cs
- MaskedTextBoxDesignerActionList.cs
- AccessKeyManager.cs
- SkipQueryOptionExpression.cs
- ToolStripDropDownClosedEventArgs.cs
- UIElement3D.cs
- AlternationConverter.cs
- Context.cs
- InstanceKeyCollisionException.cs
- CultureTableRecord.cs
- LifetimeMonitor.cs
- InlinedAggregationOperatorEnumerator.cs
- FileVersionInfo.cs
- Funcletizer.cs
- WorkflowMarkupSerializationManager.cs
- TextOnlyOutput.cs
- WindowsTokenRoleProvider.cs
- CellPartitioner.cs
- RtType.cs
- StructuredProperty.cs
- xml.cs
- RtfToken.cs
- Token.cs
- EqualityComparer.cs
- InputBinder.cs
- MergePropertyDescriptor.cs