public void NotifyHash(string hash, IProjectionVersioningPolicy policy) { EnsureThereIsNoOutdatedBuildingVersions(); if (ShouldReplay(hash)) { Replay(hash, policy); } }
public void Rebuild(string hash, IProjectionVersioningPolicy policy) { if (CanRebuild(hash)) { ProjectionVersion currentLiveVersion = state.Versions.GetNext(policy, hash); var timebox = GetVersionRequestTimebox(hash); RequestVersion(state.Id, currentLiveVersion.WithStatus(ProjectionStatus.Rebuilding), timebox); } }
private bool CanReplay(string hash, IProjectionVersioningPolicy policy) { bool isNewHashTheLiveOne = state.Versions.IsHashTheLiveOne(hash); bool isVersionable = state.Versions.IsVersionable(policy); bool doesntHaveBuildingVersion = state.Versions.HasBuildingVersion() == false; return((doesntHaveBuildingVersion && isVersionable) || (doesntHaveBuildingVersion && isVersionable == false && isNewHashTheLiveOne == false)); }
/// <summary> /// Replay all events into a new version of the projection. /// </summary> /// <param name="hash"></param> /// <param name="policy"></param> public void Replay(string hash, IProjectionVersioningPolicy policy) { EnsureThereIsNoOutdatedBuildingVersions(); if (CanReplay(hash, policy)) { ProjectionVersion projectionVersion = state.Versions.GetNext(policy, hash); VersionRequestTimebox timebox = GetVersionRequestTimebox(hash); RequestVersion(state.Id, projectionVersion, timebox); } }
public bool IsVersionable(IProjectionVersioningPolicy policy) { try { string projectionName = versions.First().ProjectionName; return(policy.IsVersionable(projectionName)); } catch (Exception) { return(true); } }
public ProjectionVersion GetNext(IProjectionVersioningPolicy policy, string hash) { if (IsVersionable(policy)) { var maxRevision = versions.Max(ver => ver.Revision); var candidate = versions.Where(x => x.Revision == maxRevision).FirstOrDefault(); // TODO: This will crash with null ref return(candidate.NextRevision(hash)); } else { if (HasLiveVersion) { return(GetLive().NonVersionableRevision(hash)); // here comes the problem } else { var maxRevision = versions.Max(ver => ver.Revision); var candidate = versions.Where(x => x.Revision == maxRevision).FirstOrDefault(); // TODO: This will crash with null ref return(candidate.NonVersionableRevision(hash)); } } }
public ProjectionVersionManagerAppService(IAggregateRepository repository, IProjectionVersioningPolicy projectionVersioningPolicy) : base(repository) { this.projectionVersioningPolicy = projectionVersioningPolicy; }