Пример #1
0
        public async Task MustLoadChaptersFromBookId()
        {
            var chapters = (await kitabDb.ChaptersByBookIdAsync(1)).ToArray();

            Assert.AreEqual(chapters.Length, 28, "Problem");
        }
Пример #2
0
        public async Task TestCreate()
        {
            //var book =await dbSqlContext.Books.FirstOrDefaultAsync();

            //         foreach (var b in kitabDb.Contents.Books)
            //         {
            //             dbSqlContext.Add(mapper.Map<Peshitta.Infrastructure.Sqlite.Model.Book>(b.Value));
            //           //  await dbSqlContext.SaveChangesAsync();
            //         }

            //         await dbSqlContext.SaveChangesAsync();
            //         foreach (var be in (await kitabDb.BookEditions).Data)
            //         {
            //             var beC = mapper.Map<Peshitta.Infrastructure.Sqlite.Model.bookedition>(be);
            //             //beC.bookEditionid = be.Key;
            //             dbSqlContext.Add(beC);
            //         }
            //         await dbSqlContext.SaveChangesAsync();
            //         dbSqlContext.Publications.AddRange(new Peshitta.Infrastructure.Sqlite.Model.Publication { Code = "AB", Name = "Peshitta" },
            //             new Peshitta.Infrastructure.Sqlite.Model.Publication { Code = "PS", Name = "Syriac Peshitta" });
            //         var idsExclude = new[] { 6353, 4985, 4771, 8531 , 3533, 8471, -18867, 7353 };
            //         foreach (var w in kitabDb.Contents.Words.Where(w => !idsExclude.Contains(w.Key)))
            //         {
            //             var mapped = mapper.Map<Peshitta.Infrastructure.Sqlite.Model.words>(w.Value);
            //             mapped.LangId = w.Value.LangId;
            //            // if (!(await dbSqlContext.Words.ContainsAsync(mapped)))
            //            if (mapped.id>= -15164)
            //             {
            //                 mapped.LangId = 90;
            //                 mapped.hash = new WordLanguageKey(mapped.word, mapped.LangId).GetHashCode();
            //             }
            //             dbSqlContext.Add(mapped);

            //             //var p = await dbSqlContext.Words.FirstOrDefaultAsync();
            //         }
            //         await dbSqlContext.SaveChangesAsync();
            //         foreach (var w in kitabDb.Contents.BookChapters)
            //         {
            //             var mapped = mapper.Map<Peshitta.Infrastructure.Sqlite.Model.BookChapter>(w.Value);

            //             // if (!(await dbSqlContext.Words.ContainsAsync(mapped)))
            //             dbSqlContext.Add(mapped);
            //             //var p = await dbSqlContext.Words.FirstOrDefaultAsync();
            //         }
            //         await dbSqlContext.SaveChangesAsync();


            //         foreach (var w in kitabDb.Contents.BookChapterAlineas)
            //         {
            //             var mapped = mapper.Map<Peshitta.Infrastructure.Sqlite.Model.BookChapterAlinea>(w.Value);
            //             mapped.bookchapteralineaid = w.Key.bookchapteralineaid;
            //             mapped.Alineaid = w.Key.Alineaid;
            //             // if (!(await dbSqlContext.Words.ContainsAsync(mapped)))

            //             dbSqlContext.Add(mapped);
            //             //   await dbSqlContext.SaveChangesAsync();
            //             //var p = await dbSqlContext.Words.FirstOrDefaultAsync();
            //         }
            //         await dbSqlContext.SaveChangesAsync();
            //delete FROM text where textid >=13117
            foreach (var be in (await kitabDb.BookEditions).Data)
            {
                var beC = await dbSqliteContext.BookEdition.FindAsync(be.bookEditionid);

                foreach (var chap in (await kitabDb.ChaptersByBookIdAsync(be.bookid)))
                {
                    if (be.langid == 19)
                    {
                        kitabDb.ActivePublications = new [] { "AB" };
                        if (!(new[] { 33, 34 }.Contains(be.bookEditionid)))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        kitabDb.ActivePublications = new [] { "PS" };
                        continue;
                    }
                    foreach (var ta in (await kitabDb.LoadChapterAsync(chap.Key.chapter, be.bookEditionid)).Data)
                    {
                        foreach (var t in ta.Texts)
                        {
                            //if (t.BookChapterAlineaid <= 6850) // be.bookEditionid == 1 && ( chap.Key.chapter < 27 || (chap.Key.chapter == 27 && t.Alineaid<=30))
                            //{
                            //    continue;
                            //}
                            if (await dbSqliteContext.Text.AsNoTracking().AnyAsync(a => a.textid == t.TextId))
                            {
                                continue;
                            }
                            Trace.TraceInformation("Chap {0}, bookedition id {1}, verse {2}", chap.Key.chapter, be.bookEditionid, t.Alineaid);
                            var text = new Peshitta.Infrastructure.Sqlite.Model.Text
                            {
                                Alineaid            = t.Alineaid,
                                bookeditionid       = t.bookeditionid,
                                textid              = t.TextId,
                                timestamp           = t.timestamp,
                                BookChapterAlineaid = ta.BookChapterAlineaId,
                            };
                            text.bookedition   = beC;
                            text.bookeditionid = beC.bookEditionid;

                            var plain   = t.Content;
                            var remarks = t.Remarks;
                            dbSqliteContext.Text.Add(text);
                            await dbSqliteContext.SaveChangesAsync();

                            foreach (var(ArchiveDate, expanded) in t.Histories)
                            {
                                if (ArchiveDate == DateTime.MinValue)
                                {
                                    continue;
                                }
                                await _repo.CompressVerse(t.TextId, ArchiveDate, expanded.Content, expanded.Remarks, null);
                            }
                            await _repo.CompressVerse(t.TextId, t.timestamp, t.Content, t.Remarks, null);
                        }
                    }
                }
            }
        }