Esempio n. 1
0
        public ActionResult AlignChapters(int id1, int id2)
        {
            var book1 = db.Books.Find(id1);
            var book2 = db.Books.Find(id2);
            TwinBook tb = new TwinBook()
                {
                    Book1 = book1,
                    Book2 = book2
                };
            try
            {
                tb = db.TwinBooks.Single(t => t.Book1.Id == id1 && t.Book2.Id == id2);
            }
            catch (Exception e)
            {
                tb = new TwinBook()
                {
                    Book1 = book1,
                    Book2 = book2
                };
                db.TwinBooks.Add(tb);
                db.SaveChanges();
            }

            return View(tb);
        }
Esempio n. 2
0
        public void reactivate(TwinBook tb)
        {
            var bindings = tb.Bookmarks
                .OrderByDescending(r => r.CreatedAt).ToList();
            for (int i = 0; i < bindings.Count; i++ )
            {

                var b = bindings.ElementAt(i);
                tb.Bookmarks.Single(r => r.Id == b.Id).Active = true;
                var affected = tb.Bookmarks.Where(r => ((r.Bookmark1.Order - b.Bookmark1.Order) * (r.Bookmark2.Order - b.Bookmark2.Order) <= 0)
                    && ((r.CreatedAt < b.CreatedAt && r.Type == b.Type) || r.Type < b.Type));
                foreach (var a in affected)
                {
                    a.Active = false;
                }
                bindings.RemoveAll(r => ((r.Bookmark1.Order - b.Bookmark1.Order) * (r.Bookmark2.Order - b.Bookmark2.Order) <= 0)
                    && (r.CreatedAt < b.CreatedAt));
            }
        }
Esempio n. 3
0
        public static string CreateTweenBook(TwinBook tb)
        {
            Book book1 = tb.Book1;
            Book book2 = tb.Book2;
            List<ChapterBinding> chapters = tb.Chapters.ToList();
            string path = "~/App_Data/TwinBooks/" + book1.Id + "-" + book2.Id + ".html";
            //if (System.IO.File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(path))) return path;
            HtmlDocument doc = new HtmlDocument();
            doc.Load(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/TwinBooks/twin_template.html"));
            var left = doc.DocumentNode.SelectSingleNode("//body//*[@class='left-twin']");
            var chapters1 = getBindedChapters(chapters, book1, book2);
            left.InnerHtml = (ExtractChapters(book1, chapters1));
            var right = doc.DocumentNode.SelectSingleNode("//body//*[@class='right-twin']");
            var chapters2 = getBindedChapters(chapters, book2, book1);
            right.InnerHtml = (ExtractChapters(book2, chapters2));

            doc.Save(System.Web.Hosting.HostingEnvironment.MapPath(path));
            return path;
        }
Esempio n. 4
0
        public static List<BookmarkBinding> AlignByChapters(TwinBook tb)
        {
            Book book1 = tb.Book1;
            Book book2 = tb.Book2;
            string path = tb.Path;
            HtmlDocument doc = new HtmlDocument();
            doc.Load(System.Web.Hosting.HostingEnvironment.MapPath(path));
            var left = doc.DocumentNode.SelectSingleNode("//body//*[@class='left-twin']");
            var right = doc.DocumentNode.SelectSingleNode("//body//*[@class='right-twin']");

            var bindings = new List<BookmarkBinding>();

            int count = 0;
            var chapters2 = SelectChapters(right);
            foreach (HtmlNode chapter1 in SelectChapters(left))
            {
                var raw = AlignChunks(chapter1.InnerHtml, chapters2.ElementAt(count).InnerHtml);

                foreach (var b in raw)
                {
                    Bookmark bm1 = book1.Bookmarks.Single(r => r.BookmarkId == b.Bookmark1.BookmarkId);
                    Bookmark bm2 = book2.Bookmarks.Single(r => r.BookmarkId == b.Bookmark2.BookmarkId);
                    BookmarkBinding bm = new BookmarkBinding()
                    {
                        Bookmark1 = bm1,
                        Bookmark2 = bm2,
                        Type = 0
                    };
                    bindings.Add(bm);

                }
                count++;
            }

            return bindings;
        }