コード例 #1
0
 private static void FillValidatorValueBinding(ResolvedContentNode resolvedContentNode,
                                               ref List <string> propertiesBindings)
 {
     propertiesBindings.AddRange(resolvedContentNode.GetDescendantControls <Validator>()
                                 .Select(l => l.GetValueBindingOrNull(Validator.ValueProperty))
                                 .Where(l => l != null).Select(l => l.Binding.Value));
 }
コード例 #2
0
 private static void FillValidatorShowErrorMessageTextValue(ResolvedContentNode resolvedContentNode,
                                                            ref List <string> propertiesBindings)
 {
     propertiesBindings.AddRange(resolvedContentNode.GetDescendantControls <Validator>()
                                 .Select(l => l.GetValueOrNull(Validator.ShowErrorMessageTextProperty))
                                 .Where(l => l != null));
 }
コード例 #3
0
 private static void FillComboBoxDataSourceBinding(ResolvedContentNode resolvedContentNode,
                                                   ref List <string> propertiesBindings)
 {
     propertiesBindings.Add(resolvedContentNode.GetDescendantControls <ComboBox>()
                            .Select(c => c.GetValueBindingText(ItemsControl.DataSourceProperty))
                            .FirstOrDefault());
 }
コード例 #4
0
        private static void FillDivDataContextValueBinding(ResolvedContentNode resolvedContentNode,
                                                           ref List <string> propertiesBindings)
        {
            IEnumerable <ResolvedControl> divs = GetDivsInResolvedTreeRoot(resolvedContentNode);

            propertiesBindings.AddRange(divs.Select(
                                            resolvedControl => resolvedControl.GetValueBindingText(DotvvmBindableObject.DataContextProperty)));
        }
コード例 #5
0
 public static void ValidatePropertiesBindings(ResolvedContentNode resolvedContentNode,
                                               List <Property> propertiesToValidate)
 {
     foreach (var property in propertiesToValidate)
     {
         ValidatePropertyBinding(resolvedContentNode, property);
     }
 }
コード例 #6
0
        private static void FillRepeaterLiteralBinding(ResolvedContentNode resolvedContentNode,
                                                       ref List <string> propertiesBindings)
        {
            var repeaterTemplate = GetRepeaterTemplate(resolvedContentNode);

            propertiesBindings.AddRange(repeaterTemplate.GetDescendantControls <Literal>()
                                        .Select(l => l.GetValueBindingOrNull(Literal.TextProperty))
                                        .Where(l => l != null).Select(l => l.Binding.Value));
        }
コード例 #7
0
 public static void CheckControlTypeCount <T>(ResolvedContentNode resolvedTreeRoot, int count)
     where T : HtmlGenericControl
 {
     if (resolvedTreeRoot.GetDescendantControls <T>().Count() != count)
     {
         throw new CodeValidationException(string.Format(ValidationErrorMessages.TypeControlCountError, count,
                                                         typeof(T).Name));
     }
 }
コード例 #8
0
        public static ResolvedControl GetControlInRepeater <T>(ResolvedContentNode resolvedContentNode)
            where T : HtmlGenericControl
        {
            var repeaterTemplate = GetRepeaterTemplate(resolvedContentNode);

            return(repeaterTemplate
                   .GetDescendantControls <T>()
                   .Single());
        }
コード例 #9
0
        public static IEnumerable <ResolvedTreeNode> GetDescendants(this ResolvedContentNode node)
        {
            yield return(node);

            foreach (ResolvedTreeNode child in node.Content.SelectMany(n => n.GetDescendants()))
            {
                yield return(child);
            }
        }
コード例 #10
0
        private static void FillDivValidatorValueBinding(ResolvedContentNode resolvedContentNode,
                                                         ref List <string> propertiesBindings)
        {
            IEnumerable <ResolvedControl> divs   = GetDivsInResolvedTreeRoot(resolvedContentNode);
            IEnumerable <string>          result = divs.Select(
                rs => rs.GetValueBindingTextOrNull(Validator.ValueProperty)).
                                                   Where(rs => rs != null);

            propertiesBindings.AddRange(result);
        }
コード例 #11
0
        private static void FillFormValidatorInvalidCssClassValue(ResolvedContentNode resolvedContentNode,
                                                                  ref List <string> propertiesBindings)
        {
            IEnumerable <ResolvedControl> forms  = GetFormsInResolvedTreeRoot(resolvedContentNode);
            IEnumerable <string>          result = forms.Select(
                rs => rs.GetValueOrNull(Validator.InvalidCssClassProperty))
                                                   .Where(rs => rs != null);

            propertiesBindings.AddRange(result);
        }
コード例 #12
0
        public static void CheckCountOfHtmlTagWithPropertyDescriptor(ResolvedContentNode resolvedTreeRoot, string htmlTag, int count, IPropertyDescriptor propertyDescriptor, CodeValidationException codeValidationException)
        {
            var counter = resolvedTreeRoot
                          .GetChildrenControls <HtmlGenericControl>()
                          .Where(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == htmlTag)
                          .Count(d => d.GetValueOrNull(propertyDescriptor) != null);

            if (counter != count)
            {
                throw codeValidationException;
            }
        }
コード例 #13
0
        private static IEnumerable <string> GetRepeaterDivClassBinding(ResolvedContentNode resolvedContentNode)
        {
            var result = new List <string>();
            var divs   = GetDivsInResolvedTreeRoot(resolvedContentNode);

            foreach (var resolvedControl in divs)
            {
                var divClassProperties = resolvedControl.Properties
                                         .Where(p => p.Value.Property.Name == "Attributes:class")
                                         .Select(p => p.Value)
                                         .OfType <ResolvedPropertyBinding>()
                                         .ToList();
                result.AddRange(divClassProperties.Select(a => a.Binding.Value));
            }
            return(result);
        }
コード例 #14
0
        public static void CheckCountOfHtmlTag(ResolvedContentNode resolvedTreeRoot, string htmlTag, int count, CodeValidationException codeValidationException = null)
        {
            var counter = resolvedTreeRoot
                          .GetChildrenControls <HtmlGenericControl>()
                          .Count(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == htmlTag);

            if (counter != count)
            {
                if (codeValidationException == null)
                {
                    throw new CodeValidationException(string.Format(ValidationErrorMessages.HtmlTagCountError, count,
                                                                    htmlTag));
                }
                throw codeValidationException;
            }
        }
コード例 #15
0
        private static void FillDivClassValue(ResolvedContentNode resolvedContentNode,
                                              ref List <string> propertiesBindings)
        {
            var result = new List <string>();
            IEnumerable <ResolvedControl> divs = GetDivsInResolvedTreeRoot(resolvedContentNode);

            foreach (var resolvedControl in divs)
            {
                var divClassProperties = resolvedControl.Properties
                                         .Where(p => p.Value.Property.Name == "Attributes:class")
                                         .Select(p => p.Value)
                                         .OfType <ResolvedPropertyBinding>()
                                         .ToList();
                result.AddRange(divClassProperties.Select(a => a.Binding.Value));
            }
            propertiesBindings.AddRange(result);
        }
コード例 #16
0
 private static IEnumerable <ResolvedControl> GetFormsInResolvedTreeRoot(ResolvedContentNode resolvedContentNode)
 {
     return(resolvedContentNode.GetChildrenControls <HtmlGenericControl>()
            .Where(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == "form").ToList());
 }
コード例 #17
0
 private static void FillComboBoxSelectedValueBinding(ResolvedContentNode resolvedContentNode,
                                                      ref List <string> propertiesBindings)
 {
     propertiesBindings.AddRange(resolvedContentNode.GetDescendantControls <ComboBox>()
                                 .Select(c => c.GetValueBindingText(Selector.SelectedValueProperty)));
 }
コード例 #18
0
 private static void FillComboBoxValueMemberValue(ResolvedContentNode resolvedContentNode,
                                                  ref List <string> propertiesBindings)
 {
     propertiesBindings.AddRange(resolvedContentNode.GetDescendantControls <ComboBox>()
                                 .Select(c => c.GetValue(SelectorBase.ItemValueBindingProperty)));
 }
コード例 #19
0
 private static void FillTextBoxTextBinding(ResolvedContentNode resolvedContentNode, ref List <string> propertyBindings)
 {
     propertyBindings.AddRange(resolvedContentNode.GetDescendantControls <TextBox>()
                               .Select(c => c.GetValueBindingText(TextBox.TextProperty)));
 }
コード例 #20
0
 public static ResolvedPropertyTemplate GetRepeaterTemplate(ResolvedContentNode resolvedContentNode)
 {
     return(resolvedContentNode.GetDescendantControls <Repeater>().Single()
            .Properties[Repeater.ItemTemplateProperty]
            .CastTo <ResolvedPropertyTemplate>());
 }
コード例 #21
0
 public static IEnumerable <ResolvedControl> GetDescendantControls <T>(this ResolvedContentNode node)
 {
     return(GetDescendants(node).OfType <ResolvedControl>().Where(c => c.Metadata.Type == typeof(T)));
 }
コード例 #22
0
 private ResolvedBinding[] GetLiteralBindings(ResolvedContentNode node) =>
 (from c in node.Content.SelectRecursively(c => c.Content)
      where c.Metadata.Type == typeof(Literal)
  let text = FunctionalExtensions.GetValueOrDefault(c.Properties, Literal.TextProperty)
                 where text is ResolvedPropertyBinding
             select((ResolvedPropertyBinding)text).Binding).ToArray();
コード例 #23
0
 private static void FillCheckBoxCheckedItemsBinding(ResolvedContentNode resolvedContentNode,
                                                     ref List <string> propertyBindings)
 {
     propertyBindings.AddRange(resolvedContentNode.GetDescendantControls <CheckBox>()
                               .Select(c => c.GetValueBindingText(CheckBox.CheckedItemsProperty)));
 }
コード例 #24
0
 private static void FillRadioButtonCheckedItemBinding(ResolvedContentNode resolvedContentNode,
                                                       ref List <string> propertyBindings)
 {
     propertyBindings.AddRange(resolvedContentNode.GetDescendantControls <RadioButton>()
                               .Select(c => c.GetValueBindingText(RadioButton.CheckedItemProperty)));
 }
コード例 #25
0
        public static void ValidatePropertyBinding(ResolvedContentNode resolvedContentNode, Property propertyToValidate)
        {
            var propertiesBindings = new List <string>();

            switch (propertyToValidate.TargetControlBindName)
            {
            case ControlBindName.TextBoxText:
                FillTextBoxTextBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.RadioButtonCheckedItem:
                FillRadioButtonCheckedItemBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.ComboBoxDataSource:
                FillComboBoxDataSourceBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.ComboBoxSelectedValue:
                FillComboBoxSelectedValueBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.ComboBoxValueMemberNotBind:
                FillComboBoxValueMemberValue(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.ComboBoxDisplayMemberNotBind:
                FillComboBoxDisplayMemberValue(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.RepeaterDataSource:
                FillRepeaterDataSourceBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.RepeaterLiteral:
                FillRepeaterLiteralBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.RepeaterDivClass:
                propertiesBindings.AddRange(GetRepeaterDivClassBinding(resolvedContentNode));
                break;

            case ControlBindName.CheckBoxCheckedItems:
                FillCheckBoxCheckedItemsBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.DivClass:
                FillDivClassValue(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.DivDataContext:
                FillDivDataContextValueBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.DivValidatorValue:
                FillDivValidatorValueBinding(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.DivValidatorInvalidCssClass:
                FillDivValidatorInvalidCssClassValue(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.FormValidatorInvalidCssClass:
                FillFormValidatorInvalidCssClassValue(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.DivValidatorInvalidCssClassRemove:
                FillDivValidatorInvalidCssClassValue(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.ValidatorShowErrorMessageText:
                FillValidatorShowErrorMessageTextValue(resolvedContentNode, ref propertiesBindings);
                break;

            case ControlBindName.ValidatorValue:
                FillValidatorValueBinding(resolvedContentNode, ref propertiesBindings);
                break;

            default:
                throw new ArgumentException($"Property {propertyToValidate.Name}, cant be validate in DotHtml.");
            }

            var propertyName = propertyToValidate.Name;

            if (propertyToValidate.TargetControlBindName.RemovePropertyFromCode())
            {
                if (propertiesBindings.Contains(propertyName))
                {
                    throw new CodeValidationException(string.Format(ValidationErrorMessages.DeleteCodeError,
                                                                    propertyName, propertyToValidate.TargetControlBindName.ToDescriptionString()));
                }
            }
            else
            {
                if (!propertiesBindings.Contains(propertyName))
                {
                    throw new CodeValidationException(string.Format(ValidationErrorMessages.ValueBindingError,
                                                                    propertyToValidate.TargetControlBindName.ToDescriptionString(), propertyName));
                }
            }
        }
コード例 #26
0
 private static void FillRepeaterDataSourceBinding(ResolvedContentNode resolvedContentNode,
                                                   ref List <string> propertyBindings)
 {
     propertyBindings.AddRange(resolvedContentNode.GetDescendantControls <Repeater>()
                               .Select(c => c.GetValueBindingText(ItemsControl.DataSourceProperty)));
 }
コード例 #27
0
 public static void ValidateStep2ValidationProperties(ResolvedContentNode resolvedContentNode)
 {
     DotHtmlCommonValidator.ValidatePropertiesBindings(resolvedContentNode, CreateStep2ValidationValueProperties());
 }
コード例 #28
0
 public static IEnumerable <ResolvedControl> GetChildrenControls <T>(this ResolvedContentNode node)
 {
     return(node.Content.OfType <ResolvedControl>().Where(c => c.Metadata.Type == typeof(T)));
 }