Example #1
0
        private async void RemoteSystemWatcher_RemoteSystemUpdated(RemoteSystemWatcher sender, RemoteSystemUpdatedEventArgs args)
        {
            var remoteSystem = _remoteSystems.Where(s => s.Id == args.RemoteSystem.Id).FirstOrDefault();

            if (remoteSystem != null)
            {
                return;
            }

            var existingSystem = _availableRemoteSystems.Where(s => s.RemoteSystem.Id == args.RemoteSystem.Id).FirstOrDefault();

            if (existingSystem == null)
            {
                var system = await AdventureRemoteSystem.CreateAdventureRemoteSystem(args.RemoteSystem).ConfigureAwait(false);

                if (system != null)
                {
                    var t = Helpers.RunOnCoreDispatcherIfPossible(() =>
                    {
                        if (_availableRemoteSystems.Where(s => s.RemoteSystem.Id == system.RemoteSystem.Id).Count() == 0)
                        {
                            _availableRemoteSystems.Add(system);
                            RemoteSystemAdded?.Invoke(this, system);
                        }
                    });
                }
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Instance = this;
            // Set the map location.
            var locationTask = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                Map.LandmarksVisible = true;
                LoadMapElements();
                if (e.Parameter != null && e.Parameter is string)
                {
                    var par = (e.Parameter as string).Split(':');
                    if (par[0] == "showmap")
                    {
                        MoveMap(par[1], par[2]);
                    }
                }

                var currentLocation = await Maps.GetCurrentLocationAsync();

                if (currentLocation != null)
                {
                    var icon      = new MapIcon();
                    icon.Location = currentLocation;
                    icon.NormalizedAnchorPoint = new Point(0.5, 0.5);
                    icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Square44x44Logo.targetsize-30.png"));

                    Map.MapElements.Add(icon);
                }
            });

            CurrentAdventure = await DataProvider.Instance.GetCurrentAdventure();

            List <UIElement> elementsToShow = new List <UIElement>();

            if (await DataProvider.Instance.GetCurrentAdventure() == null)
            {
                elementsToShow.Add(MainControlsNewAdventureButtonContainer);
                elementsToShow.Add(MainControlsViewOldAdventuresButtonContainer);
            }
            else
            {
                elementsToShow.Add(MainControlsViewOldAdventuresButtonContainer);
                elementsToShow.Add(MainControlsCaptureButtonContainer);
                elementsToShow.Add(MainControlsUploadButtonContainer);
                elementsToShow.Add(MainControlsBrowseButtonContainer);
            }

            for (var i = 0; i < elementsToShow.Count; i++)
            {
                var elem = elementsToShow[i];
                elem.Opacity    = 0;
                elem.Visibility = Visibility.Visible;
                elem.Offset(0, 20, 0).Then().Offset().Fade(1).SetDuration(200).SetDelay(i * 100).Start();
            }

            if (App.IsXbox())
            {
                MainControlsCaptureButton.Focus(FocusState.Keyboard);
                return;
            }

            Task.Run <List <AdventureRemoteSystem> >(async() =>
            {
                await Task.Delay(2000);
                return(await ConnectedService.Instance.FindAllRemoteSystemsHostingAsync());
            }).AsAsyncOperation <List <AdventureRemoteSystem> >().Completed = (s, args) =>
            {
                var systems = s.GetResults();
                if (systems.Count > 0)
                {
                    FindName("RemoteSystemContainer");

                    _system = systems.First();

                    DeviceTypeTextBlock.Text         = _system.RemoteSystem.Kind.ToString();
                    RemoteSystemContainer.Opacity    = 0;
                    RemoteSystemContainer.Visibility = Visibility.Visible;
                    RemoteSystemContainer.Scale(0.8f, 0.8f, (float)ActualWidth / 2, (float)ActualHeight / 2, 0)
                    .Then().Scale(1, 1, (float)ActualWidth / 2, (float)ActualHeight / 2).Fade(1).Start();
                }
            };
        }