// Handler for the SessionCompleted event on the Browser object.
        // This implementation writes the values returned by the VoiceXML dialog to the console.
        private void HandleSessionCompleted(object sender, SessionCompletedEventArgs e)
        {
            _waitForSessionCompleted.Set();
            VoiceXmlResult result        = e.Result;
            String         cityOffset    = result.Namelist["CityOffset"].ToString();
            String         utterance     = result.Namelist["CityOffset$.utterance"].ToString();
            String         confidence    = result.Namelist["CityOffset$.confidence"].ToString();
            String         requestedTime = result.Namelist["timeAtRequestedCity"].ToString();

            Console.WriteLine("Returned semantic result: " + cityOffset);
            Console.WriteLine("Utterance: " + utterance);
            Console.WriteLine("Confidence: " + confidence);
            Console.WriteLine("Requested time: " + requestedTime);
        }
Пример #2
0
        // Handler for the SessionCompleted event on the Browser object.
        // This implementation writes the values returned by the VoiceXML dialog to the console.
        private void HandleSessionCompleted(object sender, SessionCompletedEventArgs e)
        {
            Console.WriteLine("VXML HandleSessionCompleted.");
            VoiceXmlResult result = e.Result;

            if (e.Result != null && e.Result.Namelist != null)
            {
                string levelName = string.Empty;
                int    choice    = 0;
                var    selection = result.Namelist["menu"].ToString();
                Console.WriteLine("selected menu " + selection);

                currentLevel++;
                levelName = selection;

                if (currentLevel == 0)
                {
                    if (int.TryParse(selection, out choice))
                    {
                        var topLevels = parser.TopLevelMenuOptions();
                        var option    = topLevels.Where(opt => opt.Id.Equals(selection,
                                                                             StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        levelName = option.Name;
                    }

                    PlayMenu(levelName);

                    selectedOptions.Insert(currentLevel, levelName);
                }
                else if (currentLevel == 1)
                {
                    if (int.TryParse(selection, out choice))
                    {
                        var subLevels = parser.SubOptions(selectedOptions[0]);
                        var option    = subLevels.Where(opt => opt.Id.Equals(selection,
                                                                             StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        levelName = option.Name;
                    }

                    selectedOptions.Insert(currentLevel, levelName);
                    waitForMenuInput.Set();
                }
            }
            else
            {
                waitForMenuInput.Set();
            }
        }
Пример #3
0
        //Basic handling only.
        //In production, this is a useful place to write application logs, as appropriate.
        private void HandleSessionCompleted(object sender, SessionCompletedEventArgs e)
        {
            hangupCallButton.BackColor = buttonColor;

            if (!runCompletedCB.Checked)
            {
                return;
            }

            if (e.Error != null)
            {
                AddResultStringToOutput(String.Format("Error on return: {0}", e.Error.Message));
            }
            else if (e.Cancelled)
            {
                AddResultStringToOutput("Run was cancelled by application. Call Status: "
                                        + voiceXmlBrowser.State);
            }
            else
            {
                AddResultStringToOutput("Run completed. Reason: " + e.Result.Reason);
                AddResultStringToOutput("Namelist variables from VoiceXml page processing:\n");
                if (e.Result != null && e.Result.Namelist != null)
                {
                    foreach (string key in e.Result.Namelist.Keys)
                    {
                        AddResultStringToOutput(" " + key + " = " + e.Result.Namelist[key] + "\n");
                    }
                }
            }

            //It is good practice to check the call state after the session terminicates and take appropriate action if
            //the call is still active. Options include:
            //1. Hangup (see below)
            //2. Play a goodbye audio file on the call and then hangup
            //3. Transfer, for example to customer service
            //
            //Current implementation calls helper method, which will terminate active calls and cleanup EventHandlers.
            this.CleanupCall();
        }
Пример #4
0
        /// <summary>
        /// Invoked when the session is complete. Sets the results of the session on the given task source.
        /// </summary>
        /// <param name="tcs"></param>
        /// <param name="args"></param>
        void OnSessionCompleted(TaskCompletionSource<VoiceXmlResult> tcs, SessionCompletedEventArgs args)
        {
            if (tcs.Task.IsCompleted)
                return;

            Dispatch(() =>
            {
                if (tcs.Task.IsCompleted)
                    return;

                if (args.Cancelled)
                    tcs.SetCanceled();
                else if (args.Error != null)
                    tcs.SetException(args.Error);
                else if (args.Result.UnhandledThrowElement != null)
                    tcs.SetException(new UnhandledPageThrowException(args.Result.UnhandledThrowElement));
                else
                    tcs.SetResult(args.Result);
            });
        }