Esempio n. 1
0
 public Board()
 {
     _gameFinished = false;
     _pause        = false;
     _snake        = new Snake(PointFactory.Create(10, 10));
     _view         = new View.View();
 }
Esempio n. 2
0
        protected override void OnExecute()
        {
            var client = new Client {
                Name = Name, Email = Email, Brag = Brag, IsVerified = false, LastActiveDate = DateTime.Now
            };

            client.SetPassword(Password);

            client.Location = PointFactory.Create(Latitude, Longitude);

            client.EmailVerification = new EmailVerification {
                VerificationCode = GenerateVerificationCode(), Client = client
            };

            OnCreate(client);
            OnCreate(client.EmailVerification);

            client.ClientSettings = new ClientSettings {
                AdCount = 0, Source = Source, Client = client
            };
            OnCreate(client.ClientSettings);

            Session.Save(client);
            Session.Save(client.ClientSettings);
            Session.Save(client.EmailVerification);

            EmailVerificationCode = client.EmailVerification.VerificationCode;
        }
Esempio n. 3
0
        public void Search_Without_Location()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var services             = GetSampleServices();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <IQuery <IEnumerable <Service> > >()))
            .Returns(services);

            var categories = GetSampleCategories();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, IList <Category> > >()))
            .Returns(categories);

            var fileSystemMock        = new Mock <IFileSystem>();
            var geoCodingServicemMock = new Mock <IGeoCodingService>();

            var userLocation = PointFactory.Create(6.9319444, 79.8877778);
            var controller   = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Search", UserName));
            controller.SetUserInfoWitLocation(userLocation);

            var model = new SearchModel {
                Terms = "Foo"
            };

            controller.Search(model);

            Assert.AreEqual(model, controller.ViewData.Model);
            Assert.AreEqual(userLocation, controller.ViewData[ViewDataKeys.UserLocation]);
        }
        protected override void OnExecute()
        {
            var client = Session.QueryOver <Client>()
                         .Where(c => c.Id == ClientId)
                         .Fetch(c => c.ClientSettings).Eager.FutureValue();

            var category = new Category {
                Id = CategoryId
            };

            var service = IsServiceOffering ? (Service) new ServiceOffering() : new ServiceRequest();

            service.Title         = Title;
            service.Body          = Body;
            service.Client        = client.Value;
            service.Category      = category;
            service.EffectiveDate = EffectiveDate ?? DateTime.Now;
            service.Location      = PointFactory.Create(Latitude, Longitude);

            service.ExpiryDate = DateTime.Now.Date.AddDays(90);

            ProcessImange(service);
            OnCreate(service);

            Session.Save(service);

            client.Value.ClientSettings.AdCount++;

            Session.CreateSQLQuery("update Category set AdCount = AdCount + 1 where Id=:id")
            .SetInt32("id", CategoryId)
            .ExecuteUpdate();
        }
Esempio n. 5
0
        public void Create_Point_Assigns_Correctly()
        {
            const double lat = 9.344d;
            const double lng = 10.654d;

            var point = PointFactory.Create(lat, lng);

            Assert.AreEqual(lat, point.Y);
            Assert.AreEqual(lng, point.X);
            Assert.AreEqual(PointFactory.WorldGeodeticSystemSrid, point.SRID);
        }
Esempio n. 6
0
 protected virtual Point GetUserLocation()
 {
     if (Session[SessionKeys.User] != null)
     {
         return(((UserInfo)Session[SessionKeys.User]).Location);
     }
     else
     {
         return(PointFactory.Create(6.9319444, 79.8877778));
     }
 }
        public JsonResult ServicesNearLocation(double lat, double lng)
        {
            var userLocation = PointFactory.Create(lat, lng);

            var services = ExecuteQuery(
                session => session.QueryOver <Service>()
                .Where(s => s.EffectiveDate < DateTime.Now)
                .WhereSpatialRestrictionOn(s => s.Location).IsWithinDistance(userLocation, Distance)
                .Fetch(s => s.Category).Eager
                .List());

            LogImpressions(services);

            return(Json(Mapper.Map <IEnumerable <ServiceSerializeInfo> >(services)));
        }
        public ActionResult UpdateLocation(double lat, double lng)
        {
            if (Session[SessionKeys.User] != null)
            {
                var userInfo = (UserInfo)Session[SessionKeys.User];
                userInfo.Location = PointFactory.Create(lat, lng);
            }
            else
            {
                var userInfo = new UserInfo {
                    IsAdmin = false, IsAuthenticated = false, Location = PointFactory.Create(lat, lng)
                };
                Session[SessionKeys.User] = userInfo;
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Esempio n. 9
0
        public Point GetCoordinates(string location)
        {
            var response = SendGetRequest(SanitizeLocation(location));

            var xmlDoc = XDocument.Load(response.GetResponseStream());
            var status = xmlDoc.Elements("GeocodeResponse").Elements().Single(e => e.Name == "status").Value;

            if (status == "OK")
            {
                var locationElement = xmlDoc.Descendants().First(e => e.Name == "location");
                var lat             = locationElement.Elements().Single(e => e.Name == "lat").Value;
                var lng             = locationElement.Elements().Single(e => e.Name == "lng").Value;

                return(PointFactory.Create(double.Parse(lat), double.Parse(lng)));
            }

            return(null);
        }
Esempio n. 10
0
        //Does actions when the timer has passed a certain tick-timer.
        //Switches snake direction, checks collision, and updates snake
        //and GUI according to what happens.
        private void Tick()
        {
            var newHead        = PointFactory.Create(_snake.Last());
            var tailToClear    = PointFactory.Create(_snake.First());
            var snakeDirection = _snake.GetDirection();

            switch (snakeDirection)
            {
            case Directions.Up:
                newHead.Y -= 1;
                break;

            case Directions.Right:
                newHead.X += 1;
                break;

            case Directions.Down:
                newHead.Y += 1;
                break;

            case Directions.Left:
                newHead.X -= 1;
                break;
            }

            CheckCollision(newHead);

            //clears tail
            _snake.RemoveAt(0);
            _view.UpdatePoint(tailToClear);

            //prints tail
            foreach (Point part in _snake)
            {
                _view.UpdatePoint(part, "Tail");
            }

            //prints new head
            _snake.Add(newHead);
            _view.UpdatePoint(_snake.Last(), "Head");
        }
Esempio n. 11
0
        //Spawns an apple on the board and displays it
        private void SpawnApple()
        {
            var random       = new Random();
            var appleOnSnake = false;

            while (!appleOnSnake)
            {
                appleOnSnake = true;
                int x = random.Next(_view.GetWidth());
                int y = random.Next(_view.GetHeight());
                _apple = PointFactory.Create(x, y);

                foreach (var p in _snake)
                {
                    if (p == _apple)
                    {
                        appleOnSnake = false;
                    }
                }
            }
        }
Esempio n. 12
0
 public static void SetUserInfoWitLocation(this Controller controller)
 {
     SetUserInfoWitLocation(controller, PointFactory.Create(6.9319444, 79.8877778));
 }