Esempio n. 1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.Value == null)
            {
                return(null);
            }

            var coordinatesArray = serializer.Deserialize <double[]>(reader);

            if (coordinatesArray == null)
            {
                return(null);
            }

            var coordinates = new CoordinatesDTO(coordinatesArray[0], coordinatesArray[1]);

            if (objectType == typeof(List <ICoordinates>[]))
            {
                return(new []
                {
                    new List <ICoordinates>
                    {
                        coordinates
                    }
                });
            }

            return(coordinates);
        }
Esempio n. 2
0
 public Robot(
     IRobotLogger logger,
     CoordinatesDTO coordinates,
     IStepsCounter stepsCounter,
     CoordinatesBoundryDTO boundries
     )
 {
     _logger     = logger;
     Coordinates = coordinates;
     _counter    = stepsCounter;
     Boundries   = boundries;
 }
Esempio n. 3
0
        public string Post([FromBody] CoordinatesDTO coordinates)
        {
            string retMessage = string.Empty;

            try
            {
                //_hubContext.Clients.All.GetLocation(coordinates);
                retMessage = "Success";
            }
            catch (Exception e)
            {
                retMessage = e.ToString();
            }

            return(retMessage);
        }
Esempio n. 4
0
        public void MoveRight(int distance)
        {
            if (_lastDirection == Directions.right)
            {
                throw new MovedSameDirectionException();
            }
            _lastDirection = Directions.right;
            int newCoords = Coordinates.X + distance;

            if (newCoords > Boundries.MaxX)
            {
                throw new OutOFBoundsException();
            }

            _counter.AddStepsRight(distance);
            Coordinates = new CoordinatesDTO(newCoords, Coordinates.Y);
        }
Esempio n. 5
0
        public void MoveLeft(int distance)
        {
            if (_lastDirection == Directions.left)
            {
                throw new MovedSameDirectionException();
            }
            _lastDirection = Directions.left;
            int newCoords = Coordinates.X - distance;

            if (newCoords < Boundries.MinX)
            {
                throw new OutOFBoundsException();
            }

            _counter.AddStepsLeft(distance);
            Coordinates = new CoordinatesDTO(newCoords, Coordinates.Y);
        }
Esempio n. 6
0
        public void MoveDown(int distance)
        {
            if (_lastDirection == Directions.down)
            {
                throw new MovedSameDirectionException();
            }
            _lastDirection = Directions.down;
            int newCoords = Coordinates.Y - distance;

            if (newCoords < Boundries.MinY)
            {
                throw new OutOFBoundsException();
            }

            _counter.AddStepsDown(distance);
            Coordinates = new CoordinatesDTO(Coordinates.X, newCoords);
        }
Esempio n. 7
0
        public void MoveUp(int distance)
        {
            if (_lastDirection == Directions.up)
            {
                throw new MovedSameDirectionException();
            }
            _lastDirection = Directions.up;
            int newCoords = Coordinates.Y + distance;

            if (newCoords > Boundries.MaxY)
            {
                throw new OutOFBoundsException();
            }

            _counter.AddStepsUp(distance);
            Coordinates = new CoordinatesDTO(Coordinates.X, newCoords);
        }
Esempio n. 8
0
        public async Task <MarkDTO> Create(int userId, CoordinatesDTO obj)
        {
            try
            {
                var isExist = await Context.Marks.CountAsync(m => obj.Equals(m.Coordinates)) > 0;

                if (isExist)
                {
                    return(null);
                }
                var user = await Context.Users.FindAsync(userId);

                if (user == null)
                {
                    return(new MarkDTO
                    {
                        Id = -1
                    });
                }
                var mark = await Context.Marks.AddAsync(new DAL.Entities.Mark
                {
                    Coordinates = new DAL.Entities.Coordinates
                    {
                        Latitude  = obj.Latitude,
                        Longitude = obj.Longitude
                    },
                    User = user
                });

                var result = await Context.SaveChangesAsync();

                return(result == 0 ? null : new MarkDTO
                {
                    Id = mark.Entity.Id,
                    UserId = userId
                });
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 9
0
 public void LogCurrentCoordinates(CoordinatesDTO coordinates)
 {
     Console.WriteLine($"Robot's current position is: X:{coordinates.X} Y:{coordinates.Y}");
 }
Esempio n. 10
0
 internal static Coordinates ToCoordinates(this CoordinatesDTO coordinatesDto)
 {
     return(new Coordinates(coordinatesDto.X, coordinatesDto.Y));
 }
Esempio n. 11
0
 public Coordinates(CoordinatesDTO coordinates)
 {
     Latitude  = coordinates.Latitude;
     Longitude = coordinates.Longitude;
 }
Esempio n. 12
0
        public bool PublishWithGeoInReplyTo(double longitude, double latitude, long replyToTweetId)
        {
            var coordinates = new CoordinatesDTO(longitude, latitude);

            return(PublishWithGeoInReplyTo(coordinates, replyToTweetId));
        }
Esempio n. 13
0
        public bool PublishWithGeo(double longitude, double latitude)
        {
            var coordinates = new CoordinatesDTO(longitude, latitude);

            return(PublishWithGeo(coordinates));
        }