private StreamData GenerateStreamData(EntityInstance entityInstance, XmlBaseAnnotation baseAddressAnnotation, QueryProperty streamProperty) { string editLinkValue; string contentType; string etag; if (streamProperty.Name == AstoriaQueryStreamType.DefaultStreamPropertyName) { editLinkValue = entityInstance.StreamEditLink; contentType = entityInstance.StreamContentType; etag = entityInstance.StreamETag; } else { var namedStream = entityInstance.Properties.OfType<NamedStreamInstance>().SingleOrDefault(p => p.Name == streamProperty.Name); ExceptionUtilities.CheckObjectNotNull(namedStream, "Could not find name stream '{0}' in entity payload", streamProperty.Name); editLinkValue = namedStream.EditLink; contentType = namedStream.EditLinkContentType; etag = namedStream.ETag; } if (contentType == null) { // TODO: add atom/json? contentType = this.Random.ChooseFrom(new[] { MimeTypes.TextPlain, MimeTypes.ApplicationOctetStream, MimeTypes.ApplicationHttp }); } var streamData = new StreamData() { ContentType = contentType, ETag = etag, Content = this.Random.NextBytes(this.Random.Next(100)), }; if (editLinkValue != null) { var editLink = new Uri(editLinkValue, UriKind.RelativeOrAbsolute); if (!editLink.IsAbsoluteUri) { ExceptionUtilities.CheckObjectNotNull(baseAddressAnnotation, "Cannot construct absolute uri for edit link because xml:base annotation was missing"); editLink = new Uri(new Uri(baseAddressAnnotation.Value), editLinkValue); } streamData.EditLink = editLink.AbsoluteUri; } return streamData; }
private void UpdateStreams(StreamData streamData, IAsyncContinuation continuation) { SendStreamValueToServer( continuation, this.Asynchronous, streamData.EditLink, streamData.ContentType, streamData.ETag, streamData.Content); }