public void InitializeTest()
        {
            //Arrange
            var container   = new Container();
            var initializer = new BackEndInitializer();

            //Act
            initializer.Initialize(container);

            //Assert
            container.Verify();
        }
Пример #2
0
        public void InitializeTest()
        {
            //Arrange
            var container = new Container();
            var initializer = new BackEndInitializer();
            
            //Act
            initializer.Initialize(container);

            //Assert
            container.Verify();
        }
Пример #3
0
 public IndexLooker(BackEndInitializer backEnd)
 {
     _backEnd = backEnd;
 }
Пример #4
0
        // assumes the ReferenceItem has already been built
        public List<ReferenceItem> BuildVerseListFromRange(ReferenceItem item, BackEndInitializer backend)
        {
            if (item.Range)
            {
                List<ReferenceItem> expandedReferenceList = new List<ReferenceItem>();

                // get list of the books
                int startBookIndex = Array.IndexOf(backend.CurrentBooks, item.StartBook);
                int endBookIndex = Array.IndexOf(backend.CurrentBooks, item.EndBook);
                int startingChapter;
                int endingChapter;
                int startingVerse;
                int endingVerse;
                string book;
                // cycle through the books selected
                for (int bookIndex = startBookIndex; bookIndex <= endBookIndex; bookIndex++)
                {
                    book = backend.CurrentBooks[bookIndex];

                    if (book == item.StartBook) // get starting chapter and verse
                    { startingChapter = (int)item.StartChapter; }
                    else
                    { startingChapter = 1; }
                    if (book == item.EndBook) // get ending chapter and verse
                    { endingChapter = (int)item.EndChapter; }
                    else
                    { endingChapter = backend.CurrentChapters(book).Count(); }

                    // cycle through chapters for current book
                    for (int chapter = startingChapter; chapter <= endingChapter; chapter++)
                    {
                        if (book == item.StartBook && chapter == item.StartChapter)
                        { startingVerse = (int)item.StartVerse; }
                        else
                        { startingVerse = 1; }
                        if (book == item.EndBook && chapter == item.EndChapter)
                        { endingVerse = (int)item.EndVerse; }
                        else
                        { endingVerse = backend.CurrentVerses(book, chapter).Count; }

                        // cycle through verses for currect chapter
                        for (int verse = startingVerse; verse <= endingVerse; verse++)
                        {
                            expandedReferenceList.Add(new ReferenceItem(book, chapter,
                                verse, false, backend.GetVerse(book, chapter, verse)));
                        }
                    }
                }

                return expandedReferenceList;
            }
            else
            {
                return null;
            }
        }
Пример #5
0
        // copy over full reference data on each item
        public void CompleteReferences(BackEndInitializer backend)
        {
            ReferenceItem reference;
            for (int i = 0; i < _referenceList.Count; i++)
            {
                reference = _referenceList[i];
                // handle missing starting references
                if (reference.StartChapter == null) // whole book listed
                {
                    reference.StartChapter = 1;
                    if (reference.Range == false)
                    {
                        reference.EndBook = reference.StartBook;
                        reference.EndChapter = backend.CurrentChapters(reference.StartBook).Last();
                    }
                }
                if (reference.StartVerse == null) // whole chapter listed
                {
                    reference.StartVerse = 1;
                    if (reference.Range == false)
                    {
                        reference.EndBook = reference.StartBook;
                        if (reference.EndChapter == null)
                        {
                            reference.EndChapter = reference.StartChapter;
                        }
                        reference.EndVerse = backend.CurrentVerses(reference.StartBook, (int)reference.EndChapter).Count;
                    }
                }

                // handle missing ending references
                if (reference.Range == true)
                {
                    if (reference.EndBook == null) // no book -- john 3-4
                    {
                        reference.EndBook = reference.StartBook;
                    }

                    if(reference.EndChapter == null && reference.StartBook != reference.EndBook) // 1 john - 2 john
                    {
                        reference.EndChapter = backend.CurrentChapters(reference.EndBook).Last();
                    }
                    else if (reference.EndChapter == null) // no chapter --> john 3:3-5
                    {// so same chapter for start as end
                        reference.EndChapter = reference.StartChapter;
                    }
                    if (reference.EndVerse == null) // no verse --> john 3 - john 4 or john 3 - 4
                    {// so last verse of endChapter
                        reference.EndVerse = backend.CurrentVerses(reference.EndBook, (int)reference.EndChapter).Count;
                    }
                }

                // set reff range to true if range items have been filled in
                if (reference.EndBook != null)
                {
                    reference.Range = true;
                }
            }
        }
Пример #6
0
        public void searchString(string originalSearch, BackEndInitializer _backend, IMainWindow _view)
        {
            PresenterFolder.ReferenceList referenceList = new PresenterFolder.ReferenceList(); // list of references to display
            List<string> suggestionList = new List<string>(); // list of what user might want to type next
            string searchPhrase = "";

            string[] text = originalSearch.Replace(";", " ; ").Split(' ');  // put to space seperated array and seperate the ;'s
            text = PreSearchStringBuilder.FixBookNumberTitlesInSearchArray(text);
            text = PreSearchStringBuilder.CombineHyphenAndDashInArray(text);

            bool foundBook = false; // keeps track of whether this is part way into a reference ie. just found the a book name
            string lastFoundBook = "";
            for (int i = 0; i < text.Count(); i++)
            {
                if (text[i] == ";") // end of reference
                {
                    foundBook = false;
                }
                // look for a whole book name
                else if (!foundBook && _index.ContainsBook(text[i]))
                {
                    foundWholeBookName( ref lastFoundBook, ref text, ref i, ref suggestionList, ref _view, ref originalSearch, ref referenceList);
                    foundBook = true;
                }
                // look for -
                else if (text[i] == "-") // found a book range reference
                {
                    referenceList.CurrentReference.Range = true;
                    foundBook = false;
                }
                // look for part of a book name if last item in text[]
                else if (!foundBook)
                {
                    suggestionList = _backend.CurrentBooks.ToList().StartsWithInList(text[i]);
                    if (suggestionList != null && i == text.Count() - 1) // found part of a book name
                    {
                        _view.SearchBoxSuggestions(suggestionList, originalSearch);
                    }
                    // not a refernce so do a search of the index
                    else
                    {
                        if (i >= text.Count() - 1 && !_backend.WordExists(text[i].ToLower())) // last term
                        {
                            _view.SearchBoxSuggestions(_backend.WordsThatStartWith(text[i].ToLower()),
                                originalSearch);
                        }
                        else
                        {
                            searchPhrase += text[i].ToLower() + " ";
                        }
                    }
                }
                // look for reference numbers
                else if (foundBook)
                {
                    foundBook = false;
                    int chapNumber;
                    if ((int.TryParse(text[i], out chapNumber))) // just a number
                    {
                        if (referenceList.CurrentReference.StartChapter == null) // check if start chap is empty
                        {
                            referenceList.CurrentReference.StartChapter = chapNumber;
                        }
                        else // start chap already has something in it
                        {
                            referenceList.CurrentReference.EndChapter = chapNumber;
                        }
                    }
                    else if (text[i].Contains(':') && !(text[i].Contains('-'))) // just :
                    {
                        if (text[i].EndsWith(":")) // only chap listed return possible verses
                        {
                            // return a list of possible verses for indicated chapter
                            suggestionList = _index.GetPossibleVerses(lastFoundBook, text[i].Substring(0, text[i].Length - 1));
                            suggestionList = suggestionList.AddPrefixToList(originalSearch);
                            _view.SearchBoxSuggestions(suggestionList, originalSearch);
                        }
                        else // chap & verse so store full refence
                        {
                            string[] temp = text[i].Split(':');
                            if (referenceList.CurrentReference.StartChapter == null)
                            {
                                referenceList.CurrentReference.StartChapter = Convert.ToInt32(temp[0]);
                                referenceList.CurrentReference.StartVerse = Convert.ToInt32(temp[1]);
                            }
                            else
                            {
                                referenceList.CurrentReference.EndChapter = Convert.ToInt32(temp[0]);
                                referenceList.CurrentReference.EndVerse = Convert.ToInt32(temp[1]);
                            }
                        }
                    }// end -- // just :
                    else if (text[i].Contains('-') && !(text[i].Contains(':'))) // just - so dealing with chapters only
                    {
                        string[] temp = text[i].Split('-');
                        referenceList.CurrentReference.StartChapter = Convert.ToInt16(temp[0]);
                        referenceList.CurrentReference.EndChapter = Convert.ToInt16(temp[1]);
                        referenceList.CurrentReference.Range = true;
                    } // end  --  // just - so dealing with chapters only
                } // end --// look for reference numbers
            } // end for loop for text[i]
            if (searchPhrase != "") // do index search if needed
            {
                searchPhrase = searchPhrase.Remove(searchPhrase.Count()-1); // acount for space on end
                referenceList.AppendReferenceList(_backend.searchPhrase(searchPhrase));
            }
            if (referenceList.Items.Count > 0)
            {
                _presenter.DisplayVersesToWebView(referenceList, searchPhrase);
            }
            else
            {
                _presenter.WriteWebView("No results.");
            }
        }