internal void FireSendingRequest2(Descriptor descriptor)
 {
     HttpWebRequestMessage requestMessage = this.requestMessage as HttpWebRequestMessage;
     if (!this.IsBatchPartRequest)
     {
         if (this.GetHeader("Accept") == null)
         {
             string headerValue = this.AllowAnyAcceptType ? "*/*" : "application/atom+xml,application/xml";
             this.SetHeader("Accept", headerValue);
         }
         requestMessage.HttpWebRequest.SendChunked = this.SendChunked;
     }
     if (this.requestInfo.HasSendingRequest2EventHandlers)
     {
         HttpWebRequest request = (requestMessage == null) ? null : requestMessage.HttpWebRequest;
         IODataRequestMessage message2 = this.requestMessage;
         if ((requestMessage == null) || (request == null))
         {
             message2 = new InternalODataRequestMessage(this.requestMessage);
         }
         if (requestMessage != null)
         {
             requestMessage.BeforeSendingRequest2Event();
         }
         this.requestInfo.FireSendingRequest2(new SendingRequest2EventArgs(message2, descriptor, this.IsBatchPartRequest));
         if (requestMessage != null)
         {
             requestMessage.AfterSendingRequest2Event();
         }
     }
 }
Exemple #2
0
 internal void IncrementChange(Descriptor descriptor)
 {
     descriptor.ChangeOrder = ++this.nextChange;
 }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="headers">HTTP headers</param>
 /// <param name="descriptor">response object containing information about resources that got changed.</param>
 internal ChangeOperationResponse(Dictionary<string, string> headers, Descriptor descriptor)
     : base(headers)
 {
     Debug.Assert(descriptor != null, "descriptor != null");
     this.descriptor = descriptor;
 }
Exemple #4
0
        protected void HandleOperationResponseHeaders(HttpStatusCode statusCode, Dictionary <string, string> headers)
        {
            Descriptor descriptor = this.ChangedEntries[this.entryIndex];

            if (descriptor.DescriptorKind == DescriptorKind.Entity)
            {
                EntityDescriptor descriptor2 = (EntityDescriptor)descriptor;
                if ((((descriptor.State == EntityStates.Added) || (this.streamRequestKind == StreamRequestKind.PostMediaResource)) || Util.IsFlagSet(this.Options, SaveChangesOptions.PatchOnUpdate)) && WebUtil.SuccessStatusCode(statusCode))
                {
                    string str;
                    string str2;
                    Uri    editLink = null;
                    headers.TryGetValue("Location", out str);
                    headers.TryGetValue("DataServiceId", out str2);
                    if (str != null)
                    {
                        editLink = WebUtil.ValidateLocationHeader(str);
                    }
                    else if ((descriptor.State == EntityStates.Added) || (this.streamRequestKind == StreamRequestKind.PostMediaResource))
                    {
                        throw System.Data.Services.Client.Error.NotSupported(System.Data.Services.Client.Strings.Deserialize_NoLocationHeader);
                    }
                    if (str2 != null)
                    {
                        if (str == null)
                        {
                            throw System.Data.Services.Client.Error.NotSupported(System.Data.Services.Client.Strings.Context_BothLocationAndIdMustBeSpecified);
                        }
                        WebUtil.ValidateIdentityValue(str2);
                    }
                    else
                    {
                        str2 = str;
                    }
                    if (null != editLink)
                    {
                        this.RequestInfo.EntityTracker.AttachLocation(descriptor2.Entity, str2, editLink);
                    }
                }
                if (this.streamRequestKind != StreamRequestKind.None)
                {
                    if (!WebUtil.SuccessStatusCode(statusCode))
                    {
                        if (this.streamRequestKind == StreamRequestKind.PostMediaResource)
                        {
                            descriptor.State = EntityStates.Added;
                        }
                        this.streamRequestKind             = StreamRequestKind.None;
                        descriptor.ContentGeneratedForSave = true;
                    }
                    else
                    {
                        string str3;
                        if ((this.streamRequestKind == StreamRequestKind.PostMediaResource) && headers.TryGetValue("ETag", out str3))
                        {
                            descriptor2.ETag = str3;
                        }
                    }
                }
            }
        }
Exemple #5
0
 internal ChangeOperationResponse(Dictionary <string, string> headers, Descriptor descriptor)
     : base(headers)
 {
     Debug.Assert(descriptor != null, "descriptor != null");
     this.descriptor = descriptor;
 }
Exemple #6
0
 /// <summary>
 /// Asks the context to Fire the BuildingRequest event and get RequestMessageArgs.
 /// </summary>
 /// <param name="method">Http method for the request.</param>
 /// <param name="requestUri">Base Uri for the request.</param>
 /// <param name="headers">Request headers.</param>
 /// <param name="httpStack">HttpStack to use.</param>
 /// <param name="descriptor">Descriptor for the request, if there is one.</param>
 /// <returns>A new RequestMessageArgs object for building the request message.</returns>
 internal BuildingRequestEventArgs CreateRequestArgsAndFireBuildingRequest(string method, Uri requestUri, HeaderCollection headers, HttpStack httpStack, Descriptor descriptor)
 {
     return(this.Context.CreateRequestArgsAndFireBuildingRequest(method, requestUri, headers, httpStack, descriptor));
 }
Exemple #7
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Data.Services.Client.ChangeOperationResponse" /> class. </summary>
 /// <param name="headers">HTTP headers</param>
 /// <param name="descriptor">response object containing information about resources that got changed.</param>
 internal ChangeOperationResponse(HeaderCollection headers, Descriptor descriptor)
     : base(headers)
 {
     Debug.Assert(descriptor != null, "descriptor != null");
     this.descriptor = descriptor;
 }
Exemple #8
0
 protected int SaveResultProcessed(Descriptor descriptor)
 {
     descriptor.SaveResultWasProcessed = descriptor.State;
     int num = 0;
     if ((descriptor.DescriptorKind == DescriptorKind.Entity) && (EntityStates.Added == descriptor.State))
     {
         foreach (LinkDescriptor descriptor2 in this.RelatedLinks((EntityDescriptor) descriptor))
         {
             if (descriptor2.ContentGeneratedForSave)
             {
                 descriptor2.SaveResultWasProcessed = descriptor2.State;
                 num++;
             }
         }
     }
     return num;
 }
Exemple #9
0
 private void HandleResponsePut(Descriptor descriptor, Dictionary<string, string> responseHeaders)
 {
     if (descriptor.DescriptorKind == DescriptorKind.Entity)
     {
         string str;
         responseHeaders.TryGetValue("ETag", out str);
         EntityDescriptor entityDescriptor = (EntityDescriptor) descriptor;
         if (this.ProcessResponsePayload)
         {
             this.MaterializeResponse(entityDescriptor, this.CreateResponseInfo(entityDescriptor), str);
         }
         else
         {
             if ((EntityStates.Modified != entityDescriptor.State) && (EntityStates.Modified != entityDescriptor.StreamState))
             {
                 System.Data.Services.Client.Error.ThrowBatchUnexpectedContent(InternalError.EntryNotModified);
             }
             if (entityDescriptor.StreamState == EntityStates.Modified)
             {
                 entityDescriptor.StreamETag = str;
                 entityDescriptor.StreamState = EntityStates.Unchanged;
             }
             else
             {
                 entityDescriptor.ETag = str;
                 entityDescriptor.State = EntityStates.Unchanged;
             }
         }
     }
     else if (descriptor.DescriptorKind == DescriptorKind.Link)
     {
         if ((EntityStates.Added == descriptor.State) || (EntityStates.Modified == descriptor.State))
         {
             descriptor.State = EntityStates.Unchanged;
         }
         else if (EntityStates.Detached != descriptor.State)
         {
             System.Data.Services.Client.Error.ThrowBatchUnexpectedContent(InternalError.LinkBadState);
         }
     }
     else
     {
         string str2;
         descriptor.State = EntityStates.Unchanged;
         StreamDescriptor descriptor3 = (StreamDescriptor) descriptor;
         responseHeaders.TryGetValue("ETag", out str2);
         descriptor3.ETag = str2;
     }
 }
Exemple #10
0
 private void HandleResponsePost(Descriptor descriptor, Dictionary<string, string> contentHeaders)
 {
     if (descriptor.DescriptorKind == DescriptorKind.Entity)
     {
         string str;
         contentHeaders.TryGetValue("ETag", out str);
         this.HandleResponsePost((EntityDescriptor) descriptor, str);
     }
     else
     {
         HandleResponsePost((LinkDescriptor) descriptor);
     }
 }
Exemple #11
0
 private void HandleResponseDelete(Descriptor descriptor)
 {
     if (EntityStates.Deleted != descriptor.State)
     {
         System.Data.Services.Client.Error.ThrowBatchUnexpectedContent(InternalError.EntityNotDeleted);
     }
     if (descriptor.DescriptorKind == DescriptorKind.Entity)
     {
         EntityDescriptor resource = (EntityDescriptor) descriptor;
         this.RequestInfo.EntityTracker.DetachResource(resource);
     }
     else
     {
         this.RequestInfo.EntityTracker.DetachExistingLink((LinkDescriptor) descriptor, false);
     }
 }
Exemple #12
0
 protected void HandleOperationResponse(Descriptor descriptor, Dictionary<string, string> contentHeaders)
 {
     EntityStates unchanged = EntityStates.Unchanged;
     if (descriptor.DescriptorKind == DescriptorKind.Entity)
     {
         EntityDescriptor descriptor2 = (EntityDescriptor) descriptor;
         unchanged = descriptor2.StreamState;
     }
     if ((unchanged == EntityStates.Added) || (descriptor.State == EntityStates.Added))
     {
         this.HandleResponsePost(descriptor, contentHeaders);
     }
     else if ((unchanged == EntityStates.Modified) || (descriptor.State == EntityStates.Modified))
     {
         this.HandleResponsePut(descriptor, contentHeaders);
     }
     else if (descriptor.State == EntityStates.Deleted)
     {
         this.HandleResponseDelete(descriptor);
     }
 }