Exemple #1
0
        public static async Task <HttpResponseMessage> RunProjectionForQueryCommand(
            [HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"CQRS/RunProjectionForQuery/{queryIdentifier}")] HttpRequestMessage req,
            string queryIdentifier
            )
        {
            #region Tracing telemetry
            Activity.Current.AddTag("Query Identifier", queryIdentifier);
            #endregion

            // 1 - Read the ProjectionRequestData from the body
            ProjectionRequestedEventGridEventData data = await req.Content.ReadAsAsync <ProjectionRequestedEventGridEventData>();

            if (data != null)
            {
                if (string.IsNullOrWhiteSpace(data.InstanceKey))
                {
                    data.InstanceKey = queryIdentifier;
                }
                await RunProjectionForQuery(data);

                return(req.CreateResponse(System.Net.HttpStatusCode.OK));
            }
            else
            {
                // The projection cannot be run if there is no body supplied
                return(req.CreateResponse(System.Net.HttpStatusCode.BadRequest,
                                          "The projection details were not correctly specified in the request body"));
            }
        }
Exemple #2
0
 public static async Task OnQueryProjectionHandler(
     [EventGridTrigger] EventGridEvent eventGridEvent)
 {
     if (eventGridEvent != null)
     {
         // Get the data from the event that describes what projection is requested
         ProjectionRequestedEventGridEventData projectionRequestData = eventGridEvent.Data.ToObjectFromJson <ProjectionRequestedEventGridEventData>();
         await ProjectionHandlerFunctions.RunProjectionForQuery(projectionRequestData);
     }
 }
Exemple #3
0
        /// <summary>
        /// A projection has been requested in processing a command.
        /// This function will run it and attach the result back to the command
        /// event stream when complete.
        /// </summary>
        public static async Task RunProjectionForCommand(ProjectionRequestedEventGridEventData projectionRequestData)
        {
            if (projectionRequestData != null)
            {
                // Process the projection
                Projection projection = new Projection(
                    new ProjectionAttribute(
                        projectionRequestData.ProjectionRequest.ProjectionDomainName,
                        projectionRequestData.ProjectionRequest.ProjectionEntityTypeName,
                        projectionRequestData.ProjectionRequest.ProjectionInstanceKey,
                        projectionRequestData.ProjectionRequest.ProjectionTypeName
                        ));

                if (_projectionMap == null)
                {
                    _projectionMap = ProjectionMaps.CreateDefaultProjectionMaps();
                }

                IProjection projectionToRun     = _projectionMap.CreateProjectionClass(projectionRequestData.ProjectionRequest.ProjectionTypeName);
                IProjection completedProjection = null;

                if (projectionToRun != null)
                {
                    completedProjection = await projection.Process(projectionToRun,
                                                                   projectionRequestData.ProjectionRequest.AsOfDate);
                }

                // Attach the results back to the query event stream
                Command cmdSource = new Command(projectionRequestData.DomainName,
                                                projectionRequestData.EntityTypeName,
                                                projectionRequestData.InstanceKey);


                if (cmdSource != null)
                {
                    int CurrentSequenceNumber = 0;
                    if (completedProjection != null)
                    {
                        CurrentSequenceNumber = completedProjection.CurrentSequenceNumber;
                    }

                    await cmdSource.PostProjectionResponse(projectionRequestData.ProjectionRequest.ProjectionDomainName,
                                                           projectionRequestData.ProjectionRequest.ProjectionEntityTypeName,
                                                           projectionRequestData.ProjectionRequest.ProjectionInstanceKey,
                                                           projectionRequestData.ProjectionRequest.ProjectionTypeName,
                                                           projectionRequestData.ProjectionRequest.AsOfDate,
                                                           projectionRequestData.ProjectionRequest.CorrelationIdentifier,
                                                           CurrentSequenceNumber,
                                                           completedProjection);
                }
            }
        }