protected IEnumerable <OperationWrapper> GetOperationProjections() { ExpandedProjectionNode currentExpandedProjectionNode = this.GetCurrentExpandedProjectionNode(); if ((currentExpandedProjectionNode != null) && !currentExpandedProjectionNode.ProjectAllOperations) { return(currentExpandedProjectionNode.Operations); } return(null); }
protected IEnumerable <ProjectionNode> GetProjections() { ExpandedProjectionNode currentExpandedProjectionNode = this.GetCurrentExpandedProjectionNode(); if ((currentExpandedProjectionNode != null) && !currentExpandedProjectionNode.ProjectAllProperties) { return(currentExpandedProjectionNode.Nodes); } return(null); }
private bool PushSegment(ResourceSetWrapper container, ExpandedProjectionNode expandedNode) { if (((this.service.Configuration.MaxResultsPerCollection == 0x7fffffff) && ((container == null) || (container.PageSize == 0))) && ((this.requestDescription.RootProjectionNode == null) && !this.IsCustomPaged)) { return(false); } if (this.segmentInfo == null) { this.segmentInfo = new SegmentInfo(); } this.segmentInfo.PushSegment(container, expandedNode); return(true); }
private void BuildProjectionAndExpansionPathsForNode(List <string> parentPathSegments, StringBuilder projectionPaths, StringBuilder expansionPaths, ExpandedProjectionNode expandedNode, out bool foundProjections, out bool foundExpansions) { foundProjections = false; foundExpansions = false; List <ExpandedProjectionNode> list = new List <ExpandedProjectionNode>(); foreach (ProjectionNode node in expandedNode.Nodes) { ExpandedProjectionNode node2 = node as ExpandedProjectionNode; if (node2 == null) { AppendProjectionOrExpansionPath(projectionPaths, parentPathSegments, node.PropertyName); foundProjections = true; } else { bool flag; bool flag2; foundExpansions = true; parentPathSegments.Add(node2.PropertyName); this.BuildProjectionAndExpansionPathsForNode(parentPathSegments, projectionPaths, expansionPaths, node2, out flag2, out flag); parentPathSegments.RemoveAt(parentPathSegments.Count - 1); if (node2.ProjectAllProperties) { if (flag2) { AppendProjectionOrExpansionPath(projectionPaths, parentPathSegments, node.PropertyName + "/*"); } else { list.Add(node2); } } foundProjections |= flag2; if (!flag) { AppendProjectionOrExpansionPath(expansionPaths, parentPathSegments, node.PropertyName); } } } if (!expandedNode.ProjectAllProperties || foundProjections) { foreach (ExpandedProjectionNode node3 in list) { AppendProjectionOrExpansionPath(projectionPaths, parentPathSegments, node3.PropertyName); foundProjections = true; } } }
private static ExpandedProjectionNode ApplyProjectionForProperty(ExpandedProjectionNode parentNode, string propertyName, ResourceProperty property, ResourceType targetResourceType, bool lastPathSegment) { if (property != null) { switch (property.TypeKind) { case ResourceTypeKind.ComplexType: if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_ComplexPropertyAsInnerSelectSegment(targetResourceType.FullName, propertyName)); } break; case ResourceTypeKind.Primitive: if (!lastPathSegment) { if (property.IsOfKind(ResourcePropertyKind.Stream)) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_NamedStreamMustBeLastSegmentInSelect(propertyName)); } throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_PrimitivePropertyUsedAsNavigationProperty(targetResourceType.FullName, propertyName)); } break; case ResourceTypeKind.Collection: if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_CollectionPropertyAsInnerSelectSegment(targetResourceType.FullName, propertyName)); } break; } } ExpandedProjectionNode node = parentNode.AddProjectionNode(propertyName, property, targetResourceType, lastPathSegment); if (lastPathSegment && (node != null)) { node.ProjectionFound = true; node.MarkSubtreeAsProjected(); } return(node); }
private StringBuilder GetNextPageQueryParametersForExpandedContainer() { StringBuilder builder = new StringBuilder(); ExpandedProjectionNode currentExpandedProjectionNode = this.GetCurrentExpandedProjectionNode(); if (currentExpandedProjectionNode != null) { bool flag; bool flag2; List <string> parentPathSegments = new List <string>(); StringBuilder projectionPaths = new StringBuilder(); StringBuilder expansionPaths = new StringBuilder(); this.BuildProjectionAndExpansionPathsForNode(parentPathSegments, projectionPaths, expansionPaths, currentExpandedProjectionNode, out flag2, out flag); if (flag2 && currentExpandedProjectionNode.ProjectAllProperties) { AppendProjectionOrExpansionPath(projectionPaths, parentPathSegments, "*"); } if (projectionPaths.Length > 0) { if (builder.Length > 0) { builder.Append('&'); } builder.Append("$select=").Append(projectionPaths.ToString()); } if (expansionPaths.Length > 0) { if (builder.Length > 0) { builder.Append('&'); } builder.Append("$expand=").Append(expansionPaths.ToString()); } } if (builder.Length > 0) { builder.Append('&'); } return(builder); }
/// <summary> /// Tries to build the set of <see cref="ODataAction"/> to be advertised for the given resource. /// </summary> /// <param name="entityToSerialize">Entity that is currently being serialized.</param> /// <param name="resourceInstanceInFeed">true if the resource instance being serialized is inside a feed; false otherwise.</param> /// <param name="actions">The actions to advertise.</param> /// <returns> /// Whether any actions should be advertised. /// </returns> private bool TryGetAdvertisedActions(EntityToSerialize entityToSerialize, bool resourceInstanceInFeed, out IEnumerable <ODataAction> actions) { Debug.Assert(entityToSerialize != null, "entityToSerialize != null"); if (!this.Service.ActionProvider.IsImplemented) { actions = null; return(false); } // If GetOperationProjections returns null it means no projections are to be applied and all operations // for the current segment should be serialized. If it returns non-null only the operations described // by the returned projection segments should be serialized. ExpandedProjectionNode expandedProjectionNode = this.GetCurrentExpandedProjectionNode(); List <OperationWrapper> serviceOperationWrapperList; if (expandedProjectionNode == null || expandedProjectionNode.ProjectAllOperations) { // Note that if the service does not implement IDataServiceActionProvider and the MaxProtocolVersion < V3, // GetServiceActionsByBindingParameterType() would simply return an empty ServiceOperationWrapper collection. serviceOperationWrapperList = this.Service.ActionProvider.GetServiceActionsByBindingParameterType(entityToSerialize.ResourceType); } else { serviceOperationWrapperList = expandedProjectionNode.SelectedOperations.GetSelectedOperations(entityToSerialize.ResourceType); } Debug.Assert(serviceOperationWrapperList != null, "serviceOperationWrappers != null"); if (serviceOperationWrapperList.Count <= 0) { actions = null; return(false); } actions = this.OperationSerializer.SerializeOperations(entityToSerialize, resourceInstanceInFeed, serviceOperationWrapperList); return(true); }
private void CheckExpandPaths() { if (this.expandPathsAsText.Count > 0) { if (this.queryExpression == null) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryExpandOptionNotApplicable); } if (this.description.TargetResourceType.ResourceTypeKind == ResourceTypeKind.Collection) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryExpandOptionNotApplicable); } } this.expandPaths = new List <ExpandSegmentCollection>(this.expandPathsAsText.Count); for (int i = this.expandPathsAsText.Count - 1; i >= 0; i--) { ExpandSegmentCollection item = this.CheckSingleExpandPath(this.expandPathsAsText[i]); if (item == null) { this.expandPathsAsText.RemoveAt(i); } else { this.expandPaths.Add(item); ExpandedProjectionNode rootProjectionNode = this.GetRootProjectionNode(); for (int j = 0; j < item.Count; j++) { ExpandSegment segment = item[j]; ExpandedProjectionNode node2 = rootProjectionNode.AddExpandedNode(segment); this.GetRootProjectionNode().ExpansionOnDerivedTypesSpecified |= rootProjectionNode.HasExpandedPropertyOnDerivedType; rootProjectionNode = node2; } this.GetRootProjectionNode().ExpansionsSpecified = true; } } }
internal void PushSegment(ResourceSetWrapper set, ExpandedProjectionNode projectionNode) { this.segmentContainers.Add(set); this.segmentResultCounts.Add(0); this.projectionNodes.Add(projectionNode); }
internal static Serializer.ResourcePropertyInfo CreateResourcePropertyInfo(ResourceProperty resourceProperty, object value, ExpandedProjectionNode expandedNode, bool expand) { return(new Serializer.ResourcePropertyInfo { Property = resourceProperty, Value = value, Expand = expand, ExpandedNode = expandedNode }); }
protected bool ShouldExpandSegment(ResourceProperty property, ResourceType currentResourceType, out ExpandedProjectionNode expandedNode) { expandedNode = null; if ((this.segmentInfo == null) || (this.segmentInfo.CurrentExpandedNode == null)) { return(false); } if (this.requestDescription.RootProjectionNode.UseExpandPathsForSerialization && (this.requestDescription.RootProjectionNode.ExpandPaths != null)) { for (int i = 0; i < this.requestDescription.RootProjectionNode.ExpandPaths.Count; i++) { List <ExpandSegment> list = this.requestDescription.RootProjectionNode.ExpandPaths[i]; if (list.Count >= this.segmentInfo.Count) { bool flag = true; for (int j = 1; j < this.segmentInfo.Count; j++) { if (list[j - 1].Name != this.segmentInfo.GetSegmentName(j)) { flag = false; break; } } if (flag && (list[this.segmentInfo.Count - 1].Name == property.Name)) { return(true); } } } } else { expandedNode = this.segmentInfo.CurrentExpandedNode.FindExpandedNode(property, currentResourceType); } return(expandedNode != null); }
protected bool PushSegmentForProperty(ResourceProperty property, ResourceType currentResourceType, ExpandedProjectionNode expandedProjectionNode) { ResourceSetWrapper currentContainer = this.CurrentContainer; if (currentContainer != null) { currentContainer = this.service.Provider.GetContainer(currentContainer, currentResourceType, property); } return(this.PushSegment(currentContainer, expandedProjectionNode)); }
protected object GetExpandedProperty(IExpandedResult expanded, object customObject, ResourceProperty property, ExpandedProjectionNode expandedNode) { if (expanded == null) { return(WebUtil.GetPropertyValue(this.Provider, customObject, null, property, null)); } string name = property.Name; if ((expandedNode != null) && (this.GetCurrentExpandedProjectionNode().ResourceType != expandedNode.TargetResourceType)) { name = expandedNode.TargetResourceType.FullName + "/" + property.Name; } return(expanded.GetExpandedPropertyValue(name)); }
private void ApplyProjectionsToExpandTree(List <List <string> > selectPathsAsText) { for (int i = selectPathsAsText.Count - 1; i >= 0; i--) { List <string> list = selectPathsAsText[i]; ExpandedProjectionNode rootProjectionNode = this.GetRootProjectionNode(); ResourceType type = null; for (int j = 0; j < list.Count; j++) { bool flag2; string containerQualifiedName = list[j]; bool lastPathSegment = j == (list.Count - 1); rootProjectionNode.ProjectionFound = true; if (containerQualifiedName == "*") { rootProjectionNode.ProjectAllImmediateProperties = true; break; } if (this.service.Provider.GetNameFromContainerQualifiedName(containerQualifiedName, out flag2) == "*") { rootProjectionNode.ProjectAllImmediateOperations = true; break; } ResourceType previousSegmentResourceType = type ?? rootProjectionNode.ResourceType; ResourceProperty property = previousSegmentResourceType.TryResolvePropertyName(containerQualifiedName); if (property == null) { type = WebUtil.ResolveTypeIdentifier(this.service.Provider, containerQualifiedName, previousSegmentResourceType, type != null); if (type != null) { this.description.VerifyProtocolVersion(RequestDescription.Version3Dot0, this.service); continue; } Func <OperationWrapper, bool> predicate = null; string serviceActionName = this.service.Provider.GetNameFromContainerQualifiedName(containerQualifiedName, out flag2); OperationWrapper operation = null; if (!previousSegmentResourceType.IsOpenType || flag2) { if (predicate == null) { predicate = o => o.Name == serviceActionName; } operation = this.service.ActionProvider.GetServiceActionsByBindingParameterType(this.service.OperationContext, previousSegmentResourceType).SingleOrDefault <OperationWrapper>(predicate); } if (operation != null) { rootProjectionNode.AddOperation(operation); if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_ServiceActionMustBeLastSegmentInSelect(containerQualifiedName)); } continue; } if (!previousSegmentResourceType.IsOpenType) { throw DataServiceException.CreateSyntaxError(System.Data.Services.Strings.RequestUriProcessor_PropertyNotFound(previousSegmentResourceType.FullName, containerQualifiedName)); } if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(containerQualifiedName)); } } rootProjectionNode = ApplyProjectionForProperty(rootProjectionNode, containerQualifiedName, property, previousSegmentResourceType, lastPathSegment); type = null; } if (type != null) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier("$select", type.FullName)); } } }