Exemplo n.º 1
0
        public static IEnumerable <ControlUsageError> ValidateUsage(ResolvedControl control)
        {
            var delayProperty = control.GetValue(DelayProperty) as ResolvedPropertyValue;

            if (delayProperty != null)
            {
                if ((int)delayProperty.Value < 0)
                {
                    yield return(new ControlUsageError("Delay cannot be set to negative number."));
                }
            }

            // validate queue settings
            var includedQueues = (control.GetValue(IncludedQueuesProperty) as ResolvedPropertyValue)?.Value as string[];
            var excludedQueues = (control.GetValue(ExcludedQueuesProperty) as ResolvedPropertyValue)?.Value as string[];

            if (includedQueues != null && excludedQueues != null)
            {
                yield return(new ControlUsageError("The IncludedQueues and ExcludedQueues cannot be used together!"));
            }
            if (includedQueues != null && !ValidateQueueNames(includedQueues))
            {
                yield return(new ControlUsageError("The IncludedQueues must contain comma-separated list of queue names (which can contain alphanumeric characters, underscore or dash)!"));
            }
            if (excludedQueues != null && !ValidateQueueNames(excludedQueues))
            {
                yield return(new ControlUsageError("The ExcludedQueues must contain comma-separated list of queue names (which can contain alphanumeric characters, underscore or dash)!"));
            }
        }
Exemplo n.º 2
0
        public static new IEnumerable <ControlUsageError> ValidateUsage(ResolvedControl control)
        {
            if (!(control.GetValue(SelectedValueProperty) is ResolvedPropertySetter selectedValueBinding))
            {
                yield break;
            }
            if (control.GetValue(ItemValueBindingProperty) is ResolvedPropertySetter itemValueBinding)
            {
                var to            = selectedValueBinding.GetResultType();
                var nonNullableTo = to?.UnwrapNullableType();
                var from          = itemValueBinding.GetResultType();

                if (to != null && from != null &&
                    !to.IsAssignableFrom(from) && !nonNullableTo.IsAssignableFrom(from))
                {
                    yield return(new ControlUsageError($"Type '{from.FullName}' is not assignable to '{to.FullName}'.", selectedValueBinding.DothtmlNode));
                }
            }
            else if (control.GetValue(DataSourceProperty) is ResolvedPropertySetter dataSourceBinding)
            {
                var to            = selectedValueBinding.GetResultType();
                var nonNullableTo = to?.UnwrapNullableType();
                var from          = dataSourceBinding.GetResultType()?.UnwrapNullableType()?.GetEnumerableType();

                if (to != null && from != null &&
                    !to.IsAssignableFrom(from) && !nonNullableTo.IsAssignableFrom(from) &&
                    !(to.IsEnum && from == typeof(string)) && !(to.UnwrapNullableType().IsEnum&& from == typeof(string)))
                {
                    yield return(new ControlUsageError($"Type '{from.FullName}' is not assignable to '{to.FullName}'.", selectedValueBinding.DothtmlNode));
                }
            }
        }
Exemplo n.º 3
0
        public static IEnumerable <ControlUsageError> ValidateUsage(ResolvedControl control)
        {
            var collectionType = control.GetValue(CheckedItemsProperty)?.GetResultType();
            var valueType      = control.GetValue(CheckedValueProperty)?.GetResultType();

            if (collectionType != null && valueType != null && ReflectionUtils.GetEnumerableType(collectionType) != valueType)
            {
                yield return(new ControlUsageError(
                                 $"Type of items in CheckedItems \'{ReflectionUtils.GetEnumerableType(collectionType)}\' must be same as CheckedValue type \'{valueType}\'.",
                                 control.GetValue(CheckedItemsProperty).DothtmlNode,
                                 control.GetValue(CheckedValueProperty).DothtmlNode
                                 ));
            }
        }
Exemplo n.º 4
0
        public static IEnumerable <ControlUsageError> ValidateUsage(ResolvedControl control)
        {
            var itemType  = control.GetValue(CheckedItemProperty)?.GetResultType();
            var valueType = control.GetValue(CheckedValueProperty)?.GetResultType();

            if (itemType != null && valueType != null && itemType != valueType)
            {
                yield return(new ControlUsageError(
                                 $"CheckedItem type \'{itemType}\' must be same as CheckedValue type \'{valueType}.",
                                 control.GetValue(CheckedItemProperty).DothtmlNode,
                                 control.GetValue(CheckedValueProperty).DothtmlNode
                                 ));
            }
        }
Exemplo n.º 5
0
        public static IEnumerable <ControlUsageError> ValidateUsage(ResolvedControl control)
        {
            var to            = control.GetValue(CheckedItemsProperty)?.GetResultType()?.UnwrapNullableType()?.GetEnumerableType();
            var nonNullableTo = to?.UnwrapNullableType();
            var from          = control.GetValue(CheckedValueProperty)?.GetResultType();

            if (to != null && from != null &&
                !to.IsAssignableFrom(from) && !nonNullableTo.IsAssignableFrom(from))
            {
                yield return(new ControlUsageError(
                                 $"Type of items in CheckedItems \'{to}\' must be same as CheckedValue type \'{from}\'.",
                                 control.GetValue(CheckedItemsProperty).DothtmlNode,
                                 control.GetValue(CheckedValueProperty).DothtmlNode
                                 ));
            }
        }
Exemplo n.º 6
0
        public static IEnumerable<ControlUsageError> ValidateUsage(ResolvedControl control)
        {
            var renderWrapperTag = (control.GetValue(RenderWrapperTagProperty) as ResolvedPropertyValue)?.Value as bool? ?? false;
            var wrapperTagName = (control.GetValue(WrapperTagNameProperty) as ResolvedPropertyValue)?.Value as string;

            if (wrapperTagName?.Trim() == "")
            {
                yield return new ControlUsageError("The WrapperTagName must not be an empty string!");
            }
            else if (renderWrapperTag && (wrapperTagName == null))
            {
                yield return new ControlUsageError("The WrapperTagName property must be set when RenderWrapperTag is true!");
            }
            else if (!renderWrapperTag && (wrapperTagName != null))
            {
                yield return new ControlUsageError("The WrapperTagName property cannot be set when RenderWrapperTag is false!");
            }
        }
Exemplo n.º 7
0
        public static IEnumerable <ControlUsageError> ValidateUsage(ResolvedControl control)
        {
            var itemType        = control.GetValue(CheckedItemProperty)?.GetResultType();
            var nonNullItemType = itemType?.IsNullable() == true
                ? itemType.GetGenericArguments()[0]
                : itemType;

            var valueType = control.GetValue(CheckedValueProperty)?.GetResultType();

            if (nonNullItemType != null && valueType != null && nonNullItemType != valueType)
            {
                yield return(new ControlUsageError(
                                 $"CheckedItem type \'{itemType}\' must be the same as or a nullable " +
                                 $"variant of the CheckedValue type \'{valueType}\'.",
                                 control.GetValue(CheckedItemProperty).DothtmlNode,
                                 control.GetValue(CheckedValueProperty).DothtmlNode
                                 ));
            }
        }