protected override IDomainParser GetDomainParser(List <TldRule> rules) { var structure = new DomainDataStructure("*", new TldRule("*")); structure.AddRules(rules); return(new DomainParser(structure)); }
/// <summary> /// Add <paramref name="tldRule"/> to <paramref name="structure"/>. /// </summary> /// <param name="structure">The structure to appened the rule.</param> /// <param name="tldRule">The rule to append.</param> public static void AddRule(this DomainDataStructure structure, TldRule tldRule) { var parts = tldRule.Name.Split('.').Reverse().ToList(); for (var i = 0; i < parts.Count; i++) { var domainPart = parts[i]; if (parts.Count - 1 > i) { //Check if domain exists if (!structure.Nested.ContainsKey(domainPart)) { structure.Nested.Add(domainPart, new DomainDataStructure(domainPart)); } structure = structure.Nested[domainPart]; continue; } //Check if domain exists if (structure.Nested.ContainsKey(domainPart)) { structure.Nested[domainPart].TldRule = tldRule; continue; } structure.Nested.Add(domainPart, new DomainDataStructure(domainPart, tldRule)); } }
/// <summary> /// Add all the rules in <paramref name="tldRules"/> to <paramref name="structure"/>. /// </summary> /// <param name="structure">The structure to appened the rule.</param> /// <param name="tldRules">The rules to append.</param> public static void AddRules(this DomainDataStructure structure, IEnumerable <TldRule> tldRules) { foreach (var tldRule in tldRules) { structure.AddRule(tldRule); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(svcs => { var provider = new WebTldRuleProvider(); var rules = provider.BuildAsync().GetAwaiter().GetResult(); var structure = new DomainDataStructure("*", new TldRule("*")); structure.AddRules(rules); return(structure); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public PublicSuffixController(DomainDataStructure domainDataStructure) { this._domainDataStructure = domainDataStructure; }