コード例 #1
0
ファイル: BaseSaveResult.cs プロジェクト: modulexcite/pash-1
        protected ODataRequestMessageWrapper CreateRequest(EntityDescriptor entityDescriptor)
        {
            EntityStates               state          = entityDescriptor.State;
            Uri                        resourceUri    = entityDescriptor.GetResourceUri(this.RequestInfo.BaseUriResolver, false);
            ClientEdmModel             model          = ClientEdmModel.GetModel(this.RequestInfo.MaxProtocolVersion);
            Version                    requestVersion = DetermineRequestVersion(model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType())), state);
            string                     httpMethod     = this.GetHttpMethod(state, ref requestVersion);
            ODataRequestMessageWrapper requestMessage = this.CreateRequestMessage(resourceUri, httpMethod);

            if (this.IsBatch)
            {
                requestMessage.SetHeader("Content-ID", entityDescriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture));
            }
            if (EntityStates.Deleted != entityDescriptor.State)
            {
                requestMessage.SetHeader("Content-Type", "application/atom+xml");
            }
            if ((EntityStates.Deleted == state) || (EntityStates.Modified == state))
            {
                string latestETag = entityDescriptor.GetLatestETag();
                if (latestETag != null)
                {
                    requestMessage.SetHeader("If-Match", latestETag);
                    if (!this.IsBatch)
                    {
                        requestMessage.AddHeadersToReset("If-Match");
                    }
                }
            }
            ApplyPreferences(requestMessage, httpMethod, this.RequestInfo.AddAndUpdateResponsePreference, ref requestVersion);
            WebUtil.SetOperationVersionHeaders(requestMessage, requestVersion, this.RequestInfo.MaxProtocolVersionAsVersion);
            return(requestMessage);
        }
コード例 #2
0
 internal static void SetOperationVersionHeaders(ODataRequestMessageWrapper requestMessage, Version requestVersion, Version maxProtocolVersion)
 {
     if (requestVersion != null)
     {
         if (requestVersion > maxProtocolVersion)
         {
             throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_RequestVersionIsBiggerThanProtocolVersion(requestVersion.ToString(), maxProtocolVersion.ToString()));
         }
         if (requestVersion.Major > 0)
         {
             requestMessage.SetHeader("DataServiceVersion", requestVersion.ToString() + ";NetFx");
         }
     }
     requestMessage.SetHeader("MaxDataServiceVersion", maxProtocolVersion.ToString() + ";NetFx");
 }
コード例 #3
0
        private void SetupMediaResourceRequest(ODataRequestMessageWrapper mediaResourceRequest, DataServiceSaveStream saveStream, string etag)
        {
            IEnumerable <string> keys;

            base.mediaResourceRequestStream = saveStream.Stream;
            WebUtil.ApplyHeadersToRequest(saveStream.Args.Headers, mediaResourceRequest, true);
            Dictionary <string, string> headers = saveStream.Args.Headers;

            if (headers.ContainsKey("Accept"))
            {
                keys = new List <string>(headers.Count - 1);
                foreach (string str in headers.Keys)
                {
                    if (str != "Accept")
                    {
                        ((List <string>)keys).Add(str);
                    }
                }
            }
            else
            {
                keys = headers.Keys;
            }
            mediaResourceRequest.AddHeadersToReset(keys);
            if (etag != null)
            {
                mediaResourceRequest.SetHeader("If-Match", etag);
                mediaResourceRequest.AddHeadersToReset("If-Match");
            }
        }
コード例 #4
0
 internal static void ApplyHeadersToRequest(Dictionary <string, string> headers, ODataRequestMessageWrapper requestMessage, bool ignoreAcceptHeader)
 {
     foreach (KeyValuePair <string, string> pair in headers)
     {
         if (!string.Equals(pair.Key, "Accept", StringComparison.Ordinal) || !ignoreAcceptHeader)
         {
             requestMessage.SetHeader(pair.Key, pair.Value);
         }
     }
 }
コード例 #5
0
ファイル: BaseSaveResult.cs プロジェクト: modulexcite/pash-1
        protected ODataRequestMessageWrapper CreateRequest(LinkDescriptor binding)
        {
            if (binding.ContentGeneratedForSave)
            {
                return(null);
            }
            EntityDescriptor entityDescriptor = this.RequestInfo.EntityTracker.GetEntityDescriptor(binding.Source);
            EntityDescriptor descriptor2      = (binding.Target != null) ? this.RequestInfo.EntityTracker.GetEntityDescriptor(binding.Target) : null;
            Uri requestUri = null;

            if (entityDescriptor.GetLatestIdentity() == null)
            {
                if (!this.IsBatch)
                {
                    binding.ContentGeneratedForSave = true;
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_LinkResourceInsertFailure, entityDescriptor.SaveError);
                }
                Uri uri = this.CreateRequestRelativeUri(binding);
                requestUri = Util.CreateUri("$" + entityDescriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture) + "/" + CommonUtil.UriToString(uri), UriKind.Relative);
            }
            else
            {
                if ((!this.IsBatch && (descriptor2 != null)) && (descriptor2.GetLatestIdentity() == null))
                {
                    binding.ContentGeneratedForSave = true;
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_LinkResourceInsertFailure, descriptor2.SaveError);
                }
                requestUri = this.CreateRequestUri(entityDescriptor, binding);
            }
            ODataRequestMessageWrapper requestMessage = this.CreateRequestMessage(requestUri, GetLinkHttpMethod(binding));

            if (this.IsBatch)
            {
                requestMessage.SetHeader("Content-ID", binding.ChangeOrder.ToString(CultureInfo.InvariantCulture));
            }
            if ((EntityStates.Added == binding.State) || ((EntityStates.Modified == binding.State) && (binding.Target != null)))
            {
                requestMessage.SetHeader("Content-Type", "application/xml");
            }
            WebUtil.SetOperationVersionHeaders(requestMessage, Util.DataServiceVersion1, this.RequestInfo.MaxProtocolVersionAsVersion);
            return(requestMessage);
        }
コード例 #6
0
ファイル: BaseSaveResult.cs プロジェクト: modulexcite/pash-1
 protected static void ApplyPreferences(ODataRequestMessageWrapper requestMessage, string method, DataServiceResponsePreference responsePreference, ref Version requestVersion)
 {
     if (((string.CompareOrdinal("POST", method) == 0) || (string.CompareOrdinal("PUT", method) == 0)) || ((string.CompareOrdinal("MERGE", method) == 0) || (string.CompareOrdinal("PATCH", method) == 0)))
     {
         string preferHeaderAndRequestVersion = WebUtil.GetPreferHeaderAndRequestVersion(responsePreference, ref requestVersion);
         if (preferHeaderAndRequestVersion != null)
         {
             requestMessage.SetHeader("Prefer", preferHeaderAndRequestVersion);
         }
     }
 }
コード例 #7
0
ファイル: BaseSaveResult.cs プロジェクト: nickchal/pash
 protected static void ApplyPreferences(ODataRequestMessageWrapper requestMessage, string method, DataServiceResponsePreference responsePreference, ref Version requestVersion)
 {
     if (((string.CompareOrdinal("POST", method) == 0) || (string.CompareOrdinal("PUT", method) == 0)) || ((string.CompareOrdinal("MERGE", method) == 0) || (string.CompareOrdinal("PATCH", method) == 0)))
     {
         string preferHeaderAndRequestVersion = WebUtil.GetPreferHeaderAndRequestVersion(responsePreference, ref requestVersion);
         if (preferHeaderAndRequestVersion != null)
         {
             requestMessage.SetHeader("Prefer", preferHeaderAndRequestVersion);
         }
     }
 }
コード例 #8
0
        private ODataRequestMessageWrapper CreateMediaResourceRequest(Uri requestUri, string method, Version version, bool sendChunked, bool applyResponsePreference)
        {
            ODataRequestMessageWrapper requestMessage = this.CreateRequestMessage(requestUri, method);

            requestMessage.SendChunked = sendChunked;
            requestMessage.SetHeader("Content-Type", "*/*");
            if (applyResponsePreference)
            {
                BaseSaveResult.ApplyPreferences(requestMessage, method, base.RequestInfo.AddAndUpdateResponsePreference, ref version);
            }
            WebUtil.SetOperationVersionHeaders(requestMessage, version, base.RequestInfo.MaxProtocolVersionAsVersion);
            return(requestMessage);
        }
コード例 #9
0
        private ODataRequestMessageWrapper CheckAndProcessMediaEntryPost(EntityDescriptor entityDescriptor)
        {
            ClientEdmModel       model = ClientEdmModel.GetModel(base.RequestInfo.MaxProtocolVersion);
            ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType()));

            if (!clientTypeAnnotation.IsMediaLinkEntry && !entityDescriptor.IsMediaLinkEntry)
            {
                return(null);
            }
            if ((clientTypeAnnotation.MediaDataMember == null) && (entityDescriptor.SaveStream == null))
            {
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_MLEWithoutSaveStream(clientTypeAnnotation.ElementTypeName));
            }
            ODataRequestMessageWrapper mediaResourceRequest = null;

            if (clientTypeAnnotation.MediaDataMember != null)
            {
                string contentType = null;
                int    length      = 0;
                if (clientTypeAnnotation.MediaDataMember.MimeTypeProperty == null)
                {
                    contentType = "application/octet-stream";
                }
                else
                {
                    object obj2 = clientTypeAnnotation.MediaDataMember.MimeTypeProperty.GetValue(entityDescriptor.Entity);
                    string str2 = (obj2 != null) ? obj2.ToString() : null;
                    if (string.IsNullOrEmpty(str2))
                    {
                        throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_NoContentTypeForMediaLink(clientTypeAnnotation.ElementTypeName, clientTypeAnnotation.MediaDataMember.MimeTypeProperty.PropertyName));
                    }
                    contentType = str2;
                }
                object propertyValue = clientTypeAnnotation.MediaDataMember.GetValue(entityDescriptor.Entity);
                if (propertyValue == null)
                {
                    base.mediaResourceRequestStream = null;
                }
                else
                {
                    byte[] bytes = propertyValue as byte[];
                    if (bytes == null)
                    {
                        string   str3;
                        Encoding encoding;
                        HttpProcessUtility.ReadContentType(contentType, out str3, out encoding);
                        if (encoding == null)
                        {
                            encoding    = Encoding.UTF8;
                            contentType = contentType + ";charset=UTF-8";
                        }
                        bytes = encoding.GetBytes(ClientConvert.ToString(propertyValue));
                    }
                    length = bytes.Length;
                    base.mediaResourceRequestStream = new MemoryStream(bytes, 0, bytes.Length, false, true);
                }
                mediaResourceRequest = this.CreateMediaResourceRequest(entityDescriptor.GetResourceUri(base.RequestInfo.BaseUriResolver, false), "POST", Util.DataServiceVersion1, clientTypeAnnotation.MediaDataMember == null, true);
                mediaResourceRequest.SetHeader("Content-Length", length.ToString(CultureInfo.InvariantCulture));
                mediaResourceRequest.SetHeader("Content-Type", contentType);
                mediaResourceRequest.AddHeadersToReset("Content-Length");
                mediaResourceRequest.AddHeadersToReset("Content-Type");
            }
            else
            {
                mediaResourceRequest = this.CreateMediaResourceRequest(entityDescriptor.GetResourceUri(base.RequestInfo.BaseUriResolver, false), "POST", Util.DataServiceVersion1, clientTypeAnnotation.MediaDataMember == null, true);
                this.SetupMediaResourceRequest(mediaResourceRequest, entityDescriptor.SaveStream, null);
            }
            entityDescriptor.State = EntityStates.Modified;
            return(mediaResourceRequest);
        }
コード例 #10
0
ファイル: SaveResult.cs プロジェクト: nickchal/pash
 private void SetupMediaResourceRequest(ODataRequestMessageWrapper mediaResourceRequest, DataServiceSaveStream saveStream, string etag)
 {
     IEnumerable<string> keys;
     base.mediaResourceRequestStream = saveStream.Stream;
     WebUtil.ApplyHeadersToRequest(saveStream.Args.Headers, mediaResourceRequest, true);
     Dictionary<string, string> headers = saveStream.Args.Headers;
     if (headers.ContainsKey("Accept"))
     {
         keys = new List<string>(headers.Count - 1);
         foreach (string str in headers.Keys)
         {
             if (str != "Accept")
             {
                 ((List<string>) keys).Add(str);
             }
         }
     }
     else
     {
         keys = headers.Keys;
     }
     mediaResourceRequest.AddHeadersToReset(keys);
     if (etag != null)
     {
         mediaResourceRequest.SetHeader("If-Match", etag);
         mediaResourceRequest.AddHeadersToReset("If-Match");
     }
 }