コード例 #1
0
ファイル: CleanJob.cs プロジェクト: itabas016/ebandbox
        public void Execute(JobExecutionContext context)
        {
            CleanService service = new CleanService();

            var days = ConfigKeys.CLEANUP_NEWS_CONTENT_DAYS_AGO_VALUE.ConfigValue().ToInt32();

            service.CleanNewsContent(days);
            service.CleanAccountInvitationCode();
        }
コード例 #2
0
ファイル: CleanController.cs プロジェクト: laiqm/Learn
        public IActionResult Create(CleanArg arg)
        {
            var admin = _context.Account.SingleOrDefault(x => x.Id == 1);

            var task = CleanService.CreateTask(_http, admin, _context);

            Hangfire.BackgroundJob.Schedule <CleanService>(x => x.Clean(task.Id, arg), TimeSpan.FromSeconds(10));

            return(RedirectToAction("Check", new { task.Id }));
        }
コード例 #3
0
        public void TurnRight_ForAllFacings_TurnTheRobotToRight(FacingEnum facing, FacingEnum expectedFacing)
        {
            _order1.CurrentState = new StateOfRobot {
                Cell = new Cell {
                    Point = new Point(1, 1), State = CellStateEnum.StateS
                }, Faceing = facing
            };
            _order1.Commands = new List <CommandEnum> {
                CommandEnum.TR
            };

            var cleanService = new CleanService(_order1);

            var result = cleanService.Start();

            Assert.That(expectedFacing, Is.EqualTo(result.FinalState.Faceing));
        }
コード例 #4
0
        public void HasEnoughBatteryCappacity_ForAllCommands(CommandEnum command, int battery, bool expectedResult)
        {
            _order1.CurrentState = new StateOfRobot {
                Cell = new Cell {
                    Point = new Point(1, 1), State = CellStateEnum.StateS
                }, Faceing = FacingEnum.East
            };
            _order1.Commands = new List <CommandEnum> {
                command
            };
            _order1.Battery = battery;

            var cleanService = new CleanService(_order1);

            var result = cleanService.HasEnoughBatteryCappacity(command);

            Assert.That(expectedResult, Is.EqualTo(result));
        }
コード例 #5
0
        public void Advance_EverythingNormalForForward_RobotShouldGoNextPoint(int x, int y, FacingEnum facing, int expectedX, int expectedY)
        {
            _order1.CurrentState = new StateOfRobot {
                Cell = new Cell {
                    Point = new Point(x, y), State = CellStateEnum.StateS
                }, Faceing = facing
            };
            _order1.Commands = new List <CommandEnum> {
                CommandEnum.A
            };

            var cleanService = new CleanService(_order1);

            var result = cleanService.Start();

            Assert.That(expectedX, Is.EqualTo(result.FinalState.Cell.Point.X));
            Assert.That(expectedY, Is.EqualTo(result.FinalState.Cell.Point.Y));
            Assert.That(_order1.Battery, Is.EqualTo(78));
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString(), args[0]);

            using (StreamReader r = new StreamReader(path))
            {
                string  json          = r.ReadToEnd();
                dynamic array         = JsonConvert.DeserializeObject(json);
                var     orderFromJson = JsonConvert.DeserializeObject <OrderFromJson>(json);
                var     order         = orderFromJson.ConvertToOrder();

                CleanService cleanService = new CleanService(order);

                var result = cleanService.Start();

                var resultToJson = new ResultToJson
                {
                    Battery = result.Battery,
                    Cleaned = result.CleanedCells.Select(x => x.Point).ToList(),
                    Visited = result.VisitedCells.Select(x => x.Point).ToList(),
                    Final   = new Start
                    {
                        Facing = Enum.GetName(typeof(FacingEnum), result.FinalState.Faceing).Substring(0, 1),
                        X      = result.FinalState.Cell.Point.X,
                        Y      = result.FinalState.Cell.Point.Y
                    }
                };

                var resultJson = JsonConvert.SerializeObject(resultToJson, new PointJsonConverter());

                var resultPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString(), args[1]);

                File.WriteAllText(resultPath, JToken.Parse(resultJson).ToString(Formatting.Indented));

                Console.WriteLine("Done");
            }
        }
コード例 #7
0
        public void Start_Order1_ShouldReturnExpectedResult()
        {
            _order1.Commands = new List <CommandEnum> {
                CommandEnum.TL,
                CommandEnum.A,
                CommandEnum.C,
                CommandEnum.A,
                CommandEnum.C,
                CommandEnum.TR,
                CommandEnum.A,
                CommandEnum.C
            };
            _order1.CurrentState = new StateOfRobot
            {
                Faceing = FacingEnum.North,
                Cell    = new Cell {
                    Point = new Point(3, 0)
                }
            };
            var expectedVisitedCells = new List <Cell>
            {
                new Cell
                {
                    Point     = new Point(3, 0),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(2, 0),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(1, 0),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                }
            };
            var expectedCleanedCells = new List <Cell>
            {
                new Cell
                {
                    Point     = new Point(2, 0),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(1, 0),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                }
            };

            var cleanService = new CleanService(_order1);

            var result = cleanService.Start();

            Assert.That(54, Is.EqualTo(result.Battery));
            Assert.That(3, Is.EqualTo(result.VisitedCells.Count));
            CollectionAssert.AreEqual(expectedVisitedCells, result.VisitedCells);
            Assert.That(2, Is.EqualTo(result.CleanedCells.Count));
            CollectionAssert.AreEqual(expectedCleanedCells, result.CleanedCells);
            Assert.That(FacingEnum.East, Is.EqualTo(result.FinalState.Faceing));
        }
コード例 #8
0
        public void Start_Order2_ShouldReturnExpectedResult()
        {
            _order1.Commands = new List <CommandEnum> {
                CommandEnum.TR,
                CommandEnum.A,
                CommandEnum.C,
                CommandEnum.A,
                CommandEnum.C,
                CommandEnum.TR,
                CommandEnum.A,
                CommandEnum.C
            };
            _order1.CurrentState = new StateOfRobot
            {
                Faceing = FacingEnum.South,
                Cell    = new Cell {
                    Point = new Point(3, 1)
                }
            };

            _order1.Battery = 1094;

            var expectedVisitedCells = new List <Cell>
            {
                new Cell
                {
                    Point     = new Point(3, 2),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(3, 1),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(3, 0),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(2, 2),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                }
            };
            var expectedCleanedCells = new List <Cell>
            {
                new Cell
                {
                    Point     = new Point(3, 2),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(3, 0),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                },
                new Cell
                {
                    Point     = new Point(2, 2),
                    State     = CellStateEnum.StateS,
                    IsVisited = false
                }
            };

            var cleanService = new CleanService(_order1);

            var result = cleanService.Start();

            expectedVisitedCells = expectedVisitedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList();
            result.VisitedCells  = result.VisitedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList();

            expectedCleanedCells = expectedCleanedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList();
            result.CleanedCells  = result.CleanedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList();

            Assert.That(1040, Is.EqualTo(result.Battery));
            Assert.That(4, Is.EqualTo(result.VisitedCells.Count));
            CollectionAssert.AreEqual(expectedVisitedCells, result.VisitedCells);
            Assert.That(3, Is.EqualTo(result.CleanedCells.Count));
            CollectionAssert.AreEqual(expectedCleanedCells, result.CleanedCells);
            Assert.That(FacingEnum.East, Is.EqualTo(result.FinalState.Faceing));
        }