app_mgr.cpp 1.09 KB
#include "stdafx.h"

#include "etradeclient/utility/app_mgr.h"

#include "etradeclient/utility/logon_mgr.h"
#include "etradeclient/utility/session.h"
#include "etradeclient/utility/logging.h"

AppMgr::AppMgr() :m_is_need_relauch(false)
{}

AppMgr& AppMgr::Instance()
{
	static AppMgr instance;
	return instance;
}

bool AppMgr::IsNeedRelauch()
{
	return m_is_need_relauch||LogonMgr::Instance().IsFirstLogin();
}

void AppMgr::Exit(bool is_need_user_confirm /*= true*/)
{
	if (!is_need_user_confirm)
	{
		if (!LogonMgr::Instance().DoLogout())
			LOG_ERROR(L"创建商户操作完成后,服务端退出请求处理失败。");
		else
			LOG_TRACE(L"退出系统成功。");
		/*不让主窗口关闭的时候,再去提示用户是否退出以及做退出后台系统处理!!! */
		Session::Instance().OnExpired();
	}

	// AfxGetMainWnd() will return NULL if called from an other thread (has to do with thread local storage).
	// That's why we use AfxGetApp()->GetMainWnd() instead of AfxGetMainWnd().
	HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd();
	::PostMessage(hwnd, WM_CLOSE, NULL, NULL);
}

void AppMgr::Relauch()
{
	m_is_need_relauch = true;
	Exit(false);
}