static ISet <Endpoint> GetEndpoints(RouterConfig config) { var endpoints = new HashSet <Endpoint>(config.Routes.SelectMany(r => r.Endpoints)); config.Fallback.ForEach(f => endpoints.UnionWith(f.Endpoints)); return(endpoints); }
public static async Task <Router> CreateAsync(string id, string iotHubName, RouterConfig config, IEndpointExecutorFactory executorFactory) { Preconditions.CheckNotNull(id); Preconditions.CheckNotNull(config); Preconditions.CheckNotNull(executorFactory); var evaluator = new Evaluator(config); Dispatcher dispatcher = await Dispatcher.CreateAsync(id, iotHubName, GetEndpoints(config), executorFactory); return(new Router(id, iotHubName, evaluator, dispatcher)); }
public Evaluator(RouterConfig config, IRouteCompiler compiler) { Preconditions.CheckNotNull(config, nameof(config)); this.compiler = Preconditions.CheckNotNull(compiler); this.fallback = config.Fallback.Map(this.Compile); ImmutableDictionary <string, CompiledRoute> routesDict = config .Routes .ToImmutableDictionary(r => r.Id, r => this.Compile(r)); this.compiledRoutes = new AtomicReference <ImmutableDictionary <string, CompiledRoute> >(routesDict); }
public Evaluator(RouterConfig config) : this(config, RouteCompiler.Instance) { }