/// <summary>
        /// Initializes a new instance of the <see cref="DialogManager{TInputType}"/> class.
        /// </summary>
        /// <param name="dialogBackend"> The dialog backend for the manager to use. </param>
        /// <param name="keywordRegistration"> The keyword registration with the current keyword file information.</param>
        /// <param name="dialogAudioInput"> The input audio provider. </param>
        /// <param name="agentSessionManager"> The manager that provides the instance of agent session wrapper. </param>
        /// <param name="dialogAudioOutput"> The dialog audio output sink to use. </param>
        public DialogManager(
            IDialogBackend <TInputType> dialogBackend,
            IKeywordRegistration keywordRegistration,
            IDialogAudioInputProvider <TInputType> dialogAudioInput,
            IAgentSessionManager agentSessionManager,
            IDialogAudioOutputAdapter dialogAudioOutput = null)
        {
            Contract.Requires(dialogBackend != null);
            Contract.Requires(agentSessionManager != null);
            this.logger        = LogRouter.GetClassLogger();
            this.dialogBackend = dialogBackend;
            this.dialogBackend.SessionStarted += (id)
                                                 => this.logger.Log($"DialogManager: Session start: {id}");
            this.dialogBackend.SessionStopped += (id)
                                                 => this.logger.Log($"DialogManager: Session stop: {id}");
            this.dialogBackend.KeywordRecognizing += this.OnKeywordRecognizing;
            this.dialogBackend.KeywordRecognized  += this.OnKeywordRecognized;
            this.dialogBackend.SpeechRecognizing  += this.OnSpeechRecognizing;
            this.dialogBackend.SpeechRecognized   += async(text)
                                                     => await this.OnSpeechRecognizedAsync(text);

            this.dialogBackend.DialogResponseReceived += this.OnActivityReceived;
            this.dialogBackend.ErrorReceived          += async(errorInformation)
                                                         => await this.OnErrorReceivedAsync(errorInformation);

            this.dialogAudioInput    = dialogAudioInput;
            this.keywordRegistration = keywordRegistration;
            this.agentSessionManager = agentSessionManager;

            this.agentSessionManager.SignalDetected += (sender, args) => this.HandleSignalDetection(args);
            this.InitializeSignalDetectionHelper();

            _ = this.InitializeAsync(dialogAudioOutput);
        }
 public static async Task<DialogManager<List<byte>>> CreateMockManagerAsync(
     IDialogBackend<List<byte>> backend,
     IKeywordRegistration keywordRegistration,
     IAgentSessionManager agentSessionManager)
 {
     var dialogManager = new DialogManager<List<byte>>(backend, keywordRegistration, new AgentAudioInputProvider(), agentSessionManager);
     await dialogManager.InitializeAsync();
     return dialogManager;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MainPage"/> class.
        /// </summary>
        public MainPage()
        {
            this.logger = LogRouter.GetClassLogger();

            this.InitializeComponent();

            this.app = App.Current as App;
            this.app.HasReachedForeground = true;

            this.services            = this.app.Services;
            this.dialogManager       = this.services.GetRequiredService <IDialogManager>();
            this.keywordRegistration = this.services.GetRequiredService <IKeywordRegistration>();
            this.agentSessionManager = this.services.GetRequiredService <IAgentSessionManager>();

            this.informationLogs = new HashSet <TextBlock>();
            this.errorLogs       = new HashSet <TextBlock>();
            this.noiseLogs       = new HashSet <TextBlock>();

            // Ensure that we restore the full view (not the compact mode) upon foreground launch
            _ = this.UpdateViewStateAsync();

            // Ensure we have microphone permissions and that we pop a consent dialog if the user
            // hasn't already given an explicit yes/no.
            _ = Task.Run(async() =>
            {
                var control = await AudioCaptureControl.GetInstanceAsync();
                await control.MicrophoneCapability.RequestAccessAsync();
            });

            // Kick off the registration and/or retrieval of the 1st-stage keyword information
            _ = this.DoKeywordSetupAsync();

            // Populate the drop-down list for TTS audio output formats and select the current choice
            var supportedFormats = DirectLineSpeechAudio.SupportedOutputFormats;

            foreach (var entry in supportedFormats)
            {
                this.OutputFormatComboBox.Items.Add(entry.Label);
            }

            this.OutputFormatComboBox.SelectedItem = this.OutputFormatComboBox.Items.FirstOrDefault(item =>
                                                                                                    item.ToString() == LocalSettingsHelper.OutputFormat.Label);

            // Wire a few pieces of UI handling that aren't trivially handled by XAML bindings
            this.AddUIHandlersAsync();

            // Ensure consistency between a few dependent controls and their settings
            this.UpdateUIBasedOnToggles();

            this.Conversations = new ObservableCollection <Conversation>();

            this.ChatHistoryListView.ContainerContentChanging += this.OnChatHistoryListViewContainerChanging;
        }
        protected DialogManagerShim(
            IDialogBackend<List<byte>> backend,
            IKeywordRegistration keywordRegistration,
            DialogAudioOutputAdapter outputAdapter) :
        base(
            backend,
            keywordRegistration,
            new AgentAudioInputProvider(),
            new AgentSessionManager(),
            dialogAudioOutput: outputAdapter)
        {

        }