Example #1
0
        /// <summary>
        /// Initiate a new <see cref="MediaElement"/> class using an attachment ID.
        /// </summary>
        /// <param name="mediaType">The media type.</param>
        /// <param name="attachmentId">The attachment ID.</param>
        /// <param name="button">An optional button below the media.</param>
        /// <returns></returns>
        public static MediaElement CreateByAttachmentId(MediaElementType mediaType, string attachmentId, Button button = null)
        {
            if (attachmentId == null)
            {
                throw new ValueException("Attachment ID must be set.");
            }

            return(new MediaElement(GetMediaElementTypeString(mediaType), attachmentId, null, button));
        }
Example #2
0
        /// <summary>
        /// Returns the string representation of <see cref="MediaElementType"/>.
        /// </summary>
        /// <param name="type">The type as an enum.</param>
        /// <returns></returns>
        private static string GetMediaElementTypeString(MediaElementType type)
        {
            switch (type)
            {
            case MediaElementType.Image:
                return("image");

            case MediaElementType.Video:
                return("video");

            default:
                throw new MediaElementTypeNotSupportedException(type);
            }
        }
Example #3
0
        /// <summary>
        /// Initiate a new <see cref="MediaElement"/> class using a URL.
        /// </summary>
        /// <param name="mediaType">The media type.</param>
        /// <param name="mediaUrl">The media URL.</param>
        /// <param name="button">An optional button below the media.</param>
        /// <returns></returns>
        public static MediaElement CreateByMediaUrl(MediaElementType mediaType, string mediaUrl, Button button = null)
        {
            if (!Uri.TryCreate(mediaUrl, UriKind.Absolute, out var validUrl))
            {
                throw new ValueException("Media URL must be set and valid.");
            }

            if (validUrl.Host != "www.facebook.com" && validUrl.Host != "business.facebook.com")
            {
                throw new ValueException("URL must be a Facebook URL.");
            }

            return(new MediaElement(GetMediaElementTypeString(mediaType), null, validUrl, button));
        }
Example #4
0
 public MediaElementTypeNotSupportedException(MediaElementType type)
     : base($"Invalid media type for media element: {type.ToString()}")
 {
 }