Ejemplo n.º 1
0
        public async Task <IActionResult> Meta([FromQuery] RequestModel model)
        {
            IEnumerable <Assembly> loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => assembly.IsDynamic == false);
            Type metadata = loadedAssemblies
                            .SelectMany(assembly => assembly.GetLoadableTypes()
                                        .Where(x => typeof(IProjection).IsAssignableFrom(x))
                                        .Where(x => x.GetCustomAttributes(typeof(DataContractAttribute), false).Length > 0))
                            .Where(x => x.GetContractId() == model.ProjectionContractId)
                            .FirstOrDefault();

            if (metadata is null)
            {
                return(new BadRequestObjectResult(new ResponseResult <string>($"Projection with contract '{model.ProjectionContractId}' not found")));
            }

            var           id  = new ProjectionVersionManagerId(model.ProjectionContractId, context.Tenant);
            ProjectionDto dto = await _projectionExplorer.ExploreAsync(id, typeof(ProjectionVersionsHandler));

            var state = dto?.State as ProjectionVersionsHandlerState;

            var metaProjection = new ProjectionMeta()
            {
                ProjectionContractId = metadata.GetContractId(),
                ProjectionName       = metadata.Name,
                IsReplayable         = typeof(IAmEventSourcedProjection).IsAssignableFrom(metadata)
            };

            if (state is null)
            {
                metaProjection.Versions.Add(new ProjectionVersionDto()
                {
                    Status   = ProjectionStatus.NotPresent,
                    Hash     = projectionHasher.CalculateHash(typeof(ProjectionVersionsHandler)),
                    Revision = 0
                });
            }
            else
            {
                foreach (var ver in state.AllVersions)
                {
                    metaProjection.Versions.Add(new ProjectionVersionDto()
                    {
                        Hash     = ver.Hash,
                        Revision = ver.Revision,
                        Status   = ver.Status
                    });
                }
            }

            return(Ok(new ResponseResult <ProjectionMeta>(metaProjection)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> List()
        {
            var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => assembly.IsDynamic == false);

            var projectionMetaData = loadedAssemblies
                                     .SelectMany(ass => ass.GetLoadableTypes()
                                                 .Where(x => typeof(IProjection).IsAssignableFrom(x) && x.GetCustomAttributes(typeof(DataContractAttribute), false).Length > 0));

            ProjectionListDto result = new ProjectionListDto();

            foreach (var meta in projectionMetaData)
            {
                var id  = new ProjectionVersionManagerId(meta.GetContractId(), context.Tenant);
                var dto = await _projectionExplorer.ExploreAsync(id, typeof(ProjectionVersionsHandler));

                ProjectionVersionsHandlerState state = dto?.State as ProjectionVersionsHandlerState;
                var metaProjection = new ProjectionMeta()
                {
                    ProjectionContractId = meta.GetContractId(),
                    ProjectionName       = meta.Name,
                    IsReplayable         = typeof(IAmEventSourcedProjection).IsAssignableFrom(meta)
                };
                if (ReferenceEquals(null, state))
                {
                    metaProjection.Versions.Add(new ProjectionVersionDto()
                    {
                        Status   = ProjectionStatus.NotPresent,
                        Hash     = projectionHasher.CalculateHash(meta),
                        Revision = 0
                    });
                }
                else
                {
                    foreach (var ver in state.AllVersions)
                    {
                        metaProjection.Versions.Add(new ProjectionVersionDto()
                        {
                            Hash     = ver.Hash,
                            Revision = ver.Revision,
                            Status   = ver.Status
                        });
                    }
                }
                result.Projections.Add(metaProjection);
            }

            return(new OkObjectResult(new ResponseResult <ProjectionListDto>(result)));
        }