/// <summary> /// Generates and adds stream related attributes and elements to the entity type /// </summary> /// <param name="entityType">The entity type's metadata</param> /// <param name="entityTypeClass">The entity types declaration</param> protected override void GenerateHasStreamEntityTypeCodeElements(EntityType entityType, CodeTypeDeclaration entityTypeClass) { ExceptionUtilities.Assert(entityType.HasStream(), "This method should not be called for entity types without stream."); ClientMediaEntryAnnotation clientMediaEntryAnnotation = entityType.Annotations.OfType <ClientMediaEntryAnnotation>().FirstOrDefault(); if (clientMediaEntryAnnotation != null) { // generate MediaEntry and MimeTypeProperty properties and attributes for V1 style stream support var attributeArguments1 = new CodeAttributeArgument[] { new CodeAttributeArgument(Code.Primitive(clientMediaEntryAnnotation.MediaEntryName)), }; var attributeArguments2 = new CodeAttributeArgument[] { new CodeAttributeArgument(Code.Primitive(clientMediaEntryAnnotation.MediaEntryName)), new CodeAttributeArgument(Code.Primitive(clientMediaEntryAnnotation.MimeTypePropertyName)) }; entityTypeClass.AddCustomAttribute(Code.TypeRef("MediaEntry"), attributeArguments1); entityTypeClass.AddCustomAttribute(Code.TypeRef("MimeTypeProperty"), attributeArguments2); entityTypeClass.AddAutoImplementedProperty(Code.TypeRef <byte[]>(), clientMediaEntryAnnotation.MediaEntryName); entityTypeClass.AddAutoImplementedProperty(Code.TypeRef <string>(), clientMediaEntryAnnotation.MimeTypePropertyName); } else { // No ClientMediaEntryAnnotation is found, generate HasStream atttribute for V2 and up stream support entityTypeClass.AddCustomAttribute(Code.TypeRef("HasStream")); } }
/// <summary> /// Set stream associated with entity in V1 stream support style. /// </summary> /// <param name="objectServices">IEntityModelObjectServices to get entity object adapter</param> /// <param name="wrappedEntity">entity to set stream</param> /// <param name="clientMediaEntryAnnotation">ClientMediaEntryAnnotation of the entity</param> /// <param name="streamValue">stream bytes</param> public static void SetSaveV1Stream(IEntityModelObjectServices objectServices, WrappedObject wrappedEntity, ClientMediaEntryAnnotation clientMediaEntryAnnotation, byte[] streamValue) { var objectAdapter = objectServices.GetObjectAdapter(wrappedEntity.Product.GetType().FullName); objectAdapter.SetMemberValue(wrappedEntity.Product, clientMediaEntryAnnotation.MediaEntryName, streamValue); objectAdapter.SetMemberValue(wrappedEntity.Product, clientMediaEntryAnnotation.MimeTypePropertyName, MimeTypes.TextPlain); }