예제 #1
0
        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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 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);
     }
 }
예제 #5
0
        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;
        }
예제 #7
0
        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);
        }
예제 #8
0
    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());
    }
예제 #9
0
        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);
        }
예제 #10
0
        public void Process(DisplayMetadata modelMetaData)
        {
            modelMetaData
            .AddAdditionalValueIfNotEmpty("Orderable", IsOrderable);

            modelMetaData.TemplateHint = "PageCollection";
        }
예제 #11
0
    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());
    }
예제 #12
0
        public void Process(DisplayMetadata modelMetaData)
        {
            modelMetaData.TemplateHint = "Number";

            modelMetaData
            .AddAdditionalValueIfNotEmpty("Step", Step)
            ;
        }
예제 #13
0
        public void Process(DisplayMetadata modelMetaData)
        {
            modelMetaData
            .AddAdditionalValueIfNotEmpty("CustomEntityDefinitionCodes", string.Join(",", CustomEntityDefinitionCodes))
            .AddAdditionalValueIfNotEmpty("Orderable", IsOrderable);

            modelMetaData.TemplateHint = "CustomEntityMultiTypeCollection";
        }
예제 #14
0
        public void Process(DisplayMetadata modelMetaData)
        {
            modelMetaData
            .AddAdditionalValueIfNotEmpty("CustomEntityDefinitionCode", CustomEntityDefinitionCode)
            .AddAdditionalValueIfNotEmpty("Orderable", IsOrderable);

            modelMetaData.TemplateHint = "CustomEntityCollection";
        }
예제 #15
0
        /// <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();
            }
        }
예제 #17
0
        /// <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);
        }
예제 #18
0
        /// <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);
        }
예제 #19
0
        /// <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);
        }
예제 #20
0
        public void Process(DisplayMetadata modelMetaData)
        {
            modelMetaData
            .AddAdditionalValueIfNotEmpty("Width", Width)
            .AddAdditionalValueIfNotEmpty("Height", Height)
            .AddAdditionalValueIfNotEmpty("MinWidth", MinWidth)
            .AddAdditionalValueIfNotEmpty("MinHeight", MinHeight);

            modelMetaData.TemplateHint = "ImageAssetCollection";
        }
예제 #21
0
    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());
    }
예제 #22
0
    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());
    }
예제 #23
0
        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);
            }
        }
예제 #24
0
        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);
        }
예제 #25
0
 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";
 }
예제 #26
0
        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());
            }
        }
예제 #27
0
        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();
    }
예제 #29
0
        /// <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);
        }
예제 #30
0
        /// <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();
        }
예제 #31
0
 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));
     }
 }