Exemplo n.º 1
0
        public void NotifyHash(string hash, IProjectionVersioningPolicy policy)
        {
            EnsureThereIsNoOutdatedBuildingVersions();

            if (ShouldReplay(hash))
            {
                Replay(hash, policy);
            }
        }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
 public bool IsVersionable(IProjectionVersioningPolicy policy)
 {
     try
     {
         string projectionName = versions.First().ProjectionName;
         return(policy.IsVersionable(projectionName));
     }
     catch (Exception)
     {
         return(true);
     }
 }
Exemplo n.º 6
0
 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;
 }