public MainWindow() { InitializeComponent(); DB.Init(); string path = DB.GetPathToLibrary(); string[] arrFiles; List <string> badFiles = new List <string>(); if (Directory.Exists(path)) { arrFiles = Directory.GetFiles(path, "*.fb2", SearchOption.AllDirectories); //List<AllBook> lstAll = new List<AllBook>(); List <ReadFb2> lstReadfb2 = new List <ReadFb2>(); foreach (string name in arrFiles) { //string pathFile = @"D:\Книги\Experiments.fb2"; //ReadWriteFb2.SaveBookToDB(name); //lstAll.Add(XmlFiles.GetFieldFromFile(name)); //lstBooks.Add(ReadFb2.SaveBookToDB(name)); lstReadfb2.Add(new ReadFb2(name), badFiles); } //DB.SaveListData(lstAll); } //XmlDocument doc = new XmlDocument(); //doc.Load(pathFile); //XmlElement root = doc.DocumentElement; //XmlNode node = root.SelectSingleNode("/FictionBook/description"); //foreach (XmlElement child in root) //{ // var s = child.InnerXml; //} //XmlSerializer ser = new XmlSerializer(typeof(FictionBook)); //FictionBook fictionBook; //using (XmlReader reader = XmlReader.Create(pathFile)) //{ // fictionBook = (FictionBook)ser.Deserialize(reader); //} //var description = fictionBook.description; }
private void CreateLibrary0() { string path = DB.GetPathToLibrary(); string[] arrFiles; if (Directory.Exists(path)) { arrFiles = Directory.GetFiles(path, "*.fb2", SearchOption.AllDirectories); foreach (string name in arrFiles) { ReadWriteFB2 rw = new ReadWriteFB2(); rw.GetFieldFromFile(name); //XmlSerializer serializer = new XmlSerializer(typeof(Description), "xmlns"); //FileStream fs = new FileStream(name, FileMode.Open); //Description m0 = (Description)serializer.Deserialize(fs); //Parse p = new Parse(name); } } }
//private void serNamespace(string nSpace) //{ // xmlns.Add("", ); //} private static void CreateLibrary123() { string path = DB.GetPathToLibrary(); string[] arrFiles; if (Directory.Exists(path)) { arrFiles = Directory.GetFiles(path, "*.fb2", SearchOption.AllDirectories); List<Book> books = new List<Book>(); List<Document> documents = new List<Document>(); List<BookGenre> bookGenres = new List<BookGenre>(); List<BookWriter> bookWriters = new List<BookWriter>(); List<DocumentAuthor> documentAuthors = new List<DocumentAuthor>(); List<BookTranslator> bookTranslators = new List<BookTranslator>(); List<Parse> parses = new List<Parse>(); List<int> ids = new List<int>(); foreach (string name in arrFiles) { using (StreamReader fs = new StreamReader(name)) { string readText = fs.ReadToEnd(); Parse parse = new Parse(readText); Book book = new Book() { Book_title = parse.ti_book_title, Annotation = parse.ti_annotation, Date_write = parse.ti_date, Coverpage = parse.ti_coverpage, Book_name = parse.pi_book_name, Publisher = parse.pi_publisher, City = parse.pi_city, Year = parse.pi_year, ID_Language = DB.GetIDLanguage(parse.ti_lang), ID_LanguageAfterTranslate = DB.GetIDLanguage(parse.ti_src_lang) }; books.Add(book); //int idBook = DB.SaveData(book); Document document = new Document() { Path = name, UniqID = parse.di_id, Program_used = parse.di_program_used, Date_create_document = parse.di_date, Src_ocr = parse.di_src_ocr, Version = parse.di_version, History = parse.di_history, //ID_Book = idBook }; documents.Add(document); foreach (var item in parse.ti_genre) { int idGenre = DB.GetIDGenre(item); BookGenre bookGenre = new BookGenre() { ID_Genre = idGenre, //ID_Book = idBook }; bookGenres.Add(bookGenre); } foreach (var item in parse.ti_writer) { //int idWriter = DB.SaveData(item); BookWriter bookWriter = new BookWriter() { //ID_Writer //ID_Book }; bookWriters.Add(bookWriter); } foreach (var item in parse.di_author) { //int idWriter = DB.SaveData(item); DocumentAuthor documentAuthor = new DocumentAuthor() { //ID_Writer //ID_Book }; documentAuthors.Add(documentAuthor); } foreach (var item in parse.ti_translator) { //int idWriter = DB.SaveData(item); BookTranslator bookTranslator = new BookTranslator() { //ID_Writer //ID_Book }; bookTranslators.Add(bookTranslator); } BookSequence bookSequence = new BookSequence() { //ID_Sequence //ID_Book //Number_in_sequence }; Keyword keyword = new Keyword() { //ID_Document //Word }; foreach (var value in parse.ti_sequence) { Sequence sequence = new Sequence() { Name = value }; } Src_urls src_urls = new Src_urls() { //ID_Book //Url }; } } //1 этап //foreach (string name in arrFiles) //{ // //Encoding encoding = null; // //using (StreamReader sr = new StreamReader(name, true)) // //{ // // encoding = sr.CurrentEncoding; // //} // //List<string> lstStr = new List<string>(); // XmlReader reader = new XmlReader(name); // while (reader.Read()) // { // switch (reader.NodeType) // { // case XmlNodeType.Element: // Узел является элементом. // lstStr.Add("<" + reader.Name + ">"); // break; // case XmlNodeType.Text: // Вывести текст в каждом элементе. // lstStr.Add(reader.Value); // break; // case XmlNodeType.EndElement: // Вывести конец элемента. // lstStr.Add("</" + reader.Name + ">"); // break; // } // } // //using (StreamReader fs = new StreamReader(name, Encoding.Default)) // //{ // // string readText = fs.ReadToEnd(); // // Parse parse = new Parse(readText); // // Book book = new Book() // // { // // Book_title = parse.ti_book_title, // // Annotation = parse.ti_annotation, // // Date_write = parse.ti_date, // // Coverpage = parse.ti_coverpage, // // Book_name = parse.pi_book_name, // // Publisher = parse.pi_publisher, // // City = parse.pi_city, // // Year = parse.pi_year, // // ID_Language = DB.GetIDLanguage(parse.ti_lang), // // ID_LanguageAfterTranslate = DB.GetIDLanguage(parse.ti_src_lang) // // }; // // books.Add(book); // // parses.Add(parse); // //} //} //ids = DB.SaveListData(books); //int a = ids.Count; //int b = parses.Count; } }