예제 #1
0
        public async Task <ReadResult <IProjectionDefinition> > GetAsync(IBlobId projectionId, Type projectionType)
        {
            using (log.BeginScope(s => s
                                  .AddScope(Log.ProjectionName, projectionType.GetContractId())
                                  .AddScope(Log.ProjectionType, projectionType.Name)
                                  .AddScope(Log.ProjectionInstanceId, projectionId.RawId)))
            {
                if (ReferenceEquals(null, projectionId))
                {
                    throw new ArgumentNullException(nameof(projectionId));
                }

                try
                {
                    ProjectionStream stream = await LoadProjectionStreamAsync(projectionType, projectionId);

                    var readResult = new ReadResult <IProjectionDefinition>(await stream.RestoreFromHistoryAsync(projectionType).ConfigureAwait(false));
                    if (readResult.NotFound && log.IsDebugEnabled())
                    {
                        log.Debug(() => "Projection instance not found.");
                    }

                    return(readResult);
                }
                catch (Exception ex)
                {
                    log.ErrorException(ex, () => "Unable to load projection.");
                    return(ReadResult <IProjectionDefinition> .WithError(ex));
                }
            }
        }
예제 #2
0
        private async Task <ReadResult <ProjectionVersionsHandler> > GetProjectionVersionsFromStoreAsync(string projectionName)
        {
            try
            {
                var persistentVersionType             = typeof(ProjectionVersionsHandler);
                var projectionVersions_ProjectionName = persistentVersionType.GetContractId();

                var versionId           = new ProjectionVersionManagerId(projectionName, context.Tenant);
                var persistentVersion   = new ProjectionVersion(projectionVersions_ProjectionName, ProjectionStatus.Live, 1, projectionHasher.CalculateHash(persistentVersionType));
                ProjectionStream stream = await LoadProjectionStreamAsync(persistentVersionType, persistentVersion, versionId, new NoSnapshot(versionId, projectionVersions_ProjectionName).GetMeta()).ConfigureAwait(false);

                var queryResult = await stream.RestoreFromHistoryAsync <ProjectionVersionsHandler>().ConfigureAwait(false);

                return(new ReadResult <ProjectionVersionsHandler>(queryResult));
            }
            catch (Exception ex)
            {
                log.WarnException(ex, () => $"Failed to load projection versions. ProjectionName: {projectionName}");
                return(ReadResult <ProjectionVersionsHandler> .WithError(ex.Message));
            }
        }