protected override void OnApply(PageApplyEventArgs e)
        {
            page.SetInfoLabelText("");

            // show welcome view if user clears the URL
            if ("".Equals(OctaneConfiguration.Url))
            {
                if (OctaneMyItemsViewModel.Instance != null)
                {
                    OctaneMyItemsViewModel.Instance.Mode = MainWindowMode.FirstTime;
                }
                return;
            }

            var result = Run(async() => { return(await TestConnection()); }).Result;

            if (!result.Equals(ConnectionSuccessful))
            {
                e.ApplyBehavior = ApplyKind.CancelNoNavigate;
            }
            else
            {
                setOldCredentials();

                // reset and thus require a new octane service obj
                Run(async() => { return(await OctaneServices.Reset()); }).Wait();

                // create a new service object
                OctaneServices.Create(OctaneConfiguration.Url,
                                      OctaneConfiguration.SharedSpaceId,
                                      OctaneConfiguration.WorkSpaceId);


                // close all opened details windows so that we don't have details windows
                // for entities from different workspaces
                PluginWindowManager.CloseAllDetailsWindows();

                // disable the active item toolbar because we don't know yet
                // whether we can connect with the new Octane credentials
                MainWindowCommand.Instance.DisableActiveItemToolbar();

                openToolWindow();

                // After settings are applied we notify the main ViewModel to allow it to refresh.
                if (OctaneMyItemsViewModel.Instance != null)
                {
                    InitialisePluginComponents();
                }

                if (ssologin)
                {
                    clearUserPassTextBoxes();
                }

                base.OnApply(e);
            }

            page.SetInfoLabelText(result);
        }
        public async Task <string> TestConnection()
        {
            try
            {
                AuthenticationStrategy authenticationStrategy = null;
                if (credentialLogin)
                {
                    authenticationStrategy = new LwssoAuthenticationStrategy(new UserPassConnectionInfo(OctaneConfiguration.Username,
                                                                                                        OctaneConfiguration.Password));
                }
                else if (ssologin)
                {
                    authenticationStrategy = new SsoAuthenticationStrategy();
                }

                await authenticationStrategy.TestConnection(url);

                // Don't do advanced test connection with sso login, will cause deadlock
                if (credentialLogin)
                {
                    // reset and thus require a new octane service obj
                    Run(async() => { return(await OctaneServices.Reset()); }).Wait();

                    // hotfix for first time installing the plugin and clicking test connection
                    if (OctaneConfiguration.CredentialLogin == false)
                    {
                        OctaneConfiguration.CredentialLogin = true;
                    }

                    // create a new service object
                    OctaneServices.Create(OctaneConfiguration.Url,
                                          OctaneConfiguration.SharedSpaceId,
                                          OctaneConfiguration.WorkSpaceId);

                    await OctaneServices.GetInstance().Connect();

                    // try to get the work item root
                    await OctaneServices.GetInstance().GetAsyncWorkItemRoot();
                }

                return(ConnectionSuccessful);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        protected override void OnClosed(EventArgs e)
        {
            if (credentialLogin)
            {
                if ("".Equals(OctaneConfiguration.Url))
                {
                    if (OctaneMyItemsViewModel.Instance != null)
                    {
                        OctaneMyItemsViewModel.Instance.Mode = MainWindowMode.FirstTime;
                    }
                }
                else
                {
                    Run(async() => { return(await OctaneServices.Reset()); }).Wait();

                    OctaneConfiguration.Username = oldUserPassConnectionInfo.user;
                    OctaneConfiguration.Password = oldUserPassConnectionInfo.password;
                    ssid = oldSsid;
                    wsid = oldWsid;
                    OctaneServices.Create(oldUrl, oldSsid, oldWsid);

                    try
                    {
                        Run(async() => { await OctaneServices.GetInstance().Connect(); }).Wait();
                    }
                    catch
                    {
                        clearUserPassTextBoxes();
                    }
                    finally
                    {
                        page.SetInfoLabelText("");
                    }

                    base.OnClosed(e);
                }
            }
        }