protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _web.LoadCompleted += OnLoadCompleted;
            _web.Navigated     += OnNavigated;
            _web.Navigating    += OnNavigating;

            string ur = null;

            if (NavigationContext.QueryString.TryGetValue("uri", out ur))
            {
                var uri = new Uri(ur, UriKind.Absolute);
                if (uri != null)
                {
                    if (_token != null)
                    {
                        StatusToken.TryComplete(ref _token);
                    }
                    _token = CentralStatusManager.Instance.BeginShowEllipsisMessage("Loading information");

                    _uri = uri;
                    if (_isLoadComplete)
                    {
                        _web.Navigate(uri);
                    }
                    else
                    {
                        IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(0.75), () => OnLoadCompleted(this, new System.Windows.Navigation.NavigationEventArgs(null, null)));
                    }
                }
            }

            UpdateAppBar();
        }
Пример #2
0
        private void OnListCreateSuccess(Model.CompactList list)
        {
            NewlyCreatedList = list;

            _refreshToken = CentralStatusManager.Instance.BeginLoading("Preparing your list");

            IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(1.0), () =>
            {
                var temporary = DataManager.Current.Refresh <Model.UserLists>(
                    new LoadContext("self"),
                    OnListsLoaded,
                    OnListsFailed);
            });
        }
Пример #3
0
        private void DoQuickCheckin(Model.Venue venue)
        {
            // HORRIBLE... this code is just copied from Venue.xaml.cs
            string vid = venue.VenueId;

            // TODO: Actually this should show the check-in UI where you enter the information!

            Model.CheckinRequest request = null;

            // TODO: Use their defaults instead of false false!!!

            bool pingFacebook = false;
            bool pingTwitter  = false;

            if (_settings != null && _settings.IsLoadComplete)
            {
                pingFacebook = _settings.SendToFacebook;
                pingTwitter  = _settings.SendToTwitter;
            }

            request = Model.CheckinRequest.VenueCheckin(venue, pingTwitter, pingFacebook);

            FourSquare.Instance.Checkin(request, (success) =>
            {
                // TODO: This is the check-in powerful stuff!
                // Need to reload the page itself to get the updated "here now"
                Dispatcher.BeginInvoke(() =>
                {
                    IntervalDispatcher.
                    BeginInvoke(
                        TimeSpan.FromSeconds(1.5),
                        () =>
                    {
                        // Refresh the checkins list.
                        DataManager.Current.Refresh <Model.Checkins>("Checkins", null, null);
                    });
                });
            },
                                        (error) =>
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("We couldn't check you in now, sorry!");
                });
            });
        }
Пример #4
0
        private void StopIntervalDispatching(bool sendMessage, bool save)
        {
            if (IntervalDispatcher != null)
            {
                IntervalDispatcher.Abort();
                IntervalDispatcher = null;

                if (sendMessage)
                {
                    lock (Vk) VkNet.VkUtils.SendMessage(Vk, Message, StringConstants.Dialog_IntervalOkStopResponse);
                }

                IsIntervalDispatcherStarted = true;

                if (save)
                {
                    SaveToFile();
                }
            }
            else if (sendMessage)
            {
                VkNet.VkUtils.SendMessage(Vk, Message, StringConstants.Dialog_IntervalAlwaysNotDoResponse);
            }
        }
        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);
                }
            }
        }
Пример #6
0
 private void UpdateUserLists()
 {
     // Refresh their lists for a better UI experience.
     IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(1.5),
                                    () => DataManager.Current.Refresh <Model.UserLists>(new LoadContext("self"), null, null));
 }
Пример #7
0
        public void Update(Action <string> callback)
        {
            IWebRequestFactory iwrf = (IWebRequestFactory)Application.Current;

            Debug.Assert(iwrf != null);

            if (LocationAssistant.Instance.LastKnownLiveLocation != null &&
                LocationAssistant.Instance.Status == System.Device.Location.GeoPositionStatus.Ready)
            {
                // uses the live version.
                var    lll   = LocationAssistant.Instance.LastKnownLiveLocation;
                double lat   = lll.Latitude;
                double @long = lll.Longitude;

                PriorityQueue.AddNetworkWorkItem(() =>
                {
                    var cclient = iwrf.CreateWebRequestClient(); //new FourSquareWebClient();
                    var client  = cclient.GetWrappedClientTemporary();

                    //var r = client.CreateSimpleWebRequest(GetServiceUri(lat, @long));
                    //var r = client.CreateServiceRequest(GetServiceUri(lat, @long), false /* no credentials */);
                    client.DownloadStringCompleted += (x, xe) =>
                    {
                        if (xe.Error != null)
                        {
                            // TODO: Make sure that the chain supports a EMPTY and not NULL geocode
                            _asCoordinates = string.Format(CultureInfo.InvariantCulture, "No data connection ({0:0.000}, {1:0.000})", lat, @long);
                            Location       = _asCoordinates;

                            callback(_lastGeocode);
                        }
                        else
                        {
                            string s           = xe.Result;
                            Action <string> cb = callback;
                            PriorityQueue.AddWorkItem(() => ParseJson(s, cb));
                        }
                    };
                    client.DownloadStringAsync(GetServiceUri(lat, @long));
                });
            }
            else
            {
                //LastGeocodeName = string.Empty;
                string s = "Location service is off or unavailable.";
                if (LocationAssistant.Instance.Status == System.Device.Location.GeoPositionStatus.Initializing)
                {
                    s = string.Empty;
                    // "Finding your location...";
                }
                if (LocationAssistant.Instance.Status == System.Device.Location.GeoPositionStatus.Ready)
                {
                    s = "Looking up your address...";
                }

                Location = s;
                callback(_lastGeocode);

                // TODO: Warning, this is not a good thing to do. ?
                var cb = callback;
                IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(1), () => Update(cb));
            }
        }
        private void FindTiles()
        {
            if (_isFindingTiles)
            {
                IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(0.5), FindTiles);
                return;
            }
            _isFindingTiles = true;

            foreach (var item in standardShortcuts)
            {
                item.IsPinned = false; // clear that state.
            }

            List <TileInformation> places  = new List <TileInformation>();
            List <TileInformation> friends = new List <TileInformation>();

            var knownTiles = AppTileSettings.Instance.Tiles;

            foreach (var tile in ShellTile.ActiveTiles)
            {
                var tileNavigationUri = tile.NavigationUri;

                var tileSetting = knownTiles.Values.Where(v => v.NavigationUri == tileNavigationUri).SingleOrDefault();
                if (tileSetting == null)
                {
                    // We need to upgrade this tile.
                    UpgradeTile(tileNavigationUri);

                    // Skip the upgrade, once the upgrade is done this code
                    // should run again.
                    continue;
                }

                foreach (var standard in standardShortcuts)
                {
                    if (tile.NavigationUri == standard.NavigationUri)
                    {
                        standard.IsPinned = true;

                        if (tileSetting != null)
                        {
                            standard.OverwriteWithTileSettings(tileSetting);
                        }
                        break;
                    }
                }

                // Not a standard shortcut.
                var asString = tile.NavigationUri.ToString();

                if (asString == "/")
                {
                    if (!string.IsNullOrEmpty(tileSetting.StyleType))
                    {
                        SelectedMainIcon = tileSetting.StyleType;
                    }
                    else
                    {
                        SelectedMainIcon = null;
                    }
                }
                else if (IsPinnedVenue(tile.NavigationUri))
                {
                    var placeTile = new TileInformation
                    {
                        IsPinned = true,

                        CanChangeTitle           = true,
                        CanChangeBackgroundImage = true,

                        Title         = asString,
                        NavigationUri = tile.NavigationUri
                    };
                    placeTile.OverwriteWithTileSettings(tileSetting);
                    places.Add(placeTile);
                }
                else if (asString.StartsWith("/Views/Profile.xaml"))
                {
                    var friendTile = new TileInformation
                    {
                        IsPinned = true,

                        Title         = asString,
                        NavigationUri = tile.NavigationUri
                    };
                    friendTile.OverwriteWithTileSettings(tileSetting);
                    friends.Add(friendTile);
                }
            }

            if (ShortcutTiles != null)
            {
                ShortcutTiles = new List <TileInformation>(); // bump the ui.
            }
            ShortcutTiles = standardShortcuts;
            PlaceTiles    = places.Count > 0 ? places : null;
            FriendTiles   = friends.Count > 0 ? friends : null;

            _isFindingTiles = false;
        }
Пример #9
0
        public static void Main()
        {
            var w = 800;
            var h = 600;

            // create a new Canvas
            var canvas = new Canvas();

            canvas.Width  = w;
            canvas.Height = h;

            // add canvas to the div with id = "target" (defined in MainPage.html)
            var target = Element.GetById("target");

            target.AppendChild(canvas);

            // get the 2D context for the canvas, which contains all the draw methods
            var context = canvas.Get2DContext();

            var angleOffset = 0d;

            var timer = new IntervalDispatcher(TimeSpan.FromMilliseconds(30));

            timer.Tick += (s, e) =>
            {
                // draw background rect
                context.FillStyle = new RgbStyle(0xcc, 0x66, 0x99);
                context.FillRect(0, 0, w, h);
                context.LineWidth = 2;

                // draw flowers
                context.StrokeStyle = new RgbStyle(0x33, 0x33, 0x33);

                context.FillStyle = new RgbStyle(0xff, 0xff, 0);
                DrawFlower(context, Math.Min(w, h) * 0.4, 25d, 0.5 * w, 0.5 * h, angleOffset);

                context.FillStyle = new RgbStyle(0xff, 0x0, 0);
                DrawFlower(context, Math.Min(w, h) * 0.1, 12d, 0.5 * w, 0.5 * h, angleOffset);

                angleOffset += 0.02;
            };

            timer.Start();
            bool started = true;

            var startButton = new Element("button")
            {
                TextContent = "Start"
            };
            var stopButton = new Element("button")
            {
                TextContent = "Stop"
            };

            startButton.Click += (s, e) => {
                timer.Start();
                started             = true;
                startButton.Enabled = !started;
                stopButton.Enabled  = started;
            };

            stopButton.Click += (s, e) => {
                timer.Stop();
                started             = false;
                startButton.Enabled = !started;
                stopButton.Enabled  = started;
            };

            startButton.Enabled = !started;
            stopButton.Enabled  = started;

            target.AppendChild(startButton);
            target.AppendChild(stopButton);
        }