コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public IActionResult Post([FromBody] MiddlewareRequest request)
        {
            if (ModelState.IsValid)
            {
                CurrentRequest = request;

                return(Ok(CurrentRequest));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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));
            }
        }
コード例 #10
0
        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));
            }
        }
コード例 #11
0
        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));
            }
        }
コード例 #12
0
        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));
            }
        }
コード例 #13
0
 public abstract Task SendMessage(MiddlewareRequest message);
コード例 #14
0
 protected abstract Task ExecuteAsync(MiddlewareRequest request);