Summary

Class:Xrm.Oss.XTL.Interpreter.TokenMatcher
Assembly:Xrm.Oss.XTL.Templating
File(s):D:\Entwicklung\Xrm-Templating-Language\src\lib\Xrm.Oss.XTL.Interpreter\TokenMatcher.cs
Covered lines:32
Uncovered lines:0
Coverable lines:32
Total lines:52
Line coverage:100% (32 of 32)
Covered branches:2
Total branches:2
Branch coverage:100% (2 of 2)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage Crap Score
.cctor()10100%100%2
MatchTokens(...)22100%100%6
ProcessTokens(...)10100%100%2

File(s)

D:\Entwicklung\Xrm-Templating-Language\src\lib\Xrm.Oss.XTL.Interpreter\TokenMatcher.cs

#LineLine coverage
 1using Microsoft.Xrm.Sdk;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5using System.Text;
 6using System.Text.RegularExpressions;
 7
 8namespace Xrm.Oss.XTL.Interpreter
 9{
 10    public static class TokenMatcher
 11    {
 212        private static Regex tokenRegex = new Regex(@"\${{([\s\S]*?(?=}}))}}", RegexOptions.Compiled | RegexOptions.Cult
 13
 14        public static List<string> MatchTokens(string templateText)
 3015        {
 3016            var tokens = tokenRegex.Matches(templateText)
 3017                .Cast<Match>()
 5818                .Select(m => m.Groups[1].Value)
 3019                .Distinct()
 3020                .ToList();
 21
 3022            return tokens;
 3023        }
 24
 25        public static string ProcessTokens(string templateText, Entity dataSource, OrganizationConfig config, IOrganizat
 3026        {
 3027            var tokens = MatchTokens(templateText);
 28
 3029            tokens.ForEach(token =>
 5730            {
 5731                tracing.Trace($"Processing token '{token}'");
 3032
 5733                var processor = new XTLInterpreter(token, dataSource, config, service, tracing);
 5734                var processed = string.Empty;
 3035
 3036                try
 5737                {
 5738                    processed = processor.Produce();
 5539                }
 3240                catch (Exception ex)
 3241                {
 3242                    tracing.Trace($"Exception while processing token {token}, replacing by empty string. Message: {ex.Me
 3243                }
 3044
 5745                templateText = templateText.Replace($"${{{{{token}}}}}", processed);
 5746                tracing.Trace($"Replacing token with '{processed}'");
 5747            });
 48
 3049            return templateText;
 3050        }
 51    }
 52}