Ejemplo n.º 1
0
        internal static void SetStreamPropertyValue(object resourceToBeModified, Stream requestStream, IDataService service, System.Data.Services.RequestDescription description)
        {
            resourceToBeModified = service.Updatable.ResolveResource(resourceToBeModified);
            ResourceType resourceType = service.Provider.GetResourceType(resourceToBeModified);

            if (((description.TargetKind == RequestTargetKind.MediaResource) && !System.Data.Services.RequestDescription.IsNamedStream(description)) && !resourceType.IsMediaLinkEntry)
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_InvalidUriForMediaResource(service.OperationContext.AbsoluteRequestUri));
            }
            if (service.OperationContext.Host.HttpVerb == HttpVerbs.MERGE)
            {
                throw DataServiceException.CreateMethodNotAllowed(System.Data.Services.Strings.BadRequest_InvalidUriForMergeOperation(service.OperationContext.AbsoluteRequestUri), DataServiceConfiguration.GetAllowedMethods(service.Configuration, description));
            }
            if (service.OperationContext.Host.HttpVerb == HttpVerbs.PATCH)
            {
                throw DataServiceException.CreateMethodNotAllowed(System.Data.Services.Strings.BadRequest_InvalidUriForPatchOperation(service.OperationContext.AbsoluteRequestUri), DataServiceConfiguration.GetAllowedMethods(service.Configuration, description));
            }
            ResourceProperty streamProperty = null;

            if (description.TargetKind == RequestTargetKind.MediaResource)
            {
                streamProperty = System.Data.Services.RequestDescription.GetStreamProperty(description);
            }
            using (Stream stream = service.StreamProvider.GetWriteStream(resourceToBeModified, streamProperty, service.OperationContext))
            {
                WebUtil.CopyStream(requestStream, stream, service.StreamProvider.StreamBufferSize);
            }
        }