Beispiel #1
0
        /// <summary>
        /// It's not required, but for optimization purposes it's acceptable to cache the ConversationalAgentSession
        /// for the lifetime of the app and use it across background/foreground invocations.
        /// </summary>
        /// <returns>Cached Conversation session state.</returns>
        public async Task <IAgentSessionWrapper> GetSessionAsync()
        {
            await this.cachedSessionSemaphore.WaitAsync().ConfigureAwait(false);

            try
            {
                if (this.cachedAgentSession == null)
                {
                    this.cachedAgentSession = new AgentSessionWrapper(await ConversationalAgentSession.GetCurrentSessionAsync());
                    this.cachedAgentSession.InitializeHandlers();

                    this.cachedAgentSession.SignalDetected += this.OnInAppSignalEventDetected;
                }
            }
            catch (Exception ex)
            {
                this.logger.Log(LogMessageLevel.Error, $"Unable to configure a ConversationalAgentSession. Please check your registration with the MVA platform.\r\n{ex.Message}");
            }
            finally
            {
                this.cachedSessionSemaphore.Release();
            }

            return(this.cachedAgentSession);
        }
Beispiel #2
0
        /// <summary>
        /// It's not required, but for optimization purposes it's acceptable to cache the ConversationalAgentSession
        /// for the lifetime of the app and use it across background/foreground invocations.
        /// </summary>
        /// <returns>Cached Conversation session state.</returns>
        public async Task <IAgentSessionWrapper> GetSessionAsync()
        {
            await this.cachedSessionSemaphore.WaitAsync().ConfigureAwait(false);

            try
            {
                if (this.cachedAgentSession == null)
                {
                    this.cachedAgentSession = new AgentSessionWrapper(await ConversationalAgentSession.GetCurrentSessionAsync());
                    this.cachedAgentSession.InitializeHandlers();

                    this.cachedAgentSession.SignalDetected += this.OnInAppSignalEventDetected;

                    // When the app changes lock state, close the application to prevent duplicates running at once.
                    this.cachedAgentSession.SystemStateChanged += (s, e) =>
                    {
                        if (e.SystemStateChangeType == ConversationalAgentSystemStateChangeType.UserAuthentication)
                        {
                            WindowService.CloseWindow();
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                this.logger.Log(LogMessageLevel.Error, $"Unable to configure a ConversationalAgentSession. Please check your registration with the MVA platform.\r\n{ex.Message}");
            }
            finally
            {
                this.cachedSessionSemaphore.Release();
            }

            return(this.cachedAgentSession);
        }
Beispiel #3
0
        private void OnInAppSignalEventDetected(ConversationalAgentSession sender, ConversationalAgentSignalDetectedEventArgs args)
        {
            // KwsPerformanceLogger.kwsEventFireTime = DateTime.Now.Ticks;
            // this.kwsPerformanceLogger.LogSignalReceived("1", true, DateTime.Now.Ticks, startTime, endTime);
            this.logger.Log(LogMessageLevel.SignalDetection, $"'{sender.Signal.SignalName}' signal detected in session event handler");

            this.SignalDetected?.Invoke(this, DetectionOrigin.FromApplicationObject);
        }
        /// <summary>
        /// Ensures that calling Dispose resets the session to its initial state regardless of the current state
        /// </summary>
        private async Task DisposingResetsToInactiveStateFromAnyState()
        {
            foreach (ConversationalAgentState state in
                     new List <ConversationalAgentState>(new ConversationalAgentState[]
            {
                ConversationalAgentState.Detecting,
                ConversationalAgentState.Inactive,
                ConversationalAgentState.Listening,
                //ConversationalAgentState.ListeningAndSpeaking,
                ConversationalAgentState.Speaking,
                ConversationalAgentState.Working
            }))
            {
                await ValidStateTransition(state);

                agentSession.Dispose();
                // todo: trigger activation and verify that only the background signal is fired
                agentSession = await ConversationalAgentSession.GetCurrentSessionAsync();

                SessionStartedProperly();
            }
        }
        private void OnInAppSignalEventDetected(ConversationalAgentSession sender, ConversationalAgentSignalDetectedEventArgs args)
        {
            this.logger.Log($"'{sender.Signal.SignalName}' signal detected in session event handler");

            this.SignalDetected?.Invoke(this, DetectionOrigin.FromApplicationObject);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AgentSessionWrapper"/> class.
 /// </summary>
 /// <param name="session">Session this instance wraps.</param>
 public AgentSessionWrapper(ConversationalAgentSession session)
 {
     this.session = session;
     Contract.Assert(session != null);
 }
 public async Task TestMethodSetup()
 {
     agentSession = await ConversationalAgentSession.GetCurrentSessionAsync();
 }