コード例 #1
0
 public RegisteredRobot(Robot robot, RobotRegistration.Registration registration)
 {
     Id           = robot.Id;
     Product      = robot.Product;
     SerialNumber = robot.SerialNumber;
     Name         = registration.Name;
     Application  = registration.Application;
 }
コード例 #2
0
ファイル: Robot.cs プロジェクト: Nillerr/EventSourcing.Demo
        private void ImportRegistrations(RobotImported e)
        {
            void AddRegistration(Guid endUserId)
            {
                var newRegistration = new RobotRegistration.Registration(this, e, endUserId);

                Registrations = Registrations.Add(newRegistration);
            }

            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                if (e.Entity.C2RurEnduserValue != null)
                {
                    AddRegistration(e.Entity.C2RurEnduserValue.Value);
                }
            }
            else
            {
                latestRegistration.Apply(
                    registration =>
                {
                    if (registration.EndUserId.Value == e.Entity.C2RurEnduserValue)
                    {
                        registration.Apply(e);
                    }
                    else if (e.Entity.C2RurEnduserValue.HasValue)
                    {
                        AddRegistration(e.Entity.C2RurEnduserValue.Value);
                    }
                    else
                    {
                        Registrations = Registrations.Add(RobotRegistration.Unregistration.Instance);
                    }
                },
                    unregistration =>
                {
                    if (e.Entity.C2RurEnduserValue.HasValue)
                    {
                        AddRegistration(e.Entity.C2RurEnduserValue.Value);
                    }
                }
                    );
            }
        }
コード例 #3
0
ファイル: Robot.cs プロジェクト: Nillerr/EventSourcing.Demo
        private void Apply(RobotRegistered e)
        {
            void AddRegistration()
            {
                var registration = new RobotRegistration.Registration(this, e);

                Registrations = Registrations.Add(registration);
            }

            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                AddRegistration();
            }
            else
            {
                latestRegistration.Apply(
                    registration => throw new InvalidOperationException("Robot is already registered"),
                    unregistration => AddRegistration()
                    );
            }
        }