protected override OperationBase DeepCloneInternal() { var result = new WriteEventOnMatchingHandlingStatusOp <TId>( this.CheckRecordHandlingOps?.DeepClone(), this.EventToPutOnMatchChainOfResponsibility?.DeepClone(), this.WaitTimeBeforeRetry.DeepClone()); return(result); }
public WriteEventOnMatchingHandlingStatusOp <TId> DeepCloneWithWaitTimeBeforeRetry(TimeSpan waitTimeBeforeRetry) { var result = new WriteEventOnMatchingHandlingStatusOp <TId>( this.CheckRecordHandlingOps?.DeepClone(), this.EventToPutOnMatchChainOfResponsibility?.DeepClone(), waitTimeBeforeRetry); return(result); }
public WriteEventOnMatchingHandlingStatusOp <TId> DeepCloneWithEventToPutOnMatchChainOfResponsibility(IReadOnlyList <EventToPutWithIdOnHandlingStatusMatch <TId> > eventToPutOnMatchChainOfResponsibility) { var result = new WriteEventOnMatchingHandlingStatusOp <TId>( this.CheckRecordHandlingOps?.DeepClone(), eventToPutOnMatchChainOfResponsibility, this.WaitTimeBeforeRetry.DeepClone()); return(result); }
public WriteEventOnMatchingHandlingStatusOp <TId> DeepCloneWithCheckRecordHandlingOps(IReadOnlyCollection <CheckRecordHandlingOp> checkRecordHandlingOps) { var result = new WriteEventOnMatchingHandlingStatusOp <TId>( checkRecordHandlingOps, this.EventToPutOnMatchChainOfResponsibility?.DeepClone(), this.WaitTimeBeforeRetry.DeepClone()); return(result); }
/// <inheritdoc /> public bool Equals(WriteEventOnMatchingHandlingStatusOp <TId> other) { if (ReferenceEquals(this, other)) { return(true); } if (ReferenceEquals(other, null)) { return(false); } var result = this.CheckRecordHandlingOps.IsEqualTo(other.CheckRecordHandlingOps) && this.EventToPutOnMatchChainOfResponsibility.IsEqualTo(other.EventToPutOnMatchChainOfResponsibility) && this.WaitTimeBeforeRetry.IsEqualTo(other.WaitTimeBeforeRetry); return(result); }
public override void Execute( WriteEventOnMatchingHandlingStatusOp <TId> operation) { operation.MustForArg(nameof(operation)).NotBeNull(); var results = new Dictionary <CheckRecordHandlingOp, CheckRecordHandlingResult>(); foreach (var checkRecordHandlingOp in operation.CheckRecordHandlingOps) { var result = this.checkRecordHandlingProtocol.Execute(checkRecordHandlingOp); results.Add(checkRecordHandlingOp, result); } if (results.Any()) { var actualCompositeHandlingStatus = results .SelectMany(_ => _.Value.InternalRecordIdToHandlingStatusMap.Values) .ToList() .ToCompositeHandlingStatus(); foreach (var eventToPutWithIdOnMatch in operation.EventToPutOnMatchChainOfResponsibility) { var matches = actualCompositeHandlingStatus.MatchesAccordingToStrategy( eventToPutWithIdOnMatch.StatusToMatch, eventToPutWithIdOnMatch.CompositeHandlingStatusMatchStrategy); if (matches) { var eventToPutWithId = eventToPutWithIdOnMatch.EventToPut; IEvent eventToPut; if (eventToPutWithId.UpdateTimestampOnPut) { var eventBase = eventToPutWithId.EventToPut as EventBase; eventBase .MustForOp(Invariant($"{nameof(eventToPutWithId)}.{nameof(eventToPutWithId.EventToPut)}")) .NotBeNull( Invariant( $"Only {nameof(EventBase)} is supported, this was {eventToPutWithId.EventToPut.GetType().ToStringReadable()}.")); // ReSharper disable once PossibleNullReferenceException - checked with Must above eventToPut = eventBase.DeepCloneWithTimestampUtc(DateTime.UtcNow); } else { eventToPut = eventToPutWithId.EventToPut; } var eventToPutTags = eventToPut is IHaveTags eventToPutWithTags ? eventToPutWithTags.Tags : null; if (!NullStreamRepresentation.Equals(eventToPutWithId.StreamRepresentation)) { var targetStream = this.streamFactory.Execute(new GetStreamFromRepresentationOp(eventToPutWithId.StreamRepresentation)); targetStream.MustForOp("targetStreamMustBeIWriteOnlyStream").BeAssignableToType <IWriteOnlyStream>(); ((IWriteOnlyStream)targetStream).PutWithId(eventToPutWithId.Id, eventToPut, eventToPutTags); } switch (eventToPutWithIdOnMatch.ChainOfResponsibilityLinkMatchStrategy) { case ChainOfResponsibilityLinkMatchStrategy.MatchHaltsEvaluationOfChainAndCompletes: return; case ChainOfResponsibilityLinkMatchStrategy.MatchHaltsEvaluationOfChainAndSelfCancels: Thread.Sleep(operation.WaitTimeBeforeRetry); throw new SelfCancelRunningExecutionException("Matched status and wrote record, terminating chain but not terminating execution."); case ChainOfResponsibilityLinkMatchStrategy.Continue: // Keep going through links... break; default: throw new NotSupportedException(Invariant($"Unsupported {nameof(ChainOfResponsibilityLinkMatchStrategy)}: {eventToPutWithIdOnMatch.ChainOfResponsibilityLinkMatchStrategy}.")); } } } Thread.Sleep(operation.WaitTimeBeforeRetry); throw new SelfCancelRunningExecutionException("No matches found or the matches did not terminate the chain or execution."); } else { Thread.Sleep(operation.WaitTimeBeforeRetry); throw new SelfCancelRunningExecutionException("No records found to test."); } }