lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (LUCENENET-565) Port Lucene.Net.Replicator
Date Fri, 28 Jul 2017 17:03:00 GMT


ASF GitHub Bot commented on LUCENENET-565:

Github user AndyPook commented on the issue:
    just playing... here's how a middleware might look
    	public class Startup
    		// usual boiler plate
    		// add some method that bootstraps the index and replication service
    		public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory
    			app.UseLuceneReplicator("/_replicator", "replicaService123");
    	//  these bits live in Lucene.Net.Replicator.AspNetCore
    	public static class LuceneReplicatorMiddlewareExtensions
    		public static IApplicationBuilder UseLuceneReplicator(this IApplicationBuilder builder,
PathString prefix, object replicaService)
    			return builder.Map(prefix, app => app.UseMiddleware<LuceneReplicatorMiddleware>(replicaService));
    	public class LuceneReplicatorMiddleware
    		private readonly RequestDelegate next;
    		private readonly object replicaService;
    		public LuceneReplicatorMiddleware(RequestDelegate next, object replicaService)
    		{ = next;
    			this.replicaService= replicaService;
    		public async Task Invoke(HttpContext context)
    			var req = context.Request;
    			await context.Response.WriteAsync($"<p>{DateTime.Now.ToString()}</p>");
    			await context.Response.WriteAsync($"<p>replicaService={replicaService.ToString()}</p>");
    			await context.Response.WriteAsync($"<p>path={req.Path}</p>");
    			await context.Response.WriteAsync($"<ul>");
    			foreach(var q in req.Query)
    				await context.Response.WriteAsync($"<li>{q.Key}={q.Value}</li>");
    			await context.Response.WriteAsync($"</ul>");
    ```app.Map``` intercepts requests with that prefix (they call it "branching the request
    Where I've used "replicaService123" is just a demo of how to pass stuff into the middleware.
You'd substitute the ```ReplicationService```. Then ```Invoke``` could be as simple as ```replicaService.Perform(context.Request,
context.Response)```. But it might be better to pull the exception handling part out into
the middleware and just pass the response stream into the service.
    Note: ```req.Path``` is just the part coming after the prefix
    Anyway, just an idea

> Port Lucene.Net.Replicator
> --------------------------
>                 Key: LUCENENET-565
>                 URL:
>             Project: Lucene.Net
>          Issue Type: Task
>          Components: Lucene.Net.Replicator
>    Affects Versions: Lucene.Net 4.8.0
>            Reporter: Shad Storhaug
>            Priority: Minor
>              Labels: features

This message was sent by Atlassian JIRA

View raw message