/// <summary> /// Adds stream properties to structural value. /// </summary> /// <param name="entity">The target structural value.</param> /// <param name="payload">The payload with the entity values.</param> /// <param name="xmlBaseAnnotations">The xml base annotations ancestors and local element</param> private void AddStreamProperties(QueryStructuralValue entity, EntityInstance payload, IEnumerable <XmlBaseAnnotation> xmlBaseAnnotations) { ExceptionUtilities.CheckArgumentNotNull(entity, "entity"); ExceptionUtilities.CheckArgumentNotNull(payload, "payload"); var xmlBaseAnnotationsList = xmlBaseAnnotations.ToList(); if (payload.IsMediaLinkEntry()) { string editLink = this.NormalizeLinkFromPayload(payload.StreamEditLink, xmlBaseAnnotationsList); string selfLink = this.NormalizeLinkFromPayload(payload.StreamSourceLink, xmlBaseAnnotationsList); entity.SetStreamValue(null, payload.StreamContentType, payload.StreamETag, editLink, selfLink, new byte[0]); } foreach (var stream in payload.Properties.OfType <NamedStreamInstance>()) { string contentType = stream.SourceLinkContentType; if (contentType == null) { contentType = stream.EditLinkContentType; } string editLink = this.NormalizeLinkFromPayload(stream.EditLink, xmlBaseAnnotationsList); string selfLink = this.NormalizeLinkFromPayload(stream.SourceLink, xmlBaseAnnotationsList); entity.SetStreamValue(stream.Name, contentType, stream.ETag, editLink, selfLink, new byte[0]); } }
/// <summary> /// Extends value population to include stream data /// </summary> /// <param name="row">The row containing the data</param> /// <param name="instance">The structural instacne</param> protected override void PopulateInstanceFromRow(EntitySetDataRow row, QueryStructuralValue instance) { base.PopulateInstanceFromRow(row, instance); var rowWithStreams = row as EntitySetDataRowWithStreams; if (rowWithStreams != null) { foreach (var stream in rowWithStreams.Streams) { if (stream.IsEditLinkBasedOnConvention) { ExceptionUtilities.CheckObjectNotNull(this.LinkGenerator, "Cannot compute convention-based edit link without injected generator"); stream.EditLink = this.LinkGenerator.GenerateStreamEditLink(instance, stream.Name); // for the default stream, there must always be a self-link if (stream.Name == null && stream.SelfLink == null) { stream.SelfLink = stream.EditLink; } } instance.SetStreamValue(stream.Name, stream.ContentType, stream.ETag, stream.EditLink, stream.SelfLink, stream.Content); } } instance.MarkDynamicPropertyValues(); }
private static void InitMemberStreamTypes(QueryEntityType type, QueryStructuralValue structural) { // initialize named streams foreach (var namedStream in type.Properties.Streams()) { AstoriaQueryStreamValue qsv = new AstoriaQueryStreamValue((AstoriaQueryStreamType)namedStream.PropertyType, (byte[])null, null, type.EvaluationStrategy); structural.SetStreamValue(namedStream.Name, qsv); } }
private void SynchronizeStreams(SerializableEntity serializedEntity, QueryStructuralValue instance) { if (serializedEntity.Streams != null) { foreach (var stream in serializedEntity.Streams) { if (stream.IsEditLinkBasedOnConvention) { ExceptionUtilities.CheckObjectNotNull(this.LinkGenerator, "Cannot compute convention-based edit link without injected generator"); stream.EditLink = this.LinkGenerator.GenerateStreamEditLink(instance, stream.Name); // for the default stream, there must always be a self-link if (stream.Name == null && stream.SelfLink == null) { stream.SelfLink = stream.EditLink; } } instance.SetStreamValue(stream.Name, stream.ContentType, stream.ETag, stream.EditLink, stream.SelfLink, stream.Content); } } }
/// <summary> /// Sets the values of a stream property /// </summary> /// <param name="instance">The entity which contains the stream property</param> /// <param name="name">The name of the stream property or null to indicate the default stream</param> /// <param name="contentType">The stream's content type</param> /// <param name="etag">The stream's etag</param> /// <param name="editLink">The stream's edit-link</param> /// <param name="selfLink">The stream's self-link</param> /// <param name="content">The stream's content</param> internal static void SetStreamValue(this QueryStructuralValue instance, string name, string contentType, string etag, string editLink, string selfLink, byte[] content) { ExceptionUtilities.CheckArgumentNotNull(instance, "instance"); if (name == null) { name = AstoriaQueryStreamType.DefaultStreamPropertyName; } var value = instance.GetStreamValue(name); // if its null, it may not have been initialized at all, so reassign it to be safe if (value.IsNull) { instance.SetStreamValue(name, value); } value.Value = content; value.ContentType = contentType; value.ETag = etag; value.EditLink = CreateRelativeOrAbsoluteUriOrReturnNull(editLink); value.SelfLink = CreateRelativeOrAbsoluteUriOrReturnNull(selfLink); }
public static void SetDefaultStreamValue(this QueryStructuralValue instance, AstoriaQueryStreamValue value) { ExceptionUtilities.CheckArgumentNotNull(instance, "instance"); instance.SetStreamValue(AstoriaQueryStreamType.DefaultStreamPropertyName, value); }