Пример #1
0
        /// <summary>
        /// Run the specified projection and return the results to the caller function
        /// </summary>
        private static async Task <ProjectionResultsRecord <object> > RunProjection(ProjectionRequest request,
                                                                                    ILogger log)
        {
            if (null != request)
            {
                if (!IsProjectionRequestValid(request))
                {
                    #region Logging
                    if (null != log)
                    {
                        log.LogError($"Invalid projection request {request}");
                    }
                    #endregion
                    return(new ProjectionResultsRecord <object>()
                    {
                        Error = true,
                        StatusMessage = $"Invalid projection request {request}",
                        DomainName = request.DomainName,
                        AggregateTypeName = request.AggregateTypeName,
                        EntityUniqueIdentifier = request.AggregateInstanceUniqueIdentifier,
                        CurrentAsOfDate = request.AsOfDate.GetValueOrDefault(DateTime.UtcNow),
                        CorrelationIdentifier = request.CorrelationIdentifier,
                        ParentRequestName = request.ParentRequestName,
                        Result = null
                    });
                }

                Projection projectionEvents = new Projection(request.DomainName,
                                                             request.AggregateTypeName,
                                                             request.AggregateInstanceUniqueIdentifier,
                                                             request.ProjectionName);


                if (null != projectionEvents)
                {
                    CQRSAzure.EventSourcing.ProjectionBaseUntyped projectionToRun = null;

                    // Get an instance of the projection we want to run....
                    projectionToRun = Projection.CreateProjectionInstance(request.ProjectionName);


                    if (null != projectionToRun)
                    {
                        IProjectionResponse projectionResponse = await projectionEvents.ProcessAsync(projectionToRun);

                        if (null != projectionResponse)
                        {
                            // make a response object
                            IEnumerable <object> projectionResultObjects = Projection.GetProjectionResults(projectionToRun.CurrentValues);

                            object results = null;
                            if (null != projectionResultObjects)
                            {
                                if (projectionResultObjects.Count() == 1)
                                {
                                    results = projectionResultObjects.FirstOrDefault();
                                }
                                else
                                {
                                    results = projectionResultObjects;
                                }
                            }

                            return(new ProjectionResultsRecord <object>()
                            {
                                Error = false,
                                StatusMessage = $"Successfully returned projection request details for {request}",
                                DomainName = request.DomainName,
                                AggregateTypeName = request.AggregateTypeName,
                                EntityUniqueIdentifier = request.AggregateInstanceUniqueIdentifier,
                                CurrentAsOfDate = projectionResponse.AsOfDate.GetValueOrDefault(DateTime.UtcNow),
                                CorrelationIdentifier = request.CorrelationIdentifier,
                                ParentRequestName = request.ParentRequestName,
                                Result = results
                            });
                        }
                        else
                        {
                            #region Logging
                            if (null != log)
                            {
                                log.LogWarning($"Unable to read projection request details from {request } ");
                            }
                            #endregion
                            return(new ProjectionResultsRecord <object>()
                            {
                                Error = true,
                                StatusMessage = $"Unable to read projection request details from {request }",
                                DomainName = request.DomainName,
                                AggregateTypeName = request.AggregateTypeName,
                                EntityUniqueIdentifier = request.AggregateInstanceUniqueIdentifier,
                                CurrentAsOfDate = request.AsOfDate.GetValueOrDefault(DateTime.UtcNow),
                                CorrelationIdentifier = request.CorrelationIdentifier,
                                ParentRequestName = request.ParentRequestName,
                                Result = null
                            });
                        }
                    }
                    else
                    {
                        #region Logging
                        if (null != log)
                        {
                            log.LogError($"Unable to create projection instance details {request.ProjectionName } ");
                        }
                        #endregion
                        return(new ProjectionResultsRecord <object>()
                        {
                            Error = true,
                            StatusMessage = $"Unable to create projection instance details {request.ProjectionName }",
                            DomainName = request.DomainName,
                            AggregateTypeName = request.AggregateTypeName,
                            EntityUniqueIdentifier = request.AggregateInstanceUniqueIdentifier,
                            CurrentAsOfDate = request.AsOfDate.GetValueOrDefault(DateTime.UtcNow),
                            CorrelationIdentifier = request.CorrelationIdentifier,
                            ParentRequestName = request.ParentRequestName,
                            Result = null
                        });
                    }
                }
            }
            else
            {
                #region Logging
                if (null != log)
                {
                    log.LogWarning($"Unable to read projection request details from {request } ");
                }
                #endregion
            }

            // No results
            return(new ProjectionResultsRecord <object>()
            {
                Error = true,
                StatusMessage = $"No results found for {request}",
                DomainName = request.DomainName,
                AggregateTypeName = request.AggregateTypeName,
                EntityUniqueIdentifier = request.AggregateInstanceUniqueIdentifier,
                CurrentAsOfDate = request.AsOfDate.GetValueOrDefault(DateTime.UtcNow),
                CorrelationIdentifier = request.CorrelationIdentifier,
                ParentRequestName = request.ParentRequestName,
                Result = null
            });
        }
Пример #2
0
        public void CreateProjectionInstance_Underscored_Test()
        {
            var testProjection = Projection.CreateProjectionInstance("League_Summary_Information");

            Assert.IsNotNull(testProjection);
        }