Exemplo n.º 1
0
        public static async Task<ObservableCollection<Book>> GetBooks()
        {
            ObservableCollection<Book> books = new ObservableCollection<Book>();

			try
			{
				// Get the file.
				StorageFolder booksFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
				var file = await booksFolder.GetFileAsync("BooksList.txt");

				IList<string> lines = await Windows.Storage.FileIO.ReadLinesAsync(file);

				foreach (var l in lines)
				{
					Book book = new Book();

					var details = l.Split(':');

					book.Name = details[0];
					book.FileName = details[1];
					book.Cover = @"/BookCovers/" + details[2];

					books.Add(book);
				}

				return books;
			}
			catch (Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.Message);
				throw ex;
			}
			
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
			ObservableCollection<Dialogue> dialogues = new ObservableCollection<Dialogue>();

			b = e.Parameter as Book;

			try
			{
				dialogues = await Classic.Load(b.FileName);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine("Error loading book: " + ex.Message);

				this.Frame.GoBack();
			}

			txtTitle.Text = b.Name;
            Dialogues.DataContext = dialogues;

            //Dialogues.UpdateLayout();

            string bookmark = Classic.GetBookmark(b.FileName);
            if(!string.IsNullOrEmpty(bookmark))
            {
                Dialogue d = dialogues.Where(x => x.Line == bookmark).SingleOrDefault();

                if(d != null)
                    Dialogues.ScrollIntoView(d);
            }
                
            
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            b = e.Parameter as Book;
            ObservableCollection<Dialogue> dialogues = await Classic.Load(b.FileName);
			
			if(dialogues == null)
			{
				MessageDialog md = new MessageDialog("Error loading book.");
				await md.ShowAsync();

				return;
			}

            Dialogues.DataContext = dialogues;

            Dialogues.UpdateLayout();

            string bookmark = Classic.GetBookmark(b.FileName);
            if (!string.IsNullOrEmpty(bookmark))
            {
                Dialogue d = dialogues.Where(x => x.Line == bookmark).SingleOrDefault();

                if (d != null)
                    Dialogues.ScrollIntoView(d);
            }
            
        }