internal static T GetEnumValueFromRegistry <T>(string registryPath, string valueName, T defaultValue, Microsoft.Exchange.Diagnostics.Trace tracer) where T : struct { string valueFromRegistry = Globals.GetValueFromRegistry <string>(registryPath, valueName, defaultValue.ToString(), tracer); T result; if (Enum.TryParse <T>(valueFromRegistry, out result)) { tracer.TraceDebug <string, string>(0L, "Using enum {0} = {1} (from registry)", valueName, valueFromRegistry); return(result); } tracer.TraceError <string, string, T>(0L, "{0} has wrong enum value: {1}, using {2}.", valueName, valueFromRegistry, defaultValue); return(defaultValue); }
internal static T GetValueFromRegistry <T>(string registryPath, string valueName, T defaultValue, Microsoft.Exchange.Diagnostics.Trace tracer) { T result = defaultValue; try { using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(registryPath, false)) { if (registryKey != null) { object value = registryKey.GetValue(valueName, defaultValue); if (value is T) { tracer.TraceDebug <string, object>(0L, "Using {0} = {1} (from registry)", valueName, value); result = (T)((object)value); } else { tracer.TraceError <string, string, T>(0L, "{0} has wrong type {1}, using {2}.", valueName, (value == null) ? "<undefined>" : value.GetType().Name, defaultValue); } } else { tracer.TraceError <string, T>(0L, "Opening registry key {0} failed, using {1}.", valueName, defaultValue); } } } catch (SecurityException ex) { tracer.TraceError <string>(0L, "SecurityException: {0}", ex.Message); } catch (UnauthorizedAccessException ex2) { tracer.TraceError <string>(0L, "UnauthorizedAccessException: {0}", ex2.Message); } return(result); }
// Token: 0x0600003E RID: 62 RVA: 0x0000305A File Offset: 0x0000125A internal static void TraceDebug(Microsoft.Exchange.Diagnostics.Trace trace, string formatString, params object[] args) { trace.TraceDebug(0L, formatString + Logger.appDomainTraceInfo, args); }