コード例 #1
0
ファイル: Practice.xaml.cs プロジェクト: aata/flashcards-wp7
        public Practice()
        {
            InitializeComponent();

            session = new PracticeViewModel();

            isNewInstance = true;
            Loaded += OnLoaded;
        }
コード例 #2
0
ファイル: Practice.xaml.cs プロジェクト: aata/flashcards-wp7
        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);
        }
コード例 #3
0
ファイル: Guess.xaml.cs プロジェクト: aata/flashcards-wp7
        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);
        }
コード例 #4
0
ファイル: Practice.xaml.cs プロジェクト: aata/flashcards-wp7
        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);
        }
コード例 #5
0
ファイル: Practice.xaml.cs プロジェクト: aata/flashcards-wp7
 void EndSession(object sender, EventArgs e)
 {
     session = null;
     NavigationService.GoBack();
 }