Exemplo n.º 1
0
        public async Task <IActionResult> Create(Lawn lawn)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lawn);
                await _context.SaveChangesAsync();



                //text message for this method
                ////////
                SMSInformation twilio = new SMSInformation();

                string accountSid = twilio.accountSID;
                string authToken  = twilio.accountToken;

                TwilioClient.Init(accountSid, authToken);

                var message = MessageResource.Create(
                    body: $"Hi, {lawn.FirstName}, your lawn at {lawn.StreetAddress} has been requested, and you will be notified if it is approved.",
                    from: new Twilio.Types.PhoneNumber(twilio.twilioPhone),
                    to: new Twilio.Types.PhoneNumber(twilio.customerPhone));
                /////////



                return(RedirectToAction(nameof(Index)));
            }
            return(View(lawn));
        }
Exemplo n.º 2
0
    private void UpdateLawn(LevelGrid grid)
    {
        Lawn lawn = GetLawnAtPosition(grid);

        bool[] nearGridColor = new bool[4];
        if (grid.state > 0 && !grid.colorOn)
        {
            Vector2 uv = GetUVAtPosition(grid, grid.position);
            for (int i = 1; i <= 4; i++)
            {
                LevelGrid tmp = grid.GetNearGrid((NearGridDirection)i);
                if (tmp != null && tmp.state > 0 && grid.groundColor == tmp.groundColor)
                {
                    nearGridColor[i - 1] = true;
                }
                else
                {
                    nearGridColor[i - 1] = false;
                }
            }
            lawn.DrawGridAtPosition(uv, grid.groundColor, grid.state, nearGridColor[0], nearGridColor[1], nearGridColor[2], nearGridColor[3]);
            grid.colorOn = true;
        }
        else if (grid.state == 0 && grid.colorOn)
        {
            Vector2 uv = GetUVAtPosition(grid, grid.position);
            lawn.ClearAtPosition(uv);
            grid.colorOn = false;
        }
    }
Exemplo n.º 3
0
    public void DisableLawnAtGrid(LevelGrid grid)
    {
        Vector2 uv   = GetUVAtPosition(grid, grid.position);
        Lawn    lawn = GetLawnAtPosition(grid);

        lawn.ClearAtPosition(uv);
    }
Exemplo n.º 4
0
        public void Input_And_Output()
        {
            string input = @"5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM";

            string[] inputLines = input.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            IList <Mower> mowers = new List <Mower>();

            Lawn lawn = Lawn.Create(inputLines[0]);

            RemoteControl remoteControl = new RemoteControl();

            for (int i = 1; i < inputLines.Length - 1; i += 2)
            {
                Mower mower = new Mower(lawn.Border);
                mower.Deploy(inputLines[i]);

                remoteControl.ConnectMower(mower);
                remoteControl.Send(inputLines[i + 1]);

                mowers.Add(mower);
            }

            Assert.That(mowers.Count, Is.EqualTo(2));
            Assert.That(mowers[0].Status, Is.EqualTo("1 3 N"));
            Assert.That(mowers[1].Status, Is.EqualTo("5 1 E"));
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            var mowingMachine = new MowingMachine(TestTimer.Instance)
            {
                Orientation = "North",
                Position    = new Position()
                {
                    Length = 0,
                    Width  = 0
                }
            };

            services.AddSingleton(mowingMachine);

            var lawn = new Lawn()
            {
                Length = 5,
                Width  = 5
            };

            services.AddSingleton(lawn);

            var navigator = new Navigator(mowingMachine, lawn);

            navigator.StartNavigation();
            services.AddSingleton(navigator);

            var controllersAssembly = Assembly.Load(new AssemblyName("GardenGizmos.SLMM"));

            services.AddMvc()
            .AddApplicationPart(controllersAssembly)
            .AddControllersAsServices()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id, FirstName,LastName, Phone, StreetAddress,City,State,ZipCode,Size,Description,Photo")] Lawn lawn)
        {
            if (id != lawn.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //keep approved status on this lawn
                    lawn.Approved = true;
                    _context.Update(lawn);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LawnExists(lawn.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(lawn));
        }
Exemplo n.º 7
0
        public void Execute(MowingMachine mowingMachine, Lawn lawn)
        {
            var position = mowingMachine.NextPositionInDirection();

            if (lawn.PositionWithinBounds(position))
            {
                mowingMachine.MoveTo(position);
            }
        }
        public void FactoryMethodCreatesLawnWithWidthAndHeightMatchingSuppliedSizeString(string size,
                                                                                         int expectedWidth,
                                                                                         int expectedHeight)
        {
            var lawn = Lawn.CreateWith(size);

            Assert.That(lawn, Is.Not.Null);
            Assert.That(lawn.Width, Is.EqualTo(expectedWidth));
            Assert.That(lawn.Height, Is.EqualTo(expectedHeight));
        }
        private Models.LawnSection GetLawnSection(string lawnSectionId, Lawn lawn, bool throwIfNotFound = true)
        {
            var section = lawn.Sections.FirstOrDefault(s => s.Id == lawnSectionId);

            if (throwIfNotFound && section == null)
            {
                throw new LawnSectionNotFoundException(lawnSectionId);
            }

            return(section);
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Phone, StreetAddress,City,State,ZipCode,Size,Description,Approved,Photo")] Lawn lawn)
        {
            if (id != lawn.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(lawn);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LawnExists(lawn.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //if lawn is approved, then send a text and send user to create the first service entry, otherwise store it as denied and do nothing with it
                if (lawn.Approved == true)
                {
                    //text message for this method
                    ////////
                    SMSInformation twilio = new SMSInformation();

                    string accountSid = twilio.accountSID;
                    string authToken  = twilio.accountToken;

                    TwilioClient.Init(accountSid, authToken);

                    var message = MessageResource.Create(
                        body: $"Hi, {lawn.FirstName}, your lawn at {lawn.StreetAddress} has been approved, and it will be added to the queue for mowing.",
                        from: new Twilio.Types.PhoneNumber(twilio.twilioPhone),
                        to: new Twilio.Types.PhoneNumber(twilio.customerPhone));
                    /////////



                    return(RedirectToAction("Create", "Services", new { id = lawn.Id }));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(lawn));
        }
Exemplo n.º 11
0
        public void AreCoordinatesValid_CoordinatesParameter_ReturnsResult(ICoordinates coordinates, bool expectedResult)
        {
            // Arrange
            ILawn lawn = new Lawn(5, 5);

            // Act
            var result = lawn.AreCoordinatesValid(coordinates);

            // Assert
            Assert.Equal(expectedResult, result);
        }
Exemplo n.º 12
0
        public void When_Coordinates_Are_Five_By_Five_Then_Lawn_Is_Created_Five_By_Five()
        {
            int expectedX = 5;
            int expectedY = 5;

            Lawn actualLawn = Lawn.Create("5 5");

            Assert.IsNotNull(actualLawn);
            Assert.IsNotNull(actualLawn.Border);
            Assert.That(actualLawn.Border.X, Is.EqualTo(expectedX));
            Assert.That(actualLawn.Border.Y, Is.EqualTo(expectedY));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Get(string lawnId)
        {
            try {
                var lawn = await _lawnService.GetAsync(lawnId);

                var dto = new Lawn(lawn);
                return(Ok(dto));
            }
            catch (LawnNotFoundException)
            {
                return(NotFound());
            }
        }
Exemplo n.º 14
0
    public void FillAtPosition(Vector3 pos, WaterColor color)
    {
        LevelGrid grid = GetGridAtPosition(pos);

        if (grid.type == GridType.SOIL)
        {
            Vector2 uv   = GetUVAtPosition(grid, pos);
            Lawn    lawn = GetLawnAtPosition(grid);
            if (lawn != null)
            {
                lawn.FillAtPosition(uv, color);
            }
        }
    }
Exemplo n.º 15
0
        public IEnumerable <ILawnMower> CreateLawnMowers(InputData inputdata)
        {
            ILawn lawn = new Lawn(inputdata.LawnWidth, inputdata.LawnHeight);

            var mower = new List <ILawnMower>();

            foreach (var mowerData in inputdata.MowerData)
            {
                IPosition  position  = new Position(lawn, mowerData.StartCoordinates);
                ILawnMower lawnMower = new LawnMower(position, mowerData.Instructions);
                mower.Add(lawnMower);
            }

            return(mower);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Validate input and init Lawn
        /// </summary>
        /// <param name="input"></param>
        internal static void Init(string input)
        {
            int height;
            int width;

            var coords = input.AssertedSplitOnSpace(2);

            if (int.TryParse(coords[0], out height) && int.TryParse(coords[1], out width))
            {
                Lawn.Initialise(height, width);
            }
            else
            {
                throw new InvalidInputException(input);
            }
        }
Exemplo n.º 17
0
        public void ConfigureServices(IServiceCollection services)
        {
            var mowingMachine = new MowingMachine(new SleepTimer())
            {
                Position = new Position()
            };

            Configuration.GetSection("MowingMachine").Bind(mowingMachine);
            services.AddSingleton(mowingMachine);

            var lawn = new Lawn();

            Configuration.GetSection("Lawn").Bind(lawn);
            services.AddSingleton(lawn);

            var navigator = new Navigator(mowingMachine, lawn);

            navigator.StartNavigation();
            services.AddSingleton(navigator);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Exemplo n.º 18
0
        public void OnBeforeEachTest()
        {
            Lawn.Initialise(5, 5);

            _position = new Position(0, 0);
        }
Exemplo n.º 19
0
 public void Execute(MowingMachine mowingMachine, Lawn lawn)
 {
     mowingMachine.TurnAntiClockwise();
 }
Exemplo n.º 20
0
        public void RunFile(string FileName)
        {
            // Read each line of the file into a string array. Each element
            // of the array is one line of the file.
            string[] lines = System.IO.File.ReadAllLines(FileName);

            //Get the lawn's witdh and length
            Lawn lawn = new Lawn();

            lawn.length = (int)Char.GetNumericValue(lines[0][0]) + 1;//add one because coordinates of corners starts with (0,0)
            lawn.width  = (int)Char.GetNumericValue(lines[0][0]) + 1;
            for (int j = 1; j < lines.Length; j = j + 2)
            {
                Mower mower = new Mower();
                //Get the mower's initial position and orientation
                mower.x           = (int)Char.GetNumericValue(lines[j][0]);
                mower.y           = (int)Char.GetNumericValue(lines[j][2]);
                mower.orientation = lines[j][4];
                //Reading and interpreting the sequence of instruction
                foreach (char instruction in lines[j + 1])
                {
                    switch (instruction)
                    {
                    case 'F':                                                          //Moving forward while respecting the oriontation of the mower
                    {
                        if (mower.orientation.Equals('N') && mower.y < lawn.width - 1) //then we add 1 to y
                        {
                            mower.y = mower.y + 1;
                        }
                        if (mower.orientation.Equals('S') && mower.y > 0)
                        {
                            mower.y = mower.y - 1;
                        }
                        if (mower.orientation.Equals('E') && mower.x < lawn.length - 1)         //then we add 1 to x
                        {
                            mower.x = mower.x + 1;
                        }
                        if (mower.orientation.Equals('W') && mower.x > 0)
                        {
                            mower.x = mower.x - 1;
                        }
                    }
                    break;

                    case 'L':    //Rotate the mower to the left with 90°
                    {
                        switch (mower.orientation)
                        {
                        case 'N':
                            mower.orientation = 'W';
                            break;

                        case 'S':
                            mower.orientation = 'E';
                            break;

                        case 'E':
                            mower.orientation = 'N';
                            break;

                        case 'W':
                            mower.orientation = 'S';
                            break;
                        }
                    }
                    break;

                    case 'R':    //Rotate the mower to the right with 90°
                    {
                        switch (mower.orientation)
                        {
                        case 'N':
                            mower.orientation = 'E';
                            break;

                        case 'S':
                            mower.orientation = 'W';
                            break;

                        case 'E':
                            mower.orientation = 'S';
                            break;

                        case 'W':
                            mower.orientation = 'N';
                            break;
                        }
                    }
                    break;
                    }
                }
                Console.WriteLine("\n" + mower.x + " " + mower.y + " " + mower.orientation);
            }
            Console.WriteLine("\n" + "Press any button to continue...");
            Console.ReadKey();
        }
Exemplo n.º 21
0
 public Navigator(MowingMachine mowingMachine, Lawn lawn)
 {
     _mowingMachine = mowingMachine;
     _lawn          = lawn;
 }
Exemplo n.º 22
0
 public void OnSetup()
 {
     Lawn.Initialise(10, 10);
 }
Exemplo n.º 23
0
        MaxHeights GetMaxHeightPerRow(Lawn lawn)
        {
            MaxHeights maxHeights = new MaxHeights(lawn.Width, lawn.Height);

            //rows
            for (int i = 0; i < lawn.Height; i++)
            {
                int maxH = 0;
                for (int j = 0; j < lawn.Width; j++)
                {
                    if (lawn.Layout[i][j] > maxH)
                    {
                        maxH = lawn.Layout[i][j];
                    }
                }

                maxHeights.Row[i] = maxH;
            }

            // col
            for (int i = 0; i < lawn.Width; i++)
            {
                int maxH = 0;

                for (int j = 0; j < lawn.Height; j++)
                {
                    if (lawn.Layout[j][i] > maxH)
                    {
                        maxH = lawn.Layout[j][i];
                    }
                }

                maxHeights.Column[i] = maxH;
            }

            return maxHeights;
        }
Exemplo n.º 24
0
        List<Lawn> GetLawns(List<string> data)
        {
            int count = int.Parse(data[0]);
            var lawns = new List<Lawn>(count);

            for (int i = 1; i < data.Count; i++)
            {
                if (count-- <= 0)
                {
                    break;
                }
                var dim = data[i].Split(' ');
                int height = Int32.Parse(dim[0]);
                int width = Int32.Parse(dim[1]);

                var lawn = new Lawn(width, height);

                for (int j = 0; j < height; j++)
                {
                    var line = data[i + j + 1].Split(' ');
                    for (int k = 0; k < line.Length; k++)
                    {
                        lawn.Layout[j][k] = Int32.Parse(line[k]);
                    }
                }

                lawns.Add(lawn);
                i += lawn.Height;
            }

            return lawns;
        }
 public void FactoryMethodThrowsArgumentExceptionIfSizeStringInvalid(string invalidSize)
 {
     Assert.Throws <ArgumentException>(() => Lawn.CreateWith(invalidSize));
 }