/// <summary>Awaits until all the forms are closed.</summary>
 /// <param name="clientSession">The client Session.</param>
 public static bool AwaitSessionIsReady(this ClientSession clientSession)
 {
     return clientSession.AwaitReady(() => { }, session => session.State == ClientSessionState.Ready, false, AwaitDuration);
 }
 /// <summary>Opens the session synchronously.</summary>
 /// <param name="clientSession">The client Session.</param>
 /// <param name="uiCultureId">The language culture Id. For example "da-DK"</param>
 public static void OpenSession(
     this ClientSession clientSession,
     string uiCultureId)
 {
     var sessionParameters = new ClientSessionParameters
     {
         CultureId = CultureInfo.CurrentCulture.Name,
         UICultureId = uiCultureId
     };
     sessionParameters.AdditionalSettings.Add("IncludeControlIdentifier", true);
     clientSession.AwaitReady(() => clientSession.OpenSessionAsync(sessionParameters));
 }
 /// <summary>Awaits until all the forms are closed.</summary>
 /// <param name="clientSession">The client Session.</param>
 public static bool AwaitAllFormsAreClosedAndSessionIsReady(this ClientSession clientSession)
 {
     return clientSession.AwaitReady(() => { }, session => session.State == ClientSessionState.Ready && !session.OpenedForms.Any(), false, AwaitAllFormsAreClosedDuration);
 }
 /// <summary>Invokes the interaction synchronously.</summary>
 /// <param name="clientSession">The client Session.</param>
 /// <param name="interaction">The interaction.</param>
 public static void InvokeInteraction(this ClientSession clientSession, ClientInteraction interaction)
 {
     clientSession.AwaitReady(() => clientSession.InvokeInteractionAsync(interaction));
 }
        /// <summary>Closes the session synchronously.</summary>
        /// <param name="clientSession">The client Session.</param>
        public static void CloseSession(this ClientSession clientSession)
        {
            if (clientSession.State == ClientSessionState.Closed)
            {
                return;
            }

            clientSession.AwaitReady(clientSession.CloseSessionAsync, session => session.State == ClientSessionState.Closed, true, AwaitForeverDuration);
        }
 /// <summary>Closes the froms in the session synchronously.</summary>
 /// <param name="clientSession">The client Session.</param>
 public static void CloseAllForms(this ClientSession clientSession)
 {
     clientSession.AwaitReady(
         () => clientSession.InvokeInteractionsAsync(
             clientSession.OpenedForms.Select(clientLogicalForm => new CloseFormInteraction(clientLogicalForm))
             ),
             session => session.State == ClientSessionState.Ready && !session.OpenedForms.Any(),
             false,
             AwaitForeverDuration
         );
 }