/// <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); }
/// <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); }
/// <summary> /// Free disposable resources per the IDisposable interface. /// </summary> /// <param name="disposing"> Whether managed state is being disposed. </param> protected virtual void Dispose(bool disposing) { if (!this.AlreadyDisposed) { if (disposing) { this.cachedAgentSession?.Dispose(); this.cachedAgentSession = null; this.cachedSessionSemaphore?.Dispose(); } } }