Example #1
0
        public Practice()
        {
            InitializeComponent();

            session = new PracticeViewModel();

            isNewInstance = true;
            Loaded += OnLoaded;
        }
Example #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.ContainsKey("resume") || (isNewInstance && e.NavigationMode != NavigationMode.New)) {
                try {
                    using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) {
                        using (var file = storage.OpenFile("Session", FileMode.Open, FileAccess.Read, FileShare.Read)) {
                            using (var sr = new StreamReader(file)) {
                                var json = JsonValue.Parse(sr);
                                session = new JsonContext().FromJson<PracticeViewModel>(json);
                            }
                        }
                    }
                }
                catch (IsolatedStorageException) { }
                catch (IOException) { }
                catch (FormatException) {}
                return;
            }

            base.OnNavigatedTo(e);
        }
Example #3
0
        void SessionChanged(PracticeViewModel oldValue)
        {
            if (oldValue != null) {
                oldValue.Finished -= PracticeFinished;
                oldValue.FinishedRound -= PracticeFinishedRound;
            }

            session = Session;

            session.Finished += PracticeFinished;
            session.FinishedRound += PracticeFinishedRound;

            if (session.IsFinished)
                GoToState(GameState.GameOverview);
            else if (session.CurrentItem == null)
                GoToState(GameState.RoundOverview);
            else
                GoToState(GameState.Guessing);
        }
Example #4
0
        void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            if (!isNewInstance)
                return;

            isNewInstance = false;

            if (NavigationContext.QueryString.ContainsKey("resume")) {
                DataContext = session;
                gamePanel.Visibility = Visibility.Visible;
                return;
            }

            if (State.ContainsKey("Session")) {
                DataContext = session = RestoreJsonState<PracticeViewModel>("Session");
                gamePanel.Visibility = Visibility.Visible;
                return;
            }

            // TODO: Doesn't download terms from API if not cached
            var sets = ((from setID in this.GetIDListParameter<long>("sets", required: false)
                         select App.ViewModel.GetSet(setID, true))
                .Concat(from g in this.GetIDListParameter<long>("groups", required: false).Select(App.ViewModel.GetGroup)
                        where g != null
                        from set in g.Sets
                        select set)).ToArray();

            foreach (var set in sets)
                set.LoadTerms();

            TryDownloadTerms(sets);
        }
Example #5
0
 void EndSession(object sender, EventArgs e)
 {
     session = null;
     NavigationService.GoBack();
 }