Exemplo n.º 1
0
        void PostNewProgress(Book book)
        {
            //StorageSettings settings = new StorageSettings();
            //Dictionary<string, object> parameters = new Dictionary<string, object>();
            //parameters.Add("UserName", settings.FacebookUserName);
            //parameters.Add("Isbn", book.VolumeInfo.Isbn);
            //parameters.Add("GoogleBookId", book.Id);
            //parameters.Add("IsFinished", false);

            //PostClient client = new PostClient(parameters);
            //client.DownloadStringCompleted += (sender, e) =>
            //{
            //    if (e.Error == null)
            //    {
            //        //Process the result...
            //        string data = e.Result;
            //    }
            //    else
            //    {
            //        MessageBox.Show("Service is not available. Try it later.");
            //    }
            //};
            //client.DownloadStringAsync(new Uri(ReadgressAPIEndpoints.ProgressUrl, UriKind.Absolute), settings.FacebookAccessToken);
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
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;
            }
        }