示例#1
0
        public async void InsertBibleText(string[] bibleText, Register register)
        {
            Bible        bible        = new Bible();
            BibleContext bibleContext = new BibleContext();

            const string pattern = @"(\d{1,3}\w)\s(\d{1,3})\s(\d{1,3})\s*\d*\s*\s*([\ \S*]*)";
            //(\d{1,3}\w)\W(\d{1,3})\W(\d{1,3})\W{1,2}\d{1,7}\W{1}([\ \S*]*)";

            // Instantiate the regular expression object.
            Regex r = new Regex(pattern, RegexOptions.IgnoreCase);

            for (int i = 8; i < bibleText.Length; i++)
            {
                Match m = r.Match(bibleText[i]);

                if (m.Groups.Count >= 4)
                {
                    bible.Id               = 0;
                    bible.Version          = register.Abbreviation;
                    bible.BookChapterVerse = m.Groups[1].ToString() + "|" + m.Groups[2].ToString() + "|" + m.Groups[3].ToString();
                    bible.Book             = m.Groups[1].ToString();
                    bible.Chapter          = m.Groups[2].ToString();
                    bible.Verse            = m.Groups[3].ToString();
                    bible.BibleText        = m.Groups[4].ToString();
                    bibleContext.Add(bible);
                    await bibleContext.SaveChangesAsync();
                }
            }
        }
示例#2
0
        public async Task <List <Bible> > GetBiblesAsync()
        {
            // 캐시가 있으면 사용
            var bibles = GetCached();

            if (bibles.Any())
            {
                return(bibles);
            }
            // 캐시가 없으면 온라인에서 가져와서 저장
            bibles = await GetBiblesOnlineAsync();

            bibles.ForEach(LinkSource);
            Cache();
            return(bibles);

            List <Bible> GetCached()
            {
                using (var db = new BibleContext())
                {
                    return(db.Bibles.Where(i => i.SourceId == Id).ToList());
                }
            }

            void Cache()
            {
                using (var db = new BibleContext())
                {
                    db.Bibles.AddRange(bibles);
                    db.SaveChanges();
                }
            }
        }
示例#3
0
        private void HistoryDeleteButton_Click(object sender, EventArgs e)
        {
            if (!(historyDataGridView.CurrentRow?.DataBoundItem is Job job))
            {
                return;
            }

            using (var db = new BibleContext())
            {
                if (db.Jobs.Any(i => i.Id == job.Id))
                {
                    db.Jobs.Attach(job);
                    db.Jobs.Remove(job);
                    db.SaveChanges();
                }
            }

            // 취소 불가능하면 바로 제거
            if (FindHistoryDataGridViewRow(job).Tag == null)
            {
                jobHistory.RemoveAt(FindHistoryDataGridViewRow(job).Index);
            }
            // 취소 가능하면 취소로 제거
            else
            {
                builder.Cancel(job);
            }
        }
        // GET: Read
        public ActionResult Index(string book, int fromChapter = 0, int fromVerse = 0, int toChapter = 0, int toVerse = 0, string v = "BTT")
        {
            db = new BibleContext(v);
            var bookId = db.Books.SingleOrDefault(b => b.Id.Equals(book) || b.UrlKeyword.Equals(book) || b.Name.Equals(book));

            if (bookId == default(Book))
            {
                return(HttpNotFound());
            }
            var    data    = new List <Verse>();
            string address = "";

            //ma-thi-o 1
            if (fromChapter > 0 && fromVerse == 0 && toChapter == 0 && toVerse == 0)
            {
                data = db.Verses.Where(ve => ve.BookId.Equals(bookId.Id) && ve.Chapter.Equals(fromChapter))
                       .OrderBy(ve => ve.Id).ToList();
                address = string.Format("{0} {1}", bookId.Name, fromChapter);
            }
            //ma-thi-o 1:1
            if (fromChapter > 0 && fromVerse > 0 && toChapter == 0 && toVerse == 0)
            {
                data.Add(db.Verses.Find(bookId.Id, fromChapter, fromVerse));
                address = string.Format("{0} {1}.{2}", bookId.Name, fromChapter, fromVerse);
            }
            //ma-thi-o 1:1-2
            if (fromChapter > 0 && fromVerse > 0 && toChapter == 0 && toVerse > 0 && fromVerse <= toVerse && fromVerse <= toVerse)
            {
                data    = db.Verses.Where(ve => ve.BookId.Equals(bookId.Id) && ve.Chapter == fromChapter && ve.Id >= fromVerse && ve.Id <= toVerse).ToList();
                address = string.Format("{0} {1}:{2}-{3}", bookId.Name, fromChapter, fromVerse, toVerse);
            }
            //ma-thi-o 1-2
            if (fromChapter > 0 && fromVerse == 0 && toChapter > 0 && toVerse == 0 && fromChapter < toChapter)
            {
                data    = db.Verses.Where(ve => ve.BookId.Equals(bookId.Id) && ve.Chapter >= fromChapter && ve.Chapter <= toChapter).ToList();
                address = string.Format("{0} {1}-{2}", bookId.Name, fromChapter, toChapter);
            }
            //ma-thi-o 1-2:5
            if (fromChapter > 0 && fromVerse == 0 && toChapter > 0 && toVerse > 0 && fromChapter < toChapter)
            {
                data = db.Verses.Where(ve => ve.BookId.Equals(bookId.Id) &&
                                       ((ve.Chapter >= fromChapter && ve.Chapter < toChapter) || (ve.Chapter == toChapter && ve.Id <= toVerse))
                                       ).ToList();
                address = string.Format("{0} {1}-{2}:{3}", bookId.Name, fromChapter, toChapter, toVerse);
            }
            //ma-thi-o 1:1-2:2
            if (fromChapter > 0 && fromVerse > 0 && toChapter > 0 && toVerse > 0 && fromChapter < toChapter)
            {
                data = db.Verses.Where(ve => ve.BookId.Equals(bookId.Id) && (
                                           (ve.Chapter == fromChapter && ve.Id >= fromVerse) ||
                                           (ve.Chapter > fromChapter && ve.Chapter < toChapter) ||
                                           (ve.Chapter == toChapter && ve.Id <= toVerse)
                                           )
                                       ).ToList();
                address = string.Format("{0} {1}:{2}-{3}:{4}", bookId.Name, fromChapter, fromVerse, toChapter, toVerse);
            }
            ViewBag.Address = address;
            return(View(data));
            //return HttpNotFound();
        }
示例#5
0
        public IActionResult Index()
        {
            var bible = new BibleContext(_appEnvironment.ContentRootPath);

            List <Chapter> chapters = bible.GetBook("Ephesians").Chapter;

            return(View(chapters));
        }
示例#6
0
        public IActionResult Favorites()
        {
            List <Verse> myVerses;

            using (var db = new BibleContext())
            {
                myVerses = db.Verses.ToList();
            }
            return(View(myVerses));
        }
示例#7
0
        // GET: Admin/BookManager
        public ActionResult Index(string version = "BTT")
        {
            var listS      = (from ConnectionStringSettings c in ConfigurationManager.ConnectionStrings select c.Name).ToList();
            var selectList = new SelectList(listS, version);

            ViewBag.Versions = selectList;
            ViewBag.Version  = version;
            db = new BibleContext(version);
            return(View(db.Books.OrderBy(b => b.Order)));
        }
示例#8
0
 public ActionResult Create(Book book, string version = "BTT")
 {
     if (ModelState.IsValid)
     {
         db = new BibleContext(version);
         book.UrlKeyword = Data.Translation.ConvertToUnsign3(book.Name);
         db.Books.Add(book);
         db.SaveChanges();
         return(RedirectToAction("Index", new { version = version }));
     }
     return(View(book));
 }
示例#9
0
        private void InitializeBuildComponent()
        {
            // TableLayoutPanel에 포함되면 SplitterWidth가 초기화되는
            // SplitContainer의 특성에 따라 값 다시 설정
            buildSplitContainer.SplitterWidth = 13;

            // 이전에 선택한 성경 중에서 성경 소스가 살아있는 성경만 불러오기
            using (var db = new BibleContext())
            {
                foreach (var bibleId in AppConfig.Context.BibleToBuild)
                {
                    var bible = db.Bibles.Find(bibleId);
                    if (bible != null && bible.Source != null)
                    {
                        biblesToBuild.Add(bible);
                    }
                }
            }

            // DataSource 사용을 위한 기초 설정
            sourceComboBox.SelectedValueChanged -= SourceComboBox_SelectedValueChanged;
            sourceComboBox.ValueMember           = nameof(Source.Id);
            sourceComboBox.DisplayMember         = nameof(Source.Name);
            sourceComboBox.SelectedValueChanged += SourceComboBox_SelectedValueChanged;

            bibleComboBox.SelectedValueChanged -= BibleComboBox_SelectedValueChanged;
            bibleComboBox.ValueMember           = nameof(Bible.Id);
            bibleComboBox.DisplayMember         = nameof(Bible.Name);
            bibleComboBox.SelectedValueChanged += BibleComboBox_SelectedValueChanged;

            biblesDataGridView.AutoGenerateColumns          = false;
            biblesSourceDataGridViewColumn.DataPropertyName = nameof(Bible.Source);
            biblesBibleDataGridViewColumn.DataPropertyName  = nameof(Bible.Name);
            biblesDataGridView.DataSource = biblesToBuild;

            // 불러오기
            templateBookNameComboBox.SelectedIndex      = (int)AppConfig.Context.ShowLongTitle;
            templateBookAbbrComboBox.SelectedIndex      = (int)AppConfig.Context.ShowShortTitle;
            templateChapterNumberComboBox.SelectedIndex = (int)AppConfig.Context.ShowChapterNumber;
            buildSplitChaptersIntoFilesCheckBox.Checked = AppConfig.Context.SeperateByChapter;

            // 소스 목록 초기화
            sourceComboBox.SelectedValueChanged -= SourceComboBox_SelectedValueChanged;
            sourceComboBox.DataSource            = Source.AvailableSources;
            sourceComboBox.SelectedItem          = null;
            sourceComboBox.SelectedValueChanged += SourceComboBox_SelectedValueChanged;
            // 마지막으로 선택한 소스 불러오기
            sourceComboBox.SelectedValue = AppConfig.Context.BibleSourceId;
        }
示例#10
0
 private void CleanCacheButton_Click(object sender, EventArgs e)
 {
     if (DialogResult.Yes == MessageBox.Show("진행 중인 작업을 취소하고 프로그램을 다시 시작할까요?", Text, MessageBoxButtons.YesNo))
     {
         using (var db = new BibleContext())
         {
             db.Database.ExecuteSqlCommand(@"
                 PRAGMA writable_schema = 1;
                 DELETE FROM sqlite_master WHERE type IN ('table', 'index', 'trigger');
                 PRAGMA writable_schema = 0;
             ");
             Application.Restart();
         }
     }
 }
示例#11
0
        public async Task <List <Chapter> > GetChaptersAsync(Book book)
        {
            // 캐시가 있으면 사용
            var chapters = GetCached();

            if (chapters.Any())
            {
                return(chapters);
            }
            // 캐시가 없으면 온라인에서 가져와서 저장
            chapters = await GetChaptersOnlineAsync(book);

            chapters.ForEach(LinkForeigns);
            chapters.Sort((a, b) => a.Number.CompareTo(b.Number));
            Cache();
            return(chapters);

            List <Chapter> GetCached()
            {
                using (var db = new BibleContext())
                {
                    return(db.Chapters.Where(i => i.BookId == book.Id)
                           .Include(chapter => chapter.Book.Bible)
                           .ToList());
                }
            }

            void LinkForeigns(Chapter chapter)
            {
                LinkSource(chapter);
                chapter.Book   = book;
                chapter.BookId = book.Id;
            }

            void Cache()
            {
                using (var db = new BibleContext())
                {
                    db.Books.Attach(chapters.First().Book);
                    db.Chapters.AddRange(chapters);
                    db.SaveChanges();
                }
            }
        }
示例#12
0
        public async Task <List <Verse> > GetVersesAsync(Chapter chapter)
        {
            // 캐시가 있으면 사용
            var verses = GetCached();

            if (verses.Any())
            {
                return(verses);
            }
            // 캐시가 없으면 온라인에서 가져와서 저장
            verses = await GetVersesOnlineAsync(chapter);

            verses.ForEach(LinkForeigns);
            verses.Sort((a, b) => a.Number.CompareTo(b.Number));
            Cache();
            return(verses);

            List <Verse> GetCached()
            {
                using (var db = new BibleContext())
                {
                    return(db.Verses.Where(i => i.ChapterId == chapter.Id)
                           .Include(verse => verse.Chapter.Book.Bible)
                           .ToList());
                }
            }

            void LinkForeigns(Verse verse)
            {
                LinkSource(verse);
                verse.Chapter   = chapter;
                verse.ChapterId = chapter.Id;
            }

            void Cache()
            {
                using (var db = new BibleContext())
                {
                    db.Chapters.Attach(verses.First().Chapter);
                    db.Verses.AddRange(verses);
                    db.SaveChanges();
                }
            }
        }
示例#13
0
        public async Task <List <Book> > GetBooksAsync(Bible bible)
        {
            // 캐시가 있으면 사용
            var books = GetCached();

            if (books.Any())
            {
                return(books);
            }
            // 캐시가 없으면 온라인에서 가져와서 저장
            books = await GetBooksOnlineAsync(bible);

            books.ForEach(LinkForeigns);
            Cache();
            return(books);

            List <Book> GetCached()
            {
                using (var db = new BibleContext())
                {
                    return(db.Books.Where(i => i.BibleId == bible.Id)
                           .Include(book => book.Bible)
                           .ToList());
                }
            }

            void LinkForeigns(Book book)
            {
                LinkSource(book);
                book.Bible   = bible;
                book.BibleId = bible.Id;
            }

            void Cache()
            {
                using (var db = new BibleContext())
                {
                    db.Bibles.Attach(books.First().Bible);
                    db.Books.AddRange(books);
                    db.SaveChanges();
                }
            }
        }
示例#14
0
        public IActionResult Save(string favorites, string serializedVerses)
        {
            Bible theWord = new Bible(favorites: favorites, verses: serializedVerses);
            var   favList = theWord.GetBibleVerses().Where((v) => v.isFavorite).ToList();

            using (var db = new BibleContext())
            {
                foreach (var verse in favList)
                {
                    if (!db.Verses.Any((v) => v.Id == verse.Id))
                    {
                        db.Verses.Add(verse);
                    }
                }

                db.SaveChanges();
            }

            return(View("Index", theWord));
        }
示例#15
0
        public void Queue(Job job)
        {
            using (var db = new BibleContext())
            {
                foreach (var i in job.Bibles)
                {
                    db.Bibles.Attach(i);
                }
                db.Jobs.Add(job);
                db.SaveChanges();
            }

            JobCancellations[job] = new CancellationTokenSource();
            OnJobQueued(new JobQueuedEventArgs(job));

            Task.Run(async() =>
            {
                var acquired = false;
                try
                {
                    Semaphore.Wait(JobCancellations[job].Token);
                    acquired = true;
                    await ProcessAsync(job, JobCancellations[job].Token);
                    OnJobCompleted(new JobCompletedEventArgs(job, null));
                }
                catch (Exception ex)
                {
                    OnJobCompleted(new JobCompletedEventArgs(job, ex));
                }
                finally
                {
                    JobCancellations.TryRemove(job, out var cts);
                    cts.Dispose();
                    if (acquired)
                    {
                        Semaphore.Release();
                    }
                }
            });
        }
示例#16
0
        private void InitializeHistoryComponent()
        {
            historyDataGridView.AutoGenerateColumns             = false;
            historyCreatedAtColumn.DataPropertyName             = nameof(Job.CreatedAt);
            historyBiblesColumn.DataPropertyName                = nameof(Job.Bibles);
            historyQueryStringColumn.DataPropertyName           = nameof(Job.QueryString);
            historySplitChaptersIntoFileColumn.DataPropertyName = nameof(Job.SplitChaptersIntoFiles);

            using (var db = new BibleContext())
            {
                foreach (var job in db.Jobs
                         .Include(w => w.JobBibles.Select(wb => wb.Bible))
                         .ToList())
                {
                    jobHistory.Insert(0, job);
                }
            }
            historyDataGridView.DataSource = jobHistory;

            builder.JobQueued    += Builder_JobQueued;
            builder.JobProgress  += Builder_JobProgress;
            builder.JobCompleted += Builder_JobCompleted;
        }
示例#17
0
 public RegistersController(BibleContext context, IWebHostEnvironment env)
 {
     _context = context;
     _env     = env;
 }
示例#18
0
 public BooksController(BibleContext context, BibleViewModel viewModel)
 {
     _context   = context;
     _viewModel = viewModel;
 }
示例#19
0
 public ActionResult Create(string version = "BTT")
 {
     db = new BibleContext(version);
     return(View());
 }
示例#20
0
 public ChaptersController(BibleContext context, BibleViewModel viewModel)
 {
     _context   = context;
     _viewModel = viewModel;
 }
示例#21
0
 public TranslationsController(BibleContext context, BibleViewModel viewModel)
 {
     _context   = context;
     _viewModel = viewModel;
 }