/// <summary> /// Creates a media attachment. /// </summary> /// <param name="type">The media type.</param> /// <param name="identifier">The media identifier to specify the media source.</param> /// <returns></returns> public MessageOptionalElementSetter CreateMediaAttachment(MediaAttachmentType type, MediaIdentifier identifier) { CheckIfAttachmentAlreadyBuilt(); TemplateBuilding = true; var payload = new MediaPayloadEntity(); identifier.AddValuesToPayloadEntity(payload); IMessageAttachmentEntity attachment; switch (type) { case MediaAttachmentType.Audio: attachment = new AudioAttachmentEntity { Payload = payload }; break; case MediaAttachmentType.Image: attachment = new ImageAttachmentEntity { Payload = payload }; break; case MediaAttachmentType.Video: attachment = new VideoAttachmentEntity { Payload = payload }; break; case MediaAttachmentType.File: attachment = new FileAttachmentEntity { Payload = payload }; break; default: throw new MediaAttachmentTypeNotSupportedException(type); } MessageEntity.Attachment = attachment; TemplateBuilding = false; return(new MessageOptionalElementSetter(this)); }
static string?ImageAttachmentFileName_StaticPropertyValidation(ImageAttachmentEntity WordAttachment, PropertyInfo pi) { var template = WordAttachment.TryGetParentEntity <EmailTemplateEntity>() !; if (template != null && WordAttachment.FileNameNode as TextTemplateParser.BlockNode == null) { try { WordAttachment.FileNameNode = EmailTemplateLogic.ParseTemplate(template, WordAttachment.FileName, out string errorMessage); return(errorMessage.DefaultToNull()); } catch (Exception ex) { return(ex.Message); } } return(null); }