Example #1
0
        protected async void BookSearchButton_Click(object sender, EventArgs e)
        {
            List <Book> Books = new List <Book>();

            try
            {
                Books = await WebTasks.FindBooks(BookSearchForm.Text);
            }
            catch (Exception exception)
            {
                ExceptionHandler(exception);
                throw new Exception();
            }
            Session["books"] = Books;
            if (Books.Count > 0)
            {
                ShowSearchResults();
                BooksList.DataSource = Books;
                BooksList.DataBind();
                BooksList.Rows          = Math.Max(6, Books.Count / 4);
                BooksList.SelectedIndex = 0;
            }
            else
            {
                SearchInProgressMessage.InnerHtml = "No results found. Try again!";
            }
        }
Example #2
0
        protected async void BookListSelectionButton_Click(object sender, EventArgs e)
        {
            var index          = BooksList.SelectedIndex;
            var books          = (List <Book>)Session.Contents["books"];
            var bookToDownload = new Book(null, null, null);

            try
            {
                bookToDownload = books.ElementAt(index);
            }
            catch (Exception exception) {
                ExceptionHandler(exception);
            }
            Book downloadedBook = null;

            if (bookToDownload != null)
            {
                try
                {
                    downloadedBook = await WebTasks.DownloadText(bookToDownload);
                }
                catch (Exception exception) {
                    ExceptionHandler(exception);
                    throw new Exception();
                }
            }
            if (downloadedBook != null)
            {
                var sentences           = SentencesParserTask.ParseSentences(downloadedBook.Text);
                var frequencyDictionary = FrequencyAnalysisTask.GetMostFrequentNextWords(sentences);
                Session["dictionary"] = frequencyDictionary;
                ShowAnalyzeForm();
            }
            else
            {
                ExceptionHandler(new NullReferenceException("Book link returned null"));
            }
        }