Exemple #1
0
        /// <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));
        }
 public MediaAttachmentTypeNotSupportedException(MediaAttachmentType type)
     : base($"Invalid media attachment type: {type.ToString()}")
 {
 }