Ejemplo n.º 1
0
 public Hostname(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw DomainError.With($"Invalid Hostname '{value}'");
     }
 }
Ejemplo n.º 2
0
 public Port(int value) : base(value)
 {
     if (value == 0)
     {
         throw DomainError.With($"Invalid Port '{value}'");
     }
 }
Ejemplo n.º 3
0
 public Description(string value) : base(value)
 {
     if (!string.IsNullOrEmpty(value) && value.Length <= 5)
     {
         throw DomainError.With($"Invalid {this.GetType().PrettyPrint()} '{value}'");
     }
 }
Ejemplo n.º 4
0
 public Code10(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value) || value.Length != 10)
     {
         throw DomainError.With($"Invalid {this.GetType().PrettyPrint()} '{value}'");
     }
 }
Ejemplo n.º 5
0
 public Username(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value) || value.Length > 100)
     {
         throw DomainError.With($"Invalid username '{value}'");
     }
 }
Ejemplo n.º 6
0
 public PublicKey(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw DomainError.With($"Invalid PublicKey '{value}'");
     }
 }
Ejemplo n.º 7
0
 public BatteryCapacity(int value) : base(value)
 {
     if (value <= 0)
     {
         throw DomainError.With($"Invalid battery capacity '{value}'");
     }
 }
Ejemplo n.º 8
0
 public Password(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw DomainError.With($"Invalid Password '{value}'");
     }
 }
Ejemplo n.º 9
0
 public Longitude(double value) : base(value)
 {
     if (value < -180 || value > 180)
     {
         throw DomainError.With($"Invalid longitude '{value}'");
     }
 }
Ejemplo n.º 10
0
 public Percentage(int value) : base(value)
 {
     if (value < 0 || value > 100)
     {
         throw DomainError.With($"Invalid percentage '{value}'");
     }
 }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
 public Latitude(double value) : base(value)
 {
     if (value < -90 || value > 90)
     {
         throw DomainError.With($"Invalid latitude '{value}'");
     }
 }
Ejemplo n.º 13
0
 public void hire(Wizard wizard)
 {
     if (isSquadFull())
     {
         throw DomainError.With("Squad is full");
     }
     Emit(new WizardHired(wizard));
 }
Ejemplo n.º 14
0
 public void Create(string name)
 {
     if (!IsNew)
     {
         throw DomainError.With("Location is already created");
     }
     Emit(new LocationCreatedEvent(name));
 }
Ejemplo n.º 15
0
 public void hire(Warrior warrior)
 {
     if (isSquadFull())
     {
         throw DomainError.With("Squad is full");
     }
     Emit(new WarriorHired(warrior));
 }
Ejemplo n.º 16
0
        // Method invoked by our command
        public void SetMagicNumer(int magicNumber)
        {
            if (_magicNumber.HasValue)
            {
                throw DomainError.With("Magic number already set");
            }

            Emit(new ExampleEvent(magicNumber));
        }
Ejemplo n.º 17
0
        public void SetUserAttribute(UserAttribute userAttribute)
        {
            if (_entity != null)
            {
                throw DomainError.With($"UserAttribute '{Id}' already exists in the collection of UserAttributes");
            }

            Emit(new UserAttributeAddedEvent(userAttribute));
        }
Ejemplo n.º 18
0
        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));
        }
Ejemplo n.º 20
0
        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));
        }
Ejemplo n.º 21
0
        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));
        }
Ejemplo n.º 23
0
        public void DomainErrorAfterFirst()
        {
            if (DomainErrorAfterFirstReceived)
            {
                throw DomainError.With("DomainErrorAfterFirst already received!");
            }

            Emit(new ThingyDomainErrorAfterFirstEvent());
        }
Ejemplo n.º 24
0
 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;
 }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        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));
        }
Ejemplo n.º 28
0
        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));
        }
Ejemplo n.º 29
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));
        }
Ejemplo n.º 30
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)}");
            }
        }