Ejemplo n.º 1
0
        public void Edit(EndUserId endUserId, string?name, RobotApplication?application)
        {
            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                throw new ValidationException("Robot is not registered");
            }

            latestRegistration.Apply(
                registration =>
            {
                if (registration.EndUserId != endUserId)
                {
                    throw new ValidationException("Robot is registered to somebody else");
                }

                var e = RobotEdited.Create(name, application);

                Apply(e);
                Append(Guid.NewGuid(), RobotEdited.EventType, e);
            },
                unregistration => throw new ValidationException("Robot is not registered")
                );
        }
Ejemplo n.º 2
0
        public void Register(EndUserId endUserId, string?name, RobotApplication?application)
        {
            void AddRegistration()
            {
                var registrationId = new RobotRegistrationId(Guid.NewGuid());
                var e = RobotRegistered.Create(registrationId, endUserId, name, application);

                Apply(e);
                Append(registrationId.Value, RobotRegistered.EventType, e);
            }

            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                AddRegistration();
            }
            else
            {
                latestRegistration.Apply(
                    registration => throw new ValidationException("Robot is already registered"),
                    unregistration => AddRegistration()
                    );
            }
        }
Ejemplo n.º 3
0
        public void Unregister(EndUserId endUserId)
        {
            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                throw new ValidationException("Robot is not registered");
            }

            latestRegistration.Apply(
                registration =>
            {
                if (registration.EndUserId == endUserId)
                {
                    var e = RobotUnregistered.Create();
                    Apply(e);
                    Append(Guid.NewGuid(), RobotUnregistered.EventType, e);
                }
                else
                {
                    throw new ValidationException("Robot is registered to somebody else");
                }
            },
                unregistration => throw new ValidationException("Robot is not registered")
                );
        }
 public Registration(Robot robot, RobotImported e, Guid endUserId)
 {
     Id          = new RobotRegistrationId(Guid.NewGuid());
     EndUserId   = new EndUserId(endUserId);
     Name        = $"{robot.Product:G} - {robot.SerialNumber}";
     Application = e.Entity.GetRobotApplication();
 }
Ejemplo n.º 5
0
        private static async Task ImportRobotAsync(IRobotStore store, RobotImported.RobotEntity entity)
        {
            var olympusControlCorpGulf = new EndUserId(Guid.Parse("1ab17979-ff43-e911-a970-000d3a391cda"));

            var robot = Robot.Import(entity);

            if (await store.ExistsAsync(robot.Id))
            {
                Console.WriteLine($"Deleting robot {robot.Id}");
                await store.DeleteAsync(robot.Id);

                Console.WriteLine($"Deleted robot {robot.Id}");
            }

            await store.CommitAsync(robot);

            for (var i = 0; i < 1; i++)
            {
                for (var j = 0; j < 3_333; j++)
                {
                    robot.Unregister(olympusControlCorpGulf);

                    var registeredApplication = Enums.GetRandomValue <RobotApplication>();
                    robot.Register(olympusControlCorpGulf, null, registeredApplication);

                    var editedApplication = Enums.GetRandomValue <RobotApplication>();
                    var name = $"{editedApplication:G} {editedApplication:G}";
                    robot.Edit(olympusControlCorpGulf, name, editedApplication);
                }

                await store.CommitAsync(robot);
            }
        }
Ejemplo n.º 6
0
 public RobotRegistration.Registration?LatestRegistrationFor(EndUserId endUserId)
 {
     return((
                from registration in Registrations
                let reg = registration.Apply(r => r, u => null)
                          where reg?.EndUserId == endUserId
                          select reg !
                ).LastOrDefault());
 }
Ejemplo n.º 7
0
 public static RobotRegistered Create(
     RobotRegistrationId registrationId,
     EndUserId endUserId,
     string?name,
     RobotApplication?application
     ) =>
 new RobotRegistered
 {
     RegistrationId = registrationId,
     EndUserId      = endUserId,
     Name           = name,
     Application    = application
 };