public void Cache(ProjectionVersion version) { if (version is null) { throw new ArgumentNullException(nameof(version)); } ProjectionVersions versions = Get(version.ProjectionName); lock (versions) { versions.Add(version); } }
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); } }
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()); }
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); } }
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); }
public ProjectionVersionManagerState() { Versions = new ProjectionVersions(); }
public ProjectionVersionManagerState() { Versions = new ProjectionVersions(); HashHistoryOfLiveVersions = new HashSet<string>(); }
public ProjectionVersionsHandlerState() { AllVersions = new ProjectionVersions(); }