コード例 #1
0
        public static FormViewModel CreateForm()
        {
            var htmlContent = new HtmlElementBuilder().SetName("HtmlContent").SetContent(
                "<h2 style=\"text-align: center;\"><strong>Demo Form<br /></strong></h2>\r\n<p>Test HTML Content embedded in the demo form</p>\r\n<ul>\r\n<li>FirstName / LastName</li>\r\n<li>Years of experiance</li>\r\n<li>Accept Terms and Conditions</li>\r\n<li>Submit</li>\r\n</ul>")
                              .Build();

            var firstNameText = new TextElementBuilder()
                                .SetName("First Name")
                                .SetLabel(ElementLabel.Left("First Name: "))
                                .SetDefaultValue("First Name")
                                .AddRules(
                ValidationRule <ITextElementViewModel> .Create(new TextElement_MaximumLength_Validator(10))
                .WithFailMessage("First Name must be less then 10 characters"),
                ValidationRule <ITextElementViewModel> .Create(new TextElement_MinimunLength_Validator(2))
                .WithFailMessage("First Name must be greater then 2 characters"))
                                .Build();

            var lastNameText = new TextElementBuilder()
                               .SetName("Last Name")
                               .SetLabel(ElementLabel.Left("Last Name: "))
                               .SetDefaultValue("Last Name")
                               .AddRules(
                ValidationRule <ITextElementViewModel> .Create(new TextElement_MaximumLength_Validator(10))
                .WithFailMessage("Last Name must be less then 10 characters"),
                ValidationRule <ITextElementViewModel> .Create(new TextElement_MinimunLength_Validator(2))
                .WithFailMessage("Last Name must be greater then 2 characters"))
                               .Build();

            var personalDetails = new ColumnBuilder().SetName("personalDetails")
                                  .AddChildren(firstNameText, lastNameText).Build();


            var experienceSelection = new SelectElementBuilder().SetName("experienceSelection")
                                      .SetLabel(ElementLabel.Left("How many years experience have you got?")).AddValues("0-1", "1-5", "5+")
                                      .SetDefaultValue("Select a value").Build();
            var termsAndConditions = new CheckElementBuilder().SetName("TermsAndConditions")
                                     .SetLabel(ElementLabel.Left("Do you accept the terms and conditions?")).SetContent("Yes / No").AddRules(
                ValidationRule <ICheckElementViewModel> .Create(new CheckElement_IsChecked_Validator())
                .WithFailMessage("You must accept the terms and conditions")).Build();

            var submitButton = new ButtonElementBuilder().SetName("Submit Button").SetContent("Submit")
                               .SetVerticalAlignment(VerticalAlignment.Bottom).Build();

            var submitEventListener = new EventListener("submit",
                                                        new ElementNameEventSpecification("submit").And(
                                                            new TypeNameEventSpecification(nameof(ButtonElementClickedEvent))),
                                                        new IdentitySpecification <FormViewModel>());

            var rowGroup1 = new RowBuilder().SetName("Data Entry Rows")
                            .AddChildren(htmlContent, personalDetails, experienceSelection, termsAndConditions).Build();

            var rootGroup = new GroupBuilder().SetName("Test Group 1").SetTitle("Demo Form Title")
                            .AddChildren(rowGroup1, submitButton).Build();

            var newForm = new FormBuilder().SetName("Demo Form").SetTitle("Demo Form Title").SetRoot(rootGroup)
                          .AddEventListeners(submitEventListener)
                          .Build();

            return(new FormViewModel(newForm));
        }
コード例 #2
0
        public static (List <ValidationRule> validationRules, int[] yourTicket, List <int[]> nearbyTickets) ParseInput(string[] input)
        {
            var validationRules = new List <ValidationRule>();
            var nearbyTickets   = new List <int[]>();

            int[] yourTicket = null;
            var   part       = 0;

            foreach (var line in input)
            {
                if (line == "nearby tickets:" || line == "your ticket:")
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(line))
                {
                    part++;
                    continue;
                }
                if (part == 0)
                {
                    var rule = ValidationRule.Create(line);
                    validationRules.Add(rule);
                }
                if (part == 1)
                {
                    yourTicket = line.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
                }
                if (part == 2)
                {
                    var ticket = line.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
                    nearbyTickets.Add(ticket);
                }
            }

            return(validationRules, yourTicket, nearbyTickets);
        }
コード例 #3
0
 protected override ICustomValidationRule GetValidationRule()
 {
     return(ValidationRule <ObjectNameViewModel> .Create(this)
            .For(x => x.Name, x => !string.IsNullOrEmpty(x.Name), "Название не должно быть пустым", false));
 }
コード例 #4
0
 protected override ICustomValidationRule GetValidationRule()
 {
     return(ValidationRule <ColorPickerViewModel> .Create(this));
 }