/// <summary> /// Open a form and closes the Cronus dialog if it is shown. If another dialog is shown this will throw an exception. /// </summary> /// <param name="clientSession">The <see cref="ClientSession"/>.</param> /// <param name="formId">The id of the form to open.</param> /// <returns>The form opened.</returns> /// <exception cref="InvalidOperationException">If a dialog is shown that is not the Cronus dialog.</exception> public static ClientLogicalForm OpenInitialForm(this ClientSession clientSession, string formId) { return(clientSession.CatchForm(delegate { ClientLogicalForm dialog = clientSession.CatchDialog( () => clientSession.InvokeInteraction(new OpenFormInteraction { Page = formId })); if (dialog != null) { if (ClientLogicalFormExtensions.IsCronusDemoDialog(dialog)) { clientSession.InvokeInteraction(new CloseFormInteraction(dialog)); } else { string exceptionMessage = "Unexpected dialog shown: " + dialog.Caption; ClientStaticStringControl staticStringControl = dialog.ContainedControls.OfType <ClientStaticStringControl>().FirstOrDefault(); if (staticStringControl != null) { exceptionMessage += " - " + staticStringControl.StringValue; } throw new InvalidOperationException(exceptionMessage); } } })); }
/// <summary> /// Determines whether [is cronus demo dialog] [the specified dialog]. /// </summary> /// <param name="dialog">The dialog.</param> /// <returns> /// <c>true</c> if [is cronus demo dialog] [the specified dialog]; otherwise, <c>false</c>. /// </returns> public static bool IsCronusDemoDialog(ClientLogicalForm dialog) { if (dialog.IsDialog) { ClientStaticStringControl staticStringControl = dialog.ContainedControls.OfType <ClientStaticStringControl>().FirstOrDefault(); if (staticStringControl != null && staticStringControl.StringValue != null) { return(staticStringControl.StringValue.ToUpperInvariant().Contains("CRONUS")); } } return(false); }