Exemplo n.º 1
0
        protected InputHandlerResult handleDirectVerseInput(
            UserSession us,
            string input)
        {
            try
            {
                int verse_id = -1;
                VerseSection vs = (VerseSection)us.getVariableObject("Browse.verse_section");
                if (vs == null)
                {
                    Console.WriteLine("Expected Browse.verse_section present, but not found");
                    return new InputHandlerResult(
                       InputHandlerResult.UNDEFINED_MENU_ACTION,
                       InputHandlerResult.DEFAULT_MENU_ID,
                       InputHandlerResult.DEFAULT_PAGE_ID);
                }
                if (Int32.TryParse(input, out verse_id))
                {
                    Verse curr_start_verse = vs.start_verse;
                    Verse end_verse = vs.end_verse;
                    Verse start_verse = curr_start_verse.chapter.getVerse(verse_id);

                    if (start_verse != null)
                    {
                        //end_verse = getDefaultEndVerse(start_verse);
                        end_verse = start_verse;
                        vs = new VerseSection(start_verse, end_verse);//we set end verse to distinguish browsing from direct input
                        us.setVariable("Browse.verse_section", vs);
                        us.recordVerseSelection(start_verse, end_verse);
                        return new InputHandlerResult(InputHandlerResult.NEW_MENU_ACTION,
                                    us.current_menu_loc,
                                    InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                    else
                    {
                        return new InputHandlerResult(
                          InputHandlerResult.UNDEFINED_MENU_ACTION,
                          InputHandlerResult.DEFAULT_MENU_ID,
                          InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                }
                else
                {
                    VerseSection vs1 = (VerseSection)us.getVariableObject("Browse.verse_section");
                    if (vs1 == null)
                    {
                        Console.WriteLine("Expected Browse.verse_section present, but not found");
                        return new InputHandlerResult(
                           InputHandlerResult.UNDEFINED_MENU_ACTION,
                           InputHandlerResult.DEFAULT_MENU_ID,
                           InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                    String current_book = "";
                    String current_chapter = "";
                    input = input.Replace(".", ":");
                    if(vs1 != null && vs1.start_verse != null)
                    {
                        current_book = vs1.start_verse.book.name;
                        current_chapter = vs1.start_verse.chapter.chapter_id.ToString(); // TODO: check the taking of chapter from start verse and not end verse
                    }
                    VerseSection vsection = Verse_Handler.getVerseSection(us, input, current_book, current_chapter);
                    if (vsection != null)
                    {
                        us.setVariable("Browse.verse_section", vsection);
                        Verse start_verse = vsection.start_verse;
                        Verse end_verse = vsection.end_verse;
                        us.recordVerseSelection(start_verse, end_verse);
                        return new InputHandlerResult(
                            InputHandlerResult.NEW_MENU_ACTION,
                            us.current_menu_loc,
                            InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                    else
                    {
                        return new InputHandlerResult(
                          InputHandlerResult.UNDEFINED_MENU_ACTION,
                          InputHandlerResult.DEFAULT_MENU_ID,
                          InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                }

            }
            catch (Exception e)
            {
                return new InputHandlerResult(
                          InputHandlerResult.UNDEFINED_MENU_ACTION,
                          InputHandlerResult.DEFAULT_MENU_ID,
                          InputHandlerResult.DEFAULT_PAGE_ID);
            }
        }
Exemplo n.º 2
0
 protected InputHandlerResult handleBrowseLinks(
     UserSession us,
     string input)
 {
     VerseSection vs = (VerseSection)us.getVariableObject("Browse.verse_section");
     if (vs == null)
     {
         Console.WriteLine("Expected Browse.verse_section present, but not found");
         return new InputHandlerResult(
            InputHandlerResult.UNDEFINED_MENU_ACTION,
            InputHandlerResult.DEFAULT_MENU_ID,
            InputHandlerResult.DEFAULT_PAGE_ID);
     }
     Verse start_verse = vs.start_verse;
     Verse end_verse = vs.end_verse;
     if (DISPLAY_MORE.Equals(input.Trim().ToUpper()))
     {
         if (end_verse != null && end_verse.next_verse != null)
         {
             start_verse = end_verse.next_verse;
             //end_verse = getDefaultEndVerse(start_verse);
             vs = new VerseSection(start_verse, null);
             us.setVariable("Browse.verse_section", vs);
             return new InputHandlerResult(InputHandlerResult.NEW_MENU_ACTION,
                         us.current_menu_loc,
                         InputHandlerResult.DEFAULT_PAGE_ID);
         }
         else
         {
             return new InputHandlerResult(
                                InputHandlerResult.UNDEFINED_MENU_ACTION,
                                InputHandlerResult.DEFAULT_MENU_ID,
                                InputHandlerResult.DEFAULT_PAGE_ID);
         }
     }
     else if (DISPLAY_NEXT_CHAPTER.Equals(input.Trim().ToUpper()))
     {
         if (start_verse != null &&
             start_verse.chapter != null  &&
             start_verse.chapter.next_chapter != null)
         {
             start_verse = start_verse.chapter.next_chapter.getVerse(1);
             //end_verse = getDefaultEndVerse(start_verse);
             vs = new VerseSection(start_verse, null);
             us.setVariable("Browse.verse_section", vs);
             return new InputHandlerResult(InputHandlerResult.NEW_MENU_ACTION,
                         us.current_menu_loc,
                         InputHandlerResult.DEFAULT_PAGE_ID);
         }
         else
         {
             return new InputHandlerResult(
                                InputHandlerResult.UNDEFINED_MENU_ACTION,
                                InputHandlerResult.DEFAULT_MENU_ID,
                                InputHandlerResult.DEFAULT_PAGE_ID);
         }
     }
     else if (DISPLAY_PREV_CHAPTER.Equals(input.Trim().ToUpper()))
     {
         if (start_verse != null &&
             start_verse.chapter != null &&
             start_verse.chapter.prev_chapter != null)
         {
             start_verse = start_verse.chapter.prev_chapter.getVerse(1);
             //end_verse = getDefaultEndVerse(start_verse);
             vs = new VerseSection(start_verse, null);
             us.setVariable("Browse.verse_section", vs);
             return new InputHandlerResult(InputHandlerResult.NEW_MENU_ACTION,
                         us.current_menu_loc,
                         InputHandlerResult.DEFAULT_PAGE_ID);
         }
         else
         {
             return new InputHandlerResult(
                                InputHandlerResult.UNDEFINED_MENU_ACTION,
                                InputHandlerResult.DEFAULT_MENU_ID,
                                InputHandlerResult.DEFAULT_PAGE_ID);
         }
     }
     else
     {
         return new InputHandlerResult(
                   InputHandlerResult.UNDEFINED_MENU_ACTION,
                   InputHandlerResult.DEFAULT_MENU_ID,
                   InputHandlerResult.DEFAULT_PAGE_ID);
     }
 }
Exemplo n.º 3
0
        public override void init(UserSession us)
        {
            //Console.WriteLine("Init Browse Interaction");
            //first we need a way to know if the screen should be cleared.
            us.setVariable(BROWSE_CLEAR_SCREEN, true);
            //now this is one big hack
            Boolean direct_select;
            try
            {
                Object o = us.removeVariable("Browse.directSelect");
                if(o==null)
                    direct_select = false;
                else
                    direct_select = (Boolean)o;
            }catch(Exception e)
            {
                direct_select = false;
            }

            int verse_history_index = getVerseHistoryIndex(us);

            //Verse was selected from history of verses
            if (verse_history_index > -1)
            {
                ReadOnlyCollection<VerseHistoryRecord> history_list = us.verse_history.getHistoryListForDisplay();
                VerseHistoryRecord vhr = history_list[verse_history_index];
                Verse start_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), vhr.start_verse);
                Verse end_verse;
                if (vhr.end_verse == null || vhr.start_verse.Equals(vhr.end_verse))
                    end_verse = start_verse;
                else if ("NULL".Equals(vhr.end_verse))
                    end_verse = BrowseBibleScreenOutputAdapter.getDefaultEndVerse(start_verse);
                else
                    end_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), vhr.end_verse);

                VerseSection vs = new VerseSection(start_verse, end_verse);
                us.setVariable("Browse.verse_section", vs);
            }
            else
            {
                String top_fav_verse = getTopFavouriteSelectedVerse(us);
                if (top_fav_verse != null)
                {
                    VerseSection vs = Verse_Handler.getVerseSection(us, top_fav_verse, null, null);
                    if (vs != null)
                    {
                        us.setVariable("Browse.verse_section", vs);
                        us.recordVerseSelection(vs.start_verse, vs.end_verse);
                    }
                }
                else
                {
                    int fav_verse_index = getFavouriteVerseIndex(us);

                    //Verse was selected from history of verses
                    if (fav_verse_index > -1)
                    {
                        ReadOnlyCollection<FavouriteVerseRecord> favourite_list = us.favourite_verses.getFavouriteListForDisplay();
                        FavouriteVerseRecord fvr = favourite_list[fav_verse_index];
                        Verse start_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), fvr.start_verse);
                        Verse end_verse;
                        if (fvr.end_verse == null || fvr.start_verse.Equals(fvr.end_verse))
                            end_verse = start_verse;
                        else if ("NULL".Equals(fvr.end_verse))
                            end_verse = BrowseBibleScreenOutputAdapter.getDefaultEndVerse(start_verse);
                        else
                            end_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), fvr.end_verse);

                        VerseSection vs = new VerseSection(start_verse, end_verse);
                        us.setVariable("Browse.verse_section", vs);
                        us.recordVerseSelection(vs.start_verse, vs.end_verse);
                    }
                    else{
                        String bookmark_verse = getBookmarkVerse(us);
                        if (bookmark_verse != null)
                        {
                            VerseSection vs = Verse_Handler.getVerseSection(us, bookmark_verse, null, null);
                            if (vs != null)
                            {
                                us.setVariable("Browse.verse_section", vs);
                                us.recordVerseSelection(vs.start_verse, vs.end_verse);
                            }
                        }
                        else
                        {
                            String daily_verse = getDailyVerseSelected(us);
                            if (daily_verse != null)
                            {
                                VerseSection vs = Verse_Handler.getVerseSection(us, daily_verse, null, null);
                                if (vs != null)
                                {
                                    us.setVariable("Browse.verse_section", vs);
                                    us.recordVerseSelection(vs.start_verse, vs.end_verse);
                                }
                            }
                            else
                            {
                                String topic_verse = getTopicVerse(us);
                                if (topic_verse != null)
                                {
                                    VerseSection vs = Verse_Handler.getVerseSection(us, topic_verse, null, null);
                                    if (vs != null)
                                    {
                                        us.setVariable("Browse.verse_section", vs);
                                        us.recordVerseSelection(vs.start_verse, vs.end_verse);
                                    }
                                }
                                else
                                {
                                    String search_verse = getSearchVerse(us);
                                    if (search_verse != null)
                                    {
                                        int search_verse_index = Int32.Parse(search_verse) - 1;
                                        SearchVerseRecord svr = us.search_results[search_verse_index];
                                        Verse start_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), svr.start_verse);
                                        VerseSection vs = new VerseSection(start_verse, start_verse);
                                        if (vs != null)
                                        {
                                            us.setVariable("Browse.verse_section", vs);
                                            us.recordVerseSelection(start_verse, start_verse);
                                        }
                                    }
                                    //verse was selected from direct select
                                    else if (direct_select == false)
                                    {

                                        Verse start_verse = BibleContainer.getInstance().getVerse(
                                                Int32.Parse(us.user_profile.getDefaultTranslationId()),
                                                Int32.Parse(us.getVariable("Testament_Handler.testament_id")),
                                                us.getVariable("BookOptionSet.book_id"),
                                                Int32.Parse(us.getVariable("ChapterOptionSet.chapter_id")),
                                                1);
                                        VerseSection vs = new VerseSection(start_verse, null);
                                        us.setVariable("Browse.verse_section", vs);
                                        us.recordVerseSelection(start_verse, null);
                                    }
                                    //Verse was selected by browsing
                                    else
                                    {
                                        VerseSection vs = (VerseSection)us.getVariableObject("Browse.verse_section");
                                        if (vs == null)
                                        {
                                            Console.WriteLine("Warning...verse_section context var was not found");
                                            throw new Exception("Expected Browse.verse_section var present but not found");
                                        }
                                        Verse start_verse = vs.start_verse;
                                        Verse end_verse = vs.end_verse;
                                        us.recordVerseSelection(start_verse, end_verse);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override InputHandlerResult handleInput(UserSession user_session, MessageReceived message_recieved)
        {
            string input = extractReply(message_recieved);
            //Console.WriteLine("in input handler: " + input);
            Console.WriteLine("User with ID: " + user_session.user_profile.id + " Entered: " + input);
            //get reply
            string curr_user_page = user_session.current_menu_loc;

            InputHandlerResult output = handleStdNavLinks(user_session, input);
            if (output.action != (InputHandlerResult.UNDEFINED_MENU_ACTION))
                return output;

            MenuManager mm = MenuManager.getInstance();
            //for now we assume this. must correct this later
            VerseMenuPage vmp = (VerseMenuPage)mm.menu_def.getMenuPage(curr_user_page);
            List<MenuOptionItem> options = vmp.options;
            foreach (MenuOptionItem option in options)
            {
                if (option.link_val.Equals(input))
                    return new InputHandlerResult(
                         InputHandlerResult.NEW_MENU_ACTION,
                         option.select_action,
                         InputHandlerResult.DEFAULT_PAGE_ID);
            }

            //now handle input
            input = input.Trim();
            if (input.Equals(""))
            {
                return new InputHandlerResult(
            "Invalid entry...Please enter a valid input (e.g. 'John 3:16' or '1 John 1:9' or read the help section for more information"); //invalid choice
            }
            input = input.Replace('.', ':');
            Verse start_verse = null;
            Verse end_verse = null;
            if (input.Contains('-'))
            {
                String[] start_end = input.Split('-');

                start_verse = getStartingVerse(user_session.user_profile.getDefaultTranslationId(), start_end[0]);
                if (start_verse == null)
                {
                    return new InputHandlerResult(
                                "Invalid entry...Please enter a valid input (e.g. 'John 3:16' or '1 John 1:9'"); //invalid choice
                }
                if (start_end.Count() >= 2)
                {
                    end_verse = getEndingVerse(user_session.user_profile.getDefaultTranslationId(), start_verse, start_end[1]);
                }
            }
            else
            {
                start_verse = getStartingVerse(user_session.user_profile.getDefaultTranslationId(), input);
            }
            user_session.deleteVariable("Browse.verse_section");

            try
            {
                if (end_verse == null)
                    end_verse = start_verse;
                VerseSection vs = new VerseSection(start_verse, end_verse);
                user_session.setVariable("Browse.verse_section", vs);
                //now this is one big hack
                user_session.setVariable("Browse.directSelect", true);
            }
            catch (XInvalidVerseSection e)
            {
                return new InputHandlerResult(e.Message); //invalid choice
            }

            return new InputHandlerResult(
                     InputHandlerResult.NEW_MENU_ACTION,
                     vmp.input_item.target_page,
                     InputHandlerResult.DEFAULT_PAGE_ID);
        }
Exemplo n.º 5
0
        //validate against NET
        public static bool validateVerseReference(String input)
        {
            //now handle input
            input = input.Trim();
            if (input.Equals(""))
            {
                return false;
            }
            input = input.Replace('.', ':');
            Verse start_verse = null;
            Verse end_verse = null;

            if (input.Contains('-'))
            {
                String[] start_end = input.Split('-');

                start_verse = getStartingVerse("2", start_end[0]);
                if (start_verse == null)
                {
                    return false;
                }
                if (start_end.Count() >= 2)
                {
                    end_verse = getEndingVerse("2", start_verse, start_end[1]);
                }
            }
            else
            {
                start_verse = getStartingVerse("2", input);
            }
            try
            {
                if (end_verse == null)
                    end_verse = start_verse;
                VerseSection vs = new VerseSection(start_verse, end_verse);
            }
            catch (XInvalidVerseSection e)
            {
                return false;
            }
            return true;
        }
Exemplo n.º 6
0
        public static VerseSection getVerseSection(
            UserSession us,
            String verse_section,
            String current_book_name,
            String current_chapter)
        {
            verse_section = verse_section.Trim();
            Verse start_verse = null;
            Verse end_verse = null;
            String book = getBookName(verse_section).Trim();
            book = BibleHelper.getFullBookName(book);
            if (book == null || (book != null && !isValidBook(us.user_profile.getDefaultTranslationId(), book)))//TODO fix this, throw Exception if book is invalid. otherwise we going to give user wrong section
            {
                if (verse_section.Contains('-'))
                {
                    String[] start_end = verse_section.Split('-');
                    String start = start_end[0];
                    if (!start.Contains(':'))
                        verse_section = current_chapter + ":" + start;
                    if (start_end.Count() > 1)
                        verse_section = verse_section + "-" + start_end[1];
                }
                verse_section = current_book_name + " " + verse_section;
            }
            else
            {
                if (verse_section.Contains('-'))
                {
                    String[] start_end = verse_section.Split('-');
                    String start = start_end[0];
                    if (!start.Contains(':'))
                        verse_section = current_chapter + ":" + start;
                    if(start_end.Count() > 1)
                            verse_section = verse_section + "-" + start_end[1];
                }
            }

            if (verse_section.Contains('-'))
            {
                String[] s_e = verse_section.Split('-');

                start_verse = getStartingVerse(us.user_profile.getDefaultTranslationId(), s_e[0]);
                if (start_verse == null)
                {
                    return null;
                }
                if (s_e.Count() >= 2)
                {
                    end_verse = getEndingVerse(us.user_profile.getDefaultTranslationId(), start_verse, s_e[1]);
                }
            }
            else
            {
                start_verse = getStartingVerse(us.user_profile.getDefaultTranslationId(), verse_section);
            }

            if (end_verse == null)
                end_verse = start_verse;
            VerseSection vs = new VerseSection(start_verse, end_verse);
            return vs;
        }