Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Log / System / IO / Log / FileLogRecordEnumerator.cs / 1305376 / FileLogRecordEnumerator.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IO.Log { using System; using System.Collections; using System.Collections.Generic; internal class FileLogRecordEnumerable : IEnumerable{ LogRecordEnumeratorType logRecordEnum; SimpleFileLog log; SequenceNumber start; bool enumRestartAreas; internal FileLogRecordEnumerable( SimpleFileLog log, SequenceNumber start, LogRecordEnumeratorType logRecordEnum, bool enumRestartAreas) { this.log = log; this.start = start; this.logRecordEnum = logRecordEnum; this.enumRestartAreas = enumRestartAreas; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public IEnumerator GetEnumerator() { return new FileLogRecordEnumerator( log, start, logRecordEnum, enumRestartAreas); } } internal class FileLogRecordEnumerator : IEnumerator { FileLogRecordStream stream = null; FileLogRecord record = null; bool enumStarted = false; SequenceNumber start; SequenceNumber current; LogRecordEnumeratorType logRecordEnum; SimpleFileLog log; bool disposed = false; bool enumRestartAreas; internal FileLogRecordEnumerator( SimpleFileLog log, SequenceNumber start, LogRecordEnumeratorType logRecordEnum, bool enumRestartAreas) { this.log = log; this.start = start; this.current = start; this.logRecordEnum = logRecordEnum; this.enumRestartAreas = enumRestartAreas; } object IEnumerator.Current { get { return this.Current; } } public LogRecord Current { get { if (this.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.enumStarted) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumNotStarted()); if (this.record == null) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumEnded()); return this.record; } } public bool MoveNext() { if (this.disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); if (this.current == SequenceNumber.Invalid) return false; if (!this.enumStarted) { this.enumStarted = true; } else { switch (this.logRecordEnum) { case LogRecordEnumeratorType.Next: this.current = this.stream.NextLsn; break; case LogRecordEnumeratorType.Previous: this.current = this.stream.Header.PreviousLsn; break; case LogRecordEnumeratorType.User: this.current = this.stream.Header.NextUndoLsn; break; } } SequenceNumber first; SequenceNumber last; log.GetLogLimits(out first, out last); if (this.current < first || last < this.current || this.current == SequenceNumber.Invalid) { this.record = null; return false; } this.stream = new FileLogRecordStream(this.log, this.current); if (!this.enumRestartAreas && this.stream.Header.IsRestartArea) { if (this.logRecordEnum == LogRecordEnumeratorType.Next) { // Move to the next record after restart area. return MoveNext(); } else { // We have hit a restart area. // Restart areas have special values for prev and next undo in the header. // Cannot enumerate further. this.record = null; return false; } } this.record = new FileLogRecord(this.stream); return true; } public void Reset() { if (this.disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); this.enumStarted = false; this.current = this.start; this.record = null; } public void Dispose() { this.disposed = true; } } } // 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; internal class FileLogRecordEnumerable : IEnumerable { LogRecordEnumeratorType logRecordEnum; SimpleFileLog log; SequenceNumber start; bool enumRestartAreas; internal FileLogRecordEnumerable( SimpleFileLog log, SequenceNumber start, LogRecordEnumeratorType logRecordEnum, bool enumRestartAreas) { this.log = log; this.start = start; this.logRecordEnum = logRecordEnum; this.enumRestartAreas = enumRestartAreas; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public IEnumerator GetEnumerator() { return new FileLogRecordEnumerator( log, start, logRecordEnum, enumRestartAreas); } } internal class FileLogRecordEnumerator : IEnumerator { FileLogRecordStream stream = null; FileLogRecord record = null; bool enumStarted = false; SequenceNumber start; SequenceNumber current; LogRecordEnumeratorType logRecordEnum; SimpleFileLog log; bool disposed = false; bool enumRestartAreas; internal FileLogRecordEnumerator( SimpleFileLog log, SequenceNumber start, LogRecordEnumeratorType logRecordEnum, bool enumRestartAreas) { this.log = log; this.start = start; this.current = start; this.logRecordEnum = logRecordEnum; this.enumRestartAreas = enumRestartAreas; } object IEnumerator.Current { get { return this.Current; } } public LogRecord Current { get { if (this.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.enumStarted) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumNotStarted()); if (this.record == null) #pragma warning suppress 56503 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.EnumEnded()); return this.record; } } public bool MoveNext() { if (this.disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); if (this.current == SequenceNumber.Invalid) return false; if (!this.enumStarted) { this.enumStarted = true; } else { switch (this.logRecordEnum) { case LogRecordEnumeratorType.Next: this.current = this.stream.NextLsn; break; case LogRecordEnumeratorType.Previous: this.current = this.stream.Header.PreviousLsn; break; case LogRecordEnumeratorType.User: this.current = this.stream.Header.NextUndoLsn; break; } } SequenceNumber first; SequenceNumber last; log.GetLogLimits(out first, out last); if (this.current < first || last < this.current || this.current == SequenceNumber.Invalid) { this.record = null; return false; } this.stream = new FileLogRecordStream(this.log, this.current); if (!this.enumRestartAreas && this.stream.Header.IsRestartArea) { if (this.logRecordEnum == LogRecordEnumeratorType.Next) { // Move to the next record after restart area. return MoveNext(); } else { // We have hit a restart area. // Restart areas have special values for prev and next undo in the header. // Cannot enumerate further. this.record = null; return false; } } this.record = new FileLogRecord(this.stream); return true; } public void Reset() { if (this.disposed) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed()); this.enumStarted = false; this.current = this.start; this.record = null; } public void Dispose() { this.disposed = true; } } } // 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
- ReachDocumentReferenceSerializerAsync.cs
- BinaryMethodMessage.cs
- ProcessModelSection.cs
- WinInet.cs
- DesignerImageAdapter.cs
- ComponentEditorPage.cs
- StrongNameSignatureInformation.cs
- EDesignUtil.cs
- ThreadPool.cs
- FontEmbeddingManager.cs
- Freezable.cs
- Section.cs
- hresults.cs
- MessageQueuePermission.cs
- TextProperties.cs
- GregorianCalendar.cs
- ApplicationProxyInternal.cs
- WebServiceErrorEvent.cs
- DataControlCommands.cs
- ProfileSettings.cs
- AsymmetricSignatureFormatter.cs
- ChainOfResponsibility.cs
- ReversePositionQuery.cs
- StateRuntime.cs
- HttpProfileBase.cs
- ProbeMatches11.cs
- ChangeNode.cs
- FilterQuery.cs
- PointConverter.cs
- GridItemCollection.cs
- AutomationElement.cs
- BufferedReceiveManager.cs
- Stopwatch.cs
- SolidColorBrush.cs
- FontFamilyIdentifier.cs
- SspiSecurityTokenParameters.cs
- ConfigurationStrings.cs
- ToolboxItemImageConverter.cs
- StringArrayConverter.cs
- ToolStripDropDownItemDesigner.cs
- COM2EnumConverter.cs
- DataServiceRequestOfT.cs
- Menu.cs
- SqlCommand.cs
- ToolStripPanelDesigner.cs
- Preprocessor.cs
- unitconverter.cs
- SrgsRule.cs
- InvalidPipelineStoreException.cs
- FragmentQuery.cs
- DataGridViewAddColumnDialog.cs
- PrePostDescendentsWalker.cs
- ProxyHwnd.cs
- HttpClientChannel.cs
- UnionCodeGroup.cs
- ObjectDataSourceEventArgs.cs
- ReachDocumentReferenceSerializer.cs
- MultiDataTrigger.cs
- FixedSOMPage.cs
- ZipIOLocalFileDataDescriptor.cs
- SemaphoreFullException.cs
- BitmapPalette.cs
- GlobalEventManager.cs
- NavigatorInput.cs
- BasicExpandProvider.cs
- SoapAttributeOverrides.cs
- PerformanceCounterPermissionEntry.cs
- securestring.cs
- XmlDocumentFragment.cs
- XmlSchemaAnnotated.cs
- FontFamilyValueSerializer.cs
- MD5Cng.cs
- ConditionalBranch.cs
- TextParagraphView.cs
- ProcessHostConfigUtils.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- CustomCredentialPolicy.cs
- ClipboardProcessor.cs
- LogicalTreeHelper.cs
- FaultContractAttribute.cs
- TypeToken.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- ImageSource.cs
- TableRowCollection.cs
- LinqDataSource.cs
- BlockCollection.cs
- SurrogateChar.cs
- FormViewInsertEventArgs.cs
- HtmlControlDesigner.cs
- PenThreadPool.cs
- QuaternionAnimation.cs
- DataGridItemCollection.cs
- TextBoxView.cs
- CapiNative.cs
- Point4DConverter.cs
- RightsManagementEncryptedStream.cs
- _FtpDataStream.cs
- ClientCredentialsElement.cs
- Compiler.cs
- WmlImageAdapter.cs