void CAccountManagerInfoPage::OnPageChanging( wxWizardExEvent& event ) { if (event.GetDirection() == false) return; CWizardAttach* pWA = ((CWizardAttach*)GetParent()); CAcctMgrListItem* pItem = (CAcctMgrListItem*)(m_pProjectListCtrl->GetClientData(m_pProjectListCtrl->GetSelection())); // Update authoritative data in CWizardAttach pWA->SetProjectURL(pItem->GetURL()); pWA->SetProjectName(pItem->GetName()); }
void CProjectProcessingPage::OnStateChange( CProjectProcessingPageEvent& WXUNUSED(event) ) { CMainDocument* pDoc = wxGetApp().GetDocument(); CWizardAttach* pWA = ((CWizardAttach*)GetParent()); ACCOUNT_IN* ai = &pWA->account_in; ACCOUNT_OUT* ao = &pWA->account_out; unsigned int i; PROJECT_ATTACH_REPLY reply; wxString strBuffer = wxEmptyString; wxDateTime dtStartExecutionTime; wxDateTime dtCurrentExecutionTime; wxTimeSpan tsExecutionTime; bool bPostNewEvent = true; int retval = 0; bool creating_account = false; wxASSERT(pDoc); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); switch(GetCurrentState()) { case ATTACHPROJECT_INIT: pWA->DisableNextButton(); pWA->DisableBackButton(); StartProgress(m_pProgressIndicator); SetNextState(ATTACHPROJECT_ACCOUNTQUERY_BEGIN); break; case ATTACHPROJECT_ACCOUNTQUERY_BEGIN: SetNextState(ATTACHPROJECT_ACCOUNTQUERY_EXECUTE); break; case ATTACHPROJECT_ACCOUNTQUERY_EXECUTE: // Attempt to create the account or reterieve the authenticator. ai->clear(); ao->clear(); // use the web RPC URL in the get_project_config response // if present, otherwise use what the user typed // if (!pWA->project_config.web_rpc_url_base.empty()) { ai->url = pWA->project_config.web_rpc_url_base; } else if (!pWA->project_config.master_url.empty()) { ai->url = pWA->project_config.master_url; } else { ai->url = (const char*)pWA->m_ProjectInfoPage->GetProjectURL().mb_str(); } if (!pWA->GetProjectAuthenticator().IsEmpty() || pWA->m_bCredentialsCached || pWA->m_bCredentialsDetected ) { if (!pWA->m_bCredentialsCached || pWA->m_bCredentialsDetected) { ao->authenticator = (const char*)pWA->GetProjectAuthenticator().mb_str(); } SetProjectCommunicationsSucceeded(true); } else { // Setup initial values for both the create and lookup API if (pWA->project_config.uses_username) { ai->email_addr = (const char*)pWA->m_AccountInfoPage->GetAccountUsername().mb_str(); } else { ai->email_addr = (const char*)pWA->m_AccountInfoPage->GetAccountEmailAddress().mb_str(); } ai->passwd = (const char*)pWA->m_AccountInfoPage->GetAccountPassword().mb_str(); ai->user_name = (const char*)::wxGetUserName().mb_str(); if (ai->user_name.empty()) { ai->user_name = (const char*)::wxGetUserId().mb_str(); } //ai->team_name = (const char*)pWA->GetTeamName().mb_str(); if (pWA->m_AccountInfoPage->m_pAccountCreateCtrl->GetValue()) { creating_account = true; // Wait until we are done processing the request. dtStartExecutionTime = wxDateTime::Now(); dtCurrentExecutionTime = wxDateTime::Now(); tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime; retval = 0; ao->error_num = ERR_RETRY; while ( !retval && ((ERR_IN_PROGRESS == ao->error_num) || (ERR_RETRY == ao->error_num)) && tsExecutionTime.GetSeconds() <= 60 && !CHECK_CLOSINGINPROGRESS() ) { if (ERR_RETRY == ao->error_num) { pDoc->rpc.create_account(*ai); } dtCurrentExecutionTime = wxDateTime::Now(); tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime; retval = pDoc->rpc.create_account_poll(*ao); IncrementProgress(m_pProgressIndicator); ::wxMilliSleep(500); ::wxSafeYield(GetParent()); } if ((!retval) && !ao->error_num) { pWA->SetAccountCreatedSuccessfully(true); } } else { creating_account = false; // Wait until we are done processing the request. dtStartExecutionTime = wxDateTime::Now(); dtCurrentExecutionTime = wxDateTime::Now(); tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime; retval = 0; ao->error_num = ERR_RETRY; while ( !retval && ((ERR_IN_PROGRESS == ao->error_num) || (ERR_RETRY == ao->error_num)) && tsExecutionTime.GetSeconds() <= 60 && !CHECK_CLOSINGINPROGRESS() ) { if (ERR_RETRY == ao->error_num) { retval = pDoc->rpc.lookup_account(*ai); if (retval) { // REPORT ERROR } } dtCurrentExecutionTime = wxDateTime::Now(); tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime; retval = pDoc->rpc.lookup_account_poll(*ao); IncrementProgress(m_pProgressIndicator); ::wxMilliSleep(500); ::wxSafeYield(GetParent()); } } if ((!retval) && !ao->error_num) { SetProjectCommunicationsSucceeded(true); } else { SetProjectCommunicationsSucceeded(false); if ((ao->error_num == ERR_DB_NOT_UNIQUE) || (ao->error_num == ERR_NONUNIQUE_EMAIL) || (ao->error_num == ERR_BAD_PASSWD && creating_account) ) { SetProjectAccountAlreadyExists(true); } else { SetProjectAccountAlreadyExists(false); } if ((ERR_NOT_FOUND == ao->error_num) || (ao->error_num == ERR_DB_NOT_FOUND) || (ERR_BAD_EMAIL_ADDR == ao->error_num) || (ERR_BAD_PASSWD == ao->error_num) ) { SetProjectAccountNotFound(true); } else { SetProjectAccountNotFound(false); } strBuffer = pWA->m_CompletionErrorPage->m_pServerMessagesCtrl->GetLabel(); if ((HTTP_STATUS_NOT_FOUND == ao->error_num)) { strBuffer += _("Required files not found on the server."); } else if ((HTTP_STATUS_INTERNAL_SERVER_ERROR == ao->error_num)) { strBuffer += _("An internal server error has occurred."); } else { if (ao->error_msg.size()) { strBuffer += wxString(ao->error_msg.c_str(), wxConvUTF8) + wxString(wxT("\n")); } } pWA->m_CompletionErrorPage->m_pServerMessagesCtrl->SetLabel(strBuffer); } } SetNextState(ATTACHPROJECT_ATTACHPROJECT_BEGIN); break; case ATTACHPROJECT_ATTACHPROJECT_BEGIN: SetNextState(ATTACHPROJECT_ATTACHPROJECT_EXECUTE); break; case ATTACHPROJECT_ATTACHPROJECT_EXECUTE: if (GetProjectCommunicationsSucceeded()) { // Wait until we are done processing the request. dtStartExecutionTime = wxDateTime::Now(); dtCurrentExecutionTime = wxDateTime::Now(); tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime; retval = 0; reply.error_num = ERR_RETRY; while ( !retval && ((ERR_IN_PROGRESS == reply.error_num) || (ERR_RETRY == reply.error_num)) && tsExecutionTime.GetSeconds() <= 60 && !CHECK_CLOSINGINPROGRESS() ) { if (ERR_RETRY == reply.error_num) { if (pWA->m_bCredentialsCached) { pDoc->rpc.project_attach_from_file(); } else { pDoc->rpc.project_attach( ai->url.c_str(), ao->authenticator.c_str(), pWA->project_config.name.c_str() ); } } dtCurrentExecutionTime = wxDateTime::Now(); tsExecutionTime = dtCurrentExecutionTime - dtStartExecutionTime; retval = pDoc->rpc.project_attach_poll(reply); IncrementProgress(m_pProgressIndicator); ::wxMilliSleep(500); ::wxSafeYield(GetParent()); } if (!retval && !reply.error_num) { SetProjectAttachSucceeded(true); pWA->SetAttachedToProjectSuccessfully(true); pWA->SetProjectURL(wxString(ai->url.c_str(), wxConvUTF8)); pWA->SetProjectAuthenticator(wxString(ao->authenticator.c_str(), wxConvUTF8)); } else { SetProjectAttachSucceeded(false); strBuffer = pWA->m_CompletionErrorPage->m_pServerMessagesCtrl->GetLabel(); if ((HTTP_STATUS_INTERNAL_SERVER_ERROR == reply.error_num)) { strBuffer += _("An internal server error has occurred."); } else { for (i=0; i<reply.messages.size(); i++) { strBuffer += wxString(reply.messages[i].c_str(), wxConvUTF8) + wxString(wxT("\n")); } } pWA->m_CompletionErrorPage->m_pServerMessagesCtrl->SetLabel(strBuffer); } } else { SetProjectAttachSucceeded(false); } SetNextState(ATTACHPROJECT_CLEANUP); break; case ATTACHPROJECT_CLEANUP: FinishProgress(m_pProgressIndicator); SetNextState(ATTACHPROJECT_END); break; default: // Allow a glimps of what the result was before advancing to the next page. wxSleep(1); pWA->EnableNextButton(); pWA->EnableBackButton(); pWA->SimulateNextButton(); bPostNewEvent = false; break; } Update(); if (bPostNewEvent && !CHECK_CLOSINGINPROGRESS()) { CProjectProcessingPageEvent TransitionEvent(wxEVT_PROJECTPROCESSING_STATECHANGE, this); AddPendingEvent(TransitionEvent); } }