Example #1
0
        /// <summary>
        /// Will expand the input into the appropriate content based on scope.
        /// </summary>
        /// <param name="scopeName">The scope name.</param>
        /// <param name="input">The input to be expanded.</param>
        /// <param name="htmlEncode">Function that will html encode the output.</param>
        /// <param name="attributeEncode">Function that will html attribute encode the output.</param>
        /// <returns>The expanded content.</returns>
        protected override string PerformExpand(string scopeName, string input, Func <string, string> htmlEncode, Func <string, string> attributeEncode)
        {
            if (scopeName == ScopeName.InvalidVideo)
            {
                throw new ArgumentException("Invalid video type.", "type");
            }

            string[] parameters = input.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string   url        = Parameters.ExtractUrl(parameters);

            WikiPlex.Legacy.HorizontalAlign align = Parameters.ExtractAlign(parameters, WikiPlex.Legacy.HorizontalAlign.Center);

            IVideoRenderer videoRenderer = GetVideoRenderer(scopeName);

            videoRenderer.Dimensions = Parameters.ExtractDimensions(parameters, 285, 320);

            var content = new StringBuilder();

            using (var tw = new StringWriter(content))
                using (var writer = new WikiPlex.Legacy.HtmlTextWriter(tw, string.Empty))
                {
                    writer.NewLine = string.Empty;
                    writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "video");
                    writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Style, string.Format("text-align:{0}", align));
                    writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Div);

                    writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "player");
                    writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Span);

                    videoRenderer.Render(url, writer);

                    writer.RenderEndTag(); // </span>

                    writer.Write("<br />");

                    writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "external");
                    writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Span);
                    writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Href, url);
                    writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Target, "_blank");
                    writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.A);
                    writer.Write("Launch in another window");
                    writer.RenderEndTag();
                    writer.RenderEndTag();

                    writer.RenderEndTag(); // </div>
                }

            return(content.ToString());
        }
Example #2
0
        /// <summary>
        /// This will extract the horizontal alignment parameter.
        /// </summary>
        /// <param name="parameters">The collection of parameters.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>The <see cref="HorizontalAlign"/> value.</returns>
        /// <exception cref="ArgumentException">
        /// Thrown if the alignment value is not a valid enum value.
        ///
        /// -- or --
        ///
        /// Thrown if the alignment is not Center, Left, or Right
        /// </exception>
        public static WikiPlex.Legacy.HorizontalAlign ExtractAlign(System.Collections.Generic.ICollection <string> parameters, WikiPlex.Legacy.HorizontalAlign defaultValue)
        {
            string align;

            if (!TryGetValue(parameters, "align", out align))
            {
                return(defaultValue);
            }

            if (!Utility.IsDefinedOnEnum <WikiPlex.Legacy.HorizontalAlign>(align))
            {
                throw new System.ArgumentException("Invalid parameter.", "align");
            }

            var alignment = (WikiPlex.Legacy.HorizontalAlign)System.Enum.Parse(typeof(WikiPlex.Legacy.HorizontalAlign), align, true);

            if (alignment != WikiPlex.Legacy.HorizontalAlign.Center && alignment != WikiPlex.Legacy.HorizontalAlign.Left && alignment != WikiPlex.Legacy.HorizontalAlign.Right)
            {
                throw new System.ArgumentException("Invalid parameter.", "align");
            }

            return(alignment);
        }