コード例 #1
0
ファイル: Cache.cs プロジェクト: klzig/WarmShowers-Windows
        /// <summary>
        /// Normal entry point for hosts request, with viewport caching
        /// </summary>
        public void getHosts()
        {
            if (App.ViewModelMain.debug)
            {   // Debug: Bypass viewport cache.
                getHostsForce(App.nearby.mapCenter);
                return;
            }

            Zoomed zoom = Zoomed.noChange;
            LocationRect newViewport = App.nearby.locationRect;
            GreatCircle gc = new GreatCircle();

            // This sanity check avoids some map initialization problems in WP8
            if (!isInside(App.nearby.mapCenter, newViewport)) return;

            //            if (mapInit)
            //            {   // Skip first query after map initialization
            //                mapInit = false;
            //                return;
            //            }

            /*
                       Deployment.Current.Dispatcher.BeginInvoke(() =>
                         {
            //App.nearby.myMap.Children.Remove(line);
                             line = new MapPolyline();
            line.Locations = new LocationCollection();
            line.Stroke = new SolidColorBrush(Colors.Blue);
            line.StrokeThickness = 5;
            line.Opacity = 0.7;
            LocationRect loc = newViewport;
            line.Locations.Add(loc.Northwest);
            line.Locations.Add(loc.Northeast);
            line.Locations.Add(loc.Southeast);
            line.Locations.Add(loc.Southwest);
            line.Locations.Add(loc.Northwest);
            App.nearby.myMap.Children.Add(line);
                         });
             */

            /*            if (firstTime)
            {   // First request after startup
                if (getHosts2(App.ViewModelMain.mapLocation))
                {
                    firstTime = false;
                }
                return;
            }
            */
            GeoCoordinate newCenter = App.ViewModelMain.mapLocation;

            zoom = checkNorth(newViewport.North, zoom);
            if (Zoomed.panned != zoom)
            {
                zoom = checkSouth(newViewport.South, zoom);
                if (Zoomed.panned != zoom)
                {
                    zoom = checkEast(newViewport.East, zoom);
                    if (Zoomed.panned != zoom)
                    {
                        zoom = checkWest(newViewport.West, zoom);
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine("Count: " + lastResults);

            switch (zoom)
            {
                case Zoomed.Out:
                    if (!gc.isEqual(newCenter, lastCenter))
                    {   // If zoomed out, keep pushpins in the middle
                        getHostsForce(newCenter);
                        zoom = Zoomed.panned;
                    }
                    else if (lastResults < resultLimit)
                    {   // Otherwise query only if we haven't hit the limit yet
                        getHostsForce(newCenter);
                    }
                    break;
                case Zoomed.panned:
                    getHostsForce(newCenter);

                    // This was causing map intitialization problems with WP8 device, putting it back in...
                    if (!gc.isEqual(newCenter, lastCenter))
                    {
                        getHostsForce(newCenter);
                    }
                    else
                    {   // This isn't a pan, but a zoom in that straddles an asymmetric lastViewport
                        zoom = Zoomed.In;
                    }

                    break;
                case Zoomed.In:         // Fall-thru
                case Zoomed.noChange:   // Fall-thru
                default:
                    break;
            }
            System.Diagnostics.Debug.WriteLine("Zoomed: " + zoom);
        }
コード例 #2
0
        private void UpdateLine2()
        {
            GreatCircle gc = new GreatCircle();

            //  return;  // Todo:  Fake names for screen shots

            string line = gc.date_mmmddyyyy(_time);
            if (_newMessageCount > 0)
            {
                line += " " + _newMessageCount.ToString() + " ";

                if (_newMessageCount == 1)
                {
                     line += WebResources.NewMessage;
                }
                else
                {
                    line += WebResources.NewMessages;
                }
            }
            line2 = line;
        }
コード例 #3
0
        /// <summary>
        /// Common pin functionality
        /// </summary>
        private bool pin(HostProfile host)
        {
            int uId = host.uId;
            GreatCircle gc = new GreatCircle();

            if (foundProfiles.Count == 0)
            {   // Clear the "no found hosts" help message
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    App.ViewModelMain.foundItems.Clear();
                });
            }

            host.lastUpdateTime = gc.Now();

            // Deal with case where host is already pinned
            if (isPinned(uId))
            {
                foundProfiles.Remove(uId);
            }
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                App.ViewModelMain.unPin(uId);
            });

            // Add pinned items to store and pinnedList UI
            foundProfiles.Add(uId, host);
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                App.ViewModelMain.Pin(uId, host.name, host.lastUpdateTime);
                App.ViewModelHost.Pin(uId);
            });

            return true;
        }
コード例 #4
0
        /// <summary>
        /// Change username in pinned list
        /// </summary>
        public void UpdateUsernamePinned(int uId, string uName)
        {
            GreatCircle gc = new GreatCircle();

            PinnedItemViewModel found = FindItemInPinnedList(uId);
            if (null != found)
            {
                long time = found.Time;
                int userID = found.userID;

                App.ViewModelMain.pinnedItems.Remove(found);
                App.ViewModelMain.pinnedItems.Add(new PinnedItemViewModel() { Name = uName, Time = time, userID = userID });
            }
        }
コード例 #5
0
        private void ApplicationBarIconButton_Click_Reply(object sender, EventArgs e)
        {
            this.Focus();  // Hide keyboard

            FeedbackData feedbackData = App.settings.messageData.feedbackData;

            // Catch anything that wasn't edited
            feedbackData.to = To.Text;
            feedbackData.body = Body.Text;
            feedbackData.experience = (String) Experience.SelectedItem;
            feedbackData.guestOrHost = (String) GuestOrHost.SelectedItem;
            feedbackData.monthMet = MonthMet.SelectedIndex;
            feedbackData.yearMet = (String) YearMet.SelectedItem;

            GreatCircle gc = new GreatCircle();
            if (gc.GetWordCount(feedbackData.body) < 10)
            {
                Status.Text = WebResources.SendingFeedbackTooShort;
                return;
            }

            if (WebService.SendFeedback())
            {
                Status.Text = WebResources.SendingFeedback;
            }
            else
            {
                Status.Text = WebResources.SendingFeedbackFailed;
            }

            App.pinned.pin();
        }
コード例 #6
0
        public void update(int uId, long time)
        {
            GreatCircle gc = new GreatCircle();

            HostProfile host = null;
            if (foundProfiles.ContainsKey(uId))
            {
                if (foundProfiles.TryGetValue(uId, out host))
                {
                    if (null != host)
                    {
                        host.lastUpdateTime = time;
                        //  foundProfiles.Add(uId, host);  // Todo:  I don't think we need to add it back????
                        App.ViewModelMain.UpdateTimestampPinned(uId, time);
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Update UI with profile results
        /// </summary>
        public void loadProfile()
        {
            if (null != host.profile.user_Result)  // cache may be incomplete
            {
                User user = host.profile.user_Result;
                GeoCoordinate loc = new GeoCoordinate();
                loc.Latitude = user.latitude;
                loc.Longitude = user.longitude;
                GreatCircle gc = new GreatCircle();

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    App.ViewModelHost.aboutItems.Clear();
                    App.ViewModelHost.aboutItems.Add(new AboutItemViewModel()
                    {
                        Line2 = WebResources.MemberFor + " " + gc.TimeSince(user.created),
                        Line3 = WebResources.LastAccess + " " + gc.TimeSince(user.access) + WebResources.ago,
                        Line4 = gc.Distance(loc) + " " + WebResources.FromCurrentLocation,
                        Type = AboutItemViewModel.AboutType.general
                    });
                });

                loadProfileCommon(user.latitude, user.longitude, user.street, user.additional, user.city, user.province, user.country, user.postal_code);

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (!string.IsNullOrEmpty(user.mobilephone))
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutPhone, Line2 = user.mobilephone, Type = AboutItemViewModel.AboutType.phone });
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutSMS, Line2 = user.mobilephone, Type = AboutItemViewModel.AboutType.sms });
                    }
                    if (!string.IsNullOrEmpty(user.homephone) && user.homephone != user.mobilephone)
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutHomePhone, Line2 = user.homephone, Type = AboutItemViewModel.AboutType.phone });
                    }
                    if (!string.IsNullOrEmpty(user.workphone) && user.workphone != user.mobilephone && user.workphone != user.homephone)
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutWorkPhone, Line2 = user.workphone, Type = AboutItemViewModel.AboutType.phone });
                    }
                    if (!string.IsNullOrEmpty(user.URL))
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutURL, Line2 = user.URL, Type = AboutItemViewModel.AboutType.web });
                    }
                    if (!string.IsNullOrEmpty(user.picture))
                    {
                        App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Picture = user.profile_image_mobile_photo_456, Type = AboutItemViewModel.AboutType.picture });

                    }
                    App.ViewModelHost.aboutItems.Add(new AboutItemViewModel() { Line1 = WebResources.AboutComments, Line2 = user.comments, Type = AboutItemViewModel.AboutType.comments });

                    App.ViewModelHost.hostingItems.Clear();
                    if (!string.IsNullOrEmpty(user.languagesspoken))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderLanguagesSpoken, Line2 = user.languagesspoken });
                    }
                    if (!string.IsNullOrEmpty(user.preferred_notice))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderPreferred_notice, Line2 = user.preferred_notice });
                    }
                    if (!string.IsNullOrEmpty(user.maxcyclists))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderMaxCyclists, Line2 = user.maxcyclists });
                    }
                    if (!string.IsNullOrEmpty(user.bikeshop))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderBikeShop, Line2 = user.bikeshop });
                    }
                    if (!string.IsNullOrEmpty(user.campground))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderCampground, Line2 = user.campground });
                    }
                    if (!string.IsNullOrEmpty(user.motel))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderMotel, Line2 = user.motel });
                    }
                    string offer = getHostMayOffer();
                    if (!string.IsNullOrEmpty(offer))
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.HostingHeaderHostMayOffer, Line2 = offer });
                    }
                    // Handle hosting list being empty
                    if (App.ViewModelHost.hostingItems.Count < 1)
                    {
                        App.ViewModelHost.hostingItems.Add(new HostingItemViewModel() { Line1 = WebResources.none });
                    }
                });
            }
        }
コード例 #8
0
        /// <summary>
        /// Update UI with messages 
        /// </summary>
        public void loadMessages()
        {
            if (null != host.messages.messages_result)
            {
                if (null != host.messages.messages_result.messages)  // cache may be incomplete
                {
                    GreatCircle gc = new GreatCircle();

                    Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModelHost.messageItems.Clear(); });

                    // Handle messages list being empty
                    int len = host.messages.messages_result.messages.Count;
                    if (len < 1)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            App.ViewModelHost.messageItems.Add(new MessagesItemViewModel()
                            {
                                Header1 = WebResources.none,
                            });
                        });
                    }
                    else
                    {
                        foreach (var message in host.messages.messages_result.messages)
                        {
                            long date = message.last_updated;
                            string header = gc.date_mmmddyyyy(date);

                            if (1 == message.is_new)
                            {
                                header += " " + message.is_new.ToString() + " " + WebResources.NewMessageReceived;
                            }
                            else if (1 < message.is_new)    // is_new represents the number of new messages, it's not a new message boolean!
                            {
                                header += " " + message.is_new.ToString() + " " + WebResources.NewMessagesReceived;
                            }

                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                App.ViewModelHost.messageItems.Add(new MessagesItemViewModel()
                                {
                                    Header1 = message.subject,
                                    Header2 = header,
                                    threadID = message.thread_id
                                });
                            });
                        }
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Update UI with message 
        /// </summary>
        public void loadMessage()
        {
            GreatCircle gc = new GreatCircle();

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                App.ViewModelMessage.messageItems.Clear();

                // Handle message list being empty
                int len = messageThread.message_result.messages.Count();
                if (len < 1)
                {
                    App.ViewModelMessage.messageItems.Add(new MessageItemViewModel()
                    {
                        Header1 = WebResources.none,
                    });
                }
                else
                {
                    App.ViewModelMessage.subject = messageThread.message_result.subject;
                    for (int i = len - 1; i >= 0; i--)
                    {   // Display most recent message first
                        MessageThread.Message message = messageThread.message_result.messages[i];

                        long date = message.timestamp;

                        //Lookup author fullname
                        int uid;
                        int.TryParse(message.author, out uid);
                        string author = getFullName(uid);

                        string header = WebResources.SentBy + " " + author + " " + WebResources.On + " " + gc.date_mmmddyyyy(date);
                        if (1 == message.is_new) header += " - " + WebResources.New;

                        App.ViewModelMessage.messageItems.Add(new MessageItemViewModel()
                        {
                            Header1 = header,
                            Body = message.body
                        });
                    }
                }
            });
        }
コード例 #10
0
        /// <summary>
        /// Update UI with hosts results
        /// </summary>
        public void loadHosts()
        {
            if (null == App.nearby.hosts) return;
            else if (null == App.nearby.hosts.hosts_Result) return;
            Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModelMain.nearbyItems.Clear(); });

            if (!App.settings.isLocationEnabled)
            {   // User deliberately disabled location service
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel()
                    {
                        Name = WebResources.NearbyListLocationDisabledHeader,
                        Line2 = WebResources.NearbyListLocationDisabledBody
                    });
                });
                return;
            }

            int len = hosts.hosts_Result.accounts.Count;
            if (len < 1)
            {   // Display empty list message to user and return
                // Todo:  Filter feature
                //                if (App.ViewModelFilter.isFiltered())
                //                {   // With filter active message
                //                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                //                    {
                //                        App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel()
                //                        {
                //                            Name = WebResources.NearbyListEmptyHeader,
                //                            Line2 = WebResources.NearbyListEmptyBody1 + "\n\n" +
                //                                WebResources.NearbyListEmptyBody2 + "\n\n" + WebResources.NearbyListEmptyBody3
                //                        });
                //                    });
                //                }
                //                else
                {   // Without filter active message
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel()
                        {
                            Name = WebResources.NearbyListEmptyHeader,
                            Line2 = WebResources.NearbyListEmptyBody1 + "\n\n" + WebResources.NearbyListEmptyBody3
                        });
                    });
                }
                return;
            }

            // Add hosts to main list
            List<MapCoord> mapCoords = new List<MapCoord>();
            GreatCircle gc = new GreatCircle();
            foreach (var account in hosts.hosts_Result.accounts)
            {
                MapCoord coord = new MapCoord();
                coord.geoCoord = new GeoCoordinate(account.latitude, account.longitude);
                coord.userName = account.fullname;
                coord.uId = account.uid;
                if (App.pinned.isPinned(coord.uId))
                {
                    coord.type = PushpinType.pinned;
                }
                else
                {
                    coord.type = PushpinType.unpinned;
                }
                mapCoords.Add(coord);

                App.nearby.viewportCache.hostLocation(coord.geoCoord);

                string distance = gc.Distance(coord.geoCoord);
                double d = gc.dDistance(coord.geoCoord);
                if (App.pinned.isPinned(account.uid))
                {
                    distance += " - " + WebResources.pinned;
                }

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                { App.ViewModelMain.nearbyItems.Add(new NearbyItemViewModel() { Name = account.fullname, Line2 = distance, userID = account.uid, Distance = d }); });
            }

            Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModelMain.mapItems.Clear(); });

            // Add hosts to map
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                foreach (MapCoord coord in mapCoords)
                {
                    App.ViewModelMain.mapItems.Add(new MapItemViewModel() { location = coord.geoCoord, username = coord.userName, Type = coord.type, userID = coord.uId });
                }
            });
        }
コード例 #11
0
        /// <summary>
        /// Update UI with feedback results
        /// </summary>
        public void loadFeedback()
        {
            if (null != host.feedback.recommendations_Result.recommendations)   // cache may be incomplete
            {
                GreatCircle gc = new GreatCircle();

                Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModelHost.feedbackItems.Clear(); });

                // Handle feedback list being empty
                int len = host.feedback.recommendations_Result.recommendations.Count;
                if (len < 1)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        App.ViewModelHost.feedbackItems.Add(new FeedbackItemViewModel()
                        {
                            Header1 = WebResources.none,
                        });
                    });
                }
                else
                {
                    foreach (var recommendation in host.feedback.recommendations_Result.recommendations)
                    {
                        long date = recommendation.recommendation.field_hosting_date_value;
                        string header = "";

                        header += recommendation.recommendation.field_rating_value;
                        header += " - ";

                        header += recommendation.recommendation.field_guest_or_host_value;
                        if (date != 0)
                        {
                            date += 86400;  // Fudge to kick us into the next month.  Warm showers server bug?
                            header += " - ";
                            header += gc.date(date);
                        }

                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            App.ViewModelHost.feedbackItems.Add(new FeedbackItemViewModel()
                            {
                                Header1 = header,
                                Header2 = recommendation.recommendation.fullname,
                                Body = recommendation.recommendation.body,
                                userID = recommendation.recommendation.uid
                            });
                        });
                    }
                }
            }
        }