/// <summary> /// Constructor /// </summary> /// <param name="page">Text of .biis page</param> /// <param name="buttonDelegates">Actions, on which buttons will subscribe</param> public BiisPage(string page, params ButtonDelegate[] buttonDelegates) { // add actions ButtonDelegates.AddRange(buttonDelegates); // Find all elements and parse .biis to .html var htmlPage = string.Empty; for (Match match = Regex.Match(page, ButtonRegexPattern); match.Success; match = match.NextMatch()) { var button = new BiisButton { Name = match.Groups["name"].Value, Text = match.Groups["text"].Value }; foreach (var buttonDelegate in ButtonDelegates) { var delegateName = buttonDelegate.Method.Name; if (delegateName != match.Groups["onClick"].Value) continue; button.ButtonOnClickDelegate = buttonDelegate; button.OnClickTarget = match.Groups["onClickTarget"].Value; } htmlPage = Regex.Replace(page, ButtonRegexPattern, $"<button name=\"{button.Name}\" type=\"submit\">{button.Text}</button>"); Controls.Add(button); } for(Match match = Regex.Match(page, LabelRegexPattern); match.Success; match = match.NextMatch()) { var label = new BiisLabel { Name = match.Groups["name"].Value, Text = match.Groups["text"].Value }; Controls.Add(label); htmlPage = Regex.Replace(htmlPage, $@"<biisLabel\s+name=""{label.Name}"">(?<text>.*)</biisLabel>", $"<label name=\"{label.Name}\">{label.Text}</label>"); } HtmlPage = htmlPage; }
// BiisButton onClick implmentation public static void Button_OnClick(BiisLabel biisControl) => biisControl.Text = DateTime.Now.ToShortDateString();