示例#1
0
        public async Task <IHttpActionResult> SaveAsLastVisited(SaveAsLastVisitedBindingModel model)
        {
            var result = new SaveAsLastVisitedViewModel();

            var visiteds = await _lastVisitedAccess.LoadAsync(UserName);

            if (visiteds != null)
            {
                var splitted = visiteds.Visited.Split('|').ToList();

                if (splitted.Contains(model.Url))
                {
                    splitted.Remove(model.Url);
                }

                var final = new List <string> {
                    model.Url
                };
                final.AddRange(splitted);
                visiteds.Visited = string.Join("|", final.Take(5));
            }
            else
            {
                visiteds = new LastVisited()
                {
                    UserName = UserName, Visited = model.Url
                };
            }

            await _lastVisitedAccess.SaveOrUpdateAsync(visiteds);

            result.Result = true;

            return(Ok(result));
        }
示例#2
0
        public ActionResult LastVisiteds()
        {
            var lastVisited = new LastVisited();
            var urls        = _lastVisitedAccess.Load(UserName);

            if (urls != null)
            {
                var sb = new StringBuilder();
                sb.Append("[");
                foreach (var url in urls.Visited.Split('|'))
                {
                    sb.AppendFormat("'{0}',", url);
                }

                if (sb.Length > 0)
                {
                    sb.Remove(sb.Length - 1, 1);
                }
                sb.Append("]");

                lastVisited.Urls = sb.ToString();
            }
            else
            {
                lastVisited.Urls = string.Empty;
            }

            return(View(lastVisited));
        }
示例#3
0
        public async void lastvisited_insert_and_delete()
        {
            var context           = new JobTimerDbContext();
            var lastVisitedAccess = new LastVisitedAccess(context);

            var lastVisited = new LastVisited();

            lastVisited.UserName = _fixture.Create <string>();
            lastVisited.Visited  = _fixture.Create <string>();

            await lastVisitedAccess.SaveAsync(lastVisited);

            lastVisited.ID.Should().NotBe(0);

            var loaded = await lastVisitedAccess.LoadAsync(lastVisited.ID);

            loaded.UserName.Should().Be(lastVisited.UserName);
            loaded.Visited.Should().Be(lastVisited.Visited);

            var deletedCount = await lastVisitedAccess.DeleteAsync(loaded);

            deletedCount.Should().BeGreaterOrEqualTo(1);
        }
示例#4
0
        private void FindNext(Block block, bool New, Vector3 Goal, int RougCounter = 0)
        {
            block.visited = true;

            List <Block> Neighbours         = GetNeighbours(block);
            float        BestNeighbour      = -1;
            Block        BestNeighbourBlock = null;

            foreach (Block neighbours in Neighbours)
            {
                float distance = ManhattanDistance(neighbours.BasePosition, Goal, block.BasePosition) + neighbours.Weight;
                if (distance < BestNeighbour || BestNeighbour == -1)
                {
                    BestNeighbour      = distance;
                    BestNeighbourBlock = neighbours;
                }
            }

            if (New)
            {
                Block OldNeighbour = GetNeighbours(block, true).FirstOrDefault();
                if (OldNeighbour != null)
                {
                    OpenWall(block, OldNeighbour);
                }
            }

            if (random.Next(0, 6) == 5 && Goal == RealGoal)
            {
                RougCounter = 10;
                Goal        = new Vector3(random.Next(0, int.Parse(FoundationSize.ToString())), random.Next(0, int.Parse(BuldingHeight.ToString())), random.Next(0, int.Parse(FoundationSize.ToString())));
            }

            if (Goal != RealGoal)
            {
                if (!block.IsTheEnd(Goal))
                {
                    if (BestNeighbourBlock != null)
                    {
                        OpenWall(block, BestNeighbourBlock);
                        RougCounter--;

                        FindNext(BestNeighbourBlock, false, Goal, RougCounter);
                    }
                }
            }
            else
            {
                if (!block.IsTheEnd(Goal))
                {
                    if (BestNeighbourBlock != null)
                    {
                        LastVisited.Add(block);
                        OpenWall(block, BestNeighbourBlock);
                        FindNext(BestNeighbourBlock, false, RealGoal);
                    }
                    else
                    {
                        Block lastItem = LastVisited.LastOrDefault();
                        if (lastItem != null)
                        {
                            Vector3 goal = Goal == RealGoal ? RealGoal : Goal;
                            LastVisited.Remove(lastItem);
                            FindNext(lastItem, false, goal);
                        }
                    }
                }
            }
        }