Ejemplo n.º 1
0
        private void LoginSucceded(FacebookOAuthResult oauthResult)
        {
            var fb = new FacebookClient(oauthResult.AccessToken);

            fb.GetCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                    return;
                }
                var result = (IDictionary<string, object>)e.GetResultData();

                StorageSettings settings = new StorageSettings();
                settings.FacebookAccessToken = oauthResult.AccessToken;
                settings.FacebookAccessTokenExpires = oauthResult.Expires;
                settings.FacebookUserName = result["username"].ToString();

                SaveNewUserToXmlFile(result["username"].ToString());

                Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)));
            };

            fb.GetAsync("me");
        }
Ejemplo n.º 2
0
        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            StorageSettings settings = new StorageSettings();

            if (string.IsNullOrEmpty(settings.FacebookAccessToken))
            {
                NavigationService.Navigate(new Uri("/WelcomePage.xaml", UriKind.Relative));
            }

            else
            {
                if (App.BookViewModel.IsDataLoading)
                {
                    App.BookViewModel.LoadData();
                }

                string itemIndex;
                if (NavigationContext.QueryString.TryGetValue("goto", out itemIndex))
                {
                    ReadgressPanorama.DefaultItem = ReadgressPanorama.Items[Convert.ToInt32(itemIndex)];
                }
            }
        }
Ejemplo n.º 3
0
        public void LoadData()
        {
            StorageSettings settings = new StorageSettings();

            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = storage.OpenFile(App.LocalStorageFile, FileMode.Open, FileAccess.Read))
                {
                    XDocument doc = XDocument.Load(stream);
                    var progresses = doc.Descendants("Progress").Where(
                         e => e.Attribute("UserName").Value == settings.FacebookUserName);
                    if (progresses != null)
                    {
                        int index = 0;
                        foreach (var progress in progresses)
                        {
                            bool isFinished = Convert.ToBoolean(progress.Element("IsFinished").Value);
                            var book = new Book
                            {
                                Id = progress.Element("GoogleBookId").Value,
                                VolumeInfo = new VolumeInfo
                                {
                                    Title = progress.Element("Title").Value,
                                    SubTitle = progress.Element("SubTitle").Value,
                                    Authors = progress.Element("Authors").Value.Split(new char[] { ',' }).ToList(),
                                    IsFinished = isFinished,
                                    ImageLinks = new ImageLinks { SmallThumbnail = progress.Element("CoverMedium").Value.Replace("&zoom=1", "&zoom=5") },
                                    IndustryIdentifiers = new List<IndustryIdentifiers>() { new IndustryIdentifiers { Type = "ISBN_10", identifier = progress.Attribute("Isbn").Value } }
                                }
                            };
                            if (isFinished)
                            {
                                FinishedBooks.Add(book);
                            }
                            else
                            {
                                //if (index < 3)
                                //{
                                //    FirstThreeReadingBooks.Add(book);
                                //}
                                //else if (index < 6)
                                //{
                                //    SecondThreeReadingBooks.Add(book);
                                //}
                                ReadingBooks.Add(book);
                                index++;
                            }
                        }
                    }
                    this.hasNoFinishedBook = FinishedBooks.Count == 0;
                    this.hasNoReadingBook = ReadingBooks.Count == 0;
                    this.hasTooManyReadingBooks = ReadingBooks.Count > 6;
                }

                this.isDataLoading = false;
            }
        }
Ejemplo n.º 4
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (PageNumberTB.Text == hintText || string.IsNullOrEmpty(PageNumberTB.Text) || PageNumberTB.Text.Contains("."))
            {
                MessageBox.Show("page number must be an integer");
            }
            else
            {
                int pageNumber = Convert.ToInt32(this.PageNumberTB.Text);
                DateTime createdOn = Convert.ToDateTime(this.When.Value);

                bool xmlChanged = false;

                StorageSettings settings = new StorageSettings();

                using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    XDocument doc = null;
                    using (IsolatedStorageFileStream stream = storage.OpenFile(App.LocalStorageFile, FileMode.Open, FileAccess.Read))
                    {
                        doc = XDocument.Load(stream);
                        var existingBook = doc.Descendants("Progress").Where(
                             elm => elm.Attribute("UserName").Value == settings.FacebookUserName && elm.Attribute("Isbn").Value == isbn).FirstOrDefault();

                        if (existingBook != null)
                        {
                            if (!string.IsNullOrEmpty(lastPage))
                            {
                                existingBook.Element("IsFinished").SetValue(true);
                                var book = App.BookViewModel.ReadingBooks.Where(b => b.VolumeInfo.Isbn == isbn).First();
                                App.BookViewModel.ReadingBooks.Remove(book);
                                App.BookViewModel.FinishedBooks.Add(book);
                                App.BookViewModel.HasNoFinishedBook = false;
                                App.BookViewModel.HasNoReadingBook = App.BookViewModel.ReadingBooks.Count == 0;
                                App.ProgressViewModel.Progress.IsFinished = true;
                                NavigationService.Navigate(new Uri("/MainPage.xaml?goto=1", UriKind.Relative));
                            }
                            XElement bookmarkElm = new XElement("Bookmark",
                                new XElement("PageNumber", pageNumber),
                                new XElement("CreatedOn", createdOn));

                            XElement bookmarks = existingBook.Element("Bookmarks");
                            bookmarks.Add(bookmarkElm);
                            xmlChanged = true;
                            App.ProgressViewModel.Bookmarks.Insert(0, new Bookmark { CreatedOn = createdOn, PageNumber = pageNumber });
                            App.ProgressViewModel.HasNoBookmark = false;
                        }

                    }

                    if (doc != null && xmlChanged)
                    {
                        using (IsolatedStorageFileStream stream = storage.OpenFile(App.LocalStorageFile, FileMode.Open, FileAccess.Write))
                        {
                            doc.Save(stream);
                        }
                    }

                    NavigationService.GoBack();
                }

            }
        }
Ejemplo n.º 5
0
        void AddNewProgress(Book book)
        {
            StorageSettings settings = new StorageSettings();
            bool xmlChanged = false;

            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                XDocument doc = null;
                using (IsolatedStorageFileStream stream = storage.OpenFile(App.LocalStorageFile, FileMode.Open, FileAccess.Read))
                {
                    doc = XDocument.Load(stream);
                    var existingBook = doc.Descendants("Progress").Where(
                         e => e.Attribute("UserName").Value == settings.FacebookUserName && e.Attribute("Isbn").Value == book.VolumeInfo.Isbn).FirstOrDefault();
                    if (existingBook == null)
                    {
                        XElement progressElm = new XElement("Progress",
                            new XAttribute("UserName", settings.FacebookUserName),
                            new XAttribute("Isbn", book.VolumeInfo.Isbn),
                            new XElement("GoogleBookId", book.Id),
                            new XElement("Title", book.VolumeInfo.Title),
                            new XElement("SubTitle", book.VolumeInfo.SubTitle),
                            new XElement("Authors", book.VolumeInfo.AuthorsStr),
                            new XElement("CoverMedium", book.VolumeInfo.Cover_Medium),
                            new XElement("PageCount", book.VolumeInfo.PageCount),
                            new XElement("PublishedDate", book.VolumeInfo.PublishedDate),
                            new XElement("Publisher", book.VolumeInfo.Publisher),
                            new XElement("IsFinished", false),
                            new XElement("Bookmarks"));
                        XElement progresses = doc.Descendants("Progresses").First();
                        progresses.Add(progressElm);
                        if (App.BookViewModel.FirstThreeReadingBooks.Count < 3)
                        {
                            App.BookViewModel.FirstThreeReadingBooks.Add(book);
                        }
                        else if (App.BookViewModel.SecondThreeReadingBooks.Count < 3)
                        {
                            App.BookViewModel.SecondThreeReadingBooks.Add(book);
                        }

                        App.BookViewModel.ReadingBooks.Add(book);
                        App.BookViewModel.HasNoReadingBook = false;
                        xmlChanged = true;
                    }
                    else
                    {
                        doc = null;
                        MessageBox.Show("you have added this book");
                    }

                }

                if (doc != null && xmlChanged)
                {
                    using (IsolatedStorageFileStream stream = storage.OpenFile(App.LocalStorageFile, FileMode.Open, FileAccess.Write))
                    {
                        doc.Save(stream);
                    }
                }

                BookList.IsSelectionEnabled = false;
            }
        }
Ejemplo n.º 6
0
        public void LoadData(string isbn)
        {
            this.progress = new Progress();
            this.Bookmarks.Clear();

            StorageSettings settings = new StorageSettings();

            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = storage.OpenFile(App.LocalStorageFile, FileMode.Open, FileAccess.Read))
                {
                    XDocument doc = XDocument.Load(stream);
                    var progressElm = doc.Descendants("Progress").Where(
                         e => e.Attribute("UserName").Value == settings.FacebookUserName && e.Attribute("Isbn").Value == isbn).FirstOrDefault();
                    if (progressElm != null)
                    {
                        this.progress.UserName = settings.FacebookUserName;
                        this.progress.Isbn = isbn;
                        this.progress.Title = progressElm.Element("Title").Value;
                        this.progress.SubTitle = progressElm.Element("SubTitle").Value;
                        this.progress.Authors = progressElm.Element("Authors").Value;
                        this.progress.GoogleBookId = progressElm.Element("GoogleBookId").Value;
                        this.progress.CoverMedium = progressElm.Element("CoverMedium").Value;
                        this.progress.PublishedDate = Convert.ToDateTime(progressElm.Element("PublishedDate").Value).ToShortDateString();
                        this.progress.Publisher = progressElm.Element("Publisher").Value;
                        this.progress.PageCount = Convert.ToInt32(progressElm.Element("PageCount").Value);
                        this.progress.IsFinished = Convert.ToBoolean(progressElm.Element("IsFinished").Value);

                        this.progress.Bookmarks = new List<Bookmark>();

                        var bookmarkElms = progressElm.Descendants("Bookmark").OrderByDescending(b => (DateTime)b.Element("CreatedOn"));
                        foreach (var bookmarkElm in bookmarkElms)
                        {
                            Bookmark bookmark = new Bookmark();

                            bookmark.CreatedOn = Convert.ToDateTime(bookmarkElm.Element("CreatedOn").Value);
                            bookmark.PageNumber = Convert.ToInt32(bookmarkElm.Element("PageNumber").Value);

                            this.Bookmarks.Add(bookmark);
                        }
                        this.hasNoBookmark = this.Bookmarks.Count == 0;
                    }
                }
            }
            IsDataLoading = false;
        }