Exemplo n.º 1
0
        public void Embed()
        {
            // Load the JSON
            string json = File.ReadAllText(PathResolver.MapPath("~/Samples/Embed.json"));

            // Parse the grid control
            JObject control = JObject.Parse(json);

            // Get the JToken for the value
            JToken token = control.GetValue("value");

            GridControlEmbedValue embed = GridControlEmbedValue.Parse(null, token);

            Assert.IsTrue(embed.IsValid);
            Assert.IsTrue(embed is IHtmlString);
            Assert.AreEqual(Environment.NewLine, embed.GetSearchableText());

            //Assert.AreEqual(true, embed.Constrain);
            Assert.AreEqual(360, embed.Width);
            Assert.AreEqual(240, embed.Height);
            Assert.AreEqual("https://www.youtube.com/watch?v=VTnDYxwhSaI", embed.Url);
            Assert.AreEqual("", embed.Info);
            Assert.AreEqual("<iframe width=\"360\" height=\"203\" src=\"https://www.youtube.com/embed/VTnDYxwhSaI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>", embed.Preview + "");

            Assert.AreEqual("<iframe width=\"360\" height=\"203\" src=\"https://www.youtube.com/embed/VTnDYxwhSaI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>", embed.Value);
            Assert.AreEqual("<iframe width=\"360\" height=\"203\" src=\"https://www.youtube.com/embed/VTnDYxwhSaI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>", embed.HtmlValue + "");
        }
        /// <summary>
        /// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridControlValue"/>.
        /// </summary>
        /// <param name="control">The parent control.</param>
        /// <param name="token">The instance of <see cref="JToken"/> representing the control value.</param>
        /// <param name="value">The converted value.</param>
        public virtual bool ConvertControlValue(GridControl control, JToken token, out IGridControlValue value)
        {
            value = null;

            switch (control.Editor.Alias)
            {
            case "media":
                value = GridControlMediaValue.Parse(control, token as JObject);
                break;

            case "embed":
                value = GridControlEmbedValue.Parse(control, token);
                break;

            case "rte":
                value = GridControlRichTextValue.Parse(control, token);
                break;

            case "macro":
                value = GridControlMacroValue.Parse(control, token as JObject);
                break;

            case "headline":
            case "quote":
                value = GridControlTextValue.Parse(control, token);
                break;
            }

            return(value != null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridControlValue"/>.
        /// </summary>
        /// <param name="control">The parent control.</param>
        /// <param name="token">The instance of <see cref="JToken"/> representing the control value.</param>
        /// <param name="value">The converted value.</param>
        public virtual bool ConvertControlValue(GridControl control, JToken token, out IGridControlValue value)
        {
            value = null;

            if (IsEmbedEditor(control.Editor))
            {
                value = GridControlEmbedValue.Parse(control, token);
            }
            else if (IsMacroEditor(control.Editor))
            {
                value = GridControlMacroValue.Parse(control, token as JObject);
            }
            else if (IsMediaEditor(control.Editor))
            {
                value = GridControlMediaValue.Parse(control, token as JObject);
            }
            else if (IsRichTextEditor(control.Editor))
            {
                value = GridControlRichTextValue.Parse(control, token);
            }
            else if (IsTextStringEditor(control.Editor))
            {
                value = GridControlTextValue.Parse(control, token);
            }

            return(value != null);
        }