public Hostname(string value) : base(value) { if (string.IsNullOrEmpty(value)) { throw DomainError.With($"Invalid Hostname '{value}'"); } }
public Port(int value) : base(value) { if (value == 0) { throw DomainError.With($"Invalid Port '{value}'"); } }
public Description(string value) : base(value) { if (!string.IsNullOrEmpty(value) && value.Length <= 5) { throw DomainError.With($"Invalid {this.GetType().PrettyPrint()} '{value}'"); } }
public Code10(string value) : base(value) { if (string.IsNullOrEmpty(value) || value.Length != 10) { throw DomainError.With($"Invalid {this.GetType().PrettyPrint()} '{value}'"); } }
public Username(string value) : base(value) { if (string.IsNullOrEmpty(value) || value.Length > 100) { throw DomainError.With($"Invalid username '{value}'"); } }
public PublicKey(string value) : base(value) { if (string.IsNullOrEmpty(value)) { throw DomainError.With($"Invalid PublicKey '{value}'"); } }
public BatteryCapacity(int value) : base(value) { if (value <= 0) { throw DomainError.With($"Invalid battery capacity '{value}'"); } }
public Password(string value) : base(value) { if (string.IsNullOrEmpty(value)) { throw DomainError.With($"Invalid Password '{value}'"); } }
public Longitude(double value) : base(value) { if (value < -180 || value > 180) { throw DomainError.With($"Invalid longitude '{value}'"); } }
public Percentage(int value) : base(value) { if (value < 0 || value > 100) { throw DomainError.With($"Invalid percentage '{value}'"); } }
public async Task ExecuteAsync(IResolver resolver, CancellationToken cancellationToken) { var queryProcessor = resolver.Resolve <IQueryProcessor>(); var updateItineraryService = resolver.Resolve <IUpdateItineraryService>(); var commandBus = resolver.Resolve <ICommandBus>(); var routingService = resolver.Resolve <IRoutingService>(); var cargo = (await queryProcessor.ProcessAsync(new GetCargosQuery(CargoId), cancellationToken).ConfigureAwait(false)).Single(); var updatedItinerary = await updateItineraryService.UpdateItineraryAsync(cargo.Itinerary, cancellationToken).ConfigureAwait(false); if (cargo.Route.Specification().IsSatisfiedBy(updatedItinerary)) { await commandBus.PublishAsync(new CargoSetItineraryCommand(cargo.Id, updatedItinerary), cancellationToken).ConfigureAwait(false); return; } var newItineraries = await routingService.CalculateItinerariesAsync(cargo.Route, cancellationToken).ConfigureAwait(false); var newItinerary = newItineraries.FirstOrDefault(); if (newItinerary == null) { // TODO: Tell domain that a new itinerary could not be found throw DomainError.With("Could not find itinerary"); } await commandBus.PublishAsync(new CargoSetItineraryCommand(cargo.Id, newItinerary), cancellationToken).ConfigureAwait(false); }
public Latitude(double value) : base(value) { if (value < -90 || value > 90) { throw DomainError.With($"Invalid latitude '{value}'"); } }
public void hire(Wizard wizard) { if (isSquadFull()) { throw DomainError.With("Squad is full"); } Emit(new WizardHired(wizard)); }
public void Create(string name) { if (!IsNew) { throw DomainError.With("Location is already created"); } Emit(new LocationCreatedEvent(name)); }
public void hire(Warrior warrior) { if (isSquadFull()) { throw DomainError.With("Squad is full"); } Emit(new WarriorHired(warrior)); }
// Method invoked by our command public void SetMagicNumer(int magicNumber) { if (_magicNumber.HasValue) { throw DomainError.With("Magic number already set"); } Emit(new ExampleEvent(magicNumber)); }
public void SetUserAttribute(UserAttribute userAttribute) { if (_entity != null) { throw DomainError.With($"UserAttribute '{Id}' already exists in the collection of UserAttributes"); } Emit(new UserAttributeAddedEvent(userAttribute)); }
public void AddRecord(Employee record) { if (_records.Any(m => m.Id == record.Id)) { throw DomainError.With($"Employee '{Id}' already has a record with ID '{record.Id}'"); } Emit(new EmployeeAddedEvent(record)); }
public void UpdateMagicNumber(int magicNumber) { if (!_magicNumber.HasValue) { throw DomainError.With("Magic never wasn't already set"); } Emit(new ExampleEvent(magicNumber, DateTimeOffset.UtcNow)); }
public void AddMessage(ThingyMessage message) { if (_messages.Any(m => m.Id == message.Id)) { throw DomainError.With($"Thingy '{Id}' already has a message with ID '{message.Id}'"); } Emit(new ThingyMessageAddedEvent(message)); }
public void UpdateRecord(Employee employee) { if (!_records.Any(m => m.Id == employee.Id)) { throw DomainError.With($"Employee '{Id}' already has no record with ID '{employee.Id}'"); } Emit(new EmployeeUpdatedEvent(employee)); }
public void AddRecord(Company record) { if (_records.Any(m => m.Value.Id == record.Id)) { throw DomainError.With($"Company '{Id}' already has a record with ID '{record.Id}'"); } Emit(new CompanyAddedEvent(record)); }
public void DomainErrorAfterFirst() { if (DomainErrorAfterFirstReceived) { throw DomainError.With("DomainErrorAfterFirst already received!"); } Emit(new ThingyDomainErrorAfterFirstEvent()); }
public async Task HandleAsync( IDomainEvent <BankStatementAggregate, BankStatementId, BankStatementTextMatched3Event> domainEvent, ISagaContext sagaContext, CancellationToken cancellationToken) { if (State != SagaState.Running) { throw DomainError.With("Saga must be running!"); } Emit(new BankStatementSagaTextMatchedEvent()); await Task.CompletedTask; }
public override async Task ExecuteAsync(TreatmentMachineAggregate aggregate, AddTreatmentMachineWithAdvanceCapabilityCommand command, CancellationToken cancellationToken) { var query = new GetTreatmentMachineByNameQuery(command.Name); if (await _queryProcessor.ProcessAsync(query, cancellationToken).ConfigureAwait(false) != null) { throw DomainError.With($"Treatment machine with name '{command.Name}' already exists."); } aggregate.AddMachineWithAdvancedCapability(command.Name); }
public override async Task ExecuteAsync(TreatmentRoomAggregate aggregate, AddTreatmentRoomCommand command, CancellationToken cancellationToken) { var query = new GetTreatmentRoomByNameQuery(command.Name); if (await this.queryProcessor.ProcessAsync(query, cancellationToken) != null) { throw DomainError.With($"Treatment room with name '{command.Name}' already exists."); } aggregate.Add(command.Name); }
public void AddMessageHistory(ThingyMessage[] messages) { var existingIds = _messages.Select(m => m.Id).Intersect(_messages.Select(m => m.Id)).ToArray(); if (existingIds.Any()) { throw DomainError.With($"Thingy '{Id}' already has messages with IDs " + $"'{string.Join(",", existingIds.Select(id => id.ToString()))}'"); } Emit(new ThingyMessageHistoryAddedEvent(messages)); }
public Task HandleAsync( IDomainEvent <ThingyAggregate, ThingyId, ThingySagaStartRequestedEvent> domainEvent, ISagaContext sagaContext, CancellationToken cancellationToken) { // This check is redundant! We do it to verify EventFlow works correctly if (State != SagaState.New) { throw DomainError.With("Saga must be new!"); } Emit(new ThingySagaStartedEvent(domainEvent.AggregateIdentity)); return(Task.FromResult(0)); }
public Task HandleAsync( IDomainEvent <ExampleAggregate, ExampleId, ResetEvent> domainEvent, ISagaContext sagaContext, CancellationToken cancellationToken) { // This check is redundant! We do it to verify EventFlow works correctly if (State != SagaState.Running) { throw DomainError.With("Saga must be running!"); } Emit(new ExampleSagaCompletedEvent()); return(Task.FromResult(0)); }
public static void ThrowDomainErrorIfNotSatisfied <T>( this ISpecification <T> specification, T obj) { if (specification == null) { throw new ArgumentNullException(nameof(specification)); } var whyIsNotStatisfiedBy = specification.WhyIsNotSatisfiedBy(obj).ToList(); if (whyIsNotStatisfiedBy.Any()) { throw DomainError.With( $"'{specification.GetType().PrettyPrint()}' is not satisfied because of {string.Join(" and ", whyIsNotStatisfiedBy)}"); } }