Ejemplo n.º 1
0
        protected object GetObjectFromSegmentInfo(ResourceType resourceType, System.Data.Services.SegmentInfo segmentInfo, bool verifyETag, bool checkForNull, bool replaceResource)
        {
            object crossReferencedResource;

            if (segmentInfo.RequestExpression == null)
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_ResourceCanBeCrossReferencedOnlyForBindOperation);
            }
            if (IsCrossReferencedSegment(segmentInfo, this.service))
            {
                crossReferencedResource = GetCrossReferencedResource(segmentInfo);
            }
            else
            {
                crossReferencedResource = GetResource(segmentInfo, (resourceType != null) ? resourceType.FullName : null, this.Service, checkForNull);
                if (verifyETag)
                {
                    this.service.Updatable.SetETagValues(crossReferencedResource, segmentInfo.TargetContainer);
                }
            }
            if (replaceResource)
            {
                crossReferencedResource = this.Updatable.ResetResource(crossReferencedResource);
                WebUtil.CheckResourceExists(crossReferencedResource != null, segmentInfo.Identifier);
            }
            return(crossReferencedResource);
        }
Ejemplo n.º 2
0
        protected override object Read(System.Data.Services.SegmentInfo segmentInfo)
        {
            ODataEntry     entry;
            ResourceType   targetResourceType = segmentInfo.TargetResourceType;
            IEdmEntityType schemaType         = (IEdmEntityType)base.GetSchemaType(targetResourceType);
            ODataReader    odataReader        = base.MessageReader.CreateODataEntryReader(schemaType);

            try
            {
                entry = this.ReadEntry(odataReader, segmentInfo);
            }
            catch (UriFormatException exception)
            {
                if (this.ContentFormat == ContentFormat.Atom)
                {
                    throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.Syndication_ErrorReadingEntry(exception.Message), exception);
                }
                throw;
            }
            ODataEntryAnnotation entryAnnotation = entry.GetAnnotation <ODataEntryAnnotation>();

            base.RecurseEnter();
            this.ApplyEntityProperties(segmentInfo, entry, entryAnnotation);
            base.RecurseLeave();
            return(entryAnnotation.EntityResource);
        }
Ejemplo n.º 3
0
 internal static Dictionary <string, object> ReadPayloadParameters(System.Data.Services.SegmentInfo actionSegment, IDataService dataService)
 {
     System.Data.Services.RequestDescription description = new System.Data.Services.RequestDescription(new System.Data.Services.SegmentInfo[] { actionSegment }, RequestUriProcessor.GetResultUri(dataService.OperationContext));
     description.VerifyRequestVersion(System.Data.Services.RequestDescription.Version3Dot0, dataService);
     using (Deserializer deserializer = CreateDeserializer(description, dataService, false, UpdateTracker.CreateUpdateTracker(dataService)))
     {
         return((Dictionary <string, object>)deserializer.Deserialize(actionSegment));
     }
 }
Ejemplo n.º 4
0
        protected override object Read(System.Data.Services.SegmentInfo segmentInfo)
        {
            Uri url = base.MessageReader.ReadEntityReferenceLink().Url;

            if (string.IsNullOrEmpty(CommonUtil.UriToString(url)))
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_MissingUriForLinkOperation);
            }
            return(RequestUriProcessor.GetAbsoluteUriFromReference(url, base.Service.OperationContext.AbsoluteServiceUri, base.RequestDescription.RequestVersion));
        }
Ejemplo n.º 5
0
 internal RequestDescription(SegmentInfo[] segmentInfos, Uri resultUri)
 {
     this.segmentInfos = segmentInfos;
     this.resultUri = resultUri;
     this.responseVersion = DataServiceDefaultResponseVersion;
     this.actualResponseVersion = this.ResponseVersion;
     this.PreferenceApplied = System.Data.Services.PreferenceApplied.None;
     this.containerName = (((this.LastSegmentInfo.TargetKind != RequestTargetKind.PrimitiveValue) && (this.LastSegmentInfo.TargetKind != RequestTargetKind.OpenPropertyValue)) && (this.LastSegmentInfo.TargetKind != RequestTargetKind.MediaResource)) ? this.LastSegmentInfo.Identifier : ((this.LastSegmentInfo.TargetSource == RequestTargetSource.ServiceOperation) ? null : segmentInfos[segmentInfos.Length - 2].Identifier);
     this.mimeType = ((this.TargetSource == RequestTargetSource.Property) && (this.Property != null)) ? this.Property.MimeType : ((this.TargetSource == RequestTargetSource.ServiceOperation) ? this.LastSegmentInfo.Operation.MimeType : null);
 }
Ejemplo n.º 6
0
        private object CreateNestedEntityAndApplyProperties(System.Data.Services.SegmentInfo segmentInfo, ODataEntry entry)
        {
            ODataEntryAnnotation entryAnnotation = entry.GetAnnotation <ODataEntryAnnotation>();

            base.RecurseEnter();
            this.CreateEntityResource(segmentInfo, entry, entryAnnotation, false);
            this.ApplyEntityProperties(segmentInfo, entry, entryAnnotation);
            base.RecurseLeave();
            return(entryAnnotation.EntityResource);
        }
Ejemplo n.º 7
0
 internal RequestDescription(RequestTargetKind targetKind, RequestTargetSource targetSource, Uri resultUri)
 {
     SegmentInfo info = new SegmentInfo {
         TargetKind = targetKind,
         TargetSource = targetSource,
         SingleResult = true
     };
     this.segmentInfos = new SegmentInfo[] { info };
     this.resultUri = resultUri;
     this.responseVersion = DataServiceDefaultResponseVersion;
     this.actualResponseVersion = this.ResponseVersion;
     this.PreferenceApplied = System.Data.Services.PreferenceApplied.None;
 }
 internal IEnumerable GetResultEnumerableFromRequest(SegmentInfo segmentInfo)
 {
     object obj2 = this.Execute(segmentInfo.RequestExpression);
     IQueryable query = obj2 as IQueryable;
     if (query != null)
     {
         this.dataService.InternalOnRequestQueryConstructed(query);
     }
     if ((segmentInfo.SingleResult && (query == null)) || (obj2 is IDataServiceInvokable))
     {
         obj2 = new object[] { obj2 };
     }
     return (IEnumerable) obj2;
 }
Ejemplo n.º 9
0
 internal SegmentInfo(SegmentInfo other)
 {
     this.Identifier = other.Identifier;
     this.Key = other.Key;
     this.Operation = other.Operation;
     this.ProjectedProperty = other.ProjectedProperty;
     this.RequestExpression = other.RequestExpression;
     this.RequestEnumerable = other.RequestEnumerable;
     this.SingleResult = other.SingleResult;
     this.TargetContainer = other.TargetContainer;
     this.TargetKind = other.TargetKind;
     this.TargetSource = other.TargetSource;
     this.targetResourceType = other.targetResourceType;
 }
Ejemplo n.º 10
0
        internal static object GetResource(System.Data.Services.SegmentInfo segmentInfo, string fullTypeName, IDataService service, bool checkForNull)
        {
            if (segmentInfo.TargetContainer != null)
            {
                DataServiceConfiguration.CheckResourceRights(segmentInfo.TargetContainer, EntitySetRights.ReadSingle);
            }
            segmentInfo.RequestEnumerable = (IEnumerable)service.ExecutionProvider.Execute(segmentInfo.RequestExpression);
            object resource = service.Updatable.GetResource((IQueryable)segmentInfo.RequestEnumerable, fullTypeName);

            if ((resource == null) && (segmentInfo.HasKeyValues || checkForNull))
            {
                throw DataServiceException.CreateResourceNotFound(segmentInfo.Identifier);
            }
            return(resource);
        }
Ejemplo n.º 11
0
        private void ApplyFeedInNavigationProperty(ResourceProperty navigationProperty, ResourceSetWrapper targetResourceSet, object entityResource, ODataFeed feed)
        {
            ODataFeedAnnotation annotation = feed.GetAnnotation <ODataFeedAnnotation>();

            if (base.Update && ((this.ContentFormat != ContentFormat.VerboseJson) || (annotation.Count > 0)))
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_DeepUpdateNotSupported);
            }
            System.Data.Services.SegmentInfo segmentInfo = Deserializer.CreateSegment(navigationProperty, navigationProperty.Name, targetResourceSet, false);
            foreach (ODataEntry entry in annotation)
            {
                object resourceToBeAdded = this.CreateNestedEntityAndApplyProperties(segmentInfo, entry);
                base.Updatable.AddReferenceToCollection(entityResource, navigationProperty.Name, resourceToBeAdded);
            }
        }
Ejemplo n.º 12
0
 /// <summary>Copy constructor.</summary>
 /// <param name="other">Another <see cref="SegmentInfo"/> to get a shallow copy of.</param>
 internal SegmentInfo(SegmentInfo other)
 {
     Debug.Assert(other != null, "other != null");
     this.Identifier = other.Identifier;
     this.Key = other.Key;
     this.Operation = other.Operation;
     this.OperationParameters = other.OperationParameters;
     this.ProjectedProperty = other.ProjectedProperty;
     this.RequestEnumerable = other.RequestEnumerable;
     this.SingleResult = other.SingleResult;
     this.TargetContainer = other.TargetContainer;
     this.TargetKind = other.TargetKind;
     this.TargetSource = other.TargetSource;
     this.targetResourceType = other.targetResourceType;
 }
Ejemplo n.º 13
0
        private void ApplyEntityProperties(System.Data.Services.SegmentInfo segmentInfo, ODataEntry entry, ODataEntryAnnotation entryAnnotation)
        {
            object       entityResource     = entryAnnotation.EntityResource;
            ResourceType entityResourceType = entryAnnotation.EntityResourceType;

            this.ApplyValueProperties(entry, entityResourceType, entityResource);
            this.ApplyNavigationProperties(entryAnnotation, segmentInfo.TargetContainer, entityResourceType, entityResource);
            if (base.Update)
            {
                base.Tracker.TrackAction(entityResource, segmentInfo.TargetContainer, UpdateOperations.Change);
            }
            else
            {
                base.Tracker.TrackAction(entityResource, segmentInfo.TargetContainer, UpdateOperations.Add);
            }
        }
Ejemplo n.º 14
0
        protected override object Read(System.Data.Services.SegmentInfo segmentInfo)
        {
            ResourceProperty  projectedProperty;
            ResourceType      resourceType;
            IEdmTypeReference typeReference;

            if (segmentInfo.TargetKind == RequestTargetKind.OpenProperty)
            {
                projectedProperty = null;
                resourceType      = null;
                typeReference     = null;
            }
            else
            {
                projectedProperty = segmentInfo.ProjectedProperty;
                resourceType      = projectedProperty.ResourceType;
                typeReference     = base.GetTypeReference(resourceType, projectedProperty.CustomAnnotations.ToList <KeyValuePair <string, object> >());
                if ((projectedProperty.Kind == ResourcePropertyKind.Primitive) && MetadataProviderUtils.ShouldDisablePrimitivePropertyNullValidation(projectedProperty, (IEdmPrimitiveTypeReference)typeReference))
                {
                    typeReference = base.GetSchemaType(resourceType).ToTypeReference(true);
                }
                if (((projectedProperty.Kind == ResourcePropertyKind.ComplexType) && base.Service.Provider.IsV1Provider) && !typeReference.IsNullable)
                {
                    typeReference = base.GetSchemaType(resourceType).ToTypeReference(true);
                }
            }
            ODataProperty property2 = base.MessageReader.ReadProperty(typeReference);

            if ((((this.ContentFormat != ContentFormat.PlainXml) || ((segmentInfo.TargetKind != RequestTargetKind.OpenProperty) && (property2.Value != null))) && ((this.ContentFormat != ContentFormat.VerboseJson) || (property2.Name.Length != 0))) && (string.CompareOrdinal(segmentInfo.Identifier, property2.Name) != 0))
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.PlainXml_IncorrectElementName(segmentInfo.Identifier, property2.Name));
            }
            object odataValue = property2.Value;

            if ((segmentInfo.TargetKind == RequestTargetKind.OpenProperty) && (odataValue is ODataCollectionValue))
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_OpenCollectionProperty(property2.Name));
            }
            object obj3 = base.ConvertValue(odataValue, ref resourceType);

            if (segmentInfo.TargetKind == RequestTargetKind.OpenProperty)
            {
                segmentInfo.TargetResourceType = resourceType;
            }
            return(obj3);
        }
Ejemplo n.º 15
0
 private void ApplyEntryInNavigationProperty(ResourceProperty navigationProperty, ResourceSetWrapper targetResourceSet, object entityResource, ODataEntry entry)
 {
     if (((this.ContentFormat != ContentFormat.VerboseJson) || (entry != null)) && base.Update)
     {
         throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_DeepUpdateNotSupported);
     }
     if (entry == null)
     {
         this.SetResourceReferenceToNull(entityResource, navigationProperty);
     }
     else
     {
         System.Data.Services.SegmentInfo segmentInfo = Deserializer.CreateSegment(navigationProperty, navigationProperty.Name, targetResourceSet, true);
         object propertyValue = this.CreateNestedEntityAndApplyProperties(segmentInfo, entry);
         base.Updatable.SetReference(entityResource, navigationProperty.Name, propertyValue);
     }
 }
Ejemplo n.º 16
0
        protected override object Read(System.Data.Services.SegmentInfo segmentInfo)
        {
            Func <OperationParameter, bool> predicate  = null;
            Func <OperationParameter, bool> func2      = null;
            IEdmFunctionImport          functionImport = base.GetFunctionImport(segmentInfo.Operation);
            ODataParameterReader        reader         = base.MessageReader.CreateODataParameterReader(functionImport);
            Dictionary <string, object> dictionary     = new Dictionary <string, object>(EqualityComparer <string> .Default);

            while (reader.Read())
            {
                ResourceType parameterType;
                object       obj2;
                switch (reader.State)
                {
                case ODataParameterReaderState.Value:
                    if (predicate == null)
                    {
                        predicate = p => p.Name == reader.Name;
                    }
                    parameterType = segmentInfo.Operation.Parameters.Single <OperationParameter>(predicate).ParameterType;
                    obj2          = base.ConvertValue(reader.Value, ref parameterType);
                    break;

                case ODataParameterReaderState.Collection:
                {
                    ODataCollectionReader collectionReader = reader.CreateCollectionReader();
                    if (func2 == null)
                    {
                        func2 = p => p.Name == reader.Name;
                    }
                    parameterType = segmentInfo.Operation.Parameters.Single <OperationParameter>(func2).ParameterType;
                    obj2          = base.ConvertValue(ReadCollectionParameterValue(collectionReader), ref parameterType);
                    break;
                }

                case ODataParameterReaderState.Completed:
                    return(dictionary);

                default:
                    throw new InvalidOperationException(System.Data.Services.Strings.DataServiceException_GeneralError);
                }
                dictionary.Add(reader.Name, obj2);
            }
            return(dictionary);
        }
Ejemplo n.º 17
0
 protected static System.Data.Services.SegmentInfo CreateSegment(ResourceProperty property, string propertyName, ResourceSetWrapper propertySet, bool singleResult)
 {
     System.Data.Services.SegmentInfo info = new System.Data.Services.SegmentInfo {
         TargetSource = RequestTargetSource.Property,
         SingleResult = singleResult,
         Identifier   = propertyName
     };
     if (property == null)
     {
         info.TargetKind = RequestTargetKind.OpenProperty;
         return(info);
     }
     info.TargetKind         = RequestTargetKind.Resource;
     info.Identifier         = propertyName;
     info.ProjectedProperty  = property;
     info.TargetResourceType = property.ResourceType;
     info.TargetContainer    = propertySet;
     return(info);
 }
 internal static IEnumerator GetSingleResultFromRequest(SegmentInfo segmentInfo)
 {
     IEnumerator enumerator2;
     IEnumerator requestEnumerator = WebUtil.GetRequestEnumerator(segmentInfo.RequestEnumerable);
     bool flag = true;
     try
     {
         WebUtil.CheckResourceExists(requestEnumerator.MoveNext(), segmentInfo.Identifier);
         RequestDescription.CheckNullDirectReference(requestEnumerator.Current, segmentInfo);
         flag = false;
         enumerator2 = requestEnumerator;
     }
     finally
     {
         if (flag)
         {
             WebUtil.Dispose(requestEnumerator);
         }
     }
     return enumerator2;
 }
        protected sealed override object Deserialize(System.Data.Services.SegmentInfo segmentInfo)
        {
            object obj2;

            try
            {
                obj2 = this.Read(segmentInfo);
            }
            catch (XmlException exception)
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.DataServiceException_GeneralError, exception);
            }
            catch (ODataContentTypeException exception2)
            {
                throw new DataServiceException(0x19f, null, System.Data.Services.Strings.DataServiceException_UnsupportedMediaType, null, exception2);
            }
            catch (ODataException exception3)
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.DataServiceException_GeneralError, exception3);
            }
            return(obj2);
        }
Ejemplo n.º 20
0
 internal object ReadEntity()
 {
     System.Data.Services.RequestDescription requestDescription = this.RequestDescription;
     if (requestDescription.TargetKind == RequestTargetKind.Resource)
     {
         this.RequestDescription.UpdateAndCheckEpmFeatureVersion(this.description.LastSegmentInfo.TargetContainer, this.Service);
     }
     System.Data.Services.SegmentInfo lastSegmentInfo = requestDescription.LastSegmentInfo;
     if (!this.Update)
     {
         lastSegmentInfo = new System.Data.Services.SegmentInfo {
             TargetKind         = lastSegmentInfo.TargetKind,
             TargetSource       = lastSegmentInfo.TargetSource,
             SingleResult       = true,
             ProjectedProperty  = lastSegmentInfo.ProjectedProperty,
             TargetResourceType = lastSegmentInfo.TargetResourceType,
             TargetContainer    = lastSegmentInfo.TargetContainer,
             Identifier         = lastSegmentInfo.Identifier
         };
     }
     return(this.Deserialize(lastSegmentInfo));
 }
Ejemplo n.º 21
0
        protected override object Read(System.Data.Services.SegmentInfo segmentInfo)
        {
            ResourceType      resourceType;
            IEdmTypeReference typeReference;
            ResourceProperty  projectedProperty = segmentInfo.ProjectedProperty;

            if (projectedProperty == null)
            {
                resourceType  = null;
                typeReference = null;
            }
            else
            {
                resourceType  = projectedProperty.ResourceType;
                typeReference = base.GetTypeReference(resourceType, projectedProperty.CustomAnnotations.ToList <KeyValuePair <string, object> >());
            }
            object obj3 = ODataMessageReaderDeserializer.ConvertPrimitiveValue(base.MessageReader.ReadValue(typeReference), ref resourceType);

            if (projectedProperty == null)
            {
                segmentInfo.TargetResourceType = resourceType;
            }
            return(obj3);
        }
Ejemplo n.º 22
0
        private void CreateEntityResource(System.Data.Services.SegmentInfo segmentInfo, ODataEntry entry, ODataEntryAnnotation entryAnnotation, bool topLevel)
        {
            object obj2;

            base.CheckAndIncrementObjectCount();
            ResourceType entryResourceType = this.GetEntryResourceType(entry, segmentInfo.TargetResourceType);

            base.UpdateAndCheckRequestResponseDSV(entryResourceType, topLevel);
            if (segmentInfo.TargetKind == RequestTargetKind.OpenProperty)
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(segmentInfo.Identifier));
            }
            if (base.Update)
            {
                obj2 = base.GetObjectFromSegmentInfo(entryResourceType, segmentInfo, true, true, base.Service.OperationContext.Host.HttpVerb == HttpVerbs.PUT);
            }
            else
            {
                DataServiceConfiguration.CheckResourceRights(segmentInfo.TargetContainer, EntitySetRights.WriteAppend);
                obj2 = base.Updatable.CreateResource(segmentInfo.TargetContainer.Name, entryResourceType.FullName);
            }
            entryAnnotation.EntityResource     = obj2;
            entryAnnotation.EntityResourceType = entryResourceType;
        }
Ejemplo n.º 23
0
 internal static bool IsCrossReferencedSegment(System.Data.Services.SegmentInfo segmentInfo, IDataService service)
 {
     return(segmentInfo.Identifier.StartsWith("$", StringComparison.Ordinal) && (service.GetSegmentForContentId(segmentInfo.Identifier) != null));
 }
Ejemplo n.º 24
0
 internal static void CheckNullDirectReference(object result, SegmentInfo segmentInfo)
 {
     if (segmentInfo.IsDirectReference && (result == null))
     {
         throw DataServiceException.CreateResourceNotFound(segmentInfo.Identifier);
     }
 }
Ejemplo n.º 25
0
 internal static RequestDescription CreateSingleResultRequestDescription(RequestDescription description, object entity)
 {
     SegmentInfo info = new SegmentInfo {
         RequestExpression = Expression.Constant(entity),
         RequestEnumerable = new object[] { entity },
         TargetKind = description.TargetKind,
         TargetSource = description.TargetSource,
         SingleResult = true,
         ProjectedProperty = description.Property,
         TargetResourceType = description.TargetResourceType,
         TargetContainer = description.LastSegmentInfo.TargetContainer,
         Identifier = description.LastSegmentInfo.Identifier
     };
     SegmentInfo[] segmentInfos = description.SegmentInfos;
     segmentInfos[segmentInfos.Length - 1] = info;
     return new RequestDescription(segmentInfos, description.ResultUri) { responseVersion = description.ResponseVersion, actualResponseVersion = description.ActualResponseVersion, PreferenceApplied = description.PreferenceApplied };
 }
Ejemplo n.º 26
0
 internal static object GetCrossReferencedResource(System.Data.Services.SegmentInfo segmentInfo)
 {
     object[] requestEnumerable = (object[])segmentInfo.RequestEnumerable;
     return(requestEnumerable[0]);
 }
Ejemplo n.º 27
0
 protected abstract object Deserialize(System.Data.Services.SegmentInfo segmentInfo);
Ejemplo n.º 28
0
 internal object ReadEntity()
 {
     System.Data.Services.RequestDescription requestDescription = this.RequestDescription;
     if (requestDescription.TargetKind == RequestTargetKind.Resource)
     {
         this.RequestDescription.UpdateAndCheckEpmFeatureVersion(this.description.LastSegmentInfo.TargetContainer, this.Service);
     }
     System.Data.Services.SegmentInfo lastSegmentInfo = requestDescription.LastSegmentInfo;
     if (!this.Update)
     {
         lastSegmentInfo = new System.Data.Services.SegmentInfo {
             TargetKind = lastSegmentInfo.TargetKind,
             TargetSource = lastSegmentInfo.TargetSource,
             SingleResult = true,
             ProjectedProperty = lastSegmentInfo.ProjectedProperty,
             TargetResourceType = lastSegmentInfo.TargetResourceType,
             TargetContainer = lastSegmentInfo.TargetContainer,
             Identifier = lastSegmentInfo.Identifier
         };
     }
     return this.Deserialize(lastSegmentInfo);
 }
Ejemplo n.º 29
0
 protected static System.Data.Services.SegmentInfo CreateSegment(ResourceProperty property, string propertyName, ResourceSetWrapper propertySet, bool singleResult)
 {
     System.Data.Services.SegmentInfo info = new System.Data.Services.SegmentInfo {
         TargetSource = RequestTargetSource.Property,
         SingleResult = singleResult,
         Identifier = propertyName
     };
     if (property == null)
     {
         info.TargetKind = RequestTargetKind.OpenProperty;
         return info;
     }
     info.TargetKind = RequestTargetKind.Resource;
     info.Identifier = propertyName;
     info.ProjectedProperty = property;
     info.TargetResourceType = property.ResourceType;
     info.TargetContainer = propertySet;
     return info;
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Get the single result from the given segment info
        /// </summary>
        /// <param name="segmentInfo">segmentInfo which contains the request query</param>
        /// <returns>query result as returned by the IQueryable query</returns>
        internal static IEnumerator GetSingleResultFromEnumerable(SegmentInfo segmentInfo)
        {
            IEnumerator queryResults = WebUtil.GetRequestEnumerator(segmentInfo.RequestEnumerable);
            bool shouldDispose = true;
            try
            {
                WebUtil.CheckResourceExists(queryResults.MoveNext(), segmentInfo.Identifier);

                CheckQueryResult(queryResults.Current, segmentInfo);

                shouldDispose = false;
                return queryResults;
            }
            finally
            {
                // Dispose the Enumerator in case of error
                if (shouldDispose)
                {
                    WebUtil.Dispose(queryResults);
                }
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Initializes a new RequestDescription for a query specified by the
        /// request Uri.
        /// </summary>
        /// <param name="segmentInfos">list containing information about each segment of the request uri</param>
        /// <param name="containerName">Name of the container source.</param>
        /// <param name="usesContainerName">Whether the container name should be used to name the result.</param>
        /// <param name="mimeType">The MIME type for the requested resource, if specified.</param>
        /// <param name="resultUri">URI to the results requested (with no query component).</param>
        internal RequestDescription(
            SegmentInfo[] segmentInfos,
            string containerName, 
            bool usesContainerName,
            string mimeType,
            Uri resultUri)
        {
            Debug.Assert(segmentInfos != null && segmentInfos.Length != 0, "segmentInfos != null && segmentInfos.Length != 0");
            Debug.Assert(resultUri != null, "resultUri != null");
            Debug.Assert(resultUri.IsAbsoluteUri, "resultUri.IsAbsoluteUri(" + resultUri + ")");
            this.segmentInfos = segmentInfos;
            this.containerName = containerName;
            this.usesContainerName = usesContainerName;
            this.mimeType = mimeType;
            this.resultUri = resultUri;

            this.requireMinimumVersion = new Version(1, 0);
            this.responseVersion = DataServiceDefaultResponseVersion;
            this.maxFeatureVersion = new Version(1, 0);
        }
 internal static IDataServiceInvokable CreateInvokableFromSegment(SegmentInfo actionSegment)
 {
     return actionSegment.RequestEnumerable.OfType<IDataServiceInvokable>().Single<IDataServiceInvokable>();
 }
 internal static void ResolveActionResult(SegmentInfo actionSegment)
 {
     object result = CreateInvokableFromSegment(actionSegment).GetResult();
     if (((result != null) && actionSegment.SingleResult) && !(result is IQueryable))
     {
         result = new object[] { result };
     }
     actionSegment.RequestEnumerable = (IEnumerable) result;
 }
 internal static bool IsServiceActionSegment(SegmentInfo segment)
 {
     return ((segment.Operation != null) && (segment.Operation.Kind == OperationKind.Action));
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Checks query result.
        /// </summary>
        /// <param name="result">Query result to be checked.</param>
        /// <param name="segmentInfo">Segment details for the <paramref name="result"/>.</param>
        internal static void CheckQueryResult(object result, SegmentInfo segmentInfo)
        {
            // e.g. /Customers(4) - if there is a direct reference to an entity, it should not be null.
            // e.g. $value also must not be null, since you are dereferencing the values
            // Any other case, having null is fine
            if (segmentInfo.IsDirectReference && result == null)
            {
                throw DataServiceException.CreateResourceNotFound(segmentInfo.Identifier);
            }

            IEnumerable enumerable;
            if (segmentInfo.TargetKind == RequestTargetKind.OpenProperty &&
                WebUtil.IsElementIEnumerable(result, out enumerable))
            {
                throw DataServiceException.CreateSyntaxError(
                    Strings.InvalidUri_OpenPropertiesCannotBeCollection(segmentInfo.Identifier));
            }
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Create a new request description from the given request description and new entity as the result.
        /// </summary>
        /// <param name="description">Existing request description.</param>
        /// <param name="entity">entity that needs to be the result of the new request.</param>
        /// <param name="container">container to which the entity belongs to.</param>
        /// <returns>a new instance of request description containing information about the given entity.</returns>
        internal static RequestDescription CreateSingleResultRequestDescription(
            RequestDescription description, object entity, ResourceSetWrapper container)
        {
            // Create a new request description for the results that will be returned.
            SegmentInfo segmentInfo = new SegmentInfo();
            segmentInfo.RequestEnumerable = new object[] { entity };
            segmentInfo.TargetKind = description.TargetKind;
            segmentInfo.TargetSource = description.TargetSource;
            segmentInfo.SingleResult = true;
            segmentInfo.ProjectedProperty = description.Property;
            segmentInfo.TargetResourceType = container != null ? container.ResourceType : null;
            segmentInfo.TargetContainer = container;
            segmentInfo.Identifier = description.LastSegmentInfo.Identifier;
#if DEBUG
            segmentInfo.AssertValid();
#endif
            SegmentInfo[] segmentInfos = description.SegmentInfos;
            segmentInfos[segmentInfos.Length - 1] = segmentInfo;

            RequestDescription resultDescription = new RequestDescription(
                segmentInfos,
                container != null ? container.Name : null,
                description.UsesContainerName,
                description.MimeType,
                description.ResultUri);

            resultDescription.requireMinimumVersion = description.RequireMinimumVersion;
            resultDescription.responseVersion = description.ResponseVersion;
            resultDescription.maxFeatureVersion = description.MaxFeatureVersion;
            return resultDescription;
        }
Ejemplo n.º 37
0
 protected override object Deserialize(System.Data.Services.SegmentInfo segmentInfo)
 {
     return(base.Service.OperationContext.Host.RequestStream);
 }
 protected abstract object Read(System.Data.Services.SegmentInfo segmentInfo);
Ejemplo n.º 39
0
        /// <summary>
        /// Initializes a new RequestDescription for a query specified by the
        /// request Uri.
        /// </summary>
        /// <param name="targetKind">The kind of target for the request.</param>
        /// <param name="targetSource">The source for this target.</param>
        /// <param name="resultUri">URI to the results requested (with no query component).</param>
        internal RequestDescription(RequestTargetKind targetKind, RequestTargetSource targetSource, Uri resultUri)
        {
            WebUtil.DebugEnumIsDefined(targetKind);
            Debug.Assert(resultUri != null, "resultUri != null");
            Debug.Assert(resultUri.IsAbsoluteUri, "resultUri.IsAbsoluteUri(" + resultUri + ")");

            SegmentInfo segment = new SegmentInfo();
            segment.TargetKind = targetKind;
            segment.TargetSource = targetSource;
            segment.SingleResult = true;
            this.segmentInfos = new SegmentInfo[] { segment };
            this.resultUri = resultUri;

            this.requireMinimumVersion = new Version(1, 0);
            this.responseVersion = DataServiceDefaultResponseVersion;
            this.maxFeatureVersion = new Version(1, 0);
        }
Ejemplo n.º 40
0
        private ODataEntry ReadEntry(ODataReader odataReader, System.Data.Services.SegmentInfo topLevelSegmentInfo)
        {
            ODataEntry        entry = null;
            Stack <ODataItem> stack = new Stack <ODataItem>();

            while (odataReader.Read())
            {
                if (stack.Count >= 100)
                {
                    throw DataServiceException.CreateDeepRecursion(100);
                }
                switch (odataReader.State)
                {
                case ODataReaderState.FeedStart:
                {
                    ODataFeed feed2 = (ODataFeed)odataReader.Item;
                    feed2.SetAnnotation <ODataFeedAnnotation>(new ODataFeedAnnotation());
                    ODataNavigationLink link3 = (ODataNavigationLink)stack.Peek();
                    link3.GetAnnotation <ODataNavigationLinkAnnotation>().Add(feed2);
                    stack.Push(feed2);
                    break;
                }

                case ODataReaderState.FeedEnd:
                    stack.Pop();
                    break;

                case ODataReaderState.EntryStart:
                {
                    ODataEntry           entry2     = (ODataEntry)odataReader.Item;
                    ODataEntryAnnotation annotation = null;
                    if (entry2 != null)
                    {
                        annotation = new ODataEntryAnnotation();
                        entry2.SetAnnotation <ODataEntryAnnotation>(annotation);
                    }
                    if (stack.Count == 0)
                    {
                        entry = entry2;
                        this.CreateEntityResource(topLevelSegmentInfo, entry2, annotation, true);
                    }
                    else
                    {
                        ODataItem item = stack.Peek();
                        ODataFeed feed = item as ODataFeed;
                        if (feed != null)
                        {
                            feed.GetAnnotation <ODataFeedAnnotation>().Add(entry2);
                        }
                        else
                        {
                            ODataNavigationLink link = (ODataNavigationLink)item;
                            link.GetAnnotation <ODataNavigationLinkAnnotation>().Add(entry2);
                        }
                    }
                    stack.Push(entry2);
                    break;
                }

                case ODataReaderState.EntryEnd:
                    stack.Pop();
                    break;

                case ODataReaderState.NavigationLinkStart:
                {
                    ODataNavigationLink link2 = (ODataNavigationLink)odataReader.Item;
                    link2.SetAnnotation <ODataNavigationLinkAnnotation>(new ODataNavigationLinkAnnotation());
                    ODataEntry entry3 = (ODataEntry)stack.Peek();
                    entry3.GetAnnotation <ODataEntryAnnotation>().Add(link2);
                    stack.Push(link2);
                    break;
                }

                case ODataReaderState.NavigationLinkEnd:
                    stack.Pop();
                    break;

                case ODataReaderState.EntityReferenceLink:
                {
                    ODataEntityReferenceLink link4 = (ODataEntityReferenceLink)odataReader.Item;
                    ODataNavigationLink      link5 = (ODataNavigationLink)stack.Peek();
                    link5.GetAnnotation <ODataNavigationLinkAnnotation>().Add(link4);
                    break;
                }
                }
            }
            return(entry);
        }