Example #1
0
void CMainFrame::OnSpareAdd(UINT wNotifyCode, int wID, HWND hwndCtl)
{
	CNBDevice *pDevice = m_viewTreeList.GetSelectedDevice();

	if(!pDevice)
		return;

	if(!pDevice->GetCommandAbility(wID))
		return;

	CNBLogicalDevice *pLogicalDevice = dynamic_cast<CNBLogicalDevice *>(pDevice);
	if(!pLogicalDevice || !pLogicalDevice->IsOperatableAll())
		return;

	CNBSelectDeviceDlg dlgSelectDevice(
		IDD_DEVICE_LIST, 
		IDS_SPARE_ADD_DLG_CAPTION, 
		IDS_SPARE_ADD_DLG_MESSAGE, 
		GetOperatableSingleDevices(), 
		1, 
		CheckCapacityForSpare, 
		pLogicalDevice);

	if(dlgSelectDevice.DoModal() != IDOK)
		return;

	CNBUnitDevice *pUnitDevice = dlgSelectDevice.GetSelectedDevice();

	// Bind & Synchronize 
	NDASCOMM_CONNECTION_INFO ci, ci_spare;
	(*pLogicalDevice)[0]->InitConnectionInfo(&ci, TRUE);
	pUnitDevice->InitConnectionInfo(&ci_spare, TRUE);

	AutoCursor l_auto_cursor(IDC_WAIT);
	BOOL bResults = NdasOpSpareAdd(
		&ci, &ci_spare);
	l_auto_cursor.Release();

	pLogicalDevice->HixChangeNotify(pGetNdasHostGuid());
	pUnitDevice->HixChangeNotify(pGetNdasHostGuid());

	if(!bResults)
	{
		CString strMsg;

		DWORD dwLastError = ::GetLastError();

		strMsg.LoadString(IDS_OPERATION_FAIL);

		ShowErrorMessageBox(strMsg);

		return;
	}

	OnRefreshStatus(NULL, NULL, NULL);
}
Example #2
0
void CMainFrame::OnSingle(UINT wNotifyCode, int wID, HWND hwndCtl)
{
	CString strMsg;

	CNBDevice *pDevice = m_viewTreeList.GetSelectedDevice();

	if(!pDevice)
		return;

	if(!pDevice->GetCommandAbility(wID))
		return;

	CNBUnitDevice *pUnitDevice;
	if(dynamic_cast<CNBLogicalDevice *>(pDevice))
	{
		CNBLogicalDevice *pLogicalDevice = dynamic_cast<CNBLogicalDevice *>(pDevice);
		if(!pLogicalDevice || !pLogicalDevice->IsOperatableAll())
			return;

		pUnitDevice = (*pLogicalDevice)[0];
	}
	else
	{
		pUnitDevice = dynamic_cast<CNBUnitDevice *>(pDevice);
		if(!pUnitDevice || !pUnitDevice->IsOperatable())
			return;
	}

	if(!pUnitDevice)
		return;

	NBUnitDevicePtrList listUnitDevices;
	listUnitDevices.push_back(pUnitDevice);

	CNBSelectDeviceDlg dlgSelectDevice(
		IDD_DEVICE_LIST, 
		IDS_SINGLE_DLG_CAPTION, 
		IDS_SINGLE_DLG_MESSAGE, 
		listUnitDevices, 
		0, 
		NULL, 
		NULL);

	if(dlgSelectDevice.DoModal() != IDOK)
		return;


	NDASCOMM_CONNECTION_INFO ConnectionInfo;
	if(!pUnitDevice->InitConnectionInfo(&ConnectionInfo, TRUE))
	{
		
		// "%1!s! does not have a write access privilege. You need to set write key to this NDAS device before this action."
		strMsg.FormatMessage(IDS_ERROR_NOT_REGISTERD_WRITE_FMT,
			pUnitDevice->GetName()
			);
		CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox(
			strMsg,
			strTitle,
			MB_OK|MB_ICONERROR
			);

		return;
	}

	AutoCursor l_auto_cursor(IDC_WAIT);
	UINT32 BindResult = NdasOpBind(
		1,
		&ConnectionInfo,
		NMT_SINGLE,
		0);
	l_auto_cursor.Release();

	if(1 != BindResult)
	{
		DWORD dwLastError = ::GetLastError();

		switch(dwLastError)
		{
		case NDASCOMM_ERROR_RW_USER_EXIST:
		case NDASOP_ERROR_ALREADY_USED:
		case NDASOP_ERROR_DEVICE_FAIL:
		case NDASOP_ERROR_NOT_SINGLE_DISK:
		case NDASOP_ERROR_DEVICE_UNSUPPORTED:
		case NDASOP_ERROR_NOT_BOUND_DISK: // does not return this error
			strMsg.FormatMessage(IDS_BIND_FAIL_AT_SINGLE_NDAS_FMT, pUnitDevice->GetName());
			break;
		default:
			strMsg.LoadString(IDS_BIND_FAIL);
			break;
		}

		ShowErrorMessageBox(strMsg);
	}

	pUnitDevice->HixChangeNotify(pGetNdasHostGuid());

	OnRefreshStatus(NULL, NULL, NULL);
}