Пример #1
0
        public void Cache(ProjectionVersion version)
        {
            if (version is null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            ProjectionVersions versions = Get(version.ProjectionName);

            lock (versions)
            {
                versions.Add(version);
            }
        }
Пример #2
0
        public void Cache(ProjectionVersion version)
        {
            ProjectionVersions versions;

            if (store.TryGetValue(version.ProjectionName, out versions))
            {
                versions.Add(version);
            }
            else
            {
                var initialVersion = new ProjectionVersions();
                initialVersion.Add(version);
                store.AddOrUpdate(version.ProjectionName, initialVersion, (key, val) => val);
            }
        }
Пример #3
0
        ProjectionVersions GetProjectionVersions(string contractId)
        {
            ProjectionVersions versions = inMemoryVersionStore.Get(contractId);

            if (versions == null || versions.Count == 0)
            {
                var versionId                   = new ProjectionVersionManagerId(contractId);
                var persistentVersionType       = typeof(PersistentProjectionVersionHandler);
                var persistentVersionContractId = persistentVersionType.GetContractId();
                var persistentVersion           = new ProjectionVersion(persistentVersionContractId, ProjectionStatus.Live, 1, persistentVersionType.GetProjectionHash());
                ProjectionStream stream         = LoadProjectionStream(typeof(PersistentProjectionVersionHandler), persistentVersion, versionId, new NoSnapshot(versionId, contractId));
                var queryResult                 = stream.RestoreFromHistory <PersistentProjectionVersionHandler>();
                if (queryResult.Success)
                {
                    if (queryResult.Projection.State.Live != null)
                    {
                        inMemoryVersionStore.Cache(queryResult.Projection.State.Live);
                    }
                    if (queryResult.Projection.State.Building != null)
                    {
                        inMemoryVersionStore.Cache(queryResult.Projection.State.Building);
                    }
                    versions = inMemoryVersionStore.Get(contractId);
                }

                // inception
                if (versions == null || versions.Count == 0)
                {
                    if (string.Equals(persistentVersionContractId, contractId, StringComparison.OrdinalIgnoreCase))
                    {
                        inMemoryVersionStore.Cache(persistentVersion);
                        versions = inMemoryVersionStore.Get(contractId);
                    }
                    else
                    {
                        var initialVersion = new ProjectionVersion(contractId, ProjectionStatus.Building, 1, contractId.GetTypeByContract().GetProjectionHash());
                        inMemoryVersionStore.Cache(initialVersion);
                        versions = inMemoryVersionStore.Get(contractId);
                    }
                }
            }

            return(versions ?? new ProjectionVersions());
        }
Пример #4
0
        public void Cache(ProjectionVersion version)
        {
            if (ReferenceEquals(null, version))
            {
                throw new ArgumentNullException(nameof(version));
            }

            ProjectionVersions versions;

            if (store.TryGetValue(version.ProjectionName, out versions))
            {
                versions.Add(version);
            }
            else
            {
                var initialVersion = new ProjectionVersions();
                initialVersion.Add(version);
                store.AddOrUpdate(version.ProjectionName, initialVersion, (key, val) => val);
            }
        }
Пример #5
0
        public async Task <bool> ShouldBeCanceledAsync(ProjectionVersion version, DateTimeOffset dueDate)
        {
            if (HasReplayTimeout(dueDate))
            {
                logger.Error(() => $"Rebuild of projection `{version}` has expired. Version:{version} Deadline:{dueDate}.");
                return(true);
            }

            ProjectionVersions allVersions = await GetAllVersionsAsync(version).ConfigureAwait(false);

            if (allVersions.IsOutdatad(version))
            {
                logger.Error(() => $"Version `{version}` is outdated. There is a newer one which is already live.");
                return(true);
            }
            else if (allVersions.IsCanceled(version) && version.ProjectionName.Equals(ProjectionVersionsHandler.ContractId, StringComparison.OrdinalIgnoreCase) == false)
            {
                logger.Error(() => $"Version `{version}` was canceled");
                return(true);
            }

            return(false);
        }
Пример #6
0
 public ProjectionVersionManagerState()
 {
     Versions = new ProjectionVersions();
 }
 public ProjectionVersionManagerState()
 {
     Versions = new ProjectionVersions();
     HashHistoryOfLiveVersions = new HashSet<string>();
 }
Пример #8
0
 public ProjectionVersionsHandlerState()
 {
     AllVersions = new ProjectionVersions();
 }