Exemple #1
0
        public IActionResult Index()
        {
            var template       = System.IO.File.ReadAllText("Views/Home/Template.cshtml");
            var mailComponents = new List <IMailComponent>();

            const string pattern = "<component>([a-zA-Z]+)<\\/component>";
            var          matches = Regex.Matches(template, pattern);

            var mailComponentFactory = new MailComponentFactory();

            var currentIndex = 0;

            foreach (Match match in matches)
            {
                if (currentIndex < match.Index)
                {
                    mailComponents.Add(new Content(template.Substring(currentIndex, match.Index - currentIndex)));
                }

                var component = match.Groups[1].Value;
                mailComponents.Add(mailComponentFactory.Create(component));
                currentIndex = match.Index + match.Length;
            }

            if (template.Length > currentIndex)
            {
                mailComponents.Add(new Content(template.Substring(currentIndex, template.Length - currentIndex)));
            }

            return(View(mailComponents));
        }
Exemple #2
0
        private void GetNestedMailComponents(IParentNode element, ICollection <IMailComponent> mailComponents)
        {
            if (!element.Children.Any())
            {
                return;
            }

            var mailComponentFactory = new MailComponentFactory();

            foreach (var el in element.Children.ToList())
            {
                mailComponents.Add(string.Equals(el.LocalName, "component", StringComparison.OrdinalIgnoreCase)
                    ? mailComponentFactory.Create(el.TextContent)
                    : new Content(el.ToHtml()));

                GetNestedMailComponents(el, mailComponents);
            }
        }