public void TreeViewItem_FileFB2_GetInfo() { string str = @"E:\librus_MyHomeLib\Davydov_Moskovit.454563.fb2"; TreeViewItem_FileFB2 item = (TreeViewItem_FileFB2)TreeItemsFactory.GetItem(str); IEnumerable <string> childs = item.GetChilds(); foreach (string child in childs) { Debug.WriteLine(child); } Assert.IsInstanceOfType(childs, typeof(IEnumerable <string>)); }
//private void ProcessUpdateBook(Book book, DBModel db) //{ // bool addBook; // if (book == null) // { // Debug.WriteLine("Failed"); // return; // } // CheckBooksGenres(db, book); // addBook = CheckBooksAuthors(db, book) | CheckBooksKeyWords(db, book) | addDuplicated; // addBook = (!checkUnknown4Duplicated && book.Caption.CompareTo("<Unknown>") == 0) || CheckBookInDB(db, book); // if (addBook) // { // addBook2DB(db, book); // try // { // db.SaveChanges(); // } // catch (DbEntityValidationException ex) // { // Debug.WriteLine(string.IsNullOrEmpty(book.Caption.Trim())); // Debug.WriteLine(" {0} - {1} - {2}", book.Caption, book.Caption.CompareTo("<Unknown>"), addBook); // foreach (var entityValidationErrors in ex.EntityValidationErrors) // { // foreach (var validationError in entityValidationErrors.ValidationErrors) // { // Debug.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); // } // } // throw ex; // } // } //} //private void addBook2DB(DBModel db, Book book) //{ // db.Books.Add(book); //} //private void ProcessUpdateFB2(TreeViewItem_FileFB2 fb2, DBModel db) //{ // bool addBook; // Book book = GetBook(fb2); // if (book == null) // { // Debug.WriteLine(fb2.Name + " : Failed"); // return; // } // lock (lockerZip) // { // CheckBooksGenres(db, book); // addBook = CheckBooksAuthors(db, book) | CheckBooksKeyWords(db, book) | CheckBookInDB(db, book); // //addBook = addBook || CheckBookInDB(db, book); // addBook = (!checkUnknown4Duplicated && book.Caption.CompareTo("<Unknown>") == 0) || CheckBookInDB(db, book); // //Debug.WriteLine("Book: {0} - {1}", book.Caption, addBook); // if (addBook && fb2.State != ItemState.Error) // { // //Debug.WriteLine("Save"); // //book.BookFile = fb2.Byte4Book; // book.Encoding = fb2.Encoding4File; // db.Books.Add(book); // try // { // db.SaveChanges(); // } // catch (DbEntityValidationException ex) // { // Debug.WriteLine(string.IsNullOrEmpty(book.Caption.Trim())); // Debug.WriteLine(" {0} - {1} - {2}", book.Caption, book.Caption.CompareTo("<Unknown>"), addBook); // foreach (var entityValidationErrors in ex.EntityValidationErrors) // { // foreach (var validationError in entityValidationErrors.ValidationErrors) // { // Debug.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); // } // } // throw ex; // } // } // } //} private Book GetBook(TreeViewItem_FileFB2 fb2) { TreeViewItem_Attribute attr; string caption; Book book = new Book() { Caption = "<Unknown>" }; foreach (var i in fb2.GetChilds_Items()) { attr = i as TreeViewItem_Attribute; if (attr != null && attr.Type == ItemType.Attribute) { switch (attr.AttributeType) { case AttributeType.Author: AddAuthor2Book(attr, book); break; case AttributeType.Title: caption = attr.AttributeValue.Trim(); if (string.IsNullOrEmpty(caption) != true) { book.Caption = caption; } break; case AttributeType.GenreFB2: AddGenreFB2Book(attr, book); break; case AttributeType.Genre: AddKeyWords2Book(attr, book); break; default: break; } } } book.Encoding = fb2.Encoding4File; return(book); }
public void TreeViewItem_FileFB2_GetAuthors() { string str = @"E:\librus_MyHomeLib\Davydov_Moskovit.454563.fb2"; TreeViewItem_FileFB2 item = (TreeViewItem_FileFB2)TreeItemsFactory.GetItem(str); Debug.WriteLine("============1============"); var authors = item.GetAuthors(); foreach (ITreeViewItem child in authors) { Debug.WriteLine(child.Name); Debug.WriteLine("========================"); foreach (var itm in child.GetChilds_Items()) { Debug.WriteLine(itm.Name); } Debug.WriteLine("========================"); } Assert.AreEqual(3, authors.Count()); }
public void TreeViewItem_FileFB2_GetChilds_Items() { string str = @"E:\librus_MyHomeLib\Davydov_Moskovit.454563.fb2"; TreeViewItem_FileFB2 item = (TreeViewItem_FileFB2)TreeItemsFactory.GetItem(str); IEnumerable <ITreeViewItem> childs = item.GetChilds_Items(); foreach (ITreeViewItem child in childs) { if (child is TreeViewItem_Attribute) { Debug.WriteLine(((TreeViewItem_Attribute)child).AttributeType); } Debug.WriteLine("========================"); IEnumerable <string> childs1 = child.GetChilds(); foreach (string child1 in childs1) { Debug.WriteLine(child1); } Debug.WriteLine(child.Name); } Assert.IsInstanceOfType(childs, typeof(IEnumerable <ITreeViewItem>)); }