Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / Internal / NeedSkipTokenVisitor.cs / 1305376 / NeedSkipTokenVisitor.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Visitor to evaluate if skip tokens are needed for an expansion
//
//
// @owner [....]
//---------------------------------------------------------------------
namespace System.Data.Services.Internal
{
#region Namespaces
using System.Collections.Generic;
using System.Data.Services.Providers;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
#endregion
///
/// Visitor to evaluate if skip tokens are needed for a given
///
internal sealed class NeedSkipTokenVisitor : ALinqExpressionVisitor
{
/// Resource type for which we are evaluating ordering expressions
private readonly ResourceType rt;
/// Resource property to which the ordering expression corresponds
private ResourceProperty property;
/// Initializes a new instance.
private NeedSkipTokenVisitor()
: this(null)
{
}
///
/// Initializes a new instance.
///
/// Resource type for which we are evaluating ordering expressions
private NeedSkipTokenVisitor(ResourceType rt)
{
this.rt = rt;
}
///
/// True of skiptoken is required for this instance, false otherwise
///
private bool NeedSkipToken
{
get;
set;
}
///
/// Resource property to which the ordering expression corresponds
///
private ResourceProperty Property
{
get
{
return this.rt != null ? this.property : null;
}
}
///
/// Finds out if the given required a skip token
/// expression in the expansion
///
/// Input orderingInfo.
/// true if skip token expression is needed, false otherwise
internal static bool IsSkipTokenRequired(OrderingInfo orderingInfo)
{
if (orderingInfo != null && orderingInfo.IsPaged)
{
foreach (OrderingExpression o in orderingInfo.OrderingExpressions)
{
LambdaExpression l = (LambdaExpression)o.Expression;
NeedSkipTokenVisitor visitor = new NeedSkipTokenVisitor();
visitor.Visit(l.Body);
if (visitor.NeedSkipToken)
{
return true;
}
}
}
return false;
}
///
/// Obtains a collection of resource properties that are needed for skip token generation
///
/// Input orderingInfo.
/// Resource type for which to collect the skip token properties
/// Collection of resource properties used in $skiptoken
internal static ICollection CollectSkipTokenProperties(OrderingInfo orderingInfo, ResourceType rt)
{
Debug.Assert(orderingInfo != null, "Must have valid ordering information to collect skip token properties");
Debug.Assert(orderingInfo.IsPaged, "Must have paging enabled to collection skip token properties");
List resourceProperties = new List();
foreach (OrderingExpression o in orderingInfo.OrderingExpressions)
{
LambdaExpression l = (LambdaExpression)o.Expression;
NeedSkipTokenVisitor visitor = new NeedSkipTokenVisitor(rt);
visitor.Visit(l.Body);
if (visitor.NeedSkipToken)
{
return null;
}
else
{
Debug.Assert(visitor.Property != null, "Must have a valid property if skip token is not needed");
resourceProperties.Add(visitor.Property);
}
}
return resourceProperties;
}
///
/// Override the method to decide if we need skip token expression in the expansion
///
/// Input expression
/// Output expression which is the same as input expression for this visitor
internal override Expression Visit(Expression exp)
{
if (exp == null)
{
return exp;
}
switch (exp.NodeType)
{
case ExpressionType.MemberAccess:
case ExpressionType.Parameter:
return base.Visit(exp);
default:
this.NeedSkipToken = true;
return exp;
}
}
///
/// Override for member access visitor
///
/// Member access expression
/// Same expressions as
internal override Expression VisitMemberAccess(MemberExpression m)
{
if (m.Member.MemberType != MemberTypes.Property || m.Expression.NodeType != ExpressionType.Parameter)
{
this.NeedSkipToken = true;
return m;
}
else
{
// Is this a visitor for collection of resource properties
if (this.rt != null)
{
this.property = this.rt.TryResolvePropertyName(m.Member.Name);
Debug.Assert(
this.property != null && this.property.ResourceType.ResourceTypeKind == ResourceTypeKind.Primitive,
"skip token should be made up of primitive properties.");
}
return base.VisitMemberAccess(m);
}
}
///
/// Override for parameter expression
///
/// Parameter expression
/// Same parameter as
internal override Expression VisitParameter(ParameterExpression p)
{
if (this.rt != null && p.Type != this.rt.InstanceType)
{
this.NeedSkipToken = true;
return p;
}
else
{
return base.VisitParameter(p);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Visitor to evaluate if skip tokens are needed for an expansion
//
//
// @owner [....]
//---------------------------------------------------------------------
namespace System.Data.Services.Internal
{
#region Namespaces
using System.Collections.Generic;
using System.Data.Services.Providers;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
#endregion
///
/// Visitor to evaluate if skip tokens are needed for a given
///
internal sealed class NeedSkipTokenVisitor : ALinqExpressionVisitor
{
/// Resource type for which we are evaluating ordering expressions
private readonly ResourceType rt;
/// Resource property to which the ordering expression corresponds
private ResourceProperty property;
/// Initializes a new instance.
private NeedSkipTokenVisitor()
: this(null)
{
}
///
/// Initializes a new instance.
///
/// Resource type for which we are evaluating ordering expressions
private NeedSkipTokenVisitor(ResourceType rt)
{
this.rt = rt;
}
///
/// True of skiptoken is required for this instance, false otherwise
///
private bool NeedSkipToken
{
get;
set;
}
///
/// Resource property to which the ordering expression corresponds
///
private ResourceProperty Property
{
get
{
return this.rt != null ? this.property : null;
}
}
///
/// Finds out if the given required a skip token
/// expression in the expansion
///
/// Input orderingInfo.
/// true if skip token expression is needed, false otherwise
internal static bool IsSkipTokenRequired(OrderingInfo orderingInfo)
{
if (orderingInfo != null && orderingInfo.IsPaged)
{
foreach (OrderingExpression o in orderingInfo.OrderingExpressions)
{
LambdaExpression l = (LambdaExpression)o.Expression;
NeedSkipTokenVisitor visitor = new NeedSkipTokenVisitor();
visitor.Visit(l.Body);
if (visitor.NeedSkipToken)
{
return true;
}
}
}
return false;
}
///
/// Obtains a collection of resource properties that are needed for skip token generation
///
/// Input orderingInfo.
/// Resource type for which to collect the skip token properties
/// Collection of resource properties used in $skiptoken
internal static ICollection CollectSkipTokenProperties(OrderingInfo orderingInfo, ResourceType rt)
{
Debug.Assert(orderingInfo != null, "Must have valid ordering information to collect skip token properties");
Debug.Assert(orderingInfo.IsPaged, "Must have paging enabled to collection skip token properties");
List resourceProperties = new List();
foreach (OrderingExpression o in orderingInfo.OrderingExpressions)
{
LambdaExpression l = (LambdaExpression)o.Expression;
NeedSkipTokenVisitor visitor = new NeedSkipTokenVisitor(rt);
visitor.Visit(l.Body);
if (visitor.NeedSkipToken)
{
return null;
}
else
{
Debug.Assert(visitor.Property != null, "Must have a valid property if skip token is not needed");
resourceProperties.Add(visitor.Property);
}
}
return resourceProperties;
}
///
/// Override the method to decide if we need skip token expression in the expansion
///
/// Input expression
/// Output expression which is the same as input expression for this visitor
internal override Expression Visit(Expression exp)
{
if (exp == null)
{
return exp;
}
switch (exp.NodeType)
{
case ExpressionType.MemberAccess:
case ExpressionType.Parameter:
return base.Visit(exp);
default:
this.NeedSkipToken = true;
return exp;
}
}
///
/// Override for member access visitor
///
/// Member access expression
/// Same expressions as
internal override Expression VisitMemberAccess(MemberExpression m)
{
if (m.Member.MemberType != MemberTypes.Property || m.Expression.NodeType != ExpressionType.Parameter)
{
this.NeedSkipToken = true;
return m;
}
else
{
// Is this a visitor for collection of resource properties
if (this.rt != null)
{
this.property = this.rt.TryResolvePropertyName(m.Member.Name);
Debug.Assert(
this.property != null && this.property.ResourceType.ResourceTypeKind == ResourceTypeKind.Primitive,
"skip token should be made up of primitive properties.");
}
return base.VisitMemberAccess(m);
}
}
///
/// Override for parameter expression
///
/// Parameter expression
/// Same parameter as
internal override Expression VisitParameter(ParameterExpression p)
{
if (this.rt != null && p.Type != this.rt.InstanceType)
{
this.NeedSkipToken = true;
return p;
}
else
{
return base.VisitParameter(p);
}
}
}
}
// 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
- Timeline.cs
- EdmComplexPropertyAttribute.cs
- CodeRemoveEventStatement.cs
- CaseInsensitiveOrdinalStringComparer.cs
- TakeOrSkipWhileQueryOperator.cs
- ObsoleteAttribute.cs
- OciHandle.cs
- CompoundFileDeflateTransform.cs
- DataGridPageChangedEventArgs.cs
- DesignerRegionMouseEventArgs.cs
- HttpHandlerActionCollection.cs
- ExtensionFile.cs
- Token.cs
- LocatorBase.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- EntityDataSourceConfigureObjectContext.cs
- DataGridHeaderBorder.cs
- QilLoop.cs
- RealizationContext.cs
- BrowserCapabilitiesCompiler.cs
- XmlUrlResolver.cs
- XmlUTF8TextWriter.cs
- XPathAncestorQuery.cs
- LiteralControl.cs
- HttpServerChannel.cs
- State.cs
- SafeHGlobalHandleCritical.cs
- IssuedTokensHeader.cs
- AppSettingsSection.cs
- TagMapInfo.cs
- Pair.cs
- CellRelation.cs
- Faults.cs
- XMLSyntaxException.cs
- EncodingFallbackAwareXmlTextWriter.cs
- NonClientArea.cs
- SimpleTypeResolver.cs
- ProxyFragment.cs
- ViewPort3D.cs
- XmlSerializerSection.cs
- XmlSchemaSimpleContentExtension.cs
- SchemaManager.cs
- MeshGeometry3D.cs
- NameValueCollection.cs
- ConditionBrowserDialog.cs
- StringDictionary.cs
- MetadataProperty.cs
- TableLayoutPanelDesigner.cs
- GenerateScriptTypeAttribute.cs
- MD5CryptoServiceProvider.cs
- InvokePattern.cs
- RemotingServices.cs
- PropertyMap.cs
- MemberAccessException.cs
- securitycriticaldataClass.cs
- ToolStripButton.cs
- UrlMappingsSection.cs
- AddInStore.cs
- ProgressPage.cs
- RulePatternOps.cs
- ConnectionOrientedTransportManager.cs
- ArraySegment.cs
- KeyTime.cs
- RemotingSurrogateSelector.cs
- CompensateDesigner.cs
- DisableDpiAwarenessAttribute.cs
- ManipulationBoundaryFeedbackEventArgs.cs
- Set.cs
- WebPartConnectVerb.cs
- IntSecurity.cs
- BufferedGraphics.cs
- WebPartConnectionsEventArgs.cs
- NoneExcludedImageIndexConverter.cs
- OdbcEnvironment.cs
- JsonSerializer.cs
- SymbolType.cs
- OptionUsage.cs
- LayoutEditorPart.cs
- SqlIdentifier.cs
- DeferredSelectedIndexReference.cs
- DetailsViewRowCollection.cs
- ValidatingReaderNodeData.cs
- ApplicationServicesHostFactory.cs
- DefaultMemberAttribute.cs
- MouseWheelEventArgs.cs
- TextTreeTextNode.cs
- smtpconnection.cs
- PhysicalOps.cs
- DataKeyCollection.cs
- FigureParagraph.cs
- CfgParser.cs
- sqlmetadatafactory.cs
- RoutedUICommand.cs
- DiagnosticTrace.cs
- VolatileEnlistmentMultiplexing.cs
- StorageMappingFragment.cs
- NotifyIcon.cs
- StateWorkerRequest.cs
- TextShapeableCharacters.cs
- OdbcConnectionOpen.cs