Beispiel #1
0
 private StreamDescriptor CreateDefaultStreamDescriptor()
 {
     if (this.defaultStreamDescriptor == null)
     {
         this.defaultStreamDescriptor = new StreamDescriptor(this);
     }
     return(this.defaultStreamDescriptor);
 }
Beispiel #2
0
        /// <summary>
        /// Gets the stream info with the given name.
        /// </summary>
        /// <param name="name">name of the stream.</param>
        /// <param name="namedStreamInfo">information about the stream with the given name.</param>
        /// <returns>true if there is a stream with the given name, otherwise returns false.</returns>
        internal bool TryGetNamedStreamInfo(string name, out StreamDescriptor namedStreamInfo)
        {
            namedStreamInfo = null;

            if (this.streamDescriptors != null)
            {
                return(this.streamDescriptors.TryGetValue(name, out namedStreamInfo));
            }

            return(false);
        }
Beispiel #3
0
        private ODataRequestMessageWrapper CreateNamedStreamRequest(StreamDescriptor namedStreamInfo)
        {
            Uri latestEditLink = namedStreamInfo.GetLatestEditLink();

            if (latestEditLink == null)
            {
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_SetSaveStreamWithoutNamedStreamEditLink(namedStreamInfo.Name));
            }
            ODataRequestMessageWrapper mediaResourceRequest = this.CreateMediaResourceRequest(latestEditLink, "PUT", Util.DataServiceVersion3, true, false);

            this.SetupMediaResourceRequest(mediaResourceRequest, namedStreamInfo.SaveStream, namedStreamInfo.GetLatestETag());
            return(mediaResourceRequest);
        }
Beispiel #4
0
 internal StreamDescriptor AddStreamInfoIfNotPresent(string name)
 {
     StreamDescriptor descriptor;
     if (this.streamDescriptors == null)
     {
         this.streamDescriptors = new Dictionary<string, StreamDescriptor>(StringComparer.Ordinal);
     }
     if (!this.streamDescriptors.TryGetValue(name, out descriptor))
     {
         descriptor = new StreamDescriptor(name, this);
         this.streamDescriptors.Add(name, descriptor);
     }
     return descriptor;
 }
Beispiel #5
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;
     }
 }
Beispiel #6
0
        internal StreamDescriptor AddStreamInfoIfNotPresent(string name)
        {
            StreamDescriptor descriptor;

            if (this.streamDescriptors == null)
            {
                this.streamDescriptors = new Dictionary <string, StreamDescriptor>(StringComparer.Ordinal);
            }
            if (!this.streamDescriptors.TryGetValue(name, out descriptor))
            {
                descriptor = new StreamDescriptor(name, this);
                this.streamDescriptors.Add(name, descriptor);
            }
            return(descriptor);
        }
Beispiel #7
0
 /// <summary>
 /// Constructs a new async result object
 /// </summary>
 /// <param name="context">The source of the operation.</param>
 /// <param name="method">Name of the method which is invoked asynchronously.</param>
 /// <param name="request">The <see cref="HttpWebRequest"/> object which is wrapped by this async result.</param>
 /// <param name="callback">User specified callback for the async operation.</param>
 /// <param name="state">User state for the async callback.</param>
 /// <param name="streamDescriptor">stream descriptor whose value is getting queried.</param>
 internal GetReadStreamResult(
     DataServiceContext context,
     string method,
     ODataRequestMessageWrapper request,
     AsyncCallback callback,
     object state,
     StreamDescriptor streamDescriptor)
     : base(context, method, callback, state)
 {
     Debug.Assert(request != null, "Null request can't be wrapped to a result.");
     Debug.Assert(streamDescriptor != null, "streamDescriptor != null");
     this.requestMessage   = request;
     this.Abortable        = request;
     this.streamDescriptor = streamDescriptor;
     this.requestInfo      = new RequestInfo(context);
 }
Beispiel #8
0
        internal void MergeStreamDescriptor(StreamDescriptor materializedStreamDescriptor)
        {
            if (this.streamDescriptors == null)
            {
                this.streamDescriptors = new Dictionary <string, StreamDescriptor>(StringComparer.Ordinal);
            }
            StreamDescriptor descriptor = null;

            if (!this.streamDescriptors.TryGetValue(materializedStreamDescriptor.Name, out descriptor))
            {
                this.streamDescriptors[materializedStreamDescriptor.Name] = materializedStreamDescriptor;
                materializedStreamDescriptor.EntityDescriptor             = this;
            }
            else
            {
                StreamDescriptor.MergeStreamDescriptor(descriptor, materializedStreamDescriptor);
            }
        }
Beispiel #9
0
 internal static void MergeStreamDescriptor(StreamDescriptor existingStreamDescriptor, StreamDescriptor newStreamDescriptor)
 {
     if (newStreamDescriptor.SelfLink != null)
     {
         existingStreamDescriptor.SelfLink = newStreamDescriptor.SelfLink;
     }
     if (newStreamDescriptor.EditLink != null)
     {
         existingStreamDescriptor.EditLink = newStreamDescriptor.EditLink;
     }
     if (newStreamDescriptor.ContentType != null)
     {
         existingStreamDescriptor.ContentType = newStreamDescriptor.ContentType;
     }
     if (newStreamDescriptor.ETag != null)
     {
         existingStreamDescriptor.ETag = newStreamDescriptor.ETag;
     }
 }
Beispiel #10
0
 internal static void MergeStreamDescriptor(StreamDescriptor existingStreamDescriptor, StreamDescriptor newStreamDescriptor)
 {
     if (newStreamDescriptor.SelfLink != null)
     {
         existingStreamDescriptor.SelfLink = newStreamDescriptor.SelfLink;
     }
     if (newStreamDescriptor.EditLink != null)
     {
         existingStreamDescriptor.EditLink = newStreamDescriptor.EditLink;
     }
     if (newStreamDescriptor.ContentType != null)
     {
         existingStreamDescriptor.ContentType = newStreamDescriptor.ContentType;
     }
     if (newStreamDescriptor.ETag != null)
     {
         existingStreamDescriptor.ETag = newStreamDescriptor.ETag;
     }
 }
Beispiel #11
0
        /// <summary>
        /// Merges the given named stream info object.
        /// If the stream descriptor is already present, then this method merges the info from the given stream descriptor
        /// into the existing one, otherwise justs add this given stream descriptor to the list of stream descriptors for
        /// this entity.
        /// </summary>
        /// <param name="materializedStreamDescriptor">namedStreamInfo instance containing information about the stream.</param>
        internal void MergeStreamDescriptor(StreamDescriptor materializedStreamDescriptor)
        {
            if (this.streamDescriptors == null)
            {
                this.streamDescriptors = new Dictionary <string, StreamDescriptor>(StringComparer.Ordinal);
            }

            StreamDescriptor existingStreamDescriptor = null;

            if (!this.streamDescriptors.TryGetValue(materializedStreamDescriptor.Name, out existingStreamDescriptor))
            {
                this.streamDescriptors[materializedStreamDescriptor.Name] = materializedStreamDescriptor;
                materializedStreamDescriptor.EntityDescriptor             = this;
            }
            else
            {
                StreamDescriptor.MergeStreamDescriptor(existingStreamDescriptor, materializedStreamDescriptor);
                Debug.Assert(ReferenceEquals(existingStreamDescriptor.EntityDescriptor, this), "All stream descriptors that are already tracked by the entity must point to the same entity descriptor instance");
            }
        }
Beispiel #12
0
        /// <summary>
        /// Merge the information from the new stream info into the existing one.
        /// </summary>
        /// <param name="existingStreamDescriptor">stream info into which the data needs to be merged.</param>
        /// <param name="newStreamDescriptor">stream info which contains the latest data.</param>
        internal static void MergeStreamDescriptor(StreamDescriptor existingStreamDescriptor, StreamDescriptor newStreamDescriptor)
        {
            // overwrite existing information with new ones (coming from the payload).
            if (newStreamDescriptor.SelfLink != null)
            {
                existingStreamDescriptor.SelfLink = newStreamDescriptor.SelfLink;
            }

            if (newStreamDescriptor.EditLink != null)
            {
                existingStreamDescriptor.EditLink = newStreamDescriptor.EditLink;
            }

            if (newStreamDescriptor.ContentType != null)
            {
                existingStreamDescriptor.ContentType = newStreamDescriptor.ContentType;
            }

            if (newStreamDescriptor.ETag != null)
            {
                existingStreamDescriptor.ETag = newStreamDescriptor.ETag;
            }
        }
Beispiel #13
0
 internal GetReadStreamResult(DataServiceContext context, string method, ODataRequestMessageWrapper request, AsyncCallback callback, object state, StreamDescriptor streamDescriptor) : base(context, method, callback, state)
 {
     this.requestMessage = request;
     base.Abortable = request;
     this.streamDescriptor = streamDescriptor;
 }
Beispiel #14
0
 internal override void ClearChanges()
 {
     this.transientNamedStreamInfo = null;
     this.CloseSaveStream();
 }
Beispiel #15
0
 internal void MergeStreamDescriptor(StreamDescriptor materializedStreamDescriptor)
 {
     if (this.streamDescriptors == null)
     {
         this.streamDescriptors = new Dictionary<string, StreamDescriptor>(StringComparer.Ordinal);
     }
     StreamDescriptor descriptor = null;
     if (!this.streamDescriptors.TryGetValue(materializedStreamDescriptor.Name, out descriptor))
     {
         this.streamDescriptors[materializedStreamDescriptor.Name] = materializedStreamDescriptor;
         materializedStreamDescriptor.EntityDescriptor = this;
     }
     else
     {
         StreamDescriptor.MergeStreamDescriptor(descriptor, materializedStreamDescriptor);
     }
 }
Beispiel #16
0
 internal bool TryGetNamedStreamInfo(string name, out StreamDescriptor namedStreamInfo)
 {
     namedStreamInfo = null;
     return ((this.streamDescriptors != null) && this.streamDescriptors.TryGetValue(name, out namedStreamInfo));
 }
Beispiel #17
0
 private StreamDescriptor CreateDefaultStreamDescriptor()
 {
     if (this.defaultStreamDescriptor == null)
     {
         this.defaultStreamDescriptor = new StreamDescriptor(this);
     }
     return this.defaultStreamDescriptor;
 }
 internal GetReadStreamResult(DataServiceContext context, string method, ODataRequestMessageWrapper request, AsyncCallback callback, object state, StreamDescriptor streamDescriptor) : base(context, method, callback, state)
 {
     this.requestMessage   = request;
     base.Abortable        = request;
     this.streamDescriptor = streamDescriptor;
 }
Beispiel #19
0
 /// <summary>
 /// clears all the changes - like closes the save stream, clears the transient entity descriptor.
 /// This method is called when the client is done with sending all the pending requests.
 /// </summary>
 internal override void ClearChanges()
 {
     this.transientNamedStreamInfo = null;
     this.CloseSaveStream();
 }
Beispiel #20
0
 private ODataRequestMessageWrapper CreateNamedStreamRequest(StreamDescriptor namedStreamInfo)
 {
     Uri latestEditLink = namedStreamInfo.GetLatestEditLink();
     if (latestEditLink == null)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_SetSaveStreamWithoutNamedStreamEditLink(namedStreamInfo.Name));
     }
     ODataRequestMessageWrapper mediaResourceRequest = this.CreateMediaResourceRequest(latestEditLink, "PUT", Util.DataServiceVersion3, true, false);
     this.SetupMediaResourceRequest(mediaResourceRequest, namedStreamInfo.SaveStream, namedStreamInfo.GetLatestETag());
     return mediaResourceRequest;
 }