public void Build(UnitOfWork uow, string byzPath, string troPath, string pbpwPath)
        {
            var byzConnection  = GetConnection(byzPath);
            var troConnection  = GetConnection(troPath);
            var pbpwConnection = GetConnection(pbpwPath);

            var translation = CreateTranslation(uow);

            TroVerses    = GetTroVerseInfos(troConnection);
            ByzVerses    = GetByzVerses(byzConnection);
            PbpwVerses   = GetPbpwVerseInfos(pbpwConnection);
            Strongs      = new XPQuery <StrongCode>(uow).Where(x => x.Lang == Language.Greek);
            BaseBooks    = new XPQuery <BookBase>(uow).Where(x => x.Status.BiblePart == BiblePart.NewTestament).OrderBy(x => x.NumberOfBook);
            GrammarCodes = new XPQuery <GrammarCode>(uow).OrderBy(x => x.GrammarCodeVariant1);

            foreach (var baseBook in BaseBooks)
            {
                var chapterCount = ByzVerses.Where(x => x.Book == baseBook.NumberOfBook)
                                   .Max(x => x.Chapter);
                Book book = null;
                if (book.IsNull())
                {
                    book = new Book(uow)
                    {
                        BaseBook          = baseBook,
                        BookName          = baseBook.BookName,
                        BookShortcut      = baseBook.BookShortcut,
                        Color             = baseBook.Color,
                        NumberOfBook      = baseBook.NumberOfBook,
                        NumberOfChapters  = chapterCount,
                        ParentTranslation = translation
                    };
                    book.Save();
                    uow.CommitChanges();
                    uow.ReloadChangedObjects();

#if DEBUG
                    System.Diagnostics.Debug.WriteLine("-----------------------------------------------");
                    System.Diagnostics.Debug.Write($"{baseBook.BookTitle}");
#endif
                }

                for (int chapterIndex = 1; chapterIndex <= chapterCount; chapterIndex++)
                {
                    var versesCount = ByzVerses.Where(x => x.Book == baseBook.NumberOfBook &&
                                                      x.Chapter == chapterIndex)
                                      .Max(x => x.Verse);
                    Chapter chapter = null;
                    if (chapter.IsNull())
                    {
                        chapter = new Chapter(uow)
                        {
                            NumberOfChapter = chapterIndex,
                            NumberOfVerses  = versesCount,
                            ParentBook      = book
                        };
                        chapter.Save();
                        uow.CommitChanges();
                        uow.ReloadChangedObjects();
#if DEBUG
                        System.Diagnostics.Debug.WriteLine("");
                        System.Diagnostics.Debug.Write($"Rozdział {chapterIndex}");
#endif
                    }
                    for (int verseIndex = 1; verseIndex <= versesCount; verseIndex++)
                    {
                        Verse verse = null;
                        if (verse.IsNull())
                        {
                            var pbpwVerse = PbpwVerses.Where(x => x.Book == baseBook.NumberOfBook &&
                                                             x.Chapter == chapterIndex &&
                                                             x.Verse == verseIndex).FirstOrDefault();
                            verse = new Verse(uow)
                            {
                                NumberOfVerse = verseIndex,
                                ParentChapter = chapter,
                                Text          = pbpwVerse.IsNotNull() ? pbpwVerse.VerseText : String.Empty
                            };
                            verse.Save();
                            uow.CommitChanges();
                            uow.ReloadChangedObjects();
#if DEBUG
                            System.Diagnostics.Debug.WriteLine("");
                            System.Diagnostics.Debug.Write($"{verseIndex}. ");
#endif
                        }

                        var vi = ByzVerses.Where(x => x.Book == baseBook.NumberOfBook &&
                                                 x.Chapter == chapterIndex &&
                                                 x.Verse == verseIndex).FirstOrDefault();
                        if (vi.IsNotNull())
                        {
                            var ti = GetTroVerseInfo(vi);
                            if (ti.IsNotNull())
                            {
                                var wordIndex = 1;
                                foreach (var viWord in vi.Words)
                                {
                                    var tiWord = ti.Words.Where(x => x.WordIndex == viWord.WordIndex).FirstOrDefault();
                                    if (tiWord.IsNotNull())
                                    {
                                        if (tiWord.StrongCode != viWord.StrongCode)
                                        {
                                            // może kod się różni ale dla pewności porównam transliterację
                                            if (!Compare(viWord, tiWord))
                                            {
                                                // tu trzeba sprawdzić czy to słowo nie występuje gdzieś dalej
                                                // wówczas trzeba przetłumaczyć słowa w oparciu o wcześniej
                                                // zbudowany słownik aż do wystąpienia tego słowa w tekście
                                                // TRO



                                                tiWord = ti.Words.Where(x => x.StrongCode == viWord.StrongCode &&
                                                                        x.GrammarCode != null &&
                                                                        x.GrammarCode.Contains(viWord.GrammarCode) &&
                                                                        x.WordIndex >= viWord.WordIndex).FirstOrDefault();
                                                if (tiWord.IsNull())
                                                {
                                                    tiWord = ti.Words.Where(x => x.StrongCode == viWord.StrongCode &&
                                                                            x.GrammarCode != null &&
                                                                            x.GrammarCode.Contains(viWord.GrammarCode)).FirstOrDefault();
                                                }

                                                if (tiWord.IsNull())
                                                {
                                                    tiWord = new TroVerseWordInfo()
                                                    {
                                                        GrammarCode  = viWord.GrammarCode,
                                                        Text         = viWord.Text,
                                                        StrongCode   = viWord.StrongCode,
                                                        Translation  = viWord.Text.TransliterateAncientGreek(),
                                                        Transliterit = viWord.Text.TransliterateAncientGreek(),
                                                        WordIndex    = viWord.WordIndex
                                                    };
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        tiWord = new TroVerseWordInfo()
                                        {
                                            GrammarCode  = viWord.GrammarCode,
                                            Text         = viWord.Text,
                                            StrongCode   = viWord.StrongCode,
                                            Translation  = EMPTY_TRANSLATION,
                                            Transliterit = viWord.Text.TransliterateAncientGreek(),
                                            WordIndex    = viWord.WordIndex
                                        };
                                    }

                                    VerseWord word = null;
                                    if (word.IsNull())
                                    {
                                        word = new VerseWord(uow)
                                        {
                                            GrammarCode       = GetGrammarCode(uow, viWord.GrammarCode, tiWord.IsNotNull() ? tiWord.GrammarCode : null),
                                            StrongCode        = GetStrongCode(viWord.StrongCode),
                                            NumberOfVerseWord = wordIndex,
                                            ParentVerse       = verse,
                                            SourceWord        = viWord.Text,
                                            Translation       = tiWord.IsNotNull() ? tiWord.Translation : String.Empty,
                                            Transliteration   = tiWord.IsNotNull() ? tiWord.Transliterit : viWord.Text.TransliterateAncientGreek()
                                        };
                                        word.Save();
                                        uow.CommitChanges();
                                        uow.ReloadChangedObjects();

#if DEBUG
                                        System.Diagnostics.Debug.Write($"{word.Translation} ");
#endif
                                    }
                                    wordIndex++;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void Save()
        {
            this.Text = $"Translation editor :: {Object.Name}";
            Object.Save();
            var uow = Object.Session as UnitOfWork;

            uow.CommitChanges();

            foreach (var item in TreeItems.Where(x => x.Type == IbeTreeItemType.Book))
            {
                var bookItem = item as IbeBookTreeItem;
                if (item.IsNew)
                {
                    var book = new Book(uow)
                    {
                        AuthorName               = bookItem.AuthorName,
                        BaseBook                 = new XPQuery <BookBase>(uow).Where(x => x.Oid == bookItem.BaseBook.Id).FirstOrDefault(),
                        BookName                 = bookItem.BookName,
                        BookShortcut             = bookItem.BookShortcut,
                        Color                    = bookItem.Color,
                        IsTranslated             = bookItem.IsTranslated,
                        NumberOfBook             = bookItem.Number,
                        ParentTranslation        = Object,
                        PlaceWhereBookWasWritten = bookItem.PlaceWhereBookWasWritten,
                        Preface                  = bookItem.Preface,
                        Purpose                  = bookItem.Purpose,
                        Subject                  = bookItem.Subject,
                        TimeOfWriting            = bookItem.TimeOfWriting,
                        NumberOfChapters         = bookItem.NumberOfChapters
                    };
                    book.Save();
                    uow.CommitChanges();
                    uow.ReloadChangedObjects();

                    bookItem.IsNew   = false;
                    bookItem.Changed = false;
                    bookItem.Tag     = book.Oid;
                    // bookItem.ID = $"Book_{book.Oid}";
                }
                else if (item.Changed)
                {
                    var book = new XPQuery <Book>(uow).Where(x => x.Oid == bookItem.Tag).FirstOrDefault();
                    book.AuthorName               = bookItem.AuthorName;
                    book.BaseBook                 = new XPQuery <BookBase>(uow).Where(x => x.Oid == bookItem.BaseBook.Id).FirstOrDefault();
                    book.BookName                 = bookItem.BookName;
                    book.BookShortcut             = bookItem.BookShortcut;
                    book.Color                    = bookItem.Color;
                    book.IsTranslated             = bookItem.IsTranslated;
                    book.NumberOfBook             = bookItem.Number;
                    book.PlaceWhereBookWasWritten = bookItem.PlaceWhereBookWasWritten;
                    book.Preface                  = bookItem.Preface;
                    book.Purpose                  = bookItem.Purpose;
                    book.Subject                  = bookItem.Subject;
                    book.TimeOfWriting            = bookItem.TimeOfWriting;
                    book.NumberOfChapters         = bookItem.NumberOfChapters;

                    book.Save();
                    uow.CommitChanges();

                    bookItem.Changed = false;
                }
            }

            foreach (var item in TreeItems.Where(x => x.Type == IbeTreeItemType.Chapter))
            {
                var chapterItem = item as IbeChapterTreeItem;
                if (item.IsNew)
                {
                    var parentBookItem = TreeItems.Where(x => x.ID == chapterItem.ParentID).FirstOrDefault() as IbeBookTreeItem;

                    var chapter = new Chapter(uow)
                    {
                        IsTranslated    = chapterItem.IsTranslated,
                        NumberOfChapter = chapterItem.Number,
                        NumberOfVerses  = chapterItem.NumberOfVerses,
                        ParentBook      = new XPQuery <Book>(uow).Where(x => x.Oid == parentBookItem.Tag).FirstOrDefault()
                    };
                    chapter.Save();
                    uow.CommitChanges();
                    uow.ReloadChangedObjects();

                    chapterItem.IsNew   = false;
                    chapterItem.Changed = false;
                    chapterItem.Tag     = chapter.Oid;
                    // chapterItem.ID = $"Chapter_{chapter.Oid}";
                }
                else if (item.Changed)
                {
                    var chapter = new XPQuery <Chapter>(uow).Where(x => x.Oid == chapterItem.Tag).FirstOrDefault();
                    chapter.IsTranslated    = chapterItem.IsTranslated;
                    chapter.NumberOfChapter = chapterItem.Number;
                    chapter.NumberOfVerses  = chapterItem.NumberOfVerses;

                    chapter.Save();
                    uow.CommitChanges();

                    chapterItem.Changed = false;
                }
            }

            foreach (var item in TreeItems.Where(x => x.Type == IbeTreeItemType.Verse))
            {
                var verseItem = item as IbeVerseTreeItem;
                if (item.IsNew)
                {
                    var parentChapterItem = TreeItems.Where(x => x.ID == verseItem.ParentID).FirstOrDefault() as IbeChapterTreeItem;

                    var verse = new Verse(uow)
                    {
                        NumberOfVerse    = verseItem.Number,
                        StartFromNewLine = verseItem.StartFromNewLine,
                        Text             = verseItem.Value,
                        ParentChapter    = new XPQuery <Chapter>(uow).Where(x => x.Oid == parentChapterItem.Tag).FirstOrDefault()
                    };

                    SetSubtitle(verse, verseItem, uow, 1);
                    SetSubtitle(verse, verseItem, uow, 2);
                    //if (verseItem.SubtitleLevel1.IsNotNullOrEmpty()) {
                    //    var subtitle1 = verse.ParentChapter.Subtitles.Where(x => x.BeforeVerseNumber == verse.NumberOfVerse && x.Level == 1).FirstOrDefault();
                    //    if (subtitle1.IsNotNull()) {
                    //        subtitle1.BeforeVerseNumber = verse.NumberOfVerse;
                    //        subtitle1.ParentChapter = verse.ParentChapter;
                    //        subtitle1.Level = 1;
                    //        subtitle1.Text = verseItem.SubtitleLevel1;
                    //    }
                    //    else {
                    //        subtitle1 = new Subtitle(uow) {
                    //            BeforeVerseNumber = verse.NumberOfVerse,
                    //            ParentChapter = verse.ParentChapter,
                    //            Level = 1,
                    //            Text = verseItem.SubtitleLevel1
                    //        };
                    //    }
                    //    subtitle1.Save();
                    //}
                    //if (verseItem.SubtitleLevel2.IsNotNullOrEmpty()) {
                    //    var subtitle2 = verse.ParentChapter.Subtitles.Where(x => x.BeforeVerseNumber == verse.NumberOfVerse && x.Level == 2).FirstOrDefault();
                    //    if (subtitle2.IsNotNull()) {
                    //        subtitle2.BeforeVerseNumber = verse.NumberOfVerse;
                    //        subtitle2.ParentChapter = verse.ParentChapter;
                    //        subtitle2.Level = 1;
                    //        subtitle2.Text = verseItem.SubtitleLevel2;
                    //    }
                    //    else {
                    //        subtitle2 = new Subtitle(uow) {
                    //            BeforeVerseNumber = verse.NumberOfVerse,
                    //            ParentChapter = verse.ParentChapter,
                    //            Level = 2,
                    //            Text = verseItem.SubtitleLevel2
                    //        };
                    //    }
                    //    subtitle2.Save();
                    //}

                    verse.Save();
                    uow.CommitChanges();
                    uow.ReloadChangedObjects();

                    verseItem.IsNew   = false;
                    verseItem.Changed = false;
                    verseItem.Tag     = verse.Oid;
                }
                else if (item.Changed)
                {
                    var verse = new XPQuery <Verse>(uow).Where(x => x.Oid == verseItem.Tag).FirstOrDefault();
                    verse.StartFromNewLine = verseItem.StartFromNewLine;
                    verse.NumberOfVerse    = verseItem.Number;
                    verse.Text             = verseItem.Value;

                    SetSubtitle(verse, verseItem, uow, 1);
                    SetSubtitle(verse, verseItem, uow, 2);

                    verse.Save();
                    uow.CommitChanges();

                    verseItem.Changed = false;
                }
            }

            // refresh translations window
            try {
                if (ObjectSaved.IsNotNull())
                {
                    ObjectSaved(Object, EventArgs.Empty);
                }
            }
            catch { }
        }