static void OpenGoogleMap(Place place)
 {
     UIApplication.SharedApplication
         .OpenUrl (new NSUrl (string.Format("https://maps.google.com/?q={0},{1}",
                                            place.Latitude,
                                            place.Longitude)));
 }
 public PlaceInfoViewController(Place place)
 {
     this.Title = "Place Info";
     Place = place;
     ActiveCheckInList = new List<CheckInUserPair> ();
     RecentCheckInList = new List<CheckInUserPair> ();
 }
        public void RunTests()
        {
            using (JsonServiceClient client = new JsonServiceClient(SystemConstants.WebServiceBaseURL))
            {
                var users = new string[] { "checkInUser1", "checkInUser2", "checkInUser3", "checkInUser4", "checkInUser5"};
                var places = new Place[] {
                    new Place { Name = "Home", Address="555 street"},
                    new Place { Name = "Home", Address="999 street"},
                    new Place { Name = "Work", Address="123 street"},
                    new Place { Name = "Bar", Address="456 street"},
                    new Place { Name = "Giant Eagle", Address="456 street"},
                };
                AddUsers(client, users);

                try
                {
                    CheckInUser(client, users[0], places[0]);
                    places[0].Id = GetCheckInLastPlace(client, places[0]);

                    CheckInUser(client, users[0], places[2]);
                    places[2].Id = GetCheckInLastPlace(client, places[2]);

                    CheckInUser(client, users[0], places[1]);
                    places[1].Id = GetCheckInLastPlace(client, places[1]);

                    CheckInUser(client, users[0], places[0]);
                    places[0].Id = GetCheckInLastPlace(client, places[0]);

                    CheckInUser(client, users[0], places[0]);
                    places[0].Id = GetCheckInLastPlace(client, places[0]);

                    CheckInUser(client, users[1], places[4]);
                    places[4].Id = GetCheckInLastPlace(client, places[4]);

                    CheckInUser(client, users[2], places[2]);
                    places[2].Id = GetCheckInLastPlace(client, places[2]);

                    CheckInUser(client, users[3], places[3]);
                    places[3].Id = GetCheckInLastPlace(client, places[3]);

                    CheckInUser(client, users[3], places[0]);
                    places[0].Id = GetCheckInLastPlace(client, places[0]);

                    places.Select(p => { GetCheckInsForPlace(client, p, true); return 1; }).ToArray();

                    GetRecentPlaceList(client);
                    GetPopularPlaceList(client);
                }
                finally
                {
                    DeleteUsers(client, users);
                }
            }
        }
        public override void CheckInUserAtPlace(Place place)
        {
            User currentUser = Engine.Instance.UserAccess.GetCurrentUser ();
            if (currentUser.IsAnonymousUser)
                return;

            lock (_clientWrapper.ClientLock)
            {
                var request = new CheckInRequest { Place = place };
                _clientWrapper.Client.Put<CheckInRequestResponse>("CheckIns", request);
            }
        }
        static void OpenIOSMap(Place place)
        {
            double latitude = place.Latitude;
            double longitude = place.Longitude;
            CLLocationCoordinate2D center = new CLLocationCoordinate2D (latitude, longitude);

            MKPlacemark placemark = new MKPlacemark (center, null);
            MKMapItem mapItem = new MKMapItem (placemark);
            mapItem.Name = place.Name;
            MKLaunchOptions options = new MKLaunchOptions ();
            options.MapSpan = MKCoordinateRegion.FromDistance (center, 200, 200).Span;
            mapItem.OpenInMaps (options);
        }
        void CheckInUser(JsonServiceClient client, string userName, Place place)
        {
            LoginUser(client, userName);

            try
            {
                var request = new CheckInRequest { Place = place };
                client.Put<CheckInRequestResponse>("CheckIns", request);
                System.Threading.Thread.Sleep(1000);
            }
            finally
            {
                LogoutUser(client);
            }
        }
Exemplo n.º 7
0
        public Place AddIfNew(Place newPlace)
        {
            Place returnPlace = _list.Find (p => p.Name == newPlace.Name && p.Address == newPlace.Address);

            if (returnPlace != null)
                return returnPlace;

            if (_list.Count > 0)
                newPlace.Id = _list[_list.Count-1].Id + 1;
            else
                newPlace.Id = 1;

            _list.Add (newPlace);
            return newPlace;
        }
        public static void OpenInMaps(Place place )
        {
            bool canDoIOS6Maps = false;

            using (NSString curVer = new NSString (UIDevice.CurrentDevice.SystemVersion))
            {
                using (NSString targetVar = new NSString ("6.0"))
                {
                    canDoIOS6Maps = curVer.Compare (
                        targetVar, NSStringCompareOptions.NumericSearch) != NSComparisonResult.Ascending;

                }
            }

            if (canDoIOS6Maps)
                OpenIOSMap (place);
            else
                OpenGoogleMap (place);
        }
        public override void GetCheckinInfo(Place place, out System.Collections.Generic.List<CheckInUserPair> activeList, out System.Collections.Generic.List<CheckInUserPair> recentList, int recentLimit)
        {
            CheckInRequestResponse response;

            lock (_clientWrapper.ClientLock)
            {
                response = _clientWrapper.Client.Get<CheckInRequestResponse>(
                    string.Format("CheckIns/?PlaceId={0}&RecentLimit={1}", place.Id, recentLimit));
            }

            if (response.ActivePairList != null)
                activeList = response.ActivePairList;
            else
                activeList = new System.Collections.Generic.List<CheckInUserPair> ();
            if (response.RecentPairList != null)
                recentList = response.RecentPairList;
            else
                recentList = new System.Collections.Generic.List<CheckInUserPair> ();
        }
        private void GetCheckInsForPlace(JsonServiceClient client, Place place, bool dump)
        {
            var result = client.Get<CheckInRequestResponse>(string.Format("CheckIns/?PlaceId={0}", place.Id));

            if (!dump)
                return;
            Console.WriteLine("Active Users for palce '{0}' at {1}", place.Name, place.Address);
            foreach (CheckInUserPair pair in result.ActivePairList)
            {
                Console.WriteLine("     '{0}'", pair.User.UserName);
            }
            Console.WriteLine("\n");

            Console.WriteLine("Recent Users for palce '{0}' at {1}", place.Name, place.Address);
            foreach (CheckInUserPair pair in result.RecentPairList)
            {
                Console.WriteLine("     '{0}'", pair.User.UserName);
            }

            Console.WriteLine("\n");
        }
        private int GetCheckInLastPlace(JsonServiceClient client, Place shoudBe)
        {
            var response = client.Get<PlacesRequestResponse>(string.Format("Places/?Method=Recent&Limit=1"));

            if (response != null && response.Places != null && response.Places.Count() == 1)
            {
                Console.WriteLine("{0} should be {1} at {2}", response.Places[0].Id, shoudBe.Name, shoudBe.Address);
                return response.Places[0].Id;
            }
            throw new Exception("Did not get the Id back");
        }
        public void CheckInUserAtPlace(string username, Place place)
        {
            SetupAndCall((dbCmd) =>
            {
                SqlExpressionVisitor<Place> evPlace = OrmLiteConfig.DialectProvider.ExpressionVisitor<Place>();
                SqlExpressionVisitor<User> evUser = OrmLiteConfig.DialectProvider.ExpressionVisitor<User>();
                SqlExpressionVisitor<CheckIn> evCheckIn = OrmLiteConfig.DialectProvider.ExpressionVisitor<CheckIn>();

                // Find the user Id
                int userId;
                evUser.Where(u => u.UserName == username).Select(u => u.Id);
                var userResult = dbCmd.Select(evUser);

                if (userResult.Count == 0)
                    throw new ArgumentException(string.Format("username : '******' does not exist", username));
                userId = userResult[0].Id;

                //// Get the last checkin for the user
                evCheckIn.Where(c => c.UserId == userId).OrderByDescending(c => c.Time).Limit(1);
                var lastCheckIn = dbCmd.Select(evCheckIn);

                if (lastCheckIn.Count != 0)
                {
                    DateTime refTime = DateTime.UtcNow - new TimeSpan
                    (0, SystemConstants.RecentThresholdHours, 0, 0, 0);

                    // If it has been a while allow the checkin
                    if (refTime < lastCheckIn.First().Time)
                    {
                        //// Find the palce for that place id
                        evPlace.Where(p => p.Id == lastCheckIn.First().PlaceId).Limit(1);
                        var existingPlaceResult = dbCmd.Select(evPlace);

                        // if it is the same place just update the time
                        if (existingPlaceResult.First().Name == place.Name &&
                            existingPlaceResult.First().Address == place.Address)
                        {
                            evCheckIn.Where(c => c.Id == lastCheckIn.First().Id).Update(c => c.Time);
                            dbCmd.UpdateOnly(new CheckIn { Time = DateTime.UtcNow }, evCheckIn);
                            return;
                        }
                    }
                }

                // Add place to table if it does not exist
                // compared my name and address
                int placeId;
                evPlace = OrmLiteConfig.DialectProvider.ExpressionVisitor<Place>();
                evPlace.Where(p => p.Name == place.Name && p.Address == place.Address)
                    .Select(p => p.Id);

                var placeResult = dbCmd.Select(evPlace);

                if (placeResult.Count == 0)
                {
                    dbCmd.Insert(place);
                    placeId = (int)dbCmd.GetLastInsertId();
                }
                else
                    placeId = placeResult[0].Id;

                // Check in the user
                CheckIn checkIn = new CheckIn { UserId = userId, PlaceId = placeId, Time = DateTime.UtcNow };
                dbCmd.Insert(checkIn);
            });
        }
        // Used when viewing checkins at a place
        // There is a limit to the recent list
        //
        // activeList lists users how have checked in in the last 'RecentThresholdHours' hours
        // AND that have not checked in elsewhere since
        //
        // recentList lists last 'recentLimit' users that have checked into
        // a place and that are not in the activeList
        public abstract void GetCheckinInfo(Place place, out List<CheckInUserPair> activeList,
		                            out List<CheckInUserPair> recentList, int recentLimit);
 public abstract void CheckInUserAtPlace(Place place);
Exemplo n.º 15
0
 public void Delete(Place palceToDelete)
 {
     _list.Remove (_list.Find (e=> e.Id == palceToDelete.Id));
 }
Exemplo n.º 16
0
 public DistanceSortHelper(Place place, float lat, float lng)
 {
     Place = place;
     Distance = place.DistanceFrom (lat, lng);
 }