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
- MultiDataTrigger.cs
- TimeIntervalCollection.cs
- OleDbConnectionFactory.cs
- StorageEndPropertyMapping.cs
- DBSqlParser.cs
- BindingUtils.cs
- StringReader.cs
- PointHitTestParameters.cs
- FileCodeGroup.cs
- SmtpFailedRecipientsException.cs
- FixedSOMPageConstructor.cs
- TraceSwitch.cs
- DataObjectFieldAttribute.cs
- EntityDataSourceQueryBuilder.cs
- BookmarkUndoUnit.cs
- Material.cs
- SocketElement.cs
- ServiceSecurityContext.cs
- BatchParser.cs
- LinkButton.cs
- CDSCollectionETWBCLProvider.cs
- CryptoProvider.cs
- VisualTreeHelper.cs
- DBConnectionString.cs
- StylusPointPropertyInfoDefaults.cs
- OdbcRowUpdatingEvent.cs
- SiteMapDataSourceDesigner.cs
- COM2ComponentEditor.cs
- MouseEvent.cs
- AuthenticatedStream.cs
- StreamUpgradeBindingElement.cs
- Transform3DGroup.cs
- ImageSourceValueSerializer.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- Animatable.cs
- TokenBasedSet.cs
- Rights.cs
- XmlDataLoader.cs
- SourceElementsCollection.cs
- MouseCaptureWithinProperty.cs
- SByteStorage.cs
- BypassElementCollection.cs
- SqlDataSourceCustomCommandEditor.cs
- EmptyImpersonationContext.cs
- Timer.cs
- SafePointer.cs
- SecurityException.cs
- BrowserCapabilitiesCodeGenerator.cs
- WindowsComboBox.cs
- WSFederationHttpSecurityElement.cs
- HashMembershipCondition.cs
- ContextStack.cs
- DebuggerAttributes.cs
- AppDomain.cs
- cache.cs
- QilDataSource.cs
- DirectionalLight.cs
- FixedDocumentPaginator.cs
- XmlElementAttribute.cs
- DataGridViewCellStyleConverter.cs
- Types.cs
- PackageRelationshipCollection.cs
- QueryCursorEventArgs.cs
- DataSvcMapFile.cs
- OleDbParameterCollection.cs
- DataGridRowClipboardEventArgs.cs
- IdentityModelDictionary.cs
- DbReferenceCollection.cs
- CodeSubDirectory.cs
- PropertyConverter.cs
- HandlerFactoryWrapper.cs
- Activator.cs
- FileEnumerator.cs
- DeleteIndexBinder.cs
- TypedDatasetGenerator.cs
- MachineKeySection.cs
- Code.cs
- ComponentChangedEvent.cs
- Baml6ConstructorInfo.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- RightsManagementInformation.cs
- DbConnectionPoolCounters.cs
- ByteStreamMessageEncodingElement.cs
- HtmlPhoneCallAdapter.cs
- XmlSchemaObjectTable.cs
- RealProxy.cs
- ScriptHandlerFactory.cs
- X509CertificateCollection.cs
- BooleanConverter.cs
- KeyGestureConverter.cs
- EntityDescriptor.cs
- AutoFocusStyle.xaml.cs
- Vector3DIndependentAnimationStorage.cs
- ProjectionQueryOptionExpression.cs
- InputMethod.cs
- DataGridViewCellStyleEditor.cs
- CodeTypeMember.cs
- PagesChangedEventArgs.cs
- NopReturnReader.cs
- TimerExtension.cs