private static bool IsTransformRequired(string propertyName, DisplayMetadata modelMetadata, IReadOnlyList <object> propertyAttributes) { if (!string.IsNullOrEmpty(modelMetadata.SimpleDisplayProperty)) { return(false); } var displayAttribute = propertyAttributes.OfType <DisplayAttribute>().FirstOrDefault(); var displayNameAttribute = propertyAttributes.OfType <DisplayNameAttribute>().FirstOrDefault(); if (displayNameAttribute != null) { return(false); } if (displayAttribute?.GetName() != null) { return(false); } if (string.IsNullOrEmpty(propertyName)) { return(false); } return(true); }
/// <summary> /// Adds a value to the AdditionalValues collection with a formatted validation message taken from a /// ValidationAttribute. Intended to be used as a shortcut for adding validation messages associated with /// ValidationAttributes in an implementation of IMetadataAttribute /// </summary> /// <param name="key">The name of the property (key) to add to the collection.</param> /// <param name="value">The value to add to the collection.</param> /// <param name="attribute">The attribute from which the validation message will be extracted.</param> /// <returns>ModelMetadata instance for method chaining</returns> public static DisplayMetadata AddAdditionalValueWithValidationMessage(this DisplayMetadata modelMetaData, string key, object value, ValidationAttribute attribute) { modelMetaData.AdditionalValues.Add(key, value); modelMetaData.AdditionalValues.Add(key + "ValMsg", attribute.FormatErrorMessage(modelMetaData.DisplayName())); return(modelMetaData); }
public void Process(DisplayMetadata modelMetaData) { modelMetaData .AddAdditionalValueIfNotEmpty("Toolbars", Toolbars) .AddAdditionalValueIfNotEmpty("CustomToolbar", CustomToolbar) .TemplateHint = DataType.Html.ToString(); }
public void Configure(DisplayMetadata metadata) { foreach (var action in _displayActions) { action(metadata); } }
private void AddConfigToMetadata(DisplayMetadata modelMetaData) { if (!string.IsNullOrEmpty(ConfigFilePath)) { ValidateFilePathSource(); modelMetaData.AdditionalValues.Add("ConfigPath", ConfigFilePath); } if (ConfigSource == null) { return; } if (ConfigSource.GetConstructor(Type.EmptyTypes) == null) { var msg = $"ConfigSource type '{ConfigSource.FullName}'does not have a public parameterless constructor."; throw new InvalidOperationException(msg); } var source = Activator.CreateInstance(ConfigSource); if (source is IHtmlEditorConfigSource configSource) { modelMetaData.AdditionalValues.Add("Options", configSource.Create()); } else { var msg = $"ConfigSource type '{ConfigSource.FullName}' is not a valid config type. Valid types inherit from {typeof(IHtmlEditorConfigSource).Name}"; throw new InvalidOperationException(msg); } }
public override void SetDisplayMetadata(DisplayMetadata displayMetadata) { base.SetDisplayMetadata(displayMetadata); displayMetadata.TemplateHint = "DropDownList"; displayMetadata.AdditionalValues["OptionLabel"] = OptionLabel; }
private static bool IsTransformRequired(string propertyName, DisplayMetadata modelMetadata, IReadOnlyList <object> propertyAttributes) { if (!string.IsNullOrWhiteSpace(modelMetadata.SimpleDisplayProperty)) { return(false); } if (propertyAttributes.OfType <DisplayNameAttribute>().Any()) { return(false); } if (propertyAttributes.OfType <DisplayAttribute>().Any()) { var displayName = modelMetadata.DisplayName?.Invoke(); return(string.IsNullOrWhiteSpace(displayName)); } if (string.IsNullOrWhiteSpace(propertyName)) { return(false); } return(true); }
public void EditFormatString_LastSettingWins() { // Arrange var displayMetadata = new DisplayMetadata(); // Act 1 displayMetadata.EditFormatString = "first string"; // Assert 1 Assert.Equal("first string", displayMetadata.EditFormatString); Assert.Equal("first string", displayMetadata.EditFormatStringProvider()); // Act 2 displayMetadata.EditFormatStringProvider = () => "second string"; // Assert 2 Assert.Equal("second string", displayMetadata.EditFormatString); Assert.Equal("second string", displayMetadata.EditFormatStringProvider()); // Act 3 displayMetadata.EditFormatString = "third string"; // Assert 3 Assert.Equal("third string", displayMetadata.EditFormatString); Assert.Equal("third string", displayMetadata.EditFormatStringProvider()); }
private static bool IsTransformRequired(string propertyName, DisplayMetadata modelMetadata, IReadOnlyList <object> propertyAttributes) { if (modelMetadata.DisplayName != null) { return(false); } if (!string.IsNullOrEmpty(modelMetadata.SimpleDisplayProperty)) { return(false); } if (propertyAttributes.OfType <DisplayNameAttribute>().Any()) { return(false); } if (propertyAttributes.OfType <DisplayAttribute>().Any()) { return(false); } if (string.IsNullOrEmpty(propertyName)) { return(false); } return(true); }
public void Process(DisplayMetadata modelMetaData) { modelMetaData .AddAdditionalValueIfNotEmpty("Orderable", IsOrderable); modelMetaData.TemplateHint = "PageCollection"; }
public void NullDisplayText_LastSettingWins() { // Arrange var displayMetadata = new DisplayMetadata(); // Act 1 displayMetadata.NullDisplayText = "first string"; // Assert 1 Assert.Equal("first string", displayMetadata.NullDisplayText); Assert.Equal("first string", displayMetadata.NullDisplayTextProvider()); // Act 2 displayMetadata.NullDisplayTextProvider = () => "second string"; // Assert 2 Assert.Equal("second string", displayMetadata.NullDisplayText); Assert.Equal("second string", displayMetadata.NullDisplayTextProvider()); // Act 3 displayMetadata.NullDisplayText = "third string"; // Assert 3 Assert.Equal("third string", displayMetadata.NullDisplayText); Assert.Equal("third string", displayMetadata.NullDisplayTextProvider()); }
public void Process(DisplayMetadata modelMetaData) { modelMetaData.TemplateHint = "Number"; modelMetaData .AddAdditionalValueIfNotEmpty("Step", Step) ; }
public void Process(DisplayMetadata modelMetaData) { modelMetaData .AddAdditionalValueIfNotEmpty("CustomEntityDefinitionCodes", string.Join(",", CustomEntityDefinitionCodes)) .AddAdditionalValueIfNotEmpty("Orderable", IsOrderable); modelMetaData.TemplateHint = "CustomEntityMultiTypeCollection"; }
public void Process(DisplayMetadata modelMetaData) { modelMetaData .AddAdditionalValueIfNotEmpty("CustomEntityDefinitionCode", CustomEntityDefinitionCode) .AddAdditionalValueIfNotEmpty("Orderable", IsOrderable); modelMetaData.TemplateHint = "CustomEntityCollection"; }
/// <summary> /// Adds a value to the AdditionalValues collection if the value is not null /// </summary> /// <param name="property">The name of the property (key) to add to the collection.</param> /// <param name="value">The value to add to the collection.</param> /// <returns>ModelMetadata instance for method chaining</returns> public static DisplayMetadata AddAdditionalValueIfNotNull(this DisplayMetadata modelMetaData, string property, object value) { if (value != null) { modelMetaData.AdditionalValues.Add(property, value); } return(modelMetaData); }
/// <summary> /// Process display attibute /// </summary> /// <param name="metadata"></param> /// <param name="identity"></param> public static void Transform([NotNull] DisplayMetadata metadata, ModelMetadataIdentity identity) { Invariant.IsNotNull(metadata, "metadata"); if (!DisableNameProcessing && (metadata.DisplayName == null || metadata.DisplayName() == identity.Name)) { metadata.DisplayName = () => identity.Name.SplitUpperCaseToString(); } }
/// <summary> /// Adds a value to the AdditionalValues collection if the specified condition is true. /// </summary> /// <param name="condition">Result of a condition which will indicate whether to add the value or not</param> /// <param name="property">The name of the property (key) to add to the collection.</param> /// <param name="value">The value to add to the collection.</param> /// <returns>ModelMetadata instance for method chaining</returns> public static DisplayMetadata AddAdditionalValueIf(this DisplayMetadata modelMetaData, bool condition, string property, object value) { if (condition) { modelMetaData.AdditionalValues.Add(property, value); } return(modelMetaData); }
/// <summary> /// Adds a value to the AdditionalValues collection if the value is not null or empty (default value) /// </summary> /// <param name="property">The name of the property (key) to add to the collection.</param> /// <param name="value">The value to add to the collection.</param> /// <returns>ModelMetadata instance for method chaining</returns> public static DisplayMetadata AddAdditionalValueIfNotEmpty <T>(this DisplayMetadata modelMetaData, string property, T value) { if (value != null && !EqualityComparer <T> .Default.Equals(value, default(T))) { modelMetaData.AdditionalValues.Add(property, value); } return(modelMetaData); }
/// <summary> /// Adds a collection value to the AdditionalValues collection if the collection is not null or empty /// </summary> /// <param name="property">The name of the property (key) to add to the collection.</param> /// <param name="value">The collection value to add to the collection.</param> /// <returns>ModelMetadata instance for method chaining</returns> public static DisplayMetadata AddAdditionalValueIfNotEmpty <T>(this DisplayMetadata modelMetaData, string property, ICollection <T> value) { if (value != null && value.Any()) { modelMetaData.AdditionalValues.Add(property, value); } return(modelMetaData); }
public void Process(DisplayMetadata modelMetaData) { modelMetaData .AddAdditionalValueIfNotEmpty("Width", Width) .AddAdditionalValueIfNotEmpty("Height", Height) .AddAdditionalValueIfNotEmpty("MinWidth", MinWidth) .AddAdditionalValueIfNotEmpty("MinHeight", MinHeight); modelMetaData.TemplateHint = "ImageAssetCollection"; }
public void NullDisplayTextProvider_AffectsBothNullDisplayProperties() { // Arrange var displayMetadata = new DisplayMetadata(); // Act displayMetadata.NullDisplayTextProvider = () => "expected string"; // Assert Assert.Equal("expected string", displayMetadata.NullDisplayText); Assert.Equal("expected string", displayMetadata.NullDisplayTextProvider()); }
public void DisplayFormatString_AffectsBothDisplayFormatProperties() { // Arrange var displayMetadata = new DisplayMetadata(); // Act displayMetadata.DisplayFormatString = "expected string"; // Assert Assert.Equal("expected string", displayMetadata.DisplayFormatString); Assert.Equal("expected string", displayMetadata.DisplayFormatStringProvider()); }
public static void AddToMetadata(DisplayMetadata modelMetaData, Type optionSourceType) { if (optionSourceType == null) { throw new ArgumentNullException(nameof(optionSourceType)); } ICollection <ListOption> options = null; if (optionSourceType.IsEnum) { options = Enum .GetNames(optionSourceType) .Select(e => new ListOption(TextFormatter.PascalCaseToSentence(e), e)) .ToList(); } else { if (optionSourceType.GetConstructor(Type.EmptyTypes) == null) { var msg = "OptionSource type does not have a public parameterless constructor."; throw new InvalidOperationException(msg); } var source = Activator.CreateInstance(optionSourceType); if (source is IListOptionApiSource apiSource) { ValidateApiSource(optionSourceType, apiSource); modelMetaData.AdditionalValues.Add("OptionsApi", apiSource.Path); modelMetaData.AdditionalValues.Add("OptionName", TextFormatter.Camelize(apiSource.NameField)); modelMetaData.AdditionalValues.Add("OptionValue", TextFormatter.Camelize(apiSource.ValueField)); } else if (source is IListOptionSource listOptionSource) { options = listOptionSource.Create(); } else { var msg = "OptionSource type is not a valid type. Valid types are "; throw new InvalidOperationException(msg); } } if (options != null) { modelMetaData.AdditionalValues.Add("OptionName", "text"); modelMetaData.AdditionalValues.Add("OptionValue", "value"); modelMetaData.AdditionalValues.Add("Options", options); } }
public void Decorate(object attribute, DisplayMetadata modelMetaData) { if (attribute == null) throw new ArgumentNullException(nameof(attribute)); if (!(attribute is MaxLengthAttribute)) { throw new ArgumentException("Attribute type is not MaxLengthAttribute", nameof(attribute)); } var maxLengthttribtue = (MaxLengthAttribute)attribute; modelMetaData.AddAdditionalValueWithValidationMessage("Maxlength", maxLengthttribtue.Length, maxLengthttribtue); }
public void Process(DisplayMetadata modelMetaData) { modelMetaData.AddAdditionalValueIfNotEmpty("Tags", Tags); if (FileExtensions != null && FileExtensions.Length == 1) { modelMetaData.AddAdditionalValueIfNotEmpty("FileExtension", FileExtensions.First()); } else if (FileExtensions != null) { modelMetaData.AddAdditionalValueIfNotEmpty("FileExtensions", string.Join(", ", FileExtensions)); } modelMetaData.TemplateHint = "DocumentAsset"; }
private async void ChannelListComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ChannelBase newChannel = (ChannelListComboBox.SelectedItem as ComboBoxItem).Tag as ChannelBase; Color newColor; if (newChannel is SystemChannel) { DisplayMetadata metadata = (newChannel as SystemChannel).VisualIdentity; // 'Color' can technically be any CSS colour string // For now, we assume that it'll always be in "#000000" format int color = Int32.Parse(metadata.Color.Substring(1), System.Globalization.NumberStyles.HexNumber); newColor = Color.FromRgb( (byte)((color >> 16) & 0xFF), (byte)((color >> 8) & 0xFF), (byte)(color & 0xFF)); } else if (newChannel is DefaultChannel) { // Use white for default channel newColor = Color.FromRgb(255, 255, 255); } else if (newChannel != null) { // A new channel type has been added to the service Console.WriteLine($"Unexpected channel type {newChannel.ChannelType}"); newColor = Color.FromRgb(0, 0, 0); } else { return; } Dispatcher.Invoke(() => { ChannelColorEllipse.Fill = new SolidColorBrush() { Color = newColor }; }); try { await newChannel.JoinAsync(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void Process(DisplayMetadata modelMetaData) { modelMetaData .AddAdditionalValueIfNotEmpty("Tags", Tags) .AddAdditionalValueIfNotEmpty("Width", Width) .AddAdditionalValueIfNotEmpty("Height", Height) .AddAdditionalValueIfNotEmpty("MinWidth", MinWidth) .AddAdditionalValueIfNotEmpty("MinHeight", MinHeight) .AddAdditionalValueIfNotEmpty("PreviewWidth", PreviewWidth) .AddAdditionalValueIfNotEmpty("PreviewHeight", PreviewHeight) ; modelMetaData.TemplateHint = "ImageAsset"; }
public DisplayMetadataProviderContext( ModelMetadataIdentity key, ModelAttributes attributes) { if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } Key = key; Attributes = attributes.Attributes; PropertyAttributes = attributes.PropertyAttributes; TypeAttributes = attributes.TypeAttributes; DisplayMetadata = new DisplayMetadata(); }
/// <summary> /// Provides metadata to the model metadata creation process. /// </summary> /// <param name="metadata">The model metadata.</param> public override void OnMetadataCreated(DisplayMetadata metadata) { List <FWSizeAttribute> sizes; if (!metadata.AdditionalValues.ContainsKey(nameof(FWSizeAttribute))) { sizes = new List <FWSizeAttribute>(); metadata.AdditionalValues.Add(nameof(FWSizeAttribute), sizes); } else { sizes = metadata.AdditionalValues[nameof(FWSizeAttribute)] as List <FWSizeAttribute>; } sizes.Add(this); }
/// <summary> /// Creates a new <see cref="DisplayMetadataProviderContext"/>. /// </summary> /// <param name="key">The <see cref="ModelMetadataIdentity"/> for the <see cref="ModelMetadata"/>.</param> /// <param name="attributes">The attributes for the <see cref="ModelMetadata"/>.</param> public DisplayMetadataProviderContext( ModelMetadataIdentity key, ModelAttributes attributes) { if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } Key = key; Attributes = attributes.Attributes; PropertyAttributes = attributes.PropertyAttributes; TypeAttributes = attributes.TypeAttributes; DisplayMetadata = new DisplayMetadata(); }
public static void AddFilterData( DisplayMetadata modelMetaData, ICollection <string> fileExtensions, ICollection <string> tags ) { modelMetaData.AddAdditionalValueIfNotEmpty("Tags", tags); if (fileExtensions != null && fileExtensions.Count == 1) { modelMetaData.AddAdditionalValueIfNotEmpty("FileExtension", fileExtensions.First()); } else if (fileExtensions != null) { modelMetaData.AddAdditionalValueIfNotEmpty("FileExtensions", string.Join(", ", fileExtensions)); } }