Exemple #1
0
        public MainForm(Builder builder, BibleService bibleService, IServiceScopeFactory scopeFactory)
        {
            Builder      = builder;
            BibleService = bibleService;
            ScopeFactory = scopeFactory;

            InitializeComponent();
            InitializeBuildComponent();
            InitializeHistoryComponent();
            InitializeTemplatesComponent();
            InitializeSettingsComponent();

            // TODO: 마지막 페이지 기억하기
            mainMultiPanel.SelectedPage = buildMultiPanelPage;
        }
        // GET: Topics/Details/5
        public async Task <ActionResult> Details(Guid?id)
        {
            BibleService bib = new BibleService();
            Common       com = new Common();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Topic topic = await db.Topics.FindAsync(id);

            if (topic == null)
            {
                return(HttpNotFound());
            }
            Anchor anchor = await db.Anchors.FindAsync(topic.AnchorId);

            ViewData["Text"] = await bib.GetScriptureKJV(anchor);

            ViewData["Date"] = com.Dateconverter(topic.TimeStamp.ToLocalTime());

            return(View(topic));
        }
Exemple #3
0
        /// <summary>
        /// 선택한 소스의 성경 목록을 가져온다.
        /// </summary>
        private async void SourceComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            // 성경 목록을 가져오기 전까지 성경 목록 컨트롤 비활성화
            bibleComboBox.Enabled = false;

            // 이전에 선택한 소스의 성경 목록 가져오기 작업을 취소
            if (sourceComboBox.Tag is CancellationTokenSource previousCts)
            {
                previousCts.CancelIfNotDisposed();
                sourceComboBox.Tag = null;
            }

            // 소스를 선택하지 않았으면 아무 작업도 안함
            if (!(sourceComboBox.SelectedItem is BibleSource source))
            {
                return;
            }

            // 작업을 취소하기 위한 토큰 생성 및 연결
            using var cts      = new CancellationTokenSource();
            sourceComboBox.Tag = cts;

            // 성경 목록 가져오기
            List <Bible> bibles;

RETRY:
            try
            {
                bibles = await BibleService.GetBiblesAsync(source).ConfigureAwait(true);

                // 작업 취소 요청 수리
                cts.Token.ThrowIfCancellationRequested();
            }
            // 다른 성경 소스를 선택하여서 작업 취소
            catch (OperationCanceledException) when(cts.IsCancellationRequested)
            {
                return;
            }
            // 성경 소스가 응답이 없으면 다시 시도
            catch (Exception ex) when(ex is OperationCanceledException || ex is WebException)
            {
                if (DialogResult.Yes == MessageBox.Show(
                        $"성경 소스가 응답이 없습니다.\n다시 시도할까요?\n\n자세한 오류: {ex}",
                        "성경2PPT", MessageBoxButtons.YesNo))
                {
                    goto RETRY;
                }

                return;
            }

            // 성경 목록 가져오기를 성공하였으므로 선택한 소스를 기억
            AppConfig.Context.BibleSourceId = source.Id;

            // 성경 목록 초기화
            bibleComboBox.SelectedValueChanged -= BibleComboBox_SelectedValueChanged;
            bibleComboBox.DataSource            = bibles;
            bibleComboBox.SelectedItem          = null;
            bibleComboBox.SelectedValueChanged += BibleComboBox_SelectedValueChanged;
            // 성경 목록 컨트롤 활성화
            bibleComboBox.Enabled = true;
            // 마지막으로 선택한 성경 불러오기
            bibleComboBox.SelectedValue = AppConfig.Context.BibleVersionId;
        }
Exemple #4
0
        /// <summary>
        /// 활성화한 성경의 책 목록을 가져온다.
        /// </summary>
        private async void BiblesDataGridView_CurrentCellChanged(object sender, EventArgs e)
        {
            // 책 목록을 가져오기 전까지 책 목록 컨트롤 비활성화
            booksListView.Enabled = false;

            // 이전에 활성화한 성경의 책 목록 가져오기 작업을 취소
            if (biblesDataGridView.Tag is CancellationTokenSource previousCts)
            {
                previousCts.CancelIfNotDisposed();
                biblesDataGridView.Tag = null;
            }

            // 성경을 활성화하지 않았으면 아무 작업도 안함
            if (biblesDataGridView.CurrentRow == null)
            {
                return;
            }

            // 활성화한 성경을 기억
            var bible = biblesToBuild[biblesDataGridView.CurrentRow.Index];

            // 작업을 취소하기 위한 토큰 생성 및 연결
            using var cts          = new CancellationTokenSource();
            biblesDataGridView.Tag = cts;

            // 책 목록 가져오기
            List <Book> books;

RETRY:
            try
            {
                books = await BibleService.GetBooksAsync(bible).ConfigureAwait(true);

                // 작업 취소 요청 수리
                cts.Token.ThrowIfCancellationRequested();
            }
            // 다른 성경을 활성화하여서 작업 취소
            catch (OperationCanceledException) when(cts.IsCancellationRequested)
            {
                return;
            }
            // 성경 소스가 응답이 없으면 다시 시도
            catch (Exception ex) when(ex is OperationCanceledException || ex is WebException)
            {
                if (DialogResult.Yes == MessageBox.Show(
                        $"성경 소스가 응답이 없습니다.\n다시 시도할까요?\n\n자세한 오류: {ex}",
                        "성경2PPT", MessageBoxButtons.YesNo))
                {
                    goto RETRY;
                }

                return;
            }

            // 책 목록 초기화
            booksListView.Tag = books;
            booksListView.Items.Clear();
            foreach (var book in books)
            {
                var item = booksListView.Items.Add(book.Name);
                item.SubItems.Add(book.Abbreviation);
                item.Tag = book;
            }
            // 책 목록 컨트롤 활성화
            booksListView.Enabled = true;
        }
        /// <summary>
        /// 선택한 소스의 성경 목록을 가져온다.
        /// </summary>
        private async void SourceComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            // 성경 목록을 가져오기 전까지 성경 목록 컨트롤 비활성화
            bibleComboBox.Enabled = false;

            // 현재 소스를 선택하기 전에 선택한 소스의 성경 목록 가져오기 작업을 취소
            if (sourceComboBox.Tag is CancellationTokenSource previousCts)
            {
                previousCts.CancelIfNotDisposed();
                sourceComboBox.Tag = null;
            }

            // 소스를 선택하지 않았으면 아무 작업도 안함
            if (!(sourceComboBox.SelectedItem is BibleSource source))
            {
                return;
            }

            // 작업을 취소하기 위한 토큰 생성 및 연결
            var cts = new CancellationTokenSource();

            sourceComboBox.Tag = cts;

            // 성경 목록 가져오기
            List <Bible> bibles;

GET_BIBLES:
            try
            {
                bibles = await BibleService.GetBiblesAsync(source).ConfigureAwait(true);

                // 작업 취소 요청 수리
                cts.Token.ThrowIfCancellationRequested();
            }
            // 올바른 작업 취소 요청 시 아무 작업도 안함
            catch (OperationCanceledException) when(cts.IsCancellationRequested)
            {
                goto CLEANUP;
            }
            // 성경 소스가 응답이 없으면 다시 시도
            catch (OperationCanceledException)
            {
                if (DialogResult.No == MessageBox.Show("성경 소스가 응답이 없습니다.\n다시 시도할까요?", "성경2PPT", MessageBoxButtons.YesNo))
                {
                    goto CLEANUP;
                }

                goto GET_BIBLES;
            }
            // TODO: 작업 실패 시 오류 처리 및 컨트롤 활성화
            //catch { }

            // 성경 목록 가져오기를 성공하였으므로 선택한 소스를 기억
            AppConfig.Context.BibleSourceId = source.Id;

            // 성경 목록 초기화
            bibleComboBox.SelectedValueChanged -= BibleComboBox_SelectedValueChanged;
            bibleComboBox.DataSource            = bibles;
            bibleComboBox.SelectedItem          = null;
            bibleComboBox.SelectedValueChanged += BibleComboBox_SelectedValueChanged;
            // 성경 목록 컨트롤 활성화
            bibleComboBox.Enabled = true;
            // 마지막으로 선택한 성경 불러오기
            bibleComboBox.SelectedValue = AppConfig.Context.BibleVersionId;

CLEANUP:
            cts.Dispose();
        }
        /// <summary>
        /// 활성화한 성경의 책 목록을 가져온다.
        /// </summary>
        private async void BiblesDataGridView_CurrentCellChanged(object sender, EventArgs e)
        {
            // 책 목록을 가져오기 전까지 책 목록 컨트롤 비활성화
            booksListView.Enabled = false;

            // 현재 성경을 활성화하기 전에 활성화한 성경의 책 목록 가져오기 작업을 취소
            if (biblesDataGridView.Tag is CancellationTokenSource previousCts)
            {
                previousCts.CancelIfNotDisposed();
                biblesDataGridView.Tag = null;
            }

            // 성경을 활성화하지 않았으면 아무 작업도 안함
            if (biblesDataGridView.CurrentRow == null)
            {
                return;
            }

            // 활성화한 성경을 기억
            var bible = biblesToBuild[biblesDataGridView.CurrentRow.Index];

            // 작업을 취소하기 위한 토큰 생성 및 연결
            var cts = new CancellationTokenSource();

            biblesDataGridView.Tag = cts;

            // 책 목록 가져오기
            List <Book> books;

GET_BOOKS:
            try
            {
                books = await BibleService.GetBooksAsync(bible).ConfigureAwait(true);

                // 작업 취소 요청 수리
                cts.Token.ThrowIfCancellationRequested();
            }
            // 올바른 작업 취소 요청 시 아무 작업도 안함
            catch (OperationCanceledException) when(cts.IsCancellationRequested)
            {
                goto CLEANUP;
            }
            // 성경 소스가 응답이 없으면 다시 시도
            catch (OperationCanceledException)
            {
                if (DialogResult.No == MessageBox.Show("성경 소스가 응답이 없습니다.\n다시 시도할까요?", "성경2PPT", MessageBoxButtons.YesNo))
                {
                    goto CLEANUP;
                }

                goto GET_BOOKS;
            }
            // TODO: 작업 실패 시 오류 처리 및 컨트롤 활성화
            //catch { }

            // 책 목록 초기화
            booksListView.Tag = books;
            booksListView.Items.Clear();
            foreach (var book in books)
            {
                var item = booksListView.Items.Add(book.Name);
                item.SubItems.Add(book.Abbreviation);
                item.Tag = book;
            }
            // 책 목록 컨트롤 활성화
            booksListView.Enabled = true;

CLEANUP:
            cts.Dispose();
        }
        static void Main()
        {
            Console.WriteLine("bible.com scraper\n-=≡=-=≡=-=≡=-=≡=-\n\n");

            // get a language code
            string langPage = string.Empty;

            while (string.IsNullOrWhiteSpace(langPage))
            {
                Console.Write("Enter iso language code [eng]: ");
                Console.ForegroundColor = ConsoleColor.White;
                var languageCode = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(languageCode))
                {
                    languageCode = "eng";
                }
                languageCode = languageCode.ToLower();

                try
                {
                    langPage = Http.GetPage($"https://www.bible.com/languages/{languageCode}");
                }
                catch
                {
                    Console.WriteLine("Language is unsupported or incorrect, or something else went terribly wrong.");
                }
            }

            // get a translation
            Console.WriteLine("Possible translations: ");

            Regex translationsReg =
                new Regex(
                    "<a role=button target=_self class=\"db pb2 lh-copy yv-green link\" href=(?<url>\\/versions\\/(?<slug>(?<code>\\d*)-.*?))>(?<name>.*?)<\\/a>");
            MatchCollection results = translationsReg.Matches(langPage);

            foreach (Match m in results)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(m.Groups["code"].ToString());
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine($"\t: {m.Groups["name"]}");
            }

            string startingPageContent = string.Empty;
            string translationCode     = string.Empty;

            while (string.IsNullOrWhiteSpace(startingPageContent))
            {
                Console.Write("Enter translation code [114]: ");
                Console.ForegroundColor = ConsoleColor.White;
                translationCode         = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(translationCode))
                {
                    translationCode = "114";
                }
                translationCode = translationCode.ToLower();

                try
                {
                    string startingUrl = "https://www.bible.com" + results
                                         .FirstOrDefault(f => f.Groups["code"].ToString() == translationCode)
                                         ?.Groups["url"];

                    startingPageContent = Http.GetPage(startingUrl);
                }
                catch
                {
                    Console.WriteLine(
                        "Translation code is unsupported or incorrect, or something else went terribly wrong.");
                }
            }

            // from the startingPageContent, we need to get the link to the first verse of the Bible.
            string firstChapterUrl = "https://www.bible.com" + Regex
                                     .Match(startingPageContent,
                                            "<a class=\"db pb3 link yv-green lh-copy\" role=button href=(?<firstChapterUrl>\\/bible\\/.*?)>Read Version")
                                     .Groups["firstChapterUrl"].Value;

            // we need to collate the Bible Metadata
            string bibleName = results
                               .FirstOrDefault(f => f.Groups["code"].ToString() == translationCode)
                               ?.Groups["name"].ToString();
            string bibleCode = Regex.Match(firstChapterUrl, ".*\\.(.+?)$").Groups[1].Value;

            _bible = new BibleService(bibleCode, bibleName, uint.Parse(translationCode));

            try
            {
                if (_bible.DatabaseExists)
                {
                    Console.Write("Bible DB already exists.  RESET or RESUME [resume]: ");
                    if (Console.ReadLine()?.ToUpper().Trim() == "RESET")
                    {
                        _bible.DeleteDatabase();
                    }
                }
            }
            catch
            {
                Console.WriteLine($"can't delete existing file {bibleCode}.bible.db.  Quitting...");
                return;
            }

            _bible.InitializeDatabase();

            // pull a job from the queue and process.  Then wait a random number of seconds.
            bool done = false;

            while (!done)
            {
                Console.WriteLine($"Jobs remaining: {_bible.JobsRemaining}");

                Job job = _bible.GetRandomJob();

                Console.WriteLine($"Got job {job.Id} which is an {job.Type} job");
                switch (job.Type)
                {
                case JobTypes.EnumerateBooks:
                    EnumerateBooks(job);
                    break;

                case JobTypes.EnumerateChapters:
                    EnumerateChapters(job);
                    break;

                case JobTypes.EnumerateVerses:
                    EnumerateVerses(job);
                    break;

                default:
                    throw new InvalidOperationException("Unknown job type");
                }

                _bible.DeleteJob(job);
                done = (_bible.JobsRemaining == 0);

                Console.WriteLine("Job finished");
                //Console.ReadKey();
            }

            Console.WriteLine("All Done");
            Console.ReadKey();
        }