예제 #1
0
 public Hostname(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw DomainError.With($"Invalid Hostname '{value}'");
     }
 }
예제 #2
0
파일: Port.cs 프로젝트: serialize/LoxNET
 public Port(int value) : base(value)
 {
     if (value == 0)
     {
         throw DomainError.With($"Invalid Port '{value}'");
     }
 }
예제 #3
0
 public Description(string value) : base(value)
 {
     if (!string.IsNullOrEmpty(value) && value.Length <= 5)
     {
         throw DomainError.With($"Invalid {this.GetType().PrettyPrint()} '{value}'");
     }
 }
예제 #4
0
 public Code10(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value) || value.Length != 10)
     {
         throw DomainError.With($"Invalid {this.GetType().PrettyPrint()} '{value}'");
     }
 }
예제 #5
0
 public Username(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value) || value.Length > 100)
     {
         throw DomainError.With($"Invalid username '{value}'");
     }
 }
예제 #6
0
 public PublicKey(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw DomainError.With($"Invalid PublicKey '{value}'");
     }
 }
예제 #7
0
 public BatteryCapacity(int value) : base(value)
 {
     if (value <= 0)
     {
         throw DomainError.With($"Invalid battery capacity '{value}'");
     }
 }
예제 #8
0
 public Password(string value) : base(value)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw DomainError.With($"Invalid Password '{value}'");
     }
 }
예제 #9
0
 public Longitude(double value) : base(value)
 {
     if (value < -180 || value > 180)
     {
         throw DomainError.With($"Invalid longitude '{value}'");
     }
 }
예제 #10
0
 public Percentage(int value) : base(value)
 {
     if (value < 0 || value > 100)
     {
         throw DomainError.With($"Invalid percentage '{value}'");
     }
 }
예제 #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);
        }
예제 #12
0
 public Latitude(double value) : base(value)
 {
     if (value < -90 || value > 90)
     {
         throw DomainError.With($"Invalid latitude '{value}'");
     }
 }
예제 #13
0
 public void hire(Wizard wizard)
 {
     if (isSquadFull())
     {
         throw DomainError.With("Squad is full");
     }
     Emit(new WizardHired(wizard));
 }
예제 #14
0
 public void Create(string name)
 {
     if (!IsNew)
     {
         throw DomainError.With("Location is already created");
     }
     Emit(new LocationCreatedEvent(name));
 }
예제 #15
0
 public void hire(Warrior warrior)
 {
     if (isSquadFull())
     {
         throw DomainError.With("Squad is full");
     }
     Emit(new WarriorHired(warrior));
 }
예제 #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));
        }
예제 #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));
        }
        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));
        }
예제 #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));
        }
        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));
        }
예제 #23
0
        public void DomainErrorAfterFirst()
        {
            if (DomainErrorAfterFirstReceived)
            {
                throw DomainError.With("DomainErrorAfterFirst already received!");
            }

            Emit(new ThingyDomainErrorAfterFirstEvent());
        }
예제 #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;
 }
예제 #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);
        }
예제 #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);
        }
예제 #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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #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)}");
            }
        }