Пример #1
0
        /// <summary>
        /// Action that generates a partial view for just a comic page. This method is
        /// meant to respond to ajax requests for a comic page.
        /// </summary>
        /// <param name="comic">The name of the comic being viewed. This value must
        /// match a record in the SeqBOok table with a UriContext of the same value.
        /// </param>
        /// <param name="chapter">A chapter number 1..n</param>
        /// <param name="page">A page number 1..n</param>
        /// <returns>A partial view that contains a comic page and navigation
        /// controls.</returns>
        public ActionResult TurnPage(string comic, int chapter, int page)
        {
            //If cookie then extend expires and update the value
            HttpCookie cookie = Request.Cookies.Get(comic + "_bookmark");

            if (cookie != null)
            {
                TimeSpan expirytime = new TimeSpan(120, 0, 0, 0);
                cookie.Expires = DateTime.Today.Add(expirytime);
                cookie.Value   = comic + "|" + chapter + "|" + page;
            }
            Response.Cookies.Add(cookie);
            try
            {
                SeqBook        book     = booksRep.BookUriContext(comic);
                SeqChapter     schapter = booksRep.GetChapter(book, chapter);
                WebComicVModel wcvm     = new WebComicVModel();
                wcvm.BookName         = comic;
                wcvm.ChapterNumber    = chapter;
                wcvm.PageNumber       = (page > schapter.PageCount) ? schapter.PageCount : page;
                wcvm.ChapterPageCount = schapter.PageCount;
                return(PartialView(wcvm));
            }
            catch (BookNotFoundException bnfe)
            {
                return(PartialView("BookNotFound", bnfe));
            }
            catch (ChapterNotFoundException cnfe)
            {
                return(View("ChapterNotFound", cnfe));
            }
        }
Пример #2
0
 public SeqChapter GetChapter(SeqBook book, int chapterNum)
 {
     SeqChapter sc = book.SeqChapters.SingleOrDefault(
                    c => c.ChapterNum == chapterNum);
      if (sc == null)
     throw new ChapterNotFoundException("Chapter \"" + chapterNum +
        "\" was not found for the book \"" + book.Title + "\"");
      return sc;
 }
Пример #3
0
        /// <summary>
        /// Generate a RSS feed of some of the most recent comic page posts. This is
        /// different from recent accompanying blog posts which should use the
        /// RssFeed method.
        /// </summary>
        /// <param name="comic">The book UriContext value that is the short hand for
        /// the comic for which to build this feed.</param>
        /// <returns>RSS 2.0 feed of the 10 most recent pages of given book.</returns>
        public virtual ContentResult ComicRssFeed(string comic)
        {
            Uri    u = Request.RequestContext.HttpContext.Request.Url;
            string applicationPath = Request.RequestContext
                                     .HttpContext.Request
                                     .ApplicationPath;
            string buildDate = String.Format("{0:dddd, MMMM d, yyyy - h:mm tt}",
                                             DateTime.Now);

            //Fetch the last 10 pages updated order by desc pubDate; then make:
            //title = Chapter {chapter num} - Page {page num}
            //link = "{comic}/chapter{chapter}/page{page}/{perma}/{id}"
            //(e.g. http://sputnikx.com/eden/chapter1/page4
            //description = empty or page.Description
            //Rss elements: http://www.ibm.com/developerworks/xml/library/x-rss20/
            try
            {
                SeqBook        book        = booksRep.BookUriContext(comic);
                List <SeqPage> recentPages = booksRep.GetRecentPages(comic)
                                             .ToList <SeqPage>();
                string linkUri = u.Scheme + "://" + u.Host +
                                 ((u.Port != 80 || u.Port != 443) ? ":" + u.Port : "") +
                                 applicationPath;
                string    encoding = Response.ContentEncoding.WebName;
                string    feedName = book.Title;
                XDocument rss      = new XDocument(
                    new XDeclaration("1.0", encoding, "yes"),
                    new XElement("rss", new XAttribute("version", "2.0"),
                                 new XElement("channel",
                                              new XElement("title", feedName),
                                              new XElement("link", linkUri),
                                              new XElement("description", book.Description),
                                              new XElement("language", "en-us"),
                                              new XElement("lastBuildDate", buildDate),
                                              new XElement("generator", "Sequential 2013"),
                                              from page in recentPages
                                              select new XElement("item",
                                                                  new XElement("title",
                                                                               "Chapter " + page.SeqChapter.ChapterNum +
                                                                               " - Page " + page.PageNum),
                                                                  new XElement("link",
                                                                               linkUri + comic + "/chapter" +
                                                                               page.SeqChapter.ChapterNum + "/page" +
                                                                               page.PageNum),
                                                                  new XElement("description", page.Description),
                                                                  new XElement("pubDate", page.PubDate.ToString())
                                                                  ) //XElement item
                                              )                     //XElement channel
                                 )                                  //XElement rss
                    );                                              //XDocument
                return(Content(rss.ToString(), "application/rss+xml"));
            }
            catch (BookNotFoundException bnfe)
            {
                return(Content(bnfe.Message, "text/plain"));
            }
        }
Пример #4
0
        public SeqBook BookUriContext(string context)
        {
            SeqBook sb = db.SeqBooks.SingleOrDefault(b => b.UriContext == context);

            if (sb == null)
            {
                throw new BookNotFoundException("The book \"" + context + "\" was " +
                                                "not found.");
            }
            return(sb);
        }
Пример #5
0
        public SeqChapter GetChapter(SeqBook book, int chapterNum)
        {
            SeqChapter sc = book.SeqChapters.SingleOrDefault(
                c => c.ChapterNum == chapterNum);

            if (sc == null)
            {
                throw new ChapterNotFoundException("Chapter \"" + chapterNum +
                                                   "\" was not found for the book \"" + book.Title + "\"");
            }
            return(sc);
        }
Пример #6
0
        private void LoadByBooks()
        {
            List <Book> bookList = bookManager.GetAll();

            SequenceContent.Children.Clear();
            foreach (var item in bookList)
            {
                Button buton = SeqBook.Get(item);
                SequenceContent.Children.Add(buton);
            }
            lblAllCount.Content        = "Kayıtlı Toplam Kitap: " + bookList.Count;
            lblLibraryCount.Visibility = Visibility.Visible;
            lblLibraryCount.Content    = "Kütüphanedeki Kitap: " + bookManager.GetAll().Where(i => i.BookLocation == 0).Count().ToString();
        }
Пример #7
0
        private void SearchBox_KeyDown(object sender, KeyEventArgs e)
        {
            TextBox textBox = sender as TextBox;

            SettingManager settingManager = new SettingManager();
            Setting        setting        = settingManager.Get(2);
            bool           durum          = setting.State;

            if (e.Key == Key.Enter)
            {
                if (durum == false)
                {
                    SequenceContent.Children.Clear();
                    if (SeqEntity is Book)
                    {
                        List <Book> books = bookManager.Search(textBox.Text);
                        foreach (Book item in books)
                        {
                            Button button = SeqBook.Get(item);
                            SequenceContent.Children.Add(button);
                        }
                    }
                    else if (SeqEntity is Student)
                    {
                        List <Student> books = studentManager.Search(textBox.Text);
                        foreach (Student item in books)
                        {
                            if (item.Identity == 0)
                            {
                                continue;
                            }
                            Button button = SeqStudent.Get(item);
                            SequenceContent.Children.Add(button);
                        }
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Processes a URI that can reference a page of a comic as well as a specific
        /// blog article. A comic page (image) must be returned, but a specific blog
        /// article need not be named.
        /// </summary>
        /// <param name="comic">The name of the comic should match the <code>SeqBook
        /// </code> UriContext property. The value of this parameter is also used as
        /// the <code>SeqPost</code> BlogId for the purposes of looking up blog posts
        /// related to the comic.</param>
        /// <param name="chapter">A chapter number 1..n</param>
        /// <param name="page">A page number 1..n</param>
        /// <param name="perma">Optional. The permalink string to a blog post.</param>
        /// <param name="id">Optional. Blog post id that must accompany a
        /// permalink since this is how the system looks up the article.</param>
        /// <returns>A view that can be shown for any comic and/or blog article
        /// request.</returns>
        public ActionResult FullPathEntry(string comic, int chapter, int page,
                                          string perma   = null, int id = -1,
                                          bool rootEntry = false)
        {
            //TODO: Check for cookie and if none then set the page number.
            HttpCookie cookie = Request.Cookies.Get(comic + "_bookmark");

            if (cookie == null)
            {
                TimeSpan   expirytime = new TimeSpan(120, 0, 0, 0);
                HttpCookie hc         = new HttpCookie(comic + "_bookmark", comic + "|1|1");
                hc.Expires = DateTime.Today.Add(expirytime);
                Response.Cookies.Add(hc);
            }
            else //A cookie was found...account for 2 cases...
            {
                if (rootEntry) //User typed in just the base url.
                {
                    string[] parts = cookie.Value.Split('|');
                    comic   = parts[0];
                    chapter = Int32.Parse(parts[1]);
                    page    = Int32.Parse(parts[2]);
                }
                else //User typed in an explicit url to get here so preserve in cookie
                {
                    TimeSpan expirytime = new TimeSpan(120, 0, 0, 0);
                    cookie.Expires = DateTime.Today.Add(expirytime);
                    cookie.Value   = comic + "|" + chapter + "|" + page;
                    Response.Cookies.Add(cookie);
                }
            }

            ViewResult result;

            //Specific blog identified
            if (id > 0)
            {
                result = (ViewResult)base.GetSinglePost(comic, id);
            }
            else
            {
                result = (ViewResult)base.Index(comic);
            }
            try
            {
                SeqBook        book = booksRep.BookUriContext(comic);
                WebComicVModel wcvm = new WebComicVModel((BlogHomeVModel)result.Model);
                wcvm.BookName      = comic;
                wcvm.ChapterNumber = chapter;
                SeqChapter schapter = booksRep.GetChapter(book, chapter);
                wcvm.PageNumber       = (page > schapter.PageCount) ? schapter.PageCount : page;
                wcvm.ChapterPageCount = schapter.PageCount;
                wcvm.Controller       = "Post";
                wcvm.Action           = "AjaxPostPage"; //Need PartialView action like TurnPage
                return(View("Index", wcvm));
            }
            //These should only be thrown due to unfinished configuration.
            catch (BookNotFoundException bnfe)
            {
                return(View("BookNotFound", bnfe));
            }
            catch (ChapterNotFoundException cnfe)
            {
                return(View("ChapterNotFound", cnfe));
            }
        }