Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Log / System / IO / Log / LogRestartAreaEnumerator.cs / 1305376 / LogRestartAreaEnumerator.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IO.Log { using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; // See the notes on LogLogRecordEnumerator for why this is // thread-safe: the same arguments apply here. // class LogRestartAreaEnumerator : IEnumerator{ enum State { BeforeFirst, Valid, AfterLast, Disposed } LogRecordSequence recordSequence; State state; object syncRoot; SafeReadContext readContext; LogLogRecord current; internal LogRestartAreaEnumerator(LogRecordSequence recordSequence) { this.recordSequence = recordSequence; this.syncRoot = new object(); this.state = State.BeforeFirst; } object IEnumerator.Current { get { return this.Current; } } public LogRecord Current { get { lock(this.syncRoot) { if (this.state == State.Disposed) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); // IEnumerable interface contract for "current" member can throw InvalidOperationException. Suppressing this warning. if (this.state == State.BeforeFirst) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumNotStarted()); if (this.state == State.AfterLast) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumEnded()); return this.current; } } } public void Dispose() { lock(this.syncRoot) { if (this.current != null) { this.current.Detach(); this.current = null; } if ((this.readContext != null) && (!this.readContext.IsInvalid)) { this.readContext.Close(); } this.state = State.Disposed; } } public bool MoveNext() { lock(this.syncRoot) { if (this.state == State.Disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); if (this.state == State.AfterLast) return false; if (this.readContext == null) { return ReadRestartArea(); } else { if (this.current != null) this.current.Detach(); return ReadPreviousRestartArea(); } } } bool ReadRestartArea() { if (!((this.readContext == null || this.readContext.IsInvalid) && (this.current == null))) { // An internal consistency check has failed. The indicates a bug in IO.Log's internal processing // Rather than proceeding with non-deterministic execution and risking the loss or corruption of // log records, we failfast the process. DiagnosticUtility.FailFast("Should only call this for first record!"); } unsafe { byte *readBuffer; int bufferLength; ulong lsnRecord; if (!UnsafeNativeMethods.ReadLogRestartAreaSync( this.recordSequence.MarshalContext, out readBuffer, out bufferLength, out lsnRecord, out this.readContext)) { this.state = State.AfterLast; return false; } this.current = new LogLogRecord( new SequenceNumber(lsnRecord), SequenceNumber.Invalid, SequenceNumber.Invalid, readBuffer, bufferLength); this.state = State.Valid; return true; } } bool ReadPreviousRestartArea() { if (this.readContext == null || this.readContext.IsInvalid) { // An internal consistency check has failed. The indicates a bug in IO.Log's internal processing // Rather than proceeding with non-deterministic execution and risking the loss or corruption of // log records, we failfast the process. DiagnosticUtility.FailFast("Should only be called for records after the first!"); } unsafe { byte *readBuffer; int bufferLength; ulong lsnRecord; if (!UnsafeNativeMethods.ReadPreviousLogRestartAreaSync( this.readContext, out readBuffer, out bufferLength, out lsnRecord)) { this.state = State.AfterLast; return false; } this.current = new LogLogRecord( new SequenceNumber(lsnRecord), SequenceNumber.Invalid, SequenceNumber.Invalid, readBuffer, bufferLength); this.state = State.Valid; return true; } } public void Reset() { lock (this.syncRoot) { if (this.state == State.Disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); if (this.current != null) { this.current.Detach(); this.current = null; } if ((this.readContext != null) && (!this.readContext.IsInvalid)) { this.readContext.Close(); this.readContext = null; } this.state = State.BeforeFirst; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IO.Log { using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; // See the notes on LogLogRecordEnumerator for why this is // thread-safe: the same arguments apply here. // class LogRestartAreaEnumerator : IEnumerator { enum State { BeforeFirst, Valid, AfterLast, Disposed } LogRecordSequence recordSequence; State state; object syncRoot; SafeReadContext readContext; LogLogRecord current; internal LogRestartAreaEnumerator(LogRecordSequence recordSequence) { this.recordSequence = recordSequence; this.syncRoot = new object(); this.state = State.BeforeFirst; } object IEnumerator.Current { get { return this.Current; } } public LogRecord Current { get { lock(this.syncRoot) { if (this.state == State.Disposed) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); // IEnumerable interface contract for "current" member can throw InvalidOperationException. Suppressing this warning. if (this.state == State.BeforeFirst) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumNotStarted()); if (this.state == State.AfterLast) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumEnded()); return this.current; } } } public void Dispose() { lock(this.syncRoot) { if (this.current != null) { this.current.Detach(); this.current = null; } if ((this.readContext != null) && (!this.readContext.IsInvalid)) { this.readContext.Close(); } this.state = State.Disposed; } } public bool MoveNext() { lock(this.syncRoot) { if (this.state == State.Disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); if (this.state == State.AfterLast) return false; if (this.readContext == null) { return ReadRestartArea(); } else { if (this.current != null) this.current.Detach(); return ReadPreviousRestartArea(); } } } bool ReadRestartArea() { if (!((this.readContext == null || this.readContext.IsInvalid) && (this.current == null))) { // An internal consistency check has failed. The indicates a bug in IO.Log's internal processing // Rather than proceeding with non-deterministic execution and risking the loss or corruption of // log records, we failfast the process. DiagnosticUtility.FailFast("Should only call this for first record!"); } unsafe { byte *readBuffer; int bufferLength; ulong lsnRecord; if (!UnsafeNativeMethods.ReadLogRestartAreaSync( this.recordSequence.MarshalContext, out readBuffer, out bufferLength, out lsnRecord, out this.readContext)) { this.state = State.AfterLast; return false; } this.current = new LogLogRecord( new SequenceNumber(lsnRecord), SequenceNumber.Invalid, SequenceNumber.Invalid, readBuffer, bufferLength); this.state = State.Valid; return true; } } bool ReadPreviousRestartArea() { if (this.readContext == null || this.readContext.IsInvalid) { // An internal consistency check has failed. The indicates a bug in IO.Log's internal processing // Rather than proceeding with non-deterministic execution and risking the loss or corruption of // log records, we failfast the process. DiagnosticUtility.FailFast("Should only be called for records after the first!"); } unsafe { byte *readBuffer; int bufferLength; ulong lsnRecord; if (!UnsafeNativeMethods.ReadPreviousLogRestartAreaSync( this.readContext, out readBuffer, out bufferLength, out lsnRecord)) { this.state = State.AfterLast; return false; } this.current = new LogLogRecord( new SequenceNumber(lsnRecord), SequenceNumber.Invalid, SequenceNumber.Invalid, readBuffer, bufferLength); this.state = State.Valid; return true; } } public void Reset() { lock (this.syncRoot) { if (this.state == State.Disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); if (this.current != null) { this.current.Detach(); this.current = null; } if ((this.readContext != null) && (!this.readContext.IsInvalid)) { this.readContext.Close(); this.readContext = null; } this.state = State.BeforeFirst; } } } } // 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
- VolatileEnlistmentState.cs
- QueryStringParameter.cs
- DataTableNewRowEvent.cs
- ComAdminInterfaces.cs
- TagMapInfo.cs
- _TransmitFileOverlappedAsyncResult.cs
- RectValueSerializer.cs
- PointCollectionValueSerializer.cs
- SchemaConstraints.cs
- ReachDocumentReferenceSerializerAsync.cs
- SystemEvents.cs
- GridViewDeleteEventArgs.cs
- ThousandthOfEmRealPoints.cs
- ServicesExceptionNotHandledEventArgs.cs
- TypeNameConverter.cs
- PageThemeParser.cs
- CursorConverter.cs
- TreeViewImageIndexConverter.cs
- ImageMapEventArgs.cs
- XDRSchema.cs
- UnsafeNetInfoNativeMethods.cs
- MetadataArtifactLoaderCompositeFile.cs
- SoapObjectInfo.cs
- _Rfc2616CacheValidators.cs
- ComponentChangingEvent.cs
- QueryableFilterRepeater.cs
- Configuration.cs
- RenderContext.cs
- SafeEventLogReadHandle.cs
- SafeRightsManagementSessionHandle.cs
- SessionStateItemCollection.cs
- SmiRequestExecutor.cs
- Geometry.cs
- SchemaImporterExtension.cs
- CuspData.cs
- WebBrowserProgressChangedEventHandler.cs
- SHA1.cs
- MethodExpr.cs
- HitTestParameters3D.cs
- MenuItemStyleCollection.cs
- AssemblyCollection.cs
- FreezableCollection.cs
- ServerIdentity.cs
- ParsedAttributeCollection.cs
- Error.cs
- VisualBrush.cs
- ContainerUIElement3D.cs
- SettingsPropertyNotFoundException.cs
- GridViewCancelEditEventArgs.cs
- ResourcePart.cs
- FileRecordSequenceCompletedAsyncResult.cs
- Win32KeyboardDevice.cs
- ModuleConfigurationInfo.cs
- CompositeClientFormatter.cs
- SoapElementAttribute.cs
- ConditionCollection.cs
- NamedObject.cs
- NativeWindow.cs
- EventKeyword.cs
- ListBoxItem.cs
- TextBoxAutomationPeer.cs
- ProcessHostMapPath.cs
- RequestCachingSection.cs
- SrgsText.cs
- Bezier.cs
- GridViewDeleteEventArgs.cs
- InteropBitmapSource.cs
- TextTreeRootNode.cs
- DataViewListener.cs
- Panel.cs
- FieldAccessException.cs
- XamlStream.cs
- TrayIconDesigner.cs
- GeneralTransformGroup.cs
- EntityDataSourceColumn.cs
- ToolStripOverflow.cs
- WebPartPersonalization.cs
- XamlStyleSerializer.cs
- ScopedKnownTypes.cs
- ConfigsHelper.cs
- designeractionlistschangedeventargs.cs
- Metadata.cs
- ActiveDocumentEvent.cs
- NetSectionGroup.cs
- NetworkInformationPermission.cs
- Int32CAMarshaler.cs
- SolidColorBrush.cs
- UnsafeNativeMethods.cs
- DataGridViewComboBoxEditingControl.cs
- XmlCompatibilityReader.cs
- VerificationAttribute.cs
- DispatcherEventArgs.cs
- dsa.cs
- DataBindingHandlerAttribute.cs
- FilterQuery.cs
- PriorityBindingExpression.cs
- SerializationEventsCache.cs
- ConfigurationStrings.cs
- EntityDataSourceValidationException.cs
- CookielessData.cs