Пример #1
0
        private void btnBookmark_Click(object sender, EventArgs e)
        {
            myBm.AddPageNum(comReader.GetCurrentPageNumber());
            RefreshBookmarks();

            //write changes
            loggedInUser.MyComicLibrary.RemoveComicBook(myCb.GetArchivePath());
            myCb.BookMark = myBm;
            loggedInUser.MyComicLibrary.AddComicBook(myCb);
            accountManager.WriteComicLibrary(loggedInUser.Id, loggedInUser.MyComicLibrary);
        }
Пример #2
0
        /// <summary>
        /// reads all the User accounts from the accounts XML file, including their comic libraries
        /// </summary>
        /// <returns>
        /// array of User objects
        /// </returns>
        public new User[] ReadAllUserAccounts()
        {
            if (PathIsValid())
            {
                XDocument xDocument = XDocument.Load(filePath);
                userList = new User[UserCount];
                int index = 0;

                foreach (XElement account in xDocument.Descendants("Account"))
                {
                    //get required elements
                    XElement id_element          = account.Element("ID");
                    XElement username_element    = account.Element("Username");
                    XElement password_element    = account.Element("Password");
                    XElement libraryHead_element = account.Element("MyComicLibrary");

                    //check if id does not have 1000 as its first 4 digits
                    //the 1000 indicates an admin, any other will be a user
                    if (id_element.Value.Substring(0, 4) != "1000")
                    {
                        userList[index] = new User(Convert.ToInt32(id_element.Value));
                        {
                            userList[index].Username = username_element.Value;
                            userList[index].Password = password_element.Value;

                            ComicLibrary cbLib = new ComicLibrary();
                            //check foreach book imported in library
                            if (libraryHead_element != null &&
                                libraryHead_element.Descendants("MySavedComicBook") != null)
                            {
                                foreach (var savedCb_element in libraryHead_element.Descendants("MySavedComicBook"))
                                {
                                    //get all required elements for this saved comic book
                                    XElement archivePath_element = savedCb_element.Element("ArchivePath");
                                    XElement bookMark_element    = savedCb_element.Element("Bookmark");
                                    XElement lastViewed_element  = savedCb_element.Element("Last_Viewed");
                                    XElement rating_element      = savedCb_element.Element("MyRating");

                                    //set all required data
                                    //set all required data : use ComicAccess to get ComicBook instance of archivePath
                                    ComicAccess ca        = new ComicAccess();
                                    ComicBook   public_cb = ca.GetComicBook(archivePath_element.Value);
                                    //obtained ComicBook is common to all, get the ComicBook for this user
                                    UserComicBook private_cb = UserComicBook.MorphToUserComicBook(public_cb);
                                    private_cb.LastViewed = DateTime.Parse(lastViewed_element.Value);
                                    private_cb.RateComicBook(float.Parse(rating_element.Value));

                                    //get all required elements : get bookmark for this saved comic book
                                    XElement bookMark_maxPages_element = bookMark_element.Element("MaxPages");
                                    XElement bookmark_pageNum_element  = bookMark_element.Element("PageNum");
                                    Bookmark bm = new Bookmark(int.Parse(bookMark_maxPages_element.Value));
                                    //check if there are any bookmarked pages
                                    if (bookmark_pageNum_element.Value != "")
                                    {
                                        foreach (var pageNum in bookmark_pageNum_element.Value.Split(','))
                                        {
                                            bm.AddPageNum(int.Parse(pageNum));
                                        }
                                    }
                                    //set bookmark to user's saved comic book
                                    private_cb.BookMark = bm;

                                    //add user's saved comic book to user's comic library
                                    cbLib.AddComicBook(private_cb);
                                }
                                userList[index].MyComicLibrary = cbLib;
                            }
                            index++;
                        }
                    }
                }
                return(userList);
            }
            else
            {
                Trace.WriteLine("Set Path = " + "<" + filePath + ">" + " is invalid, cannot proceed with account access.");
                FileNotFoundException exc = new FileNotFoundException
                                            (
                    "Set Path = " + "<" + filePath + ">" + " is invalid, cannot proceed with account access."
                                            );
                throw exc;
            }
        }