Ejemplo n.º 1
0
        private void Apply(RobotRotated evt)
        {
            var robot = GetRobot(evt.Name).Value.UpdateCompassPoint(
                EnumEx.MapByStringValue <Contracts.CompassPoint, CompassPoint>(evt.CompassPoint));

            _robots[evt.Name] = robot;
        }
Ejemplo n.º 2
0
        public void RotateRobot(Rotation rotation, string name)
        {
            var maybeRobot = GetRobot(name);

            if (maybeRobot.IsNone)
            {
                throw new ApplicationException($"Robot {name} does not exist");
            }
            var robot           = maybeRobot.Value;
            var compassPointInt = Pattern.Match <Rotation, int>(rotation)
                                  .When(r => r == Rotation.Right, () => (int)robot.CompassPoint + 1)
                                  .When(r => r == Rotation.Left, () => (int)robot.CompassPoint - 1)
                                  .Result;

            var newCompassPoint = Pattern.Match <int, CompassPoint>(compassPointInt)
                                  .When(i => i == -1, () => CompassPoint.West)
                                  .Otherwise.Default(() => (CompassPoint)(compassPointInt % 4));

            var evt = new RobotRotated(Id, Version,
                                       EnumEx.MapByStringValue <CompassPoint, Contracts.CompassPoint>(newCompassPoint), name);

            RaiseDomainEvent(evt);
        }