Esempio n. 1
0
        /// <summary>
        /// Handles a new prompt for this user.
        /// </summary>
        /// <param name="newPrompt"></param>
        public void Prompt(HeldPrompt newPrompt)
        {
            if (this.clearingPrompts)
            {
                return;
            }
            int foundPrompt = -1;

            lock (this.prompts)
            {
                for (int i = 0; i < prompts.Length; i++)
                {
                    if (this.prompts[i] == null)
                    {
                        foundPrompt     = i;
                        this.prompts[i] = newPrompt;
                        break;
                    }
                }
            }
            if (foundPrompt != -1)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("New Prompt ").Append(foundPrompt + 1).Append(endOfLine);
                newPrompt.OnTransition();
                this.sendMessage(builder.ToString());
            }
            else
            {
                //this.sendMessage("You were too busy to " + TODO ?);
                newPrompt.Respond(null);
            }
        }
Esempio n. 2
0
 public void Prompt(HeldPrompt prompt)
 {
     if (Client != null)
     {
         Client.Prompt(prompt);
     }
     else
     {
         prompt.Respond(null); //Use default from prompt.
         //TODO / NOTE: Caller should do everything it's supposed to do before calling Prompt.
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Responds to a prompt and handles the prompt's return value. Non-null responses should usually call this instead of calling Respond manually.
        /// </summary>
        /// <param name="input">User's response to the prompt.</param>
        /// <param name="prompt">Prompt being responded to.</param>
        /// <param name="toPrompt">Internal 'position' of the prompt being responded to in this.prompts</param>
        private void RespondToPrompt(string input, HeldPrompt prompt, int toPrompt = -1)
        {
            HeldPrompt next;

            try
            {
                next = prompt.Respond(input); //Skip prompt number + space
            }
            catch (Exception e)
            {
                //TODO: Error logging
                sendMessage("An error has occurred while processing your input: ^n" + e.ToString());
                if (!prompt.IsStillValid())
                {
                    if (this.mainPrompt == prompt)
                    {
                        sendMessage("Logging out to get back to a working state.");
                        LogOut();
                    }
                    else
                    {
                        sendMessage("Aborting broken prompt " + toPrompt);
                        this.RemovePrompt(prompt);
                    }
                }
                return;
            }
            if (next != null && !this.clearingPrompts)
            {
                lock (this.prompts)
                {
                    if (toPrompt != -1 && this.prompts[toPrompt] == prompt)
                    {
                        this.prompts[toPrompt] = next;
                        next.OnTransition();
                    }
                    else if (toPrompt == -1 && this.mainPrompt == prompt)
                    {
                        this.mainPrompt = next;
                        next.OnTransition();
                    }
                    else
                    {
                        this.Prompt(next);
                    }
                }
            }
        }
Esempio n. 4
0
 private void ClearPrompts()
 {
     this.clearingPrompts = true;
     lock (this.prompts)
     {
         HeldPrompt next;
         for (int i = 0; i < prompts.Length; i++)
         {
             next = prompts[i];
             if (next != null && next.IsStillValid())
             {
                 next.Respond(null);
             }
             prompts[i] = null;
         }
         if (mainPrompt != null && mainPrompt.IsStillValid())
         {
             mainPrompt.Respond(null);
         }
     }
     this.clearingPrompts = false;
 }