コード例 #1
0
        public void LocateNinjas(Ninja requestor, Action<IEnumerable<Ninja>> ninjasLocated)
        {
            Task loginTask;
            if (String.IsNullOrEmpty(AuthenticationToken))
                loginTask = LoginAsync(AuthenticationProvider);
            else
                loginTask = LoginAsync(AuthenticationToken);

            loginTask.ContinueWith(delegate
                {
                    var ninjaTable = NativeClient.GetTable<Ninja>();
                    ninjaTable.InsertAsync(requestor)
                              .ContinueWith(insertTask => ninjaTable.ReadAsync())
                              .ContinueWith(insertTask => ninjasLocated(insertTask.Result.Result), TaskContinuationOptions.AttachedToParent);

                }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }
コード例 #2
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (serviceClient != null) return;

            var loginProvider = (MobileServiceAuthenticationProvider) int.Parse(NavigationContext.QueryString["provider"]);
            var nickname = NavigationContext.QueryString["nick"];
            var group = NavigationContext.QueryString["group"];
            this.group.Text = group;

            serviceClient = new ServiceClient {AuthenticationProvider = loginProvider};
            var me = new Ninja
            {
                GroupName = group,
                NickName = nickname
            };

            var watcher = new GeoCoordinateWatcher();
            watcher.PositionChanged += (sender, args) => {
                var lat = /*args.Position.Location.Latitude*/ 55.7091;
                var lon = /*args.Position.Location.Longitude*/ 013.1982;
                var geoCoordinate = new GeoCoordinate(lat, lon);
                map.SetView(geoCoordinate, 6, MapAnimationKind.Linear);
                me.Latitude = lat;
                me.Longitude = lon;
                serviceClient.LocateNinjas(me, ninjas => Dispatcher.BeginInvoke(delegate
                {
                    var children = MapExtensions.GetChildren(map);
                    foreach (var ninja in ninjas)
                    {
                        var ninjaLocation = new GeoCoordinate(ninja.Latitude, ninja.Longitude);
                        var pushpin = new Pushpin { GeoCoordinate = ninjaLocation, Content = ninja.NickName };
                        children.Add(pushpin);
                    }
                    children.Add(new Pushpin {GeoCoordinate = geoCoordinate, Content = me.NickName, Background = new SolidColorBrush(Colors.Orange) });
                }));
                watcher.Stop();
            };
            watcher.Start();
        }
コード例 #3
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            _window = new UIWindow(UIScreen.MainScreen.Bounds);

            var welcomeView = new WelcomeView(UIScreen.MainScreen.ApplicationFrame);
            _window.AddSubview(welcomeView);

            welcomeView.Done += () => {
                var rootController = new UINavigationController();
                _window.RootViewController = rootController;

                var gettingStarted = new GettingStartedViewController();
                gettingStarted.Done += () => _locationService.GetCurrentLocation(coordinate => {
                    var me = new Ninja {
                        GroupName = gettingStarted.GroupName,
                        Latitude = coordinate.Latitude,
                        Longitude = coordinate.Longitude,
                        NickName = gettingStarted.Nickname
                    };

                    NinjaClient = new ServiceClient(gettingStarted) {
                        AuthenticationProvider = gettingStarted.AuthenticationProvider
                    };

                    NinjaClient.LocateNinjas(me, ninjasLocated => InvokeOnMainThread(() => {
                        rootController.DismissViewController(true, null);
                        var mapView = new MapViewController(coordinate, ninjasLocated);
                        mapView.Title = me.GroupName;
                        rootController.PushViewController(mapView, true);
                    }));
                });

                rootController.PresentViewController(gettingStarted, true, null);
            };

            _window.MakeKeyAndVisible();

            return true;
        }
コード例 #4
0
 public NinjaAnnotation(Ninja ninja)
 {
     _title = ninja.NickName;
     _coordinate = new CLLocationCoordinate2D(ninja.Latitude, ninja.Longitude);
 }