Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / SMDiagnostics / System / ServiceModel / Diagnostics / SafeEventLogWriteHandle.cs / 1305376 / SafeEventLogWriteHandle.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using Microsoft.Win32.SafeHandles; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Globalization; using System.Diagnostics; using System.Security; using System.Runtime; [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] sealed class SafeEventLogWriteHandle : SafeHandleZeroOrMinusOneIsInvalid { // Note: RegisterEventSource returns 0 on failure [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] SafeEventLogWriteHandle() : base(true) { } [ResourceConsumption(ResourceScope.Machine)] [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] internal static SafeEventLogWriteHandle RegisterEventSource(string uncServerName, string sourceName) { SafeEventLogWriteHandle retval = NativeMethods.RegisterEventSource(uncServerName, sourceName); int error = Marshal.GetLastWin32Error(); if (retval.IsInvalid) { Debug.Print("SafeEventLogWriteHandle::RegisterEventSource[" + uncServerName + ", " + sourceName + "] Failed. Last Error: " + error.ToString(CultureInfo.InvariantCulture)); } return retval; } [DllImport("advapi32", SetLastError = true)] [ResourceExposure(ResourceScope.None)] private static extern bool DeregisterEventSource(IntPtr hEventLog); #pragma warning disable 56523 [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] override protected bool ReleaseHandle() { return DeregisterEventSource(this.handle); } #pragma warning restore 56523 } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using Microsoft.Win32.SafeHandles; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Globalization; using System.Diagnostics; using System.Security; using System.Runtime; [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] sealed class SafeEventLogWriteHandle : SafeHandleZeroOrMinusOneIsInvalid { // Note: RegisterEventSource returns 0 on failure [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] SafeEventLogWriteHandle() : base(true) { } [ResourceConsumption(ResourceScope.Machine)] [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] internal static SafeEventLogWriteHandle RegisterEventSource(string uncServerName, string sourceName) { SafeEventLogWriteHandle retval = NativeMethods.RegisterEventSource(uncServerName, sourceName); int error = Marshal.GetLastWin32Error(); if (retval.IsInvalid) { Debug.Print("SafeEventLogWriteHandle::RegisterEventSource[" + uncServerName + ", " + sourceName + "] Failed. Last Error: " + error.ToString(CultureInfo.InvariantCulture)); } return retval; } [DllImport("advapi32", SetLastError = true)] [ResourceExposure(ResourceScope.None)] private static extern bool DeregisterEventSource(IntPtr hEventLog); #pragma warning disable 56523 [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] override protected bool ReleaseHandle() { return DeregisterEventSource(this.handle); } #pragma warning restore 56523 } } // 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
- CompilerResults.cs
- MouseGesture.cs
- BitmapImage.cs
- ConnectorRouter.cs
- LoadRetryHandler.cs
- nulltextcontainer.cs
- SchemeSettingElement.cs
- TemplatePropertyEntry.cs
- AutomationPatternInfo.cs
- CheckBoxList.cs
- ShadowGlyph.cs
- HttpCookie.cs
- Reference.cs
- WindowsIdentity.cs
- HelloOperationAsyncResult.cs
- SecurityContext.cs
- XmlBindingWorker.cs
- HwndKeyboardInputProvider.cs
- ToolBar.cs
- ServerTooBusyException.cs
- SelfIssuedAuthRSAPKCS1SignatureDeformatter.cs
- BinHexDecoder.cs
- GC.cs
- FormViewCommandEventArgs.cs
- DoubleStorage.cs
- QueryParameter.cs
- EntityKey.cs
- Thread.cs
- BrushValueSerializer.cs
- Composition.cs
- EdmValidator.cs
- AssemblyCacheEntry.cs
- ConfigurationStrings.cs
- ADMembershipProvider.cs
- ExpressionBuilderCollection.cs
- PartBasedPackageProperties.cs
- DrawingBrush.cs
- followingquery.cs
- DataView.cs
- SByteConverter.cs
- OleDbCommand.cs
- InstanceOwnerQueryResult.cs
- FlowPosition.cs
- ComponentResourceKey.cs
- ExpressionBuilder.cs
- GridViewSortEventArgs.cs
- ScriptResourceInfo.cs
- CertificateReferenceElement.cs
- SslStreamSecurityBindingElement.cs
- EntityDesignerUtils.cs
- KeyValuePairs.cs
- TabPage.cs
- PersonalizationStateInfoCollection.cs
- XamlInt32CollectionSerializer.cs
- XComponentModel.cs
- PermissionAttributes.cs
- NativeMethods.cs
- RewritingPass.cs
- ObjectNavigationPropertyMapping.cs
- ObjectManager.cs
- ListSortDescription.cs
- ServiceHttpModule.cs
- SoapFormatter.cs
- serverconfig.cs
- WebBrowserProgressChangedEventHandler.cs
- DataTableMappingCollection.cs
- GridViewDeletedEventArgs.cs
- ClientCultureInfo.cs
- InputLanguageCollection.cs
- SqlDataSource.cs
- sitestring.cs
- HttpRequestTraceRecord.cs
- SecurityElement.cs
- RelationshipNavigation.cs
- DefaultPropertyAttribute.cs
- DataGridAddNewRow.cs
- XmlUtilWriter.cs
- DecimalFormatter.cs
- HostedHttpTransportManager.cs
- ExpandableObjectConverter.cs
- WebSysDisplayNameAttribute.cs
- IntSecurity.cs
- DynamicActionMessageFilter.cs
- MobileControlsSectionHelper.cs
- WebReferencesBuildProvider.cs
- ControlDesignerState.cs
- AssemblyAttributesGoHere.cs
- DataServiceBuildProvider.cs
- StrokeNodeOperations2.cs
- TreeNode.cs
- HtmlHead.cs
- AsymmetricSecurityProtocolFactory.cs
- SuppressMessageAttribute.cs
- UnsafeNativeMethodsTablet.cs
- DrawingVisual.cs
- XmlSchemaComplexType.cs
- latinshape.cs
- OutputScopeManager.cs
- QilList.cs
- UniformGrid.cs