private async Task ExecuteMiddleware(Middleware middleware, MiddlewareRequest request) { request.MiddlewareId = middleware.Id; request.PipelineId = Id; request.ReferenceId = middleware.ReferenceId.ToString(); await middleware.Inbox.SendMessage(request); }
protected override async Task ExecuteAsync(MiddlewareRequest request) { if (Status != MiddlewareStatus.Running) { throw new Exception("Pipeline not ready"); } var middleware = Middlewares[_currentMiddlewarePosition]; await ExecuteMiddleware(middleware, request); }
public IActionResult Post([FromBody] MiddlewareRequest request) { if (ModelState.IsValid) { CurrentRequest = request; return(Ok(CurrentRequest)); } else { return(BadRequest(ModelState)); } }
private Event Convert(MiddlewareRequest request) { var @event = new Event() { Payload = _converter.Serialize(request), CreatedOn = request.CreatedOn, Id = request.Id.ToString(), PartitionKey = request.MiddlewareId, ContentType = typeof(MiddlewareRequest).FullName, Properties = new Dictionary <string, object>(request.ExecutionConfiguration) }; return(@event); }
private Message Convert(MiddlewareRequest request) { var message = new Message() { Id = request.Id.ToString(), Payload = _converter.Serialize(request), Properties = new Dictionary <string, object>(request.ExecutionConfiguration), FilterCorrelation = request.MiddlewareId, IsControl = false, ContentType = typeof(MiddlewareRequest).FullName }; return(message); }
public override async Task SendMessage(MiddlewareRequest message) { var middlewareType = _middleware.GetType(); var address = _mailbox.Address as InMemoryInboxAddress; MethodInfo executionMethod = middlewareType.GetMethod(address.ExecutingMethodName); var exceutionTask = executionMethod.Invoke(_middleware, new object[] { message }) as Task; if (exceutionTask == null) { throw new Exception("Execution method in middleware is not formed correctly. It should be returning a task"); } await exceutionTask; }
public override Task Execute(PipelineRequest request) { _currentExecutingMidlewareIndex = 0; var middleware = _middlewares[_currentExecutingMidlewareIndex]; var executionId = Guid.NewGuid(); var middlewareRequest = new MiddlewareRequest() { Request = request.RequestObject, InvokedAt = DateTime.UtcNow, ExecutionConfiguration = request.Configuration, ExecutionId = executionId }; return(middleware.Invoke(middlewareRequest)); }
public override async Task ExecuteNextAsync(MiddlewareResponse response) { _currentMiddlewarePosition++; if (_currentMiddlewarePosition == Middlewares.Count) { await CompleteAsync(response); } var middleware = Middlewares[_currentMiddlewarePosition]; var request = new MiddlewareRequest(ExecutionId, response.Message) { Id = Guid.NewGuid(), ExecutionConfiguration = response.ExecutionConfiguration //TODO - Logic to be defined later }; await ExecuteMiddleware(middleware, request); }
public override Task Process(MiddlewareRequest request) { var timer = new Stopwatch(); timer.Start(); try { var items = JsonConvert.DeserializeObject <List <Item> >(request.Request); if (items == null) { timer.Stop(); var exception = new MiddlewareExceptionResponse() { Exception = new Exception("JSON not formed properly"), CompletedAt = DateTime.UtcNow, TimeTaken = timer.Elapsed, ExecutionConfiguration = request.ExecutionConfiguration }; return(Abort(exception)); } timer.Stop(); var response = new MiddlewareResponse() { Response = request.Request, CompletedAt = DateTime.UtcNow, TimeTaken = timer.Elapsed, ExecutionConfiguration = request.ExecutionConfiguration }; return(Complete(response)); } catch (Exception error) { timer.Stop(); var response = new MiddlewareExceptionResponse() { Exception = error, CompletedAt = DateTime.UtcNow, TimeTaken = timer.Elapsed, ExecutionConfiguration = request.ExecutionConfiguration }; return(Abort(response)); } }
public override Task Process(MiddlewareRequest request) { var timer = new Stopwatch(); timer.Start(); try { var items = JsonConvert.DeserializeObject <List <Item> >(request.Request); foreach (var item in items) { Console.WriteLine($"ID: {item.Id}"); Console.WriteLine($"Name: {item.Id}"); Console.WriteLine($"Description: {item.Id}"); Console.WriteLine($"SKU: {item.SKU}"); Console.WriteLine($"Cost: {item.Cost}"); } timer.Stop(); var response = new MiddlewareResponse() { Response = JsonConvert.SerializeObject(items), CompletedAt = DateTime.UtcNow, TimeTaken = timer.Elapsed, ExecutionConfiguration = request.ExecutionConfiguration }; return(Complete(response)); } catch (Exception error) { timer.Stop(); var response = new MiddlewareExceptionResponse() { Exception = error, CompletedAt = DateTime.UtcNow, TimeTaken = timer.Elapsed, ExecutionConfiguration = request.ExecutionConfiguration }; return(Abort(response)); } }
private Task ExecuteNext(MiddlewareResponse lastResponse) { var nextRequest = new MiddlewareRequest() { ExecutionConfiguration = lastResponse.ExecutionConfiguration, Request = lastResponse.Response, InvokedAt = DateTime.UtcNow, ExecutionId = ExecutionId }; _currentExecutingMidlewareIndex++; if (_currentExecutingMidlewareIndex >= _middlewares.Count) { return(Complete(lastResponse)); } else { var currentMiddleware = _middlewares[_currentExecutingMidlewareIndex]; return(currentMiddleware.Invoke(nextRequest)); } }
public override Task Process(MiddlewareRequest request) { var timer = new Stopwatch(); timer.Start(); try { var items = JsonConvert.DeserializeObject <List <Item> >(request.Request); var prefix = EnvironmentConfiguration["SKU.Prefix"] as string; foreach (var item in items) { item.SKU = prefix + Guid.NewGuid().ToString().Substring(0, 6); } timer.Stop(); var response = new MiddlewareResponse() { Response = JsonConvert.SerializeObject(items), CompletedAt = DateTime.UtcNow, TimeTaken = timer.Elapsed, ExecutionConfiguration = request.ExecutionConfiguration }; return(Complete(response)); } catch (Exception error) { timer.Stop(); var response = new MiddlewareExceptionResponse() { Exception = error, CompletedAt = DateTime.UtcNow, TimeTaken = timer.Elapsed, ExecutionConfiguration = request.ExecutionConfiguration }; return(Abort(response)); } }
public abstract Task SendMessage(MiddlewareRequest message);
protected abstract Task ExecuteAsync(MiddlewareRequest request);