public DefaultRequestDispatcherFixture() { this.responseProcessors = new List<IResponseProcessor>(); this.routeResolver = A.Fake<IRouteResolver>(); this.routeInvoker = A.Fake<IRouteInvoker>(); this.negotiator = A.Fake<IResponseNegotiator>(); A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._)) .ReturnsLazily(async arg => { var routeResult = ((Route)arg.Arguments[0]).Invoke((DynamicDictionary)arg.Arguments[2], new CancellationToken()).ConfigureAwait(false); var x = await routeResult; return (Response)x; }); this.requestDispatcher = new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker, this.negotiator); var resolvedRoute = new ResolveResult { Route = new FakeRoute(), Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>._)).Returns(resolvedRoute); }
public DefaultRequestDispatcherFixture() { this.responseProcessors = new List<IResponseProcessor>(); this.routeResolver = A.Fake<IRouteResolver>(); this.routeInvoker = A.Fake<IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg => { var tcs = new TaskCompletionSource<Response>(); var actionResult = ((Route)arg.Arguments[0]).Action.Invoke(arg.Arguments[2], new CancellationToken()); var result = actionResult.Result; tcs.SetResult(result); return tcs.Task; }); this.requestDispatcher = new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker); var resolvedRoute = new ResolveResult { Route = new FakeRoute(), Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>._)).Returns(resolvedRoute); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRoute" /> class. /// </summary> /// <param name="virtualPathResolver">The virtual path resolver.</param> /// <param name="routeResolver">The route resolver.</param> /// <param name="documentStore">The document store.</param> /// <param name="controllerMapper">The controller mapper.</param> /// <exception cref="System.ArgumentNullException"> /// virtualPathResolver /// or /// routeResolver /// or /// documentStore /// or /// controllerMapper /// </exception> public DefaultRoute(IVirtualPathResolver virtualPathResolver, IRouteResolver routeResolver, IDocumentStore documentStore, IControllerMapper controllerMapper) { if (virtualPathResolver == null) { throw new ArgumentNullException("virtualPathResolver"); } if (routeResolver == null) { throw new ArgumentNullException("routeResolver"); } if (documentStore == null) { throw new ArgumentNullException("documentStore"); } if (controllerMapper == null) { throw new ArgumentNullException("controllerMapper"); } this.VirtualPathResolver = virtualPathResolver; this.RouteResolver = routeResolver; this.DocumentStore = documentStore; this.ControllerMapper = controllerMapper; }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake<IErrorHandler>(); this.requestDispatcher = A.Fake<IRequestDispatcher>(); A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._)).Invokes(x => this.context.Response = new Response()); A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null, null)); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake<IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg => { return (Response)((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1]); }); this.engine = new NancyEngine(this.requestDispatcher, contextFactory, new[] { this.errorHandler }, A.Fake<IRequestTracing>()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public DefaultRouter(IRouter defaultHandler, IRouteResolver routeResolver, IVirtualPathResolver virtualPathResolver, RequestCulture defaultRequestCulture) { if (defaultHandler == null) { throw new ArgumentNullException(nameof(defaultHandler)); } if (routeResolver == null) { throw new ArgumentNullException(nameof(routeResolver)); } if (virtualPathResolver == null) { throw new ArgumentNullException(nameof(virtualPathResolver)); } if (defaultRequestCulture == null) { throw new ArgumentNullException(nameof(defaultRequestCulture)); } _defaultHandler = defaultHandler; _routeResolver = routeResolver; _virtualPathResolver = virtualPathResolver; _defaultRequestCulture = defaultRequestCulture; }
public NancyEngineFixture() { this.modules = new[] { new FakeNancyModuleWithBasePath() }; this.locator = A.Fake<INancyModuleLocator>(); this.resolver = A.Fake<IRouteResolver>(); this.engine = new NancyEngine(this.locator, this.resolver); }
public DefaultRequestDispatcherFixture() { this.responseProcessors = new List<IResponseProcessor>(); this.routeResolver = A.Fake<IRouteResolver>(); this.routeInvoker = A.Fake<IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg => { return (Response)((Route)arg.Arguments[0]).Action.Invoke(arg.Arguments[1]); }); this.requestDispatcher = new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker); var resolvedRoute = new ResolveResult { Route = new FakeRoute(), Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>._)).Returns(resolvedRoute); }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake<IStatusCodeHandler>(); this.requestDispatcher = A.Fake<IRequestDispatcher>(); this.diagnosticsConfiguration = new DiagnosticsConfiguration(); A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._, A<CancellationToken>._)).Invokes((x) => this.context.Response = new Response()); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A<Request>._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake<IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg => { return ((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1], A<CancellationToken>._).Result; }); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake<IRequestTracing>(), this.diagnosticsConfiguration, new DisabledStaticContentProvider()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public NancyEngineFixture() { this.application = A.Fake<INancyApplication>(); this.modules = NancyBootstrapper.BootstrapApplication().ModuleMetas; this.resolver = A.Fake<IRouteResolver>(); this.engine = new NancyEngine(this.resolver, this.application); }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandlers">Error handlers</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory, IEnumerable<IErrorHandler> errorHandlers) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandlers == null) { throw new ArgumentNullException("errorHandlers"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; this.errorHandlers = errorHandlers; }
public NancyEngineFixture() { this.modules = new NancyApplication(new DefaultModuleActivator()).GetModules(); this.locator = A.Fake<INancyModuleLocator>(); this.resolver = A.Fake<IRouteResolver>(); this.application = A.Fake<INancyApplication>(); this.engine = new NancyEngine(this.locator, this.resolver, this.application); }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.route = new FakeRoute(); A.CallTo(() => resolver.Resolve(A<Request>.Ignored, A<IRouteCache>.Ignored.Argument)).Returns(route); this.engine = new NancyEngine(resolver, A.Fake<IRouteCache>()); }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> public NancyEngine(IRouteResolver resolver) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } this.resolver = resolver; }
public DefaultHandshakeNegotiator(IHostConfiguration hostConfiguration, IProtocolSelector protocolSelector, IQueryParametersBuilder queryParametersBuilder, IRouteParametersBuilder routeParametersBuilder, IRouteResolver routeResolver, ISubProtocolNegotiator subProtocolNegotiator) { _hostConfiguration = hostConfiguration; _protocolSelector = protocolSelector; _queryParametersBuilder = queryParametersBuilder; _routeParametersBuilder = routeParametersBuilder; _routeResolver = routeResolver; _subProtocolNegotiator = subProtocolNegotiator; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRequestDispatcher"/> class, with /// the provided <paramref name="routeResolver"/>, <paramref name="responseProcessors"/> and <paramref name="routeInvoker"/>. /// </summary> /// <param name="routeResolver"></param> /// <param name="responseProcessors"></param> /// <param name="routeInvoker"></param> /// <param name="negotiator"></param> public DefaultRequestDispatcher(IRouteResolver routeResolver, IEnumerable<IResponseProcessor> responseProcessors, IRouteInvoker routeInvoker, IResponseNegotiator negotiator) { this.routeResolver = routeResolver; this.responseProcessors = responseProcessors; this.routeInvoker = routeInvoker; this.negotiator = negotiator; }
public RequestModel(NancyContext context, IRootPathProvider rootPathProvider, IRouteResolver routeResolver) { this.context = context; this.rootPathProvider = rootPathProvider; this.routeResolution = routeResolver.Resolve(context); Cookies = this.context.Request.Headers.Cookie.Select(x => new CookieModel(x)).ToArray(); QueryString = ((DynamicDictionary)this.context.Request.Query).Serialize(); Parameters = this.routeResolution.Parameters.Serialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Navigator"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="scheme">The URI scheme.</param> /// <param name="routes">The routes.</param> /// <param name="navigationService">The navigation service.</param> public Navigator(INavigatorFactory parent, string scheme, IRouteResolver routes, Func<INavigationService> navigationService) : base(navigationService) { Guard.ArgumentNotNull(parent, "root"); Guard.ArgumentNotNull(routes, "routes"); Guard.ArgumentNotNull(navigationService, "navigationService"); _parent = parent; _scheme = scheme; _routes = routes; }
/// <summary> /// Initializes a new instance of the <see cref="Navigator"/> class. /// </summary> /// <param name="factory">The factory that created this navigator.</param> /// <param name="parent">The parent navigator (can be null).</param> /// <param name="scheme">The URI scheme.</param> /// <param name="routes">The routes.</param> /// <param name="navigationService">The navigation service.</param> public Navigator(INavigatorFactory factory, INavigator parent, string scheme, IRouteResolver routes, Func<INavigationService> navigationService) : base(navigationService) { Guard.ArgumentNotNull(factory, "root"); Guard.ArgumentNotNull(routes, "routes"); Guard.ArgumentNotNull(navigationService, "navigationService"); this.factory = factory; this.parent = parent; this.scheme = scheme; this.routes = routes; }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipeline"></param> /// <param name="cacheKeyGenerator"></param> /// <param name="cacheStore"></param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipeline, ICacheKeyGenerator cacheKeyGenerator, ICacheStore cacheStore) { if (_enabled) return; _enabled = true; _cacheKeyGenerator = cacheKeyGenerator; _cacheStore = cacheStore; _nancyBootstrapper = nancyBootstrapper; _routeResolver = routeResolver; pipeline.BeforeRequest.AddItemToStartOfPipeline(CheckCache); pipeline.AfterRequest.AddItemToEndOfPipeline(SetCache); }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipeline"></param> /// <param name="varyParams"></param> /// <param name="cacheStore"></param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipeline, IEnumerable<string> varyParams, ICacheStore cacheStore) { if (_enabled) return; _enabled = true; _varyParams = varyParams.Select(key => key.ToLower().Trim()).ToArray(); _cacheStore = cacheStore; _nancyBootstrapper = nancyBootstrapper; _routeResolver = routeResolver; pipeline.BeforeRequest.AddItemToStartOfPipeline(CheckCache); pipeline.AfterRequest.AddItemToEndOfPipeline(SetCache); }
public ResourceResolver(ITypeMapper typeMapper, NancyContext context, IRouteResolver routeResolver) { if (typeMapper == null) throw new ArgumentNullException("typeMapper"); if (context == null) throw new ArgumentNullException("context"); if (routeResolver == null) throw new ArgumentNullException("routeResolver"); //if (routeResolver == null) throw new ArgumentNullException("routeResolver"); this.typeMapper = typeMapper; this.context = context; this.routeResolver = routeResolver; }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored, A<IRouteCache>.Ignored.Argument)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); this.engine = new NancyEngine(resolver, A.Fake<IRouteCache>(), contextFactory); }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="locator">An <see cref="INancyModuleLocator"/> instance, that will be used to locate <see cref="NancyModule"/> instances</param> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> public NancyEngine(IRouteResolver resolver, INancyApplication application) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (application == null) { throw new ArgumentNullException("application", "The application parameter cannot be null."); } this.resolver = resolver; this.application = application; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="locator">An <see cref="INancyModuleLocator"/> instance, that will be used to locate <see cref="NancyModule"/> instances</param> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> public NancyEngine(INancyModuleLocator locator, IRouteResolver resolver) { if (locator == null) { throw new ArgumentNullException("locator", "The locator parameter cannot be null."); } if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } this.locator = locator; this.resolver = resolver; }
/// <summary> /// Initializes a new instance of the <see cref="NavigatorFactory"/> class. /// </summary> /// <param name="uriScheme">The URI scheme that will prefix handled URI's.</param> /// <param name="routes">The routes that navigators created from this factory will use when resolving requests.</param> public NavigatorFactory(string uriScheme, IRouteResolver routes) { uriScheme = uriScheme ?? "magellan"; Guard.ArgumentNotNullOrEmpty(uriScheme, "uriScheme"); Guard.ArgumentNotNull(routes, "routes"); if (!Uri.CheckSchemeName(uriScheme)) { throw new ArgumentException(string.Format("The scheme '{0}' is not a valid URI scheme.", uriScheme)); } this.uriScheme = uriScheme; this.routes = routes; }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="Producer"/>. /// </summary> /// <param name="bus"> /// Конечная точка, для которой создается отправитель. /// </param> /// <param name="label"> /// Метка сообщения, которая будет использоваться при отправлении сообщений. /// </param> /// <param name="routeResolver"> /// Определитель маршрутов, по которым можно отсылать и получать сообщения. /// </param> /// <param name="confirmationIsRequired"> /// Если <c>true</c> - тогда отправитель будет ожидать подтверждения о том, что сообщение было сохранено в брокере. /// </param> public Producer(RabbitBus bus, MessageLabel label, IRouteResolver routeResolver, bool confirmationIsRequired) { this.Channel = bus.OpenChannel(); this.Label = label; this.RouteResolver = routeResolver; this.ConfirmationIsRequired = confirmationIsRequired; if (this.ConfirmationIsRequired) { this.confirmationTracker = new DefaultPublishConfirmationTracker(this.Channel); this.Channel.EnablePublishConfirmation(); this.Channel.OnConfirmation(this.confirmationTracker.HandleConfirmation); } this.Failed += _ => ((IBusAdvanced)bus).Panic(); }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake<IErrorHandler>(); A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored, A<IRouteCache>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); this.engine = new NancyEngine(resolver, A.Fake<IRouteCache>(), contextFactory, this.errorHandler); }
private static Response ExecuteDiagnostics(NancyContext ctx, IRouteResolver routeResolver, DiagnosticsConfiguration diagnosticsConfiguration, DefaultObjectSerializer serializer) { var session = GetSession(ctx, diagnosticsConfiguration, serializer); if (session == null) { var view = GetDiagnosticsLoginView(ctx); view.AddCookie( new NancyCookie(DiagsCookieName, String.Empty, true) { Expires = DateTime.Now.AddDays(-1) }); return(view); } // TODO - duplicate the context and strip out the "_/Nancy" bit so we don't need to use it in the module var resolveResult = routeResolver.Resolve(ctx); ctx.Parameters = resolveResult.Item2; var resolveResultPreReq = resolveResult.Item3; var resolveResultPostReq = resolveResult.Item4; ExecuteRoutePreReq(ctx, resolveResultPreReq); if (ctx.Response == null) { ctx.Response = resolveResult.Item1.Invoke(resolveResult.Item2); } if (ctx.Request.Method.ToUpperInvariant() == "HEAD") { ctx.Response = new HeadResponse(ctx.Response); } if (resolveResultPostReq != null) { resolveResultPostReq.Invoke(ctx); } AddUpdateSessionCookie(session, ctx, diagnosticsConfiguration, serializer); // If we duplicate the context this makes more sense :) return(ctx.Response); }
public ProxyMiddleware( RequestDelegate next, IRequestCreator requestCreator, IRequestSender sender, IResponseSender responseSender, IRouteResolver routeResolver, IExpressionEvaluator evaluator, ILogger <ProxyMiddleware> logger) { this.next = CheckValue(next, nameof(next)); this.requestCreator = CheckValue(requestCreator, nameof(requestCreator)); this.sender = CheckValue(sender, nameof(sender)); this.responseSender = CheckValue(responseSender, nameof(responseSender)); this.routeResolver = CheckValue(routeResolver, nameof(routeResolver)); this.evaluator = CheckValue(evaluator, nameof(evaluator)); this.logger = CheckValue(logger, nameof(logger)); }
public NancyEngineFixture() { this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake <IErrorHandler>(); A.CallTo(() => errorHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored, A <IRouteCache> .Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); this.engine = new NancyEngine(resolver, A.Fake <IRouteCache>(), contextFactory, this.errorHandler); }
private static Response ExecuteDiagnostics(NancyContext ctx, IRouteResolver routeResolver, DiagnosticsConfiguration diagnosticsConfiguration, DefaultObjectSerializer serializer, INancyEnvironment environment) { var session = GetSession(ctx, diagnosticsConfiguration, serializer); if (session == null) { var view = GetDiagnosticsLoginView(ctx, environment); view.WithCookie( new NancyCookie(diagnosticsConfiguration.CookieName, string.Empty, true) { Expires = DateTime.Now.AddDays(-1) }); return(view); } var resolveResult = routeResolver.Resolve(ctx); ctx.Parameters = resolveResult.Parameters; ExecuteRoutePreReq(ctx, CancellationToken, resolveResult.Before); if (ctx.Response == null) { var routeResult = resolveResult.Route.Invoke(resolveResult.Parameters, CancellationToken); routeResult.Wait(); ctx.Response = (Response)routeResult.Result; } if (ctx.Request.Method.Equals("HEAD", StringComparison.OrdinalIgnoreCase)) { ctx.Response = new HeadResponse(ctx.Response); } if (resolveResult.After != null) { resolveResult.After.Invoke(ctx, CancellationToken); } AddUpdateSessionCookie(session, ctx, diagnosticsConfiguration, serializer); return(ctx.Response); }
private static Response ExecuteDiagnostics(NancyContext ctx, IRouteResolver routeResolver, DiagnosticsConfiguration diagnosticsConfiguration, DefaultObjectSerializer serializer) { var session = GetSession(ctx, diagnosticsConfiguration, serializer); if (session == null) { var view = GetDiagnosticsLoginView(ctx); view.AddCookie( new NancyCookie(diagnosticsConfiguration.CookieName, String.Empty, true) { Expires = DateTime.Now.AddDays(-1) }); return(view); } var resolveResult = routeResolver.Resolve(ctx); ctx.Parameters = resolveResult.Parameters; ExecuteRoutePreReq(ctx, CancellationToken, resolveResult.Before); if (ctx.Response == null) { // Don't care about async here, so just get the result var task = resolveResult.Route.Invoke(resolveResult.Parameters, CancellationToken); task.Wait(); ctx.Response = task.Result; } if (ctx.Request.Method.ToUpperInvariant() == "HEAD") { ctx.Response = new HeadResponse(ctx.Response); } if (resolveResult.After != null) { resolveResult.After.Invoke(ctx, CancellationToken); } AddUpdateSessionCookie(session, ctx, diagnosticsConfiguration, serializer); return(ctx.Response); }
public NancyMetricsCollector(IRouteResolver routeResolver, IEnumerable <ISystemMetricCollector> collectors, NancyMetricsCollectorOptions options = null) { RouteResolver = routeResolver; Options = options ?? new NancyMetricsCollectorOptions(); ErrorRequestsProcessed = Metrics.CreateCounter("server_request_error_total", "Number of unsuccessfull processed requests.", "method", "error_code"); OngoingRequests = Metrics.CreateGauge("server_request_in_progress", "Number of ongoing requests.", "method"); RequestResponseHistogram = Metrics.CreateHistogram("server_request_duration_seconds", "Histogram of request duration in seconds.", new HistogramConfiguration() { LabelNames = new string[] { "method" }, Buckets = Options.Buckets }); var registry = Metrics.DefaultRegistry; foreach (var collector in collectors) { registry.AddBeforeCollectCallback(collector.UpdateMetrics); } }
public NancyEngineFixture() { this.environment = new DefaultNancyEnvironment(); this.environment.Tracing( enabled: true, displayErrorTraces: true); this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake <IStatusCodeHandler>(); this.requestDispatcher = A.Fake <IRequestDispatcher>(); this.negotiator = A.Fake <IResponseNegotiator>(); A.CallTo(() => this.requestDispatcher.Dispatch(A <NancyContext> ._, A <CancellationToken> ._)) .Returns(Task.FromResult(new Response())); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored, A <NancyContext> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A <Request> ._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake <IRouteInvoker>(); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake <IRequestTracing>(), new DisabledStaticContentProvider(), this.negotiator, this.environment) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public FakeEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; }
public DefaultRequestDispatcherFixture() { this.responseProcessors = new List <IResponseProcessor>(); this.routeResolver = A.Fake <IRouteResolver>(); this.routeInvoker = A.Fake <IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A <Route> ._, A <DynamicDictionary> ._, A <NancyContext> ._)).ReturnsLazily(arg => { return((Response)((Route)arg.Arguments[0]).Action.Invoke(arg.Arguments[1])); }); this.requestDispatcher = new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker); var resolvedRoute = new ResolveResult( new FakeRoute(), DynamicDictionary.Empty, null, null); A.CallTo(() => this.routeResolver.Resolve(A <NancyContext> ._)).Returns(resolvedRoute); }
public DefaultRequestDispatcherFixture() { this.responseProcessors = new List <IResponseProcessor>(); this.routeResolver = A.Fake <IRouteResolver>(); this.routeInvoker = A.Fake <IRouteInvoker>(); this.negotiator = A.Fake <IResponseNegotiator>(); A.CallTo(() => this.routeInvoker.Invoke(A <Route> ._, A <CancellationToken> ._, A <DynamicDictionary> ._, A <NancyContext> ._)).ReturnsLazily(arg => { var tcs = new TaskCompletionSource <Response>(); var actionResult = ((Route)arg.Arguments[0]).Action.Invoke(arg.Arguments[2], new CancellationToken()); if (actionResult.IsFaulted) { tcs.SetException(actionResult.Exception.InnerException); } else { tcs.SetResult(actionResult.Result); } return(tcs.Task); }); this.requestDispatcher = new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker, this.negotiator); var resolvedRoute = new ResolveResult { Route = new FakeRoute(), Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => this.routeResolver.Resolve(A <NancyContext> ._)).Returns(resolvedRoute); }
public NancyEngineFixture() { this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake <IStatusCodeHandler>(); this.requestDispatcher = A.Fake <IRequestDispatcher>(); this.diagnosticsConfiguration = new DiagnosticsConfiguration(); A.CallTo(() => this.requestDispatcher.Dispatch(A <NancyContext> ._, A <CancellationToken> ._)) .Returns(CreateResponseTask(new Response())); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored, A <NancyContext> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A <Request> ._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake <IRouteInvoker>(); A.CallTo(() => this.routeInvoker.Invoke(A <Route> ._, A <CancellationToken> ._, A <DynamicDictionary> ._, A <NancyContext> ._)).ReturnsLazily(arg => { return(((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1], A <CancellationToken> ._).Result); }); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake <IRequestTracing>(), this.diagnosticsConfiguration, new DisabledStaticContentProvider()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandlers">Error handlers</param> public NancyEngine(IRouteResolver resolver, INancyContextFactory contextFactory, IEnumerable <IErrorHandler> errorHandlers, IRequestTracing requestTracing) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandlers == null) { throw new ArgumentNullException("errorHandlers"); } this.resolver = resolver; this.contextFactory = contextFactory; this.errorHandlers = errorHandlers; this.requestTracing = requestTracing; }
public NancyEngineFixture() { this.environment = new DefaultNancyEnvironment(); this.environment.Tracing( enabled: true, displayErrorTraces: true); this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.statusCodeHandler = A.Fake<IStatusCodeHandler>(); this.requestDispatcher = A.Fake<IRequestDispatcher>(); this.negotiator = A.Fake<IResponseNegotiator>(); A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._, A<CancellationToken>._)) .Returns(Task.FromResult(new Response())); A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create(A<Request>._)).Returns(context); var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null }; A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolveResult); var applicationPipelines = new Pipelines(); this.routeInvoker = A.Fake<IRouteInvoker>(); this.engine = new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake<IRequestTracing>(), new DisabledStaticContentProvider(), this.negotiator, this.environment) { RequestPipelinesFactory = ctx => applicationPipelines }; }
/// <summary> /// The resolve for. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <returns> /// The <see cref="Producer"/>. /// </returns> public Producer ResolveFor(ISenderConfiguration configuration) { Producer producer = this.TryResolverFor(configuration.Label); if (producer == null) { using (RabbitChannel channel = this._bus.OpenChannel()) { var topologyBuilder = new TopologyBuilder(channel); var builder = new RouteResolverBuilder(this._bus.Endpoint, topologyBuilder, configuration); Maybe <Func <IRouteResolverBuilder, IRouteResolver> > routeResolverBuilder = configuration.Options.GetRouteResolverBuilder(); Assumes.True(routeResolverBuilder.HasValue, "RouteResolverBuilder must be set for [{0}]", configuration.Label); IRouteResolver routeResolver = routeResolverBuilder.Value(builder); producer = new Producer(this._bus, configuration.Label, routeResolver, configuration.Options.IsConfirmationRequired()); producer.Failed += p => { { // lock (_producers) p.Dispose(); this._producers.Remove(p.Label); } }; // lock (_producers) this._producers.Add(configuration.Label, producer); } if (configuration.RequiresCallback) { producer.UseCallbackListener(this._bus.ListenerRegistry.ResolveFor(configuration.CallbackConfiguration)); } } return(producer); }
public NancyEngineFixture() { this.resolver = A.Fake <IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake <IErrorHandler>(); A.CallTo(() => errorHandler.HandlesStatusCode(A <HttpStatusCode> .Ignored, A <NancyContext> .Ignored)).Returns(false); contextFactory = A.Fake <INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A <NancyContext> .Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); var applicationPipelines = new Pipelines(); this.engine = new NancyEngine(resolver, contextFactory, new[] { this.errorHandler }, A.Fake <IRequestTracing>()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public NancyEngineFixture() { this.resolver = A.Fake<IRouteResolver>(); this.response = new Response(); this.route = new FakeRoute(response); this.context = new NancyContext(); this.errorHandler = A.Fake<IErrorHandler>(); A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false); contextFactory = A.Fake<INancyContextFactory>(); A.CallTo(() => contextFactory.Create()).Returns(context); A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null)); var applicationPipelines = new Pipelines(); this.engine = new NancyEngine(resolver, contextFactory, new[] { this.errorHandler }, A.Fake<IRequestTracing>()) { RequestPipelinesFactory = ctx => applicationPipelines }; }
public DefaultActionBuilder(IRouteResolver actionResolver, IControllerActivator controllerActivator) { _actionResolver = actionResolver; _controllerActivator = controllerActivator; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRequestDispatcher"/> class, with /// the provided <paramref name="routeResolver"/>, <paramref name="responseProcessors"/> and <paramref name="routeInvoker"/>. /// </summary> /// <param name="routeResolver"></param> /// <param name="responseProcessors"></param> /// <param name="routeInvoker"></param> public DefaultRequestDispatcher(IRouteResolver routeResolver, IEnumerable <IResponseProcessor> responseProcessors, IRouteInvoker routeInvoker) { this.routeResolver = routeResolver; this.responseProcessors = responseProcessors; this.routeInvoker = routeInvoker; }
public FakeEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory) { Resolver = resolver ?? throw new ArgumentNullException(nameof(resolver), "The resolver parameter cannot be null."); RouteCache = routeCache ?? throw new ArgumentNullException(nameof(routeCache), "The routeCache parameter cannot be null."); ContextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory)); }
public Request(IRootPathProvider rootPath, IRouteResolver routeResolver) { this.rootPath = rootPath; this.routeResolver = routeResolver; }
public Entity(IEventStream stream, IRouteResolver resolver) { (this as INeedStream).Stream = stream; (this as INeedRouteResolver).Resolver = resolver; }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="SubscriptionEndpoint"/>. /// </summary> /// <param name="listeningSource"> /// The listening source. /// </param> /// <param name="callbackRouteResolver"> /// The callback route resolver. /// </param> public SubscriptionEndpoint(IListeningSource listeningSource, IRouteResolver callbackRouteResolver = null) { this.ListeningSource = listeningSource; this.CallbackRouteResolver = callbackRouteResolver; }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipelines"></param> /// <param name="varyParams"> </param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipelines) => Enable(nancyBootstrapper, routeResolver, pipelines, new DefaultCacheKeyGenerator(), new MemoryCacheStore());
/// <summary> /// Initializes a new instance of the <see cref="Producer"/> class. /// </summary> /// <param name="endpoint"> /// The endpoint. /// </param> /// <param name="connection"> /// Соединение с шиной сообщений /// </param> /// <param name="label"> /// Метка сообщения, которая будет использоваться при отправлении сообщений. /// </param> /// <param name="routeResolver"> /// Определитель маршрутов, по которым можно отсылать и получать сообщения. /// </param> /// <param name="confirmationIsRequired"> /// Если <c>true</c> - тогда отправитель будет ожидать подтверждения о том, что сообщение было сохранено в брокере. /// </param> public Producer(IEndpoint endpoint, IRabbitConnection connection, MessageLabel label, IRouteResolver routeResolver, bool confirmationIsRequired) { this.endpoint = endpoint; this.connection = connection; this.BrokerUrl = connection.ConnectionString; this.Label = label; this.RouteResolver = routeResolver; this.ConfirmationIsRequired = confirmationIsRequired; this.logger = LogManager.GetLogger($"{this.GetType().FullName}({this.BrokerUrl}, {this.Label}, {this.GetHashCode()})"); }
public RestfulDbMiddleware(RequestDelegate next, IRouteResolver routeResolver, IDatabaseHandler dbHandler) { this.next = next; this.routeResolver = routeResolver; this.dbHandler = dbHandler; }
/// <summary> /// Initializes a new instance of the <see cref="Navigator"/> class. /// </summary> /// <param name="factory">The factory that created this navigator.</param> /// <param name="parent">The parent navigator (can be null).</param> /// <param name="scheme">The URI scheme.</param> /// <param name="routes">The routes.</param> /// <param name="navigationService">The navigation service.</param> public Navigator(INavigatorFactory factory, INavigator parent, string scheme, IRouteResolver routes, Func <INavigationService> navigationService) : base(navigationService) { Guard.ArgumentNotNull(factory, "root"); Guard.ArgumentNotNull(routes, "routes"); Guard.ArgumentNotNull(navigationService, "navigationService"); this.factory = factory; this.parent = parent; this.scheme = scheme; this.routes = routes; }
/// <summary> /// Initializes a new instance of the <see cref="NavigatorFactory"/> class. /// </summary> /// <param name="routes">The routes that navigators created from this factory will use when resolving requests.</param> public NavigatorFactory(IRouteResolver routes) : this(null, routes) { }
public PomonaStartup(IRouteResolver routeResolver) { this.routeResolver = routeResolver; }
/// <summary> /// Создает подписку на получение ответных сообщений для указанного источника. /// </summary> /// <param name="listeningSource">Источник ответных сообщений.</param> /// <param name="callbackRouteResolver">Вычислитель маршрута ответного сообщения.</param> /// <returns>Конечная точка подписки.</returns> public ISubscriptionEndpoint ListenTo(IListeningSource listeningSource, IRouteResolver callbackRouteResolver) { return(new SubscriptionEndpoint(listeningSource, callbackRouteResolver)); }
/// <summary> /// Initializes a new instance of the <see cref="Producer"/> class. /// </summary> /// <param name="endpoint"> /// The endpoint. /// </param> /// <param name="connection"> /// Соединение с шиной сообщений /// </param> /// <param name="label"> /// Метка сообщения, которая будет использоваться при отправлении сообщений. /// </param> /// <param name="routeResolver"> /// Определитель маршрутов, по которым можно отсылать и получать сообщения. /// </param> /// <param name="confirmationIsRequired"> /// Если <c>true</c> - тогда отправитель будет ожидать подтверждения о том, что сообщение было сохранено в брокере. /// </param> public Producer(IEndpoint endpoint, IRabbitConnection connection, MessageLabel label, IRouteResolver routeResolver, bool confirmationIsRequired) { this.endpoint = endpoint; this.Channel = connection.OpenChannel(); this.BrokerUrl = connection.ConnectionString; this.logger = LogManager.GetLogger($"{this.GetType().FullName}(URL={this.BrokerUrl})"); this.Label = label; this.RouteResolver = routeResolver; this.ConfirmationIsRequired = confirmationIsRequired; if (this.ConfirmationIsRequired) { this.confirmationTracker = new DefaultPublishConfirmationTracker(this.Channel); this.Channel.EnablePublishConfirmation(); this.Channel.OnConfirmation(this.confirmationTracker.HandleConfirmation); } }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipelines"></param> /// <param name="cacheKeyGenerator"></param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipelines, ICacheKeyGenerator cacheKeyGenerator) { Enable(nancyBootstrapper, routeResolver, pipelines, cacheKeyGenerator, new WebCacheStore()); }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipelines"></param> /// <param name="varyParams"> </param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipelines, string[] varyParams) { Enable(nancyBootstrapper, routeResolver, pipelines, new DefaultCacheKeyGenerator(varyParams), new WebCacheStore()); }