private void ParseDirective([NotNull] CompositeElement parentElement) { var directive = new T4Directive(); // appends the directive start token (<#@) AppendNewChild(directive, T4TokenNodeTypes.DirectiveStart); Advance(); // builds the directive (name and attributes) var directiveBuilder = new DirectiveBuilder(this); T4TokenNodeType tokenType = GetTokenType(); while (tokenType != null && !tokenType.IsTag) { if (tokenType == T4TokenNodeTypes.Name) { directiveBuilder.AddName(); } else if (tokenType == T4TokenNodeTypes.Equal) { directiveBuilder.AddEqual(); } else if (tokenType == T4TokenNodeTypes.Quote) { directiveBuilder.AddQuote(); } else if (tokenType == T4TokenNodeTypes.Value) { directiveBuilder.AddValue(); } tokenType = Advance(); } directiveBuilder.Finish(directive); // appends the block end token if available if (tokenType == T4TokenNodeTypes.BlockEnd) { AppendNewChild(directive, T4TokenNodeTypes.BlockEnd); Advance(); } else { AppendMissingToken(directive, MissingTokenType.BlockEnd); if (_notClosedDirectives == null) { _notClosedDirectives = new List <T4Directive>(); } _notClosedDirectives.Add(directive); } AppendNewChild(parentElement, directive); // checks if we're including a file if (directive.IsSpecificDirective(_directiveInfoManager.Include)) { HandleIncludeDirective(directive, parentElement); } }
public SiteLocation(LocationConfig locationConfig, IServiceProvider serviceProvider) { Regex regex; switch (locationConfig.LocationType) { case LocationType.None: case LocationType.NoRegex: Match = httpContext => httpContext.Request.Path.Value.StartsWith(locationConfig.Location); break; case LocationType.Equal: Match = httpContext => httpContext.Request.Path.Value.Equals(locationConfig.Location); break; case LocationType.Regex: regex = new Regex(locationConfig.Location); Match = httpContext => regex.IsMatch(httpContext.Request.Path.Value); break; case LocationType.RegexCaseInsensitive: regex = new Regex(locationConfig.Location, RegexOptions.IgnoreCase); Match = httpContext => regex.IsMatch(httpContext.Request.Path.Value); break; default: throw new ArgumentOutOfRangeException(); } var directiveBuilder = new DirectiveBuilder(serviceProvider); var directiveManager = serviceProvider.GetService <DirectiveManager>(); foreach (var directiveConfig in locationConfig.Directives) { if (!directiveConfig.TryGetProperty("type", out var property)) { continue; } string directiveName = property.GetString(); if (string.IsNullOrEmpty(directiveName)) { throw new NullReferenceException("Directive name is empty or invalid."); } if (directiveManager.TryGetDirective(property.GetString(), out var directiveType)) { directiveBuilder.UseDirective(directiveType, directiveConfig); } else { throw new UnknownDirectiveException($"Unknown directive '{directiveName}', missing plugin?"); } } _directiveDelegate = directiveBuilder.Build(); }
private void ParseDirective([NotNull] CompositeElement parentElement) { var directive = new T4Directive(); // appends the directive start token (<#@) AppendNewChild(directive, T4TokenNodeTypes.DirectiveStart); Advance(); // builds the directive (name and attributes) var directiveBuilder = new DirectiveBuilder(this); T4TokenNodeType tokenType = GetTokenType(); while (tokenType != null && !tokenType.IsTag) { if (tokenType == T4TokenNodeTypes.Name) directiveBuilder.AddName(); else if (tokenType == T4TokenNodeTypes.Equal) directiveBuilder.AddEqual(); else if (tokenType == T4TokenNodeTypes.Quote) directiveBuilder.AddQuote(); else if (tokenType == T4TokenNodeTypes.Value) directiveBuilder.AddValue(); tokenType = Advance(); } directiveBuilder.Finish(directive); // appends the block end token if available if (tokenType == T4TokenNodeTypes.BlockEnd) { AppendNewChild(directive, T4TokenNodeTypes.BlockEnd); Advance(); } else { AppendMissingToken(directive, MissingTokenType.BlockEnd); if (_notClosedDirectives == null) _notClosedDirectives = new List<T4Directive>(); _notClosedDirectives.Add(directive); } AppendNewChild(parentElement, directive); // checks if we're including a file if (directive.IsSpecificDirective(_directiveInfoManager.Include)) HandleIncludeDirective(directive, parentElement); }