Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / Util / Misc.cs / 1 / Misc.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Util { using System.Collections; using System.Globalization; using System.Runtime.InteropServices; using System.Text; using System.Web.Hosting; using Microsoft.Win32; internal sealed class Misc { const string APPLICATION_ID = "\r\n\r\nApplication ID: "; const string PROCESS_ID = "\r\n\r\nProcess ID: "; const string EXCEPTION = "\r\n\r\nException: "; const string INNER_EXCEPTION = "\r\n\r\nInnerException: "; const string MESSAGE = "\r\n\r\nMessage: "; const string STACK_TRACE = "\r\n\r\nStackTrace: "; static StringComparer s_caseInsensitiveInvariantKeyComparer; internal static StringComparer CaseInsensitiveInvariantKeyComparer { get { if (s_caseInsensitiveInvariantKeyComparer == null) { s_caseInsensitiveInvariantKeyComparer = StringComparer.Create(CultureInfo.InvariantCulture, true); } return s_caseInsensitiveInvariantKeyComparer; } } internal static void WriteUnhandledExceptionToEventLog(AppDomain appDomain, Exception exception) { if (appDomain == null || exception == null) { return; } ProcessImpersonationContext imperContext = null; try { imperContext = new ProcessImpersonationContext(); String appId = appDomain.GetData(".appId") as String; if (appId == null) { appId = appDomain.FriendlyName; } string pid = SafeNativeMethods.GetCurrentProcessId().ToString(CultureInfo.InstalledUICulture); string description = SR.Resources.GetString(SR.Unhandled_Exception, CultureInfo.InstalledUICulture); Misc.ReportUnhandledException(exception, new string[5] {description, APPLICATION_ID, appId, PROCESS_ID, pid}); } catch { // ignore exceptions so that WriteErrorToEventLog never throws } finally { if (imperContext != null) { imperContext.Undo(); } } } internal static void ReportUnhandledException(Exception e, String[] strings) { StringBuilder sb = new StringBuilder(4096); for (int i = 0; i < strings.Length; i++) { sb.Append(strings[i]); } for (Exception current = e; current != null; current = current.InnerException) { if (current == e) sb.Append(EXCEPTION); else sb.Append(INNER_EXCEPTION); sb.Append(current.GetType().FullName); sb.Append(MESSAGE); sb.Append(current.Message); sb.Append(STACK_TRACE); sb.Append(current.StackTrace); } UnsafeNativeMethods.ReportUnhandledException(sb.ToString()); } #if UNUSED_CODE static IKeyComparer s_caseSensitiveInvariantKeyComparer; internal static IKeyComparer CaseSensitiveInvariantKeyComparer { get { if (s_caseSensitiveInvariantKeyComparer == null) { s_caseSensitiveInvariantKeyComparer = KeyComparer.CreateKeyComparer(CultureInfo.InvariantCulture, false); } return s_caseSensitiveInvariantKeyComparer; } } #endif internal unsafe static void CopyMemory(IntPtr src, int srcOffset, byte[] dest, int destOffset, int size) { // System.Runtime.InteropServices.Marshal.Copy(new IntPtr(src.ToInt64()+srcOffset), dest, destOffset, size); } internal unsafe static void CopyMemory(byte[] src, int srcOffset, IntPtr dest, int destOffset, int size) { // System.Runtime.InteropServices.Marshal.Copy(src, srcOffset, new IntPtr(dest.ToInt64()+destOffset), size); } internal unsafe static void CopyMemory(IntPtr src, int srcOffset, IntPtr dest, int destOffset, int size) { byte *s = ((byte*)src) + srcOffset; byte *d = ((byte*)dest) + destOffset; StringUtil.memcpyimpl(s, d, size); } internal static void ThrowIfFailedHr(int hresult) { // SUCCEEDED >= 0 // FAILED < 0 if (hresult < 0) { Marshal.ThrowExceptionForHR(hresult); } } internal static IProcessHostSupportFunctions CreateLocalSupportFunctions(IProcessHostSupportFunctions proxyFunctions) { IProcessHostSupportFunctions localFunctions = null; // get the underlying COM object IntPtr pUnk = Marshal.GetIUnknownForObject(proxyFunctions); // this object isn't a COM object if (IntPtr.Zero == pUnk) { return null; } IntPtr ppv = IntPtr.Zero; try { // QI it for the interface Guid g = typeof(IProcessHostSupportFunctions).GUID; int hresult = Marshal.QueryInterface(pUnk, ref g, out ppv); if (hresult < 0) { Marshal.ThrowExceptionForHR(hresult); } // create a RCW we can hold onto in this domain // this bumps the ref count so we can drop our refs on the raw interfaces localFunctions = (IProcessHostSupportFunctions)Marshal.GetObjectForIUnknown(ppv); } finally { // drop our explicit refs and keep the managed instance if (IntPtr.Zero != ppv) { Marshal.Release(ppv); } if (IntPtr.Zero != pUnk) { Marshal.Release(pUnk); } } return localFunctions; } // Open ASP.NET's reg key, or one of its subkeys internal static RegistryKey OpenAspNetRegKey(string subKey) { String ver = VersionInfo.SystemWebVersion; // Zero out minor version number VSWhidbey 602541 // Eg. 2.0.50727.42 becomes 2.0.50727.0 if (!string.IsNullOrEmpty(ver)) { int pos = ver.LastIndexOf('.'); if (pos > -1) { ver = ver.Substring(0, pos + 1) + "0"; } } // The main ASP.NET reg key string key = @"Software\Microsoft\ASP.NET\" + ver; // If we're asked for a subkey, append it if (subKey != null) key += @"\" + subKey; // Open and return the key return Registry.LocalMachine.OpenSubKey(key); } // Get an ASP.NET registry value, from the main key or a subkey internal static object GetAspNetRegValue(string subKey, string valueName, object defaultValue) { try { using (RegistryKey regKey = OpenAspNetRegKey(subKey)) { // Return the default value if the key doesn't exist if (regKey == null) return defaultValue; return regKey.GetValue(valueName, defaultValue); } } catch { // Return the default value if anything goes wrong return defaultValue; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Util { using System.Collections; using System.Globalization; using System.Runtime.InteropServices; using System.Text; using System.Web.Hosting; using Microsoft.Win32; internal sealed class Misc { const string APPLICATION_ID = "\r\n\r\nApplication ID: "; const string PROCESS_ID = "\r\n\r\nProcess ID: "; const string EXCEPTION = "\r\n\r\nException: "; const string INNER_EXCEPTION = "\r\n\r\nInnerException: "; const string MESSAGE = "\r\n\r\nMessage: "; const string STACK_TRACE = "\r\n\r\nStackTrace: "; static StringComparer s_caseInsensitiveInvariantKeyComparer; internal static StringComparer CaseInsensitiveInvariantKeyComparer { get { if (s_caseInsensitiveInvariantKeyComparer == null) { s_caseInsensitiveInvariantKeyComparer = StringComparer.Create(CultureInfo.InvariantCulture, true); } return s_caseInsensitiveInvariantKeyComparer; } } internal static void WriteUnhandledExceptionToEventLog(AppDomain appDomain, Exception exception) { if (appDomain == null || exception == null) { return; } ProcessImpersonationContext imperContext = null; try { imperContext = new ProcessImpersonationContext(); String appId = appDomain.GetData(".appId") as String; if (appId == null) { appId = appDomain.FriendlyName; } string pid = SafeNativeMethods.GetCurrentProcessId().ToString(CultureInfo.InstalledUICulture); string description = SR.Resources.GetString(SR.Unhandled_Exception, CultureInfo.InstalledUICulture); Misc.ReportUnhandledException(exception, new string[5] {description, APPLICATION_ID, appId, PROCESS_ID, pid}); } catch { // ignore exceptions so that WriteErrorToEventLog never throws } finally { if (imperContext != null) { imperContext.Undo(); } } } internal static void ReportUnhandledException(Exception e, String[] strings) { StringBuilder sb = new StringBuilder(4096); for (int i = 0; i < strings.Length; i++) { sb.Append(strings[i]); } for (Exception current = e; current != null; current = current.InnerException) { if (current == e) sb.Append(EXCEPTION); else sb.Append(INNER_EXCEPTION); sb.Append(current.GetType().FullName); sb.Append(MESSAGE); sb.Append(current.Message); sb.Append(STACK_TRACE); sb.Append(current.StackTrace); } UnsafeNativeMethods.ReportUnhandledException(sb.ToString()); } #if UNUSED_CODE static IKeyComparer s_caseSensitiveInvariantKeyComparer; internal static IKeyComparer CaseSensitiveInvariantKeyComparer { get { if (s_caseSensitiveInvariantKeyComparer == null) { s_caseSensitiveInvariantKeyComparer = KeyComparer.CreateKeyComparer(CultureInfo.InvariantCulture, false); } return s_caseSensitiveInvariantKeyComparer; } } #endif internal unsafe static void CopyMemory(IntPtr src, int srcOffset, byte[] dest, int destOffset, int size) { // System.Runtime.InteropServices.Marshal.Copy(new IntPtr(src.ToInt64()+srcOffset), dest, destOffset, size); } internal unsafe static void CopyMemory(byte[] src, int srcOffset, IntPtr dest, int destOffset, int size) { // System.Runtime.InteropServices.Marshal.Copy(src, srcOffset, new IntPtr(dest.ToInt64()+destOffset), size); } internal unsafe static void CopyMemory(IntPtr src, int srcOffset, IntPtr dest, int destOffset, int size) { byte *s = ((byte*)src) + srcOffset; byte *d = ((byte*)dest) + destOffset; StringUtil.memcpyimpl(s, d, size); } internal static void ThrowIfFailedHr(int hresult) { // SUCCEEDED >= 0 // FAILED < 0 if (hresult < 0) { Marshal.ThrowExceptionForHR(hresult); } } internal static IProcessHostSupportFunctions CreateLocalSupportFunctions(IProcessHostSupportFunctions proxyFunctions) { IProcessHostSupportFunctions localFunctions = null; // get the underlying COM object IntPtr pUnk = Marshal.GetIUnknownForObject(proxyFunctions); // this object isn't a COM object if (IntPtr.Zero == pUnk) { return null; } IntPtr ppv = IntPtr.Zero; try { // QI it for the interface Guid g = typeof(IProcessHostSupportFunctions).GUID; int hresult = Marshal.QueryInterface(pUnk, ref g, out ppv); if (hresult < 0) { Marshal.ThrowExceptionForHR(hresult); } // create a RCW we can hold onto in this domain // this bumps the ref count so we can drop our refs on the raw interfaces localFunctions = (IProcessHostSupportFunctions)Marshal.GetObjectForIUnknown(ppv); } finally { // drop our explicit refs and keep the managed instance if (IntPtr.Zero != ppv) { Marshal.Release(ppv); } if (IntPtr.Zero != pUnk) { Marshal.Release(pUnk); } } return localFunctions; } // Open ASP.NET's reg key, or one of its subkeys internal static RegistryKey OpenAspNetRegKey(string subKey) { String ver = VersionInfo.SystemWebVersion; // Zero out minor version number VSWhidbey 602541 // Eg. 2.0.50727.42 becomes 2.0.50727.0 if (!string.IsNullOrEmpty(ver)) { int pos = ver.LastIndexOf('.'); if (pos > -1) { ver = ver.Substring(0, pos + 1) + "0"; } } // The main ASP.NET reg key string key = @"Software\Microsoft\ASP.NET\" + ver; // If we're asked for a subkey, append it if (subKey != null) key += @"\" + subKey; // Open and return the key return Registry.LocalMachine.OpenSubKey(key); } // Get an ASP.NET registry value, from the main key or a subkey internal static object GetAspNetRegValue(string subKey, string valueName, object defaultValue) { try { using (RegistryKey regKey = OpenAspNetRegKey(subKey)) { // Return the default value if the key doesn't exist if (regKey == null) return defaultValue; return regKey.GetValue(valueName, defaultValue); } } catch { // Return the default value if anything goes wrong return defaultValue; } } } } // 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
- MouseGestureConverter.cs
- Helper.cs
- SqlOuterApplyReducer.cs
- DynamicQueryableWrapper.cs
- WebServiceMethodData.cs
- _SslSessionsCache.cs
- EntityClassGenerator.cs
- MsmqTransportReceiveParameters.cs
- DiagnosticsConfiguration.cs
- DataSetUtil.cs
- VisemeEventArgs.cs
- WebPartTransformerAttribute.cs
- MemberInfoSerializationHolder.cs
- TypeInformation.cs
- WebUtility.cs
- DataServices.cs
- TextRangeBase.cs
- MobileCategoryAttribute.cs
- DispatcherHookEventArgs.cs
- EdmValidator.cs
- querybuilder.cs
- CodeNamespaceCollection.cs
- WebConfigurationHostFileChange.cs
- XmlMtomReader.cs
- ZoneButton.cs
- FormatException.cs
- QueryCoreOp.cs
- IdentityHolder.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- CodeCompileUnit.cs
- ManifestResourceInfo.cs
- AsyncResult.cs
- PrivilegedConfigurationManager.cs
- XPathSingletonIterator.cs
- WSDualHttpBindingCollectionElement.cs
- ExpressionEditorAttribute.cs
- HttpCachePolicyElement.cs
- ToolStripOverflow.cs
- diagnosticsswitches.cs
- RightsController.cs
- JoinSymbol.cs
- ReadingWritingEntityEventArgs.cs
- FirstMatchCodeGroup.cs
- RectIndependentAnimationStorage.cs
- BitmapPalettes.cs
- NetSectionGroup.cs
- LayoutTable.cs
- Trace.cs
- RegexTree.cs
- ContractNamespaceAttribute.cs
- ContentHostHelper.cs
- Schedule.cs
- SourceLineInfo.cs
- QueryCacheEntry.cs
- AnimatedTypeHelpers.cs
- PresentationTraceSources.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- FormatterServices.cs
- TextEndOfSegment.cs
- oledbconnectionstring.cs
- Component.cs
- XamlRtfConverter.cs
- HttpVersion.cs
- Permission.cs
- SmtpMail.cs
- KeyGestureValueSerializer.cs
- SQLDouble.cs
- ZeroOpNode.cs
- MultipleFilterMatchesException.cs
- ButtonBaseAutomationPeer.cs
- EllipseGeometry.cs
- ModuleElement.cs
- JapaneseCalendar.cs
- CodeAccessSecurityEngine.cs
- XmlDataLoader.cs
- EdmTypeAttribute.cs
- LicenseContext.cs
- NotificationContext.cs
- AutoGeneratedField.cs
- ValidationError.cs
- MonitorWrapper.cs
- ByteConverter.cs
- EntityWithKeyStrategy.cs
- WebPartDisplayModeCollection.cs
- StrongNameMembershipCondition.cs
- XmlDictionaryReaderQuotas.cs
- PropertyBuilder.cs
- DesignerActionPanel.cs
- Metadata.cs
- TextDecorationLocationValidation.cs
- documentsequencetextpointer.cs
- ComponentSerializationService.cs
- CodePropertyReferenceExpression.cs
- ApplicationServicesHostFactory.cs
- XmlArrayAttribute.cs
- XmlSchemaProviderAttribute.cs
- CellRelation.cs
- ChangeToolStripParentVerb.cs
- Classification.cs
- Size.cs