/// <inheritdoc/>
        public async Task BindModelAsync(ModelBindingContext bindingContext)
        {
            var stream = bindingContext.HttpContext.Request.Body;

            using (var buffer = new MemoryStream())
            {
                await stream.CopyToAsync(buffer).ConfigureAwait(false);

                buffer.Position = 0L;

                using (var reader = new StreamReader(buffer))
                {
                    var json = await reader.ReadToEndAsync().ConfigureAwait(false);

                    var requestKeyValues = _serializer.GetKeyValuesFromJson(json);
                    var request          = new InjectEventRequest
                    {
                        Tenant      = Guid.Parse(requestKeyValues["tenant"].ToString()),
                        Artifact    = _serializer.FromJson <Artifact>(requestKeyValues["artifact"].ToString()),
                        EventSource = Guid.Parse(requestKeyValues["eventSource"].ToString()),
                    };

                    var eventType = _artifactTypeMap.GetTypeFor(request.Artifact);
                    var eventData = _serializer.FromJson(eventType, requestKeyValues["event"].ToString());
                    request.Event = eventData.ToPropertyBag();

                    bindingContext.Result = ModelBindingResult.Success(request);
                }

                bindingContext.HttpContext.Request.Body = buffer;
            }
        }
Exemple #2
0
        public ActionResult Insert([FromBody] InjectEventRequest request)
        {
            var type   = _artifactTypeMap.GetTypeFor(request.Artifact);
            var @event = _objectFactory.Build(type, request.Event) as IEvent;

            _injector.InjectEvent(
                request.Tenant,
                request.EventSource,
                @event
                );
            return(Ok());
        }