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
- ContextQuery.cs
- WorkflowDebuggerSteppingAttribute.cs
- CaretElement.cs
- NativeRightsManagementAPIsStructures.cs
- ApplicationServicesHostFactory.cs
- Label.cs
- CheckBoxStandardAdapter.cs
- OleDbConnectionInternal.cs
- RevocationPoint.cs
- GlyphShapingProperties.cs
- SmtpLoginAuthenticationModule.cs
- TitleStyle.cs
- URLEditor.cs
- XmlHierarchyData.cs
- OdbcException.cs
- Choices.cs
- ListViewItemSelectionChangedEvent.cs
- CalendarDateRange.cs
- InputReportEventArgs.cs
- XamlSerializerUtil.cs
- ResolveRequestResponseAsyncResult.cs
- _ListenerResponseStream.cs
- OleDbError.cs
- EndpointAddressElementBase.cs
- InternalConfigHost.cs
- TableItemPatternIdentifiers.cs
- DataGridViewComboBoxEditingControl.cs
- LinearKeyFrames.cs
- System.Data_BID.cs
- ServicePointManager.cs
- BrowserCapabilitiesCodeGenerator.cs
- XPathAxisIterator.cs
- FontSource.cs
- SelectionEditor.cs
- SchemaDeclBase.cs
- HighContrastHelper.cs
- ImageList.cs
- AvtEvent.cs
- cryptoapiTransform.cs
- SQLSingleStorage.cs
- MethodCallTranslator.cs
- SetterBaseCollection.cs
- ConnectionManagementElement.cs
- LayoutEngine.cs
- TableMethodGenerator.cs
- ToolStripDropDownItemDesigner.cs
- PageBuildProvider.cs
- XpsFilter.cs
- ToolStripActionList.cs
- httpapplicationstate.cs
- ApplicationCommands.cs
- DbConnectionPoolIdentity.cs
- WebPartAddingEventArgs.cs
- MembershipValidatePasswordEventArgs.cs
- GridEntry.cs
- ObjectSet.cs
- LightweightCodeGenerator.cs
- PointAnimation.cs
- ExpressionVisitor.cs
- WorkflowServiceAttributes.cs
- UriTemplateHelpers.cs
- EventDescriptor.cs
- SyndicationFeedFormatter.cs
- ListMarkerLine.cs
- ItemTypeToolStripMenuItem.cs
- CompilationLock.cs
- DataBoundControlAdapter.cs
- ComEventsInfo.cs
- ExpressionBuilderCollection.cs
- StylusEventArgs.cs
- Int32AnimationBase.cs
- EnumerableCollectionView.cs
- ListViewItemSelectionChangedEvent.cs
- DataRowCollection.cs
- Environment.cs
- PixelShader.cs
- RealizedColumnsBlock.cs
- GridItemProviderWrapper.cs
- SymLanguageType.cs
- ListMarkerSourceInfo.cs
- UnknownWrapper.cs
- XmlSchemaObjectTable.cs
- WebPartEditorCancelVerb.cs
- SoundPlayer.cs
- TemplateControlCodeDomTreeGenerator.cs
- DataConnectionHelper.cs
- SqlBooleanizer.cs
- XmlSchemaParticle.cs
- Timer.cs
- PartitionerQueryOperator.cs
- GlyphsSerializer.cs
- SecurityResources.cs
- TextDecorationLocationValidation.cs
- PrimitiveXmlSerializers.cs
- CngProperty.cs
- PropertyMap.cs
- RoutedEventConverter.cs
- SpAudioStreamWrapper.cs
- UpdatePanel.cs
- CatalogPartChrome.cs