Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / QueryOperators / ScanQueryOperator.cs / 1305376 / ScanQueryOperator.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ScanQueryOperator.cs // //[....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Threading; namespace System.Linq.Parallel { ////// A scan is just a simple operator that is positioned directly on top of some /// real data source. It's really just a place holder used during execution and /// analysis -- it should never actually get opened. /// ///internal sealed class ScanQueryOperator : QueryOperator { private readonly IEnumerable m_data; // The actual data source to scan. //------------------------------------------------------------------------------------ // Constructs a new scan on top of the target data source. // internal ScanQueryOperator(IEnumerable data) : base(Scheduling.DefaultPreserveOrder, QuerySettings.Empty) { Contract.Assert(data != null); ParallelEnumerableWrapper wrapper = data as ParallelEnumerableWrapper ; if (wrapper != null) { data = wrapper.WrappedEnumerable; } m_data = data; } //----------------------------------------------------------------------------------- // Accesses the underlying data source. // public IEnumerable Data { get { return m_data; } } //----------------------------------------------------------------------------------- // Override of the query operator base class's Open method. It creates a partitioned // stream that reads scans the data source. // internal override QueryResults Open(QuerySettings settings, bool preferStriping) { Contract.Assert(settings.DegreeOfParallelism.HasValue); IList dataAsList = m_data as IList ; if (dataAsList != null) { return new ListQueryResults (dataAsList, settings.DegreeOfParallelism.GetValueOrDefault(), preferStriping); } else { return new ScanEnumerableQueryOperatorResults(m_data, settings); } } //----------------------------------------------------------------------------------- // IEnumerable data source represented as QueryResults . Typically, we would not // use ScanEnumerableQueryOperatorResults if the data source implements IList . // internal override IEnumerator GetEnumerator(ParallelMergeOptions? mergeOptions, bool suppressOrderPreservation) { return m_data.GetEnumerator(); } //---------------------------------------------------------------------------------------- // Returns an enumerable that represents the query executing sequentially. // internal override IEnumerable AsSequentialQuery(CancellationToken token) { return m_data; } //--------------------------------------------------------------------------------------- // The state of the order index of the results returned by this operator. // internal override OrdinalIndexState OrdinalIndexState { get { return m_data is IList ? OrdinalIndexState.Indexible : OrdinalIndexState.Correct; } } //---------------------------------------------------------------------------------------- // Whether this operator performs a premature merge. // internal override bool LimitsParallelism { get { return false; } } private class ScanEnumerableQueryOperatorResults : QueryResults { private IEnumerable m_data; // The data source for the query private QuerySettings m_settings; // Settings collected from the query internal ScanEnumerableQueryOperatorResults(IEnumerable data, QuerySettings settings) { m_data = data; m_settings = settings; } internal override void GivePartitionedStream(IPartitionedStreamRecipient recipient) { // Since we are not using m_data as an IList, we can pass useStriping = false. PartitionedStream partitionedStream = ExchangeUtilities.PartitionDataSource( m_data, m_settings.DegreeOfParallelism.Value, false); recipient.Receive (partitionedStream); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // ScanQueryOperator.cs // // [....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Threading; namespace System.Linq.Parallel { ////// A scan is just a simple operator that is positioned directly on top of some /// real data source. It's really just a place holder used during execution and /// analysis -- it should never actually get opened. /// ///internal sealed class ScanQueryOperator : QueryOperator { private readonly IEnumerable m_data; // The actual data source to scan. //------------------------------------------------------------------------------------ // Constructs a new scan on top of the target data source. // internal ScanQueryOperator(IEnumerable data) : base(Scheduling.DefaultPreserveOrder, QuerySettings.Empty) { Contract.Assert(data != null); ParallelEnumerableWrapper wrapper = data as ParallelEnumerableWrapper ; if (wrapper != null) { data = wrapper.WrappedEnumerable; } m_data = data; } //----------------------------------------------------------------------------------- // Accesses the underlying data source. // public IEnumerable Data { get { return m_data; } } //----------------------------------------------------------------------------------- // Override of the query operator base class's Open method. It creates a partitioned // stream that reads scans the data source. // internal override QueryResults Open(QuerySettings settings, bool preferStriping) { Contract.Assert(settings.DegreeOfParallelism.HasValue); IList dataAsList = m_data as IList ; if (dataAsList != null) { return new ListQueryResults (dataAsList, settings.DegreeOfParallelism.GetValueOrDefault(), preferStriping); } else { return new ScanEnumerableQueryOperatorResults(m_data, settings); } } //----------------------------------------------------------------------------------- // IEnumerable data source represented as QueryResults . Typically, we would not // use ScanEnumerableQueryOperatorResults if the data source implements IList . // internal override IEnumerator GetEnumerator(ParallelMergeOptions? mergeOptions, bool suppressOrderPreservation) { return m_data.GetEnumerator(); } //---------------------------------------------------------------------------------------- // Returns an enumerable that represents the query executing sequentially. // internal override IEnumerable AsSequentialQuery(CancellationToken token) { return m_data; } //--------------------------------------------------------------------------------------- // The state of the order index of the results returned by this operator. // internal override OrdinalIndexState OrdinalIndexState { get { return m_data is IList ? OrdinalIndexState.Indexible : OrdinalIndexState.Correct; } } //---------------------------------------------------------------------------------------- // Whether this operator performs a premature merge. // internal override bool LimitsParallelism { get { return false; } } private class ScanEnumerableQueryOperatorResults : QueryResults { private IEnumerable m_data; // The data source for the query private QuerySettings m_settings; // Settings collected from the query internal ScanEnumerableQueryOperatorResults(IEnumerable data, QuerySettings settings) { m_data = data; m_settings = settings; } internal override void GivePartitionedStream(IPartitionedStreamRecipient recipient) { // Since we are not using m_data as an IList, we can pass useStriping = false. PartitionedStream partitionedStream = ExchangeUtilities.PartitionDataSource( m_data, m_settings.DegreeOfParallelism.Value, false); recipient.Receive (partitionedStream); } } } } // 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
- ScopeCompiler.cs
- Win32.cs
- FontCollection.cs
- SQLDateTime.cs
- BrowserDefinitionCollection.cs
- CompilerError.cs
- FeatureManager.cs
- _LazyAsyncResult.cs
- CookieProtection.cs
- GeometryGroup.cs
- ServicePrincipalNameElement.cs
- DataBoundControlParameterTarget.cs
- CompressedStack.cs
- WorkflowInstanceUnhandledExceptionRecord.cs
- DataTableMappingCollection.cs
- NonDualMessageSecurityOverHttpElement.cs
- BitmapEffectDrawing.cs
- SystemException.cs
- LambdaCompiler.Unary.cs
- BasicExpressionVisitor.cs
- ResXFileRef.cs
- BitmapCodecInfo.cs
- XmlSchemaSimpleContentExtension.cs
- SQLResource.cs
- TextCompositionEventArgs.cs
- ImageIndexConverter.cs
- XmlUtil.cs
- HtmlSelectionListAdapter.cs
- RegexCaptureCollection.cs
- EventLogPermissionEntryCollection.cs
- XPathQilFactory.cs
- thaishape.cs
- DirectoryLocalQuery.cs
- Quaternion.cs
- CallSiteBinder.cs
- PersistenceMetadataNamespace.cs
- HeaderedItemsControl.cs
- TemplateApplicationHelper.cs
- XmlSchemaAnnotated.cs
- ChannelBinding.cs
- TabItemAutomationPeer.cs
- DragDeltaEventArgs.cs
- ParagraphResult.cs
- CellRelation.cs
- Pts.cs
- recordstatefactory.cs
- GridSplitter.cs
- DSACryptoServiceProvider.cs
- PolyBezierSegment.cs
- VisualStyleRenderer.cs
- CoTaskMemSafeHandle.cs
- DataGridViewRowPrePaintEventArgs.cs
- SortedDictionary.cs
- Documentation.cs
- ProgressChangedEventArgs.cs
- KnownTypes.cs
- _SslState.cs
- BrowserCapabilitiesFactory.cs
- QueuePropertyVariants.cs
- NativeMsmqMessage.cs
- WindowsListBox.cs
- cookieexception.cs
- WindowsListViewItemCheckBox.cs
- MatchAllMessageFilter.cs
- HopperCache.cs
- OletxDependentTransaction.cs
- PrimitiveSchema.cs
- WorkflowTerminatedException.cs
- dtdvalidator.cs
- DataErrorValidationRule.cs
- EtwTrace.cs
- WasEndpointConfigContainer.cs
- DataRecordInfo.cs
- SupportsPreviewControlAttribute.cs
- ChannelCredentials.cs
- CollectionViewGroup.cs
- FormView.cs
- ProjectionAnalyzer.cs
- InputQueue.cs
- ComponentManagerBroker.cs
- IWorkflowDebuggerService.cs
- VideoDrawing.cs
- PackagingUtilities.cs
- OutOfProcStateClientManager.cs
- WindowHideOrCloseTracker.cs
- SqlNodeAnnotation.cs
- ToolStripSystemRenderer.cs
- TableLayout.cs
- ChangePasswordDesigner.cs
- PointConverter.cs
- SemanticAnalyzer.cs
- WebMessageFormatHelper.cs
- AssemblyBuilderData.cs
- SoapHeader.cs
- NonBatchDirectoryCompiler.cs
- ExitEventArgs.cs
- RegexRunner.cs
- LinqToSqlWrapper.cs
- UnsafeNativeMethods.cs
- SystemException.cs