Ejemplo n.º 1
0
        public void Fb2Document_Empty_EqualityTest()
        {
            var emptyFirstDocument = new Fb2Document();

            emptyFirstDocument.Book.Should().BeNull();
            emptyFirstDocument.IsLoaded.Should().BeFalse();

            emptyFirstDocument.Equals(null).Should().BeFalse();

            var emptySecondDocument = new Fb2Document();

            emptySecondDocument.Book.Should().BeNull();
            emptySecondDocument.IsLoaded.Should().BeFalse();

            emptyFirstDocument.Should().Be(emptySecondDocument);

            var emptyCreatedFirstDocument = Fb2Document.CreateDocument();

            emptyCreatedFirstDocument.Book.Should().BeNull();
            emptyCreatedFirstDocument.IsLoaded.Should().BeFalse();

            var emptyCreatedSecondDocument = Fb2Document.CreateDocument();

            emptyCreatedSecondDocument.Book.Should().BeNull();
            emptyCreatedSecondDocument.IsLoaded.Should().BeFalse();

            emptyCreatedFirstDocument.Should().Be(emptyCreatedSecondDocument);

            emptyFirstDocument.Should().Be(emptyCreatedFirstDocument);
        }
Ejemplo n.º 2
0
        public void Fb2Document_CreateWithContent_Test()
        {
            // let's imagine there was real content, right?
            var emptyCreatedFirstDocument = Fb2Document.CreateDocument(new FictionBook());

            emptyCreatedFirstDocument.Book.Should().NotBeNull();
            emptyCreatedFirstDocument.IsLoaded.Should().BeTrue();
        }
        public static bool FindTextInFb2File(string fileFullPath, string text, ref CancellationTokenSource cts)
        {
            try
            {
                using (var fileStream = new FileStream(fileFullPath, FileMode.Open))
                {
                    var document = Fb2Document.CreateDocument();
                    document.Load(fileStream);
                    foreach (var documentBody in document.Bodies)
                    {
                        if (cts.IsCancellationRequested)
                        {
                            break;
                        }

                        foreach (var documentBodyContentNode in documentBody.Content)
                        {
                            if (cts.IsCancellationRequested)
                            {
                                break;
                            }

                            var contentNodeText = Fb2.Document.Extensions.XNodeExtension.GetNodeContent(documentBodyContentNode.ToXml());
                            if (contentNodeText.Contains(text))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public async Task InstancesOfBookAreSame()
        {
            var sampleFileInfo = GetSampleFileInfo(SampleFileName);

            using (var fileReadStream = sampleFileInfo.OpenRead())
            {
                var firstDocument = new Fb2Document();
                await firstDocument.LoadAsync(fileReadStream);

                RewindStream(fileReadStream);

                var secondDocument = Fb2Document.CreateDocument();
                await secondDocument.LoadAsync(fileReadStream);

                firstDocument.Should().Be(secondDocument);

                var firstBook  = firstDocument.Book;
                var secondBook = secondDocument.Book;

                firstBook.Should().Be(secondBook);
                fileReadStream.Close();
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine(GetText());
            Console.ReadKey();

            Fb2Document fb2Document = Fb2Document.CreateDocument();
            var         options     = new ChromeOptions
            {
                //BinaryLocation = @"C:\Program Files\Google\Chrome Beta\Application\chrome.exe"
            };

            options.AddArgument("--log-level=3");
            options.AddArgument("--disable-logging");
            //options.AddArgument("--headless");

            var driver = new ChromeDriver(options)
            {
                Url = "https://author.today/"
            };

            if (!File.Exists("cookies"))
            {
                driver.FindElement(By.LinkText("Войти")).Click();
                input("Войдите в свой аккаунт, и нажмите *ENTER*");
                SaveCookies(driver.Manage().Cookies.AllCookies.ToArray());
            }
            else
            {
                driver.Manage().Cookies.DeleteAllCookies();
                foreach (var cookie in LoadCookies())
                {
                    driver.Manage().Cookies.AddCookie(cookie);
                }
                driver.Navigate().Refresh();
                SaveCookies(driver.Manage().Cookies.AllCookies.ToArray());
            }

            var bookId = input("Введите ссылку на книгу (https://author.today/work/119568)")
                         .Replace("https://", "")
                         .Replace("http://", "")
                         .Split('/')[2]
                         .intParse();

            driver.Navigate().GoToUrl($"https://author.today/reader/{bookId}");
again:
            Thread.Sleep(500);

            var fragments = driver.FindElements(By.XPath("//div[@class='text-container']//p"));

            foreach (var fragment in fragments)
            {
                Console.WriteLine($"{fragment.Text}\r\n");

                var textItem = new TextItem();
                textItem.Load(new XText(fragment.Text));

                var p = new Paragraph();
                p.Content.Add(textItem);

                var section = new BodySection();
                section.Content.Add(p);

                var body = new BookBody();
                body.Content.Add(section);

                fb2Document.Book.Content.Add(body);
            }

            File.WriteAllText("book.fb2", fb2Document.ToXmlString());

            try
            {
                driver.FindElement(By.XPath("//li[@class='next']//span[1]")).Click();
                goto again;
            }
            catch { }

            Console.ReadKey();
            driver.Close();
            driver.Quit();
            Environment.Exit(0);
        }