using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using Telligent.DynamicConfiguration.Components; using Telligent.Evolution.Extensibility.EmbeddableContent.Version1; using Telligent.Evolution.Extensibility.Version1; namespace Samples { public class SampleEmbeddable : IEmbeddableContentFragmentType, ITranslatablePlugin, IPlugin { readonly Guid _fragmentTypeId = new Guid("6c33babb0c0e45e8b691294b8b6569e5"); ITranslatablePluginController _translation; #region IEmbeddableContentFragmentType Members public string ContentFragmentName { get { return _translation.GetLanguageResourceValue("fragment_name"); } } public string ContentFragmentDescription { get { return _translation.GetLanguageResourceValue("fragment_description"); } } public Guid EmbeddedContentFragmentTypeId { get { return _fragmentTypeId; } } bool IEmbeddableContentFragmentType.CanEmbed(Guid contentTypeId, int userId) { return true; } PropertyGroup[] IEmbeddableContentFragmentType.EmbedConfiguration { get { var group = new PropertyGroup("options", _translation.GetLanguageResourceValue("configuration_group"), 1); group.Properties.Add(new Property("color", _translation.GetLanguageResourceValue("configuration_color"), PropertyType.Color, 1, "")); return new PropertyGroup[] { group }; } } void IEmbeddableContentFragmentType.AddUpdateContentFragments(Guid contentId, Guid contentTypeId, IEnumerable embeddedFragments) { } string IEmbeddableContentFragmentType.PreviewImageUrl { get { return null; } } string IEmbeddableContentFragmentType.Render(IEmbeddableContentFragment embeddedFragment, string target) { var color = embeddedFragment.GetString("color"); if (String.IsNullOrEmpty(color)) return String.Empty; return String.Format("
 
", color); } EmbeddableContentFragmentValidationState IEmbeddableContentFragmentType.Validate(IEmbeddableContentFragment embeddedFragment) { var color = embeddedFragment.GetString("color"); if (string.IsNullOrEmpty(color)) return new EmbeddableContentFragmentValidationState(false) { Message = _translation.GetLanguageResourceValue("configuration_colorinvalid") }; return new EmbeddableContentFragmentValidationState(true); } #endregion #region IPlugin Members string IPlugin.Description { get { return "Displays a box with configurable height."; } } void IPlugin.Initialize() { } string IPlugin.Name { get { return "Sample Embeddable"; } } #endregion #region ITranslatablePlugin Members Translation[] ITranslatablePlugin.DefaultTranslations { get { var translation = new Translation("en-us"); translation.Set("fragment_name", "Embeddable Box"); translation.Set("fragment_description", "Displays a box with configurable height."); translation.Set("configuration_group", "Options"); translation.Set("configuration_color", "Background Color"); translation.Set("configuration_colorinvalid", "A Background Color must be provided."); return new Translation[] { translation }; } } void ITranslatablePlugin.SetController(ITranslatablePluginController controller) { _translation = controller; } #endregion } }