/// <summary> /// Creates a request for the given named stream. /// </summary> /// <param name="namedStreamInfo">NamedStreamInfo instance containing information about the stream.</param> /// <returns>An instance of ODataRequestMessage for the given named stream.</returns> private ODataRequestMessageWrapper CreateNamedStreamRequest(StreamDescriptor namedStreamInfo) { Debug.Assert(namedStreamInfo.SaveStream != null, "The named stream must have an associated stream"); Debug.Assert(!string.IsNullOrEmpty(namedStreamInfo.SaveStream.Args.ContentType), "ContentType must not be null or empty"); Uri requestUri = namedStreamInfo.GetLatestEditLink(); if (requestUri == null) { throw Error.InvalidOperation(Strings.Context_SetSaveStreamWithoutNamedStreamEditLink(namedStreamInfo.Name)); } HeaderCollection headers = new HeaderCollection(); this.SetupMediaResourceRequest(headers, namedStreamInfo.SaveStream, namedStreamInfo.GetLatestETag()); ODataRequestMessageWrapper mediaRequestMessage = this.CreateMediaResourceRequest( requestUri, XmlConstants.HttpMethodPut, Util.ODataVersion4, true, // sendChunked false, // applyResponsePreference headers, namedStreamInfo); #if DEBUG Debug.Assert(mediaRequestMessage.GetHeader("Content-Type") == namedStreamInfo.SaveStream.Args.ContentType, "ContentType not set correctly for the named stream"); #endif return(mediaRequestMessage); }
/// <summary> /// Creates a default stream descriptor, if there is none yet, and returns it. /// If there is one already present, then returns the current instance. /// </summary> /// <returns>stream descriptor representing the default stream.</returns> private StreamDescriptor CreateDefaultStreamDescriptor() { if (this.defaultStreamDescriptor == null) { this.defaultStreamDescriptor = new StreamDescriptor(this); } return(this.defaultStreamDescriptor); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Check if there is a stream with this name. If yes, returns the information about that stream, otherwise add a streams with the given name. /// </summary> /// <param name="name">name of the stream.</param> /// <returns>an existing or new namedstreaminfo instance with the given name.</returns> internal StreamDescriptor AddStreamInfoIfNotPresent(string name) { StreamDescriptor namedStreamInfo; if (this.streamDescriptors == null) { this.streamDescriptors = new Dictionary <string, StreamDescriptor>(StringComparer.Ordinal); } if (!this.streamDescriptors.TryGetValue(name, out namedStreamInfo)) { namedStreamInfo = new StreamDescriptor(name, this); this.streamDescriptors.Add(name, namedStreamInfo); } return(namedStreamInfo); }
/// <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"); } }
/// <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; } }
/// <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(); }
/// <summary> /// Creates a default stream descriptor, if there is none yet, and returns it. /// If there is one already present, then returns the current instance. /// </summary> /// <returns>stream descriptor representing the default stream.</returns> private StreamDescriptor CreateDefaultStreamDescriptor() { if (this.defaultStreamDescriptor == null) { this.defaultStreamDescriptor = new StreamDescriptor(this); } return this.defaultStreamDescriptor; }
/// <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"); } }
/// <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; }
/// <summary> /// Check if there is a stream with this name. If yes, returns the information about that stream, otherwise add a streams with the given name. /// </summary> /// <param name="name">name of the stream.</param> /// <returns>an existing or new namedstreaminfo instance with the given name.</returns> internal StreamDescriptor AddStreamInfoIfNotPresent(string name) { StreamDescriptor namedStreamInfo; if (this.streamDescriptors == null) { this.streamDescriptors = new Dictionary<string, StreamDescriptor>(StringComparer.Ordinal); } if (!this.streamDescriptors.TryGetValue(name, out namedStreamInfo)) { namedStreamInfo = new StreamDescriptor(name, this); this.streamDescriptors.Add(name, namedStreamInfo); } return namedStreamInfo; }
private static void VerifyNamedStreamInfo(StreamDescriptor streamInfo, string selfLink, string editLink, string etag, string contentType) { Assert.AreEqual(streamInfo.StreamLink.SelfLink == null ? null : streamInfo.StreamLink.SelfLink.AbsoluteUri, selfLink == null ? null : String.Format(selfLink, streamInfo.StreamLink.Name), "self links should match"); Assert.AreEqual(streamInfo.StreamLink.EditLink == null ? null : streamInfo.StreamLink.EditLink.AbsoluteUri, editLink == null ? null : String.Format(editLink, streamInfo.StreamLink.Name), "edit links should match"); Assert.AreEqual(streamInfo.StreamLink.ContentType, contentType, "content type should match"); Assert.AreEqual(streamInfo.StreamLink.ETag, etag, "etag should match"); }
/// <summary> /// Creates a request for the given named stream. /// </summary> /// <param name="namedStreamInfo">NamedStreamInfo instance containing information about the stream.</param> /// <returns>An instance of ODataRequestMessage for the given named stream.</returns> private ODataRequestMessageWrapper CreateNamedStreamRequest(StreamDescriptor namedStreamInfo) { Debug.Assert(namedStreamInfo.SaveStream != null, "The named stream must have an associated stream"); Debug.Assert(!string.IsNullOrEmpty(namedStreamInfo.SaveStream.Args.ContentType), "ContentType must not be null or empty"); Uri requestUri = namedStreamInfo.GetLatestEditLink(); if (requestUri == null) { throw Error.InvalidOperation(Strings.Context_SetSaveStreamWithoutNamedStreamEditLink(namedStreamInfo.Name)); } HeaderCollection headers = new HeaderCollection(); this.SetupMediaResourceRequest(headers, namedStreamInfo.SaveStream, namedStreamInfo.GetLatestETag()); ODataRequestMessageWrapper mediaRequestMessage = this.CreateMediaResourceRequest( requestUri, XmlConstants.HttpMethodPut, Util.ODataVersion4, true, // sendChunked false, // applyResponsePreference headers, namedStreamInfo); #if DEBUG Debug.Assert(mediaRequestMessage.GetHeader("Content-Type") == namedStreamInfo.SaveStream.Args.ContentType, "ContentType not set correctly for the named stream"); #endif return mediaRequestMessage; }
/// <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(); }
/// <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; } }