Example #1
0
        public int setNewVenueAndCheckinList(List <Item2> itemList, DateTime dt)
        {
            int newVenueNumber = 0;

            foreach (Item2 item in itemList)
            {
                if (!Venues.Any(venue => venue.Id == item.venue.id))
                {
                    Venues.Add(new Venue
                    {
                        Id         = item.venue.id,
                        Address    = item.venue.location.address,
                        Lat        = item.venue.location.lat,
                        Lng        = item.venue.location.lng,
                        CategoryId = item.venue.categories.FirstOrDefault().id,
                        Name       = item.venue.name
                    });
                    newVenueNumber++;
                }

                Checkins.Add(new CheckinStatistic
                {
                    Venue_FK      = item.venue.id,
                    DateTime      = dt,
                    CheckinNumber = item.venue.stats.checkinsCount,
                    UserNumber    = item.venue.stats.usersCount
                }
                             );
            }
            return(newVenueNumber);
        }
Example #2
0
        public static List <Checkin> GetCheckins(Checkins checkinsWeb)
        {
            List <Checkin> checkins = new List <Checkin>();

            foreach (CheckinsItem checkinsItem in checkinsWeb.Items)
            {
                checkins.Add(GetCheckin(checkinsItem));
            }

            return(checkins);
        }
Example #3
0
        public void GetCheckins_Should_Return_Zero_When_1_Checkin_Already_Exists()
        {
            // SETUP
            var participantCheckinDate = new DateTime(2018, 10, 27, 16, 30, 00);
            var participantCheckin     = new Checkin(Email.Of("*****@*****.**"), participantCheckinDate);
            var checkinProvider        = new CheckinProvider(participantCheckin);

            // RUN
            Checkins countLateCheckin = checkinProvider.GetCheckins();

            // ASSERT
            Check.That(countLateCheckin.CountCheckins()).IsEqualTo(1);
        }
Example #4
0
        public void CountColdMeals_Should_Return_Zero_Cold_Meal_When_Zero_Participant()
        {
            // SETUP
            var checkinProvider = Substitute.For <ICheckinProvider>();

            checkinProvider.GetCheckins().Returns(Checkins.FromList(new List <Checkin>()));

            // RUN
            var coldMealsCounter = new ColdMealsCounter(checkinProvider);
            var coldMealsNumber  = coldMealsCounter.CountColdMeals();

            // ASSERT
            Check.That(coldMealsNumber).IsEqualTo(0);
        }
Example #5
0
        public void CountColdMeals_Should_Return_Zero_Cold_Meals_When_Participants_Checkin_Before_21h()
        {
            // SETUP
            var checkins = new List <Checkin>();
            var firstParticipantCheckin  = new Checkin(Email.Of("*****@*****.**"), new DateTime(2018, 10, 27, 20, 59, 59));
            var secondParticipantCheckin = new Checkin(Email.Of("*****@*****.**"), new DateTime(2018, 10, 27, 17, 13, 00));

            checkins.Add(firstParticipantCheckin);
            checkins.Add(secondParticipantCheckin);

            var checkinProvider = Substitute.For <ICheckinProvider>();

            checkinProvider.GetCheckins().Returns(Checkins.FromList(checkins));

            // RUN
            var coldMealsCounter = new ColdMealsCounter(checkinProvider);
            var coldMealsNumber  = coldMealsCounter.CountColdMeals();

            // ASSERT
            Check.That(coldMealsNumber).IsEqualTo(0);
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            LocationAssistant.Instance.WalkingPositionChanged += OnWalkingPositionChanged;

            _map = new Map();
            _map.ScaleVisibility     = System.Windows.Visibility.Visible;
            _map.CopyrightVisibility = System.Windows.Visibility.Collapsed;
            LayoutRoot.Children.Add(_map);

            _map.MapZoom     += _map_MapZoom;
            _map.MapResolved += _map_MapResolved;
            _map.MapPan      += _map_MapPan;

            IAppInfo iai = Application.Current as IAppInfo;

            if (iai != null)
            {
                _map.CredentialsProvider = new ApplicationIdCredentialsProvider(iai.BKey);
            }

            if (_layer != null && _map.Children.Contains(_layer))
            {
                _map.Children.Remove(_layer);
                _layer = null;
            }

            _layer = new MapLayer();
            _map.Children.Add(_layer);

            var loc = LocationAssistant.Instance.LastKnownLocation.AsGeoCoordinate();

            _map.SetView(loc, 14);

            if (_gpsPushpin == null)
            {
                _gpsPushpin          = new Pushpin();
                _gpsPushpin.Location = LocationAssistant.Instance.LastKnownLocation.AsGeoCoordinate();
                var cs = LayoutRoot.Resources["MePushpinStyle"] as Style;
                _gpsPushpin.Style = cs;
                _layer.Children.Add(_gpsPushpin);
            }

            if (Environment.OSVersion.Version.Minor >= 1)
            {
                // mango hack
                var st      = typeof(SystemTray);
                var opacity = st.GetProperty("Opacity");
                if (opacity != null)
                {
                    opacity.SetValue(null, 0.65, null);

                    SystemTray.IsVisible = true;
                }
            }

            //SetupAppBar();

            if (_checkins != null)
            {
                Update(_checkins);
            }
            else
            {
                _checkins = DataManager.Current.Load <Checkins>("Checkins", OnCompleted, OnError);
            }
        }
        private void Update(Checkins checkins)
        {
            if (_map != null && _map.BoundingRectangle != null)
            {
                if (_map.BoundingRectangle.Width < .0001)
                {
                    // hasn't actually loaded yet.
                    IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(.25),
                                                   () => Update(checkins));
                    return;
                }
            }
            else
            {
                // should never happen for real.
                return;
            }

            // 3 hours ago.
            DateTime threeHoursAgo = DateTime.Now - TimeSpan.FromHours(3);

            List <Checkin> nearby = new List <Checkin>();

            foreach (var x in checkins.Groups)
            {
                foreach (Checkin c in x)
                {
                    if (IsNearby(c) && c.CreatedDateTime >= threeHoursAgo)
                    {
                        nearby.Add(c);
                    }
                }
            }

            // Group by Dictionary<VenueId, List<...>>
            // Store venues as well in Dictionary<VenueId, Venue>
            Dictionary <string, List <Checkin> > groupedByVenue = new Dictionary <string, List <Checkin> >();
            Dictionary <string, CompactVenue>    venues         = new Dictionary <string, CompactVenue>();

            foreach (var entry in nearby)
            {
                if (!venues.ContainsKey(entry.Venue.VenueId))
                {
                    venues[entry.Venue.VenueId]         = entry.Venue;
                    groupedByVenue[entry.Venue.VenueId] = new List <Checkin>();
                }

                var list = groupedByVenue[entry.Venue.VenueId];
                if (list != null)
                {
                    list.Add(entry);
                }
            }

            // Clear the map.
            var pinsToRemove = new List <UIElement>();

            foreach (var child in _layer.Children)
            {
                if (child != _gpsPushpin)
                {
                    pinsToRemove.Add(child);
                }
            }

            foreach (var pin in pinsToRemove)
            {
                _layer.Children.Remove(pin);
            }

            _currentPins.Clear();

            // Add the newly grouped entries.
            foreach (var group in groupedByVenue)
            {
                var venue = venues[group.Key];
                if (venues != null && group.Value != null && group.Value.Count > 0)
                {
                    var pin = new Pushpin();
                    pin.DataContext = venue;
                    pin.Location    = venue.Location.AsGeoCoordinate();
                    pin.Content     = group.Value[0].DisplayUser;

                    // Color the pin if it's the user themselves.
                    bool isSelf      = false;
                    var  firstPerson = group.Value[0];
                    foreach (var person in group.Value)
                    {
                        if (person.User.IsSelf)
                        {
                            isSelf      = true;
                            firstPerson = person;
                            break;
                        }
                    }
                    if (isSelf)
                    {
                        pin.Background = (Brush)Application.Current.Resources["PhoneAccentBrush"];
                    }

                    Grid nestingGrid = null;

                    if (group.Value.Count > 1)
                    {
                        // Add other offset images first.
                        nestingGrid = new Grid();
                        int count = 0;

                        foreach (var person in group.Value)
                        {
                            if (person != firstPerson)
                            {
                                ++count;

                                /*Border b = new Border { Height = 48, Width = 48 };
                                 * b.Background = new SolidColorBrush(Colors.White);
                                 * b.BorderBrush = new SolidColorBrush(Colors.Black);
                                 * b.BorderThickness = new Thickness(2);
                                 * b.RenderTransform = new TranslateTransform { X = count * 6, Y = count * -6 };*/

                                var b = new Image();
                                b.Source          = new System.Windows.Media.Imaging.BitmapImage(person.User.Photo);
                                b.MaxWidth        = 24;
                                b.MaxHeight       = 24;
                                b.Stretch         = System.Windows.Media.Stretch.Uniform;
                                b.RenderTransform = new TranslateTransform {
                                    X = 42 + (count * 4), Y = 24 + (count * -4)
                                };

                                nestingGrid.Children.Add(b);
                            }
                        }
                    }

                    var pinImage = new Image();
                    pinImage.Source  = new System.Windows.Media.Imaging.BitmapImage(firstPerson.User.Photo);
                    pinImage.Width   = 48;
                    pinImage.Height  = 48;
                    pinImage.Stretch = System.Windows.Media.Stretch.Fill; // will mess with the aspect ratio a little.
                    pinImage.Margin  = new Thickness(2);

                    HyperlinkButton hb = new HyperlinkButton();
                    hb.NavigateUri = venue.VenueUri;
                    hb.Style       = Application.Current.Resources["NoHyperlink"] as Style;

                    if (nestingGrid != null)
                    {
                        nestingGrid.Children.Add(pinImage);
                        hb.Content = nestingGrid;
                        //pin.Content = nestingGrid;
                    }
                    else
                    {
                        hb.Content = pinImage;
                        //pin.Content = pinImage;
                    }

                    pin.Content = hb;

                    //pin.DataContext = venue;
                    //pin.ContentTemplate = LayoutRoot.Resources["VenuePinDataTemplate"] as DataTemplate;

                    _layer.Children.Add(pin);
                    _currentPins.Add(pin, venue);
                }
            }
        }
 private void OnCompleted(Checkins checkins)
 {
     Update(checkins);
 }
 public void AddCheckin(Checkin checkin)
 {
     Checkins.Add(checkin);
     IsСhanges = true;
 }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            LocationAssistant.Instance.WalkingPositionChanged += OnWalkingPositionChanged;

            _map = new Map();
            _map.ScaleVisibility = System.Windows.Visibility.Visible;
            _map.CopyrightVisibility = System.Windows.Visibility.Collapsed;
            LayoutRoot.Children.Add(_map);

            _map.MapZoom += _map_MapZoom;
            _map.MapResolved += _map_MapResolved;
            _map.MapPan += _map_MapPan;

            IAppInfo iai = Application.Current as IAppInfo;
            if (iai != null)
            {
                _map.CredentialsProvider = new ApplicationIdCredentialsProvider(iai.BKey);
            }

            if (_layer != null && _map.Children.Contains(_layer))
            {
                _map.Children.Remove(_layer);
                _layer = null;
            }

            _layer = new MapLayer();
            _map.Children.Add(_layer);

            var loc = LocationAssistant.Instance.LastKnownLocation.AsGeoCoordinate();
            _map.SetView(loc, 14);

            if (_gpsPushpin == null)
            {
                _gpsPushpin = new Pushpin();
                _gpsPushpin.Location = LocationAssistant.Instance.LastKnownLocation.AsGeoCoordinate();
                var cs = LayoutRoot.Resources["MePushpinStyle"] as Style;
                _gpsPushpin.Style = cs;
                _layer.Children.Add(_gpsPushpin);
            }

            if (Environment.OSVersion.Version.Minor >= 1)
            {
                // mango hack
                var st = typeof(SystemTray);
                var opacity = st.GetProperty("Opacity");
                if (opacity != null)
                {
                    opacity.SetValue(null, 0.65, null);

                    SystemTray.IsVisible = true;
                }
            }

            //SetupAppBar();

            if (_checkins != null)
            {
                Update(_checkins);
            }
            else
            {
                _checkins = DataManager.Current.Load<Checkins>("Checkins", OnCompleted, OnError);
            }
        }
        private void Update(Checkins checkins)
        {
            if (_map != null && _map.BoundingRectangle != null)
            {
                if (_map.BoundingRectangle.Width < .0001)
                {
                    // hasn't actually loaded yet.
                    IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(.25),
                        () => Update(checkins));
                    return;
                }
            }
            else
            {
                // should never happen for real.
                return;
            }

            // 3 hours ago.
            DateTime threeHoursAgo = DateTime.Now - TimeSpan.FromHours(3);

            List<Checkin> nearby = new List<Checkin>();
            foreach (var x in checkins.Groups)
            {
                foreach (Checkin c in x)
                {
                    if (IsNearby(c) && c.CreatedDateTime >= threeHoursAgo)
                    {
                        nearby.Add(c);
                    }
                }
            }

            // Group by Dictionary<VenueId, List<...>>
            // Store venues as well in Dictionary<VenueId, Venue>
            Dictionary<string, List<Checkin>> groupedByVenue = new Dictionary<string, List<Checkin>>();
            Dictionary<string, CompactVenue> venues = new Dictionary<string, CompactVenue>();

            foreach (var entry in nearby)
            {
                if (!venues.ContainsKey(entry.Venue.VenueId))
                {
                    venues[entry.Venue.VenueId] = entry.Venue;
                    groupedByVenue[entry.Venue.VenueId] = new List<Checkin>();
                }

                var list = groupedByVenue[entry.Venue.VenueId];
                if (list != null)
                {
                    list.Add(entry);
                }
            }

            // Clear the map.
            var pinsToRemove = new List<UIElement>();
            foreach (var child in _layer.Children)
            {
                if (child != _gpsPushpin)
                {
                    pinsToRemove.Add(child);
                }
            }

            foreach (var pin in pinsToRemove)
            {
                _layer.Children.Remove(pin);
            }

            _currentPins.Clear();

            // Add the newly grouped entries.
            foreach (var group in groupedByVenue)
            {
                var venue = venues[group.Key];
                if (venues != null && group.Value != null && group.Value.Count > 0)
                {
                    var pin = new Pushpin();
                    pin.DataContext = venue;
                    pin.Location = venue.Location.AsGeoCoordinate();
                    pin.Content = group.Value[0].DisplayUser;

                    // Color the pin if it's the user themselves.
                    bool isSelf = false;
                    var firstPerson = group.Value[0];
                    foreach (var person in group.Value)
                    {
                        if (person.User.IsSelf)
                        {
                            isSelf = true;
                            firstPerson = person;
                            break;
                        }
                    }
                    if (isSelf)
                    {
                        pin.Background = (Brush)Application.Current.Resources["PhoneAccentBrush"];
                    }

                    Grid nestingGrid = null;

                    if (group.Value.Count > 1)
                    {
                        // Add other offset images first.
                        nestingGrid = new Grid();
                        int count = 0;

                        foreach (var person in group.Value)
                        {
                            if (person != firstPerson)
                            {
                                ++count;

                                /*Border b = new Border { Height = 48, Width = 48 };
                                b.Background = new SolidColorBrush(Colors.White);
                                b.BorderBrush = new SolidColorBrush(Colors.Black);
                                b.BorderThickness = new Thickness(2);
                                b.RenderTransform = new TranslateTransform { X = count * 6, Y = count * -6 };*/

                                var b = new Image();
                                b.Source = new System.Windows.Media.Imaging.BitmapImage(person.User.Photo);
                                b.MaxWidth = 24;
                                b.MaxHeight = 24;
                                b.Stretch = System.Windows.Media.Stretch.Uniform;
                                b.RenderTransform = new TranslateTransform { X = 42 + (count * 4), Y = 24 + (count * -4) };

                                nestingGrid.Children.Add(b);
                            }
                        }
                    }

                    var pinImage = new Image();
                    pinImage.Source = new System.Windows.Media.Imaging.BitmapImage(firstPerson.User.Photo);
                    pinImage.Width = 48;
                    pinImage.Height = 48;
                    pinImage.Stretch = System.Windows.Media.Stretch.Fill; // will mess with the aspect ratio a little.
                    pinImage.Margin = new Thickness(2);

                    HyperlinkButton hb = new HyperlinkButton();
                    hb.NavigateUri = venue.VenueUri;
                    hb.Style = Application.Current.Resources["NoHyperlink"] as Style;
                    
                    if (nestingGrid != null)
                    {
                        nestingGrid.Children.Add(pinImage);
                        hb.Content = nestingGrid;
                        //pin.Content = nestingGrid;
                    }
                    else
                    {
                        hb.Content = pinImage;
                        //pin.Content = pinImage;
                    }

                    pin.Content = hb;

                    //pin.DataContext = venue;
                    //pin.ContentTemplate = LayoutRoot.Resources["VenuePinDataTemplate"] as DataTemplate;

                    _layer.Children.Add(pin);
                    _currentPins.Add(pin, venue);
                }
            }
        }
 private void OnCompleted(Checkins checkins)
 {
     Update(checkins);
 }
Example #13
0
        public User(Dictionary<string, object> jsonDictionary)
            : base(jsonDictionary)
        {
            Requests = "0";
            Followers = "0";
            Todos = "0";
            Friends = "0";
            Tips = "0";
            MayorshipItems = new List<Venue>();
            Mayorships = "0";
            Badges = "0";
            jsonDictionary = Helpers.ExtractDictionary(jsonDictionary, "response:user");

            Id = Helpers.GetDictionaryValue(jsonDictionary, "id");

            FirstName = Helpers.GetDictionaryValue(jsonDictionary, "firstName");
            LastName = Helpers.GetDictionaryValue(jsonDictionary, "lastName");
            HomeCity = Helpers.GetDictionaryValue(jsonDictionary, "homeCity");

            Photo = Helpers.GetDictionaryValue(jsonDictionary, "photo");
            Gender = Helpers.GetDictionaryValue(jsonDictionary, "gender");
            Relationship = Helpers.GetDictionaryValue(jsonDictionary, "relationship");

            Photo = Helpers.GetDictionaryValue(jsonDictionary, "photo");
            Gender = Helpers.GetDictionaryValue(jsonDictionary, "gender");
            Relationship = Helpers.GetDictionaryValue(jsonDictionary, "relationship");

            if (jsonDictionary.ContainsKey("badges"))
                Badges = Helpers.ExtractDictionary(jsonDictionary, "badges")["count"].ToString();

            if (jsonDictionary.ContainsKey("mayorships"))
            {
                Mayorships = Helpers.ExtractDictionary(jsonDictionary, "mayorships")["count"].ToString();
                foreach (var obj in (Object[]) Helpers.ExtractDictionary(jsonDictionary, "mayorships")["items"])
                    MayorshipItems.Add(new Venue((Dictionary<string, object>) obj));
            }
            if (jsonDictionary.ContainsKey("checkins"))
                Checkins = new Checkins(Helpers.ExtractDictionary(jsonDictionary, "checkins"));

            if (jsonDictionary.ContainsKey("friends"))
            {
                Friends = Helpers.ExtractDictionary(jsonDictionary, "friends")["count"].ToString();
                //Todo: if the count >0, get the items
            }
            if (jsonDictionary.ContainsKey("followers"))
            {
                Followers = Helpers.ExtractDictionary(jsonDictionary, "followers")["count"].ToString();
                //Todo: if the count >0, get the items
            }
            if (jsonDictionary.ContainsKey("requests"))
            {
                Requests = Helpers.ExtractDictionary(jsonDictionary, "requests")["count"].ToString();
                //Todo: if the count >0, get the items
            }
            if (jsonDictionary.ContainsKey("tips"))
            {
                Tips = Helpers.ExtractDictionary(jsonDictionary, "tips")["count"].ToString();
                //Todo: if the count >0, get the items
            }
            if (jsonDictionary.ContainsKey("todos"))
            {
                Todos = Helpers.ExtractDictionary(jsonDictionary, "todos")["count"].ToString();
                //Todo: if the count >0, get the items
            }

            Type = Helpers.GetDictionaryValue(jsonDictionary, "type");
            if (jsonDictionary.ContainsKey("contact"))
                Contact = new Contact(Helpers.ExtractDictionary(jsonDictionary, "contact"));

            Pings = Helpers.GetDictionaryValue(jsonDictionary, "pings");
            if (jsonDictionary.ContainsKey("scores"))
                Scores = new Score(Helpers.ExtractDictionary(jsonDictionary, "scores"));
        }