예제 #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;

                    // 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);
        }
 private void OnSignalRejected(DetectionOrigin origin)
 {
     if (!this.HasReachedForeground)
     {
         this.logger.Log($"Exiting application forcibly.");
         WindowService.CloseWindow();
     }
 }
 private void OnSignalRejected(DetectionOrigin origin)
 {
     if (!this.HasReachedForeground)
     {
         this.logger.Log(LogMessageLevel.ConversationalAgentSignal, $"Exiting application forcibly.");
         WindowService.CloseWindow();
     }
 }