Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var root           = Directory.Exists(@"D:\books\google_drive\books") ? @"D:\books\google_drive\books": ".";
            var properFilePath = Path.Combine(root, "MoonReader", "proper.txt");
            var properPaths    = CommonUtils.Utils.ReadLines(properFilePath);

            if (args.Length > 0 && Directory.Exists(args[0]))
            {
                root = args[0];
            }
            Console.WriteLine($"Loading files in {root} folder...");
            var          paths = Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories).Where(path => path.EndsWith(".fb2") || path.EndsWith(".epub")).ToList();
            List <Book2> books = new List <Book2>();

            foreach (var path in paths)
            {
                //пропускаем
                if (properPaths.Contains(path))
                {
                    continue;
                }
                Book2 book = path.EndsWith(".fb2") ? LoadFb2(path) : LoadEpub(path);
                if (book != null)
                {
                    books.Add(book);
                }
            }
            Console.WriteLine($"{books.Count} files loaded");
            var log     = new List <string>();
            var counter = 0;

            foreach (var book in books)
            {
                if (book.Path == book.ProperPath && !properPaths.Contains(book.ProperPath))
                {
                    properPaths.Add(book.ProperPath);
                }
                if (book.Path != book.ProperPath && !File.Exists(book.ProperPath))
                {
                    try
                    {
                        File.Move(book.Path, book.ProperPath);
                        counter++;
                        Console.WriteLine($"File '{Path.GetFileName(book.Path)} renamed to '{book.ProperFileName}.");
                        log.Add($"File '{Path.GetFileName(book.Path)} renamed to '{book.ProperFileName}.");
                        properPaths.Add(book.ProperPath);
                    } catch (Exception e)
                    {
                        log.Add($"ERROR: '{Path.GetFileName(book.Path)} could not rename to '{book.ProperFileName}: {e.Message}");
                        continue;
                    }
                }
            }
            File.WriteAllLines("log.txt", log);
            File.WriteAllLines(properFilePath, properPaths);
            Console.WriteLine($"{counter} books successfully renamed. OK!");
            Console.ReadLine();
        }
        public void SetActiveBook(QuestionBook book)
        {
            var idx = Books.IndexOf(book);

            Book1.SetQuestionBook(Books[idx - 2 < 0 ? Books.Count + idx - 2 : idx - 2]);
            Book2.SetQuestionBook(Books[idx - 1 < 0 ? Books.Count + idx - 1 : idx - 1]);
            Book3.SetQuestionBook(book);
            Book4.SetQuestionBook(Books[(idx + 1) % Books.Count]);
            Book5.SetQuestionBook(Books[(idx + 2) % Books.Count]);
        }
Exemplo n.º 3
0
        private void OnItemSelected(object sender, ItemTappedEventArgs e)
        {
            Book2  book      = (Book2)RankListView.SelectedItem;
            string Name      = book.Name;
            string author    = book.Author;
            string item      = book.ItemCaption;
            string sale      = book.SalesDate;
            string publisher = book.Publisher;
            double Value     = book.Value;
            string VI        = book.ValueImage;
            string IU        = book.ImageURL;


            Navigation.PushAsync(new SeekDetailPage(Name, author, sale, publisher, item, Value, VI, IU));
        }
Exemplo n.º 4
0
        public void printStructInfo()
        {
            Books Book1;        /* 声明 Book1,类型为 Book */
            Books Book2;        /* 声明 Book2,类型为 Book */

            /* book 1 详述 */
            Book1.title   = "C Programming";
            Book1.author  = "Nuha Ali";
            Book1.subject = "C Programming Tutorial";
            Book1.book_id = 6495407;

            /* book 2 详述 */
            Book2.title   = "Telecom Billing";
            Book2.author  = "Zara Ali";
            Book2.subject = "Telecom Billing Tutorial";
            Book2.book_id = 6495700;

            /* 打印 Book1 信息 */
            Console.WriteLine("Book 1 title : {0}", Book1.title);
            Console.WriteLine("Book 1 author : {0}", Book1.author);
            Console.WriteLine("Book 1 subject : {0}", Book1.subject);
            Console.WriteLine("Book 1 book_id :{0}", Book1.book_id);

            /* 打印 Book2 信息 */
            Console.WriteLine("Book 2 title : {0}", Book2.title);
            Console.WriteLine("Book 2 author : {0}", Book2.author);
            Console.WriteLine("Book 2 subject : {0}", Book2.subject);
            Console.WriteLine("Book 2 book_id : {0}", Book2.book_id);

//             Books Book1 = new Books(); /* 声明 Book1,类型为 Book */
//             Books Book2 = new Books(); /* 声明 Book2,类型为 Book */

            /* book 1 详述 */
            Book1.getValues("C Programming",
                            "Nuha Ali", "C Programming Tutorial", 6495407);

            /* book 2 详述 */
            Book2.getValues("Telecom Billing",
                            "Zara Ali", "Telecom Billing Tutorial", 6495700);

            /* 打印 Book1 信息 */
            Book1.display();

            /* 打印 Book2 信息 */
            Book2.display();
        }
Exemplo n.º 5
0
    static void Main(string[] args)
    {
        var Library = new Library();

        Library.Dictionary = new SortedDictionary <string, DateTime>();

        int numberOfInputs = int.Parse(Console.ReadLine());

        for (int i = 0; i < numberOfInputs; i++)
        {
            var input = Console.ReadLine()
                        .Split(' ')
                        .ToArray();

            string   title     = input[0];
            DateTime published = DateTime.ParseExact(input[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);

            var Book = new Book2();
            Book.Title           = title;
            Book.PublicationDate = published;

            Library.Dictionary[title] = published;
        }

        string cutOffAsString = Console.ReadLine();
        var    cutOffDate     = DateTime.ParseExact(cutOffAsString, "dd.MM.yyyy", CultureInfo.InvariantCulture);

        var dictOfAfterCutOff = new Dictionary <string, DateTime>(); // temptDict

        foreach (var currentBook in Library.Dictionary)
        {
            bool releasedBeforeCutOff = currentBook.Value <= cutOffDate;
            if (releasedBeforeCutOff == false)
            {
                dictOfAfterCutOff[currentBook.Key] = currentBook.Value;
            }
        }

        var resultDict = dictOfAfterCutOff.OrderBy(date => date.Value).ThenBy(title => title.Key);

        foreach (var book in resultDict)
        {
            Console.WriteLine($"{book.Key} -> {book.Value:dd.MM.yyyy}");
        }
    }
Exemplo n.º 6
0
 static Book2 LoadEpub(string path)
 {
     try
     {
         EpubBook epub = EpubReader.Read(path);
         var      book = new Book2
         {
             Authors = string.Join(", ", epub.Authors.ToArray()),
             Title   = epub.Title,
             Path    = path
         };
         return(book);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 7
0
 static Book2 LoadFb2(string path)
 {
     try
     {
         FB2File fb2  = (new FB2Reader()).ReadFromFile(path);
         var     book = new Book2
         {
             Authors = string.Join(", ", fb2.TitleInfo.BookAuthors.Select(s => s.FirstName.Text + " " + s.LastName.Text).ToArray()),
             Title   = fb2.TitleInfo.BookTitle.Text,
             Path    = path
         };
         return(book);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 8
0
        public void GetCostOfBasketForMultipleItems()
        {
            var bk1 = new Book1();

            Basket.Instance.AddItemToBasket(bk1);
            Basket.Instance.AddItemToBasket(bk1); // Book not eligible for discount

            var bk2 = new Book2();

            Basket.Instance.AddItemToBasket(bk2);

            // 2 books eligiable for discount
            // 2 * 8 = £16 * 0.95 = £15.2

            // 1 book not eligible for discount
            // 1 * 8 = £8

            // Total Cost: £15.2 + £8 = £23.2
            Assert.AreEqual(23.2, Basket.Instance.TotalCost);
        }
Exemplo n.º 9
0
        public void AddMultipleItemsToBasket()
        {
            var bk1 = new Book1();

            Basket.Instance.AddItemToBasket(bk1);
            Basket.Instance.AddItemToBasket(bk1);

            var bk2 = new Book2();

            Basket.Instance.AddItemToBasket(bk2);

            var cart = Basket.Instance.Items;

            Assert.AreEqual(2, cart.Count); // 2 unique records in the cart

            Assert.IsTrue(cart.TryGetValue(bk1.ProductCode, out Stack <IStockItem> bk1Count));
            Assert.AreEqual(2, bk1Count.Count); // x2 of book1

            Assert.IsTrue(cart.TryGetValue(bk2.ProductCode, out Stack <IStockItem> bk2Count));
            Assert.AreEqual(1, bk2Count.Count); // x1 of book2
        }
        static void Main(string[] args)
        {
            //var books = new List<Book>
            //{
            //    new Book("The Little Prince", "Exupery", 1943),
            //    new Book("The Master and Margarita", "Bulgakov", 1967),
            //};
            //XmlSerializer xmlSerializer = new XmlSerializer(books.GetType());
            //using var writer = new StreamWriter("books_new.xml");
            //xmlSerializer.Serialize(writer, books);

            XmlSerializer booksSerializer = new XmlSerializer(typeof(List <Book>), new XmlRootAttribute("books"));

            using var reader = new StreamReader("Data/book_modified3.xml");
            var books  = (List <Book>)booksSerializer.Deserialize(reader);
            var books2 = new List <Book2>();

            foreach (var item in books)
            {
                Console.WriteLine(item);
                var book = new Book2 {
                    Author = item.Author, Name = item.Name, Page = item.Page
                };
                books2.Add(book);
            }

            XmlSerializer booksSerializer2 = new XmlSerializer(typeof(List <Book2>), new XmlRootAttribute("books"));

            using var writer = new StreamWriter("Data/book_modified4.xml");
            booksSerializer2.Serialize(writer, books2);

            //var settings = new XDocument();
            //settings.Add(new XElement("books",
            //    new XElement("book",
            //        new XElement("title", "The Little Prince"),
            //        new XElement("author", "Exupery")),
            //    new XElement("book",
            //        new XElement("title", "The Master and Margarita"),
            //        new XElement("author", "Bulgakov"))));

            //settings.Save("book.xml",SaveOptions.DisableFormatting);

            //var settings = new XDocument();
            //settings.Add(new XElement("settings",
            //    new XAttribute("lang", "bg-bg"),
            //    new XElement("XPosition",
            //        new XElement("X1",123),
            //        new XElement("X2","321")),
            //    new XElement("YPosition", 321)));

            //settings.Save("settings.xml");


            //document.Declaration.Version = "3.0";
            //document.Root.Add(new XElement("car", new XElement("make", "Audi")));
            //document.Save("Data/Library_updated.xml");

            //var root = document.Root;
            //document.Root.SetAttributeValue("count", "500");

            //var books = root.Elements().Where(x => x.Element("BookPage").Value == "300").Select(x => new Book
            //{
            //    Name = x.Element("BookName").Value,
            //    Author = x.Element("BookAuthor").Value,
            //    Page = int.Parse(x.Element("BookPage").Value)
            //}).Where(x => x.Page > 300);

            //Console.WriteLine(root.Attribute("address").Value);
            //Console.WriteLine(root.Attribute("count").Value);


            //var books = root.Elements();
            //root.RemoveAll();

            //foreach (var item in books)
            //{
            //    var bookObject = new Book
            //    {
            //        Name = item.Element("BookName").Value,
            //        Author = item.Element("BookAuthor").Value,
            //        Page = int.Parse(item.Element("BookPage").Value)
            //    }
            //};
            //Console.WriteLine($"{item.Element("BookName").Value}: {item.Element("BookAuthor").Value}: {item.Element("BookPage").Value}");
            //Console.WriteLine($"{bookObject.Author}: {bookObject.Name}: {bookObject.Page}");

            //item.Element("BookPage").Value = "Ghjjjk";

            //item.RemoveAll();


            //document.Save("Data/book_modified.xml");
        }