예제 #1
0
void CMainFrame::OnCommand(UINT /*wNotifyCode*/, int wID, HWND /*hwndCtl*/)
{
	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	// Commands which do not change the tree are sent to the object directly.
	CTreeItem itemSelected = m_view.GetSelectedItem();

	if ( itemSelected.IsNull() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}

	CDiskObjectPtr obj;
	const CObjectUIHandler *phandler;
	obj = m_mapObject[m_view.GetItemData(itemSelected)];
	ATLASSERT( obj.get() != NULL );
	phandler = CObjectUIHandler::GetUIHandler( obj );
	phandler->OnCommand( obj, wID );
	
	m_view.UpdateDiskObject( obj );

	OnSelChanged(NULL);

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
}
예제 #2
0
LRESULT CMainWindow::OnTVSelChanged(int, LPNMHDR pnmh, BOOL&)
{
  // 如何解析参数
  LPNMTREEVIEW pnmtv = reinterpret_cast<LPNMTREEVIEW>(pnmh);
  CTreeViewCtrlEx tree = pnmh->hwndFrom;
  if (tree.IsWindow())
    {
      CTreeItem item = tree.GetSelectedItem();
      std::string path;
      for (; !item.IsNull(); item = item.GetParent())
	{
	  std::string name(256, 0);
	  item.GetText((LPTSTR)name.c_str(), 256);
	  std::string temp = name.c_str();
	  if (!path.empty())
	    {
	      path = temp + "/" + path;
	    }
	  else
	    {
	      path = temp;
	    }
	}
      //
      m_wndStatusBar.SetPaneText(ID_DEFAULT_PANE, TEXT(path.c_str()));
      //
      mViewWindow.changeModelFile(path);
    }

  return 0L;
}
예제 #3
0
LRESULT CMainFrame::OnTVSelChanged(int, LPNMHDR pnmh, BOOL&)
{
	// 如何解析参数
	LPNMTREEVIEW pnmtv = reinterpret_cast<LPNMTREEVIEW>(pnmh);
	CTreeViewCtrlEx tree = pnmh->hwndFrom;
	if (tree.IsWindow())
	{
		CTreeItem item = tree.GetSelectedItem();
		std::string path;
		for (; !item.IsNull() && !item.GetParent().IsNull(); item = item.GetParent())
		{
			std::string name(256, 0);
			item.GetText((LPTSTR)name.c_str(), 256);
			std::string temp = name.c_str();
			if (!path.empty())
			{
				path = temp + "/" + path;
			}
			else
			{
				path = temp;
			}
		}
		//
		if (_canvas)
		{
			path = Buddha::FileSystem::getInstancePtr()->getDataDirectory() + path;
			_canvas->changeModelFile(standardFilePath(path));
		}
	}

	return 0L;
}
예제 #4
0
CNBDevice *CNBTreeListView::GetSelectedDevice()
{
	CTreeItem itemSelected = GetTreeControl().GetSelectedItem();
	if ( !itemSelected.IsNull() )
	{
		return (CNBDevice *)itemSelected.GetData();
	}

	return NULL;
}
예제 #5
0
void CMainFrame::OnUnBind(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hwndCtl*/)
{
	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	CTreeItem itemSelected = m_view.GetSelectedItem();
	if ( itemSelected.IsNull() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}

	CDiskObjectPtr obj, parent;
	obj = m_mapObject[m_view.GetItemData(itemSelected)];
	
	// Find topmost group composite of bind
	parent = obj->GetParent();
	while ( !parent->IsRoot() )
	{
		obj = parent;
		parent = obj->GetParent();
	}

	//
	// Check whether any disk is being accessed by other program/computer
	//
	if ( !obj->CanAccessExclusive() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		WTL::CString strMsg;
		strMsg.LoadString(IDS_FAIL_TO_ACCESS_EXCLUSIVELY);
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox( 
			strMsg,
			strTitle,
			MB_OK | MB_ICONWARNING
			);
		return;
	}

	// Unbind disks
	CUnBindDlg dlgUnbind;

	dlgUnbind.SetDiskToUnbind(obj);
	if ( dlgUnbind.DoModal() == IDOK )
	{
		// AING : Cause dlgBind use ndasop.lib to bind disks, 
		// you can't ensure each disk information is stable after bind process.
		OnRefreshStatus(NULL, NULL, NULL);
	}

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
}
예제 #6
0
LRESULT CMainFrame::OnSelChanged(LPNMHDR /*lpNLHDR*/)
{
	CTreeItem itemSelected;
	itemSelected = m_view.GetSelectedItem();

	UIEnable(IDM_AGGR_UNBIND, FALSE);
	UIEnable(IDM_AGGR_SYNCHRONIZE, FALSE);
	UIEnable(IDM_AGGR_ADDMIRROR, FALSE);
	if ( !itemSelected.IsNull() )
	{
		CDiskObjectPtr obj = m_mapObject[itemSelected.GetData()];
		ATLASSERT( obj.get() != NULL );
		CCommandSet cmdSet = 
			CObjectUIHandler::GetUIHandler(obj)->GetCommandSet(obj);
		CCommandSet::iterator itr;
		for ( itr = cmdSet.begin(); itr != cmdSet.end(); itr++ )
		{
			UIEnable( itr->GetID(), !itr->IsDisabled() );
		}
	}
	return 0;
}
예제 #7
0
void CMainFrame::RefreshAction()
{
	CTreeItem itemSelected;
	itemSelected = m_viewTree.GetSelectedItem();

//	UIEnable(IDM_AGGR_BIND, FALSE);
	UIEnable(IDM_AGGR_UNBIND, FALSE);
	UIEnable(IDM_AGGR_SYNCHRONIZE, FALSE);
	UIEnable(IDM_AGGR_ADDMIRROR, FALSE);

	if ( !itemSelected.IsNull() )
	{
		CDiskObjectPtr obj = m_mapObject[itemSelected.GetData()];
		ATLASSERT( obj.get() != NULL );
		CCommandSet cmdSet = 
			CObjectUIHandler::GetUIHandler(obj)->GetCommandSet(obj);
		CCommandSet::iterator itr;
		for ( itr = cmdSet.begin(); itr != cmdSet.end(); itr++ )
		{
			UIEnable( itr->GetID(), !itr->IsDisabled() );
		}
	}
}
예제 #8
0
void CMainFrame::OnAddMirror(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hwndCtl*/)
{
	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	CTreeItem itemSelected = m_view.GetSelectedItem();

	if ( itemSelected.IsNull() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}

	CDiskObjectList singleDisks;
	CUnitDiskObjectPtr  sourceDisk;
	sourceDisk = 
		boost::dynamic_pointer_cast<CUnitDiskObject>(
			m_mapObject[m_view.GetItemData(itemSelected)]
			);
	ATLASSERT( sourceDisk.get() != NULL );

	CFindIfVisitor<FALSE> singleDiskFinder;
	singleDisks = singleDiskFinder.FindIf(m_pRoot, IsWritableUnitDisk);
	singleDisks.remove( sourceDisk );
	if ( singleDisks.size() == 0 )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		// TODO : No disk is available
		WTL::CString strMsg;
		strMsg.LoadString( IDS_MAINFRAME_NO_DISK_TO_MIRROR );
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox(
			strMsg,
			strTitle, 
			MB_OK | MB_ICONWARNING
			);
		return;
	}

	DWORD UnitNo = 0;
	CSelectMirDlg dlgSelDisk(IDD_ADDMIR);
	dlgSelDisk.SetSingleDisks( singleDisks );
	dlgSelDisk.SetSourceDisk( sourceDisk );
	if ( dlgSelDisk.DoModal() == IDOK )
	{
		CUnitDiskObjectPtr mirDisk = dlgSelDisk.GetSelectedDisk();

		// Bind & Synchronize 
		NDAS_CONNECTION_INFO ConnectionInfo[2];

		ZeroMemory(&ConnectionInfo[0], sizeof(NDAS_CONNECTION_INFO));

		ConnectionInfo[0].type = NDAS_CONNECTION_INFO_TYPE_MAC_ADDRESS;
		ConnectionInfo[0].UnitNo = sourceDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
		ConnectionInfo[0].bWriteAccess = TRUE;
		ConnectionInfo[0].ui64OEMCode = NULL;
		ConnectionInfo[0].protocol = IPPROTO_LPXTCP;
		CopyMemory(ConnectionInfo[0].MacAddress, 
				sourceDisk->GetLocation()->GetUnitDiskLocation()->MACAddr,
			LPXADDR_NODE_LENGTH);

		ZeroMemory(&ConnectionInfo[1], sizeof(NDAS_CONNECTION_INFO));

		ConnectionInfo[1].type = NDAS_CONNECTION_INFO_TYPE_MAC_ADDRESS;
		ConnectionInfo[1].UnitNo = mirDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
		ConnectionInfo[1].bWriteAccess = TRUE;
		ConnectionInfo[1].ui64OEMCode = NULL;
		ConnectionInfo[1].protocol = IPPROTO_LPXTCP;
		CopyMemory(ConnectionInfo[1].MacAddress, 
			mirDisk->GetLocation()->GetUnitDiskLocation()->MACAddr,
			LPXADDR_NODE_LENGTH);

		UINT32 BindResult = NdasOpBind(
			2,
			ConnectionInfo,
			NMT_SAFE_RAID1);

		if(2 != BindResult)
		{
	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);

			WTL :: CString strMsg;

			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:
				strMsg.FormatMessage(IDS_BIND_FAIL_AT_SINGLE_NDAS_FMT, 
					(BindResult == 0) ? sourceDisk->GetTitle() : mirDisk->GetTitle());
				break;
			default:
				strMsg.LoadString(IDS_BIND_FAIL);
				break;
	}

			ShowErrorMessageBox(strMsg);

		return;
	}

		CNdasHIXChangeNotify HixChangeNotify(pGetNdasHostGuid());
		BOOL bResults = HixChangeNotify.Initialize();
		if(bResults)
		{
			NDAS_UNITDEVICE_ID unitDeviceId;

			CopyMemory(unitDeviceId.DeviceId.Node, 
				sourceDisk->GetLocation()->GetUnitDiskLocation()->MACAddr, 
				sizeof(unitDeviceId.DeviceId.Node));
			unitDeviceId.UnitNo = 
				sourceDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
			HixChangeNotify.Notify(unitDeviceId);

			CopyMemory(unitDeviceId.DeviceId.Node, 
				mirDisk->GetLocation()->GetUnitDiskLocation()->MACAddr, 
				sizeof(unitDeviceId.DeviceId.Node));
			unitDeviceId.UnitNo = 
				mirDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
			HixChangeNotify.Notify(unitDeviceId);
		}

		CRecoverDlg dlgRecover(TRUE, IDS_LOGDEV_TYPE_DISK_RAID1, IDS_RECOVERDLG_TASK_ADD_MIRROR);

		dlgRecover.SetMemberDevice(mirDisk);
		dlgRecover.DoModal();

		OnRefreshStatus(NULL, NULL, NULL);
	}

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
}
예제 #9
0
void CMainFrame::OnSingle(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hwndCtl*/)
{
	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	WTL::CString strMsg;

	CTreeItem itemSelected = m_view.GetSelectedItem();
	if ( itemSelected.IsNull() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}

	CDiskObjectPtr obj, parent;
	obj = m_mapObject[m_view.GetItemData(itemSelected)];

	if(!obj->IsUnitDisk())
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}

	// AING_TO_DO
	{
		strMsg.LoadString(IDS_WARNING_SINGLE);
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);

		int ret = MessageBox( 
			strMsg,
			strTitle,
			MB_YESNO | MB_ICONWARNING
			);

		if(IDYES != ret)
		{
			LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
			return;
		}
	}

	//
	// Check whether any disk is being accessed by other program/computer
	//
	if ( !obj->CanAccessExclusive() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		strMsg.LoadString(IDS_FAIL_TO_ACCESS_EXCLUSIVELY);
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox( 
			strMsg,
			strTitle,
			MB_OK | MB_ICONWARNING
			);
		return;
	}

	if(!(obj->GetAccessMask() & GENERIC_WRITE))
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		// "%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,
			obj->GetTitle()
			);
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox(
			strMsg,
			strTitle,
			MB_OK|MB_ICONERROR
			);

		return;
	}

	NDAS_CONNECTION_INFO ConnectionInfo;

	CUnitDiskObjectPtr unitDisk = 
		boost::dynamic_pointer_cast<CUnitDiskObject>(obj);
	
	ZeroMemory(&ConnectionInfo, sizeof(NDAS_CONNECTION_INFO));

	ConnectionInfo.type = NDAS_CONNECTION_INFO_TYPE_MAC_ADDRESS;
	ConnectionInfo.UnitNo = unitDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
	ConnectionInfo.bWriteAccess = TRUE;
	ConnectionInfo.ui64OEMCode = NULL;
	ConnectionInfo.protocol = IPPROTO_LPXTCP;
	CopyMemory(ConnectionInfo.MacAddress, 
		unitDisk->GetLocation()->GetUnitDiskLocation()->MACAddr,
		LPXADDR_NODE_LENGTH);

	UINT32 BindResult = NdasOpBind(
		1,
		&ConnectionInfo,
		NMT_SINGLE);

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	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, unitDisk->GetTitle());
			break;
		default:
			strMsg.LoadString(IDS_BIND_FAIL);
			break;
		}

		ShowErrorMessageBox(strMsg);
	}

	CNdasHIXChangeNotify HixChangeNotify(pGetNdasHostGuid());
	BOOL bResults = HixChangeNotify.Initialize();
	if(bResults)
	{
		NDAS_UNITDEVICE_ID unitDeviceId;
		CopyMemory(unitDeviceId.DeviceId.Node, ConnectionInfo.MacAddress, 
			sizeof(unitDeviceId.DeviceId.Node));
		unitDeviceId.UnitNo = ConnectionInfo.UnitNo;
		HixChangeNotify.Notify(unitDeviceId);
	}

	OnRefreshStatus(NULL, NULL, NULL);


}
예제 #10
0
void CMainFrame::OnContextMenu(HWND /*hWnd*/, CPoint pos)
{
	if(m_bRefreshing)
		return;

	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	CRect rect;
	CPoint posInView;
	CTreeItem itemSelected;
	m_view.GetWindowRect( rect );

	if ( !rect.PtInRect(pos) )
	{
		// If clicked point is outside the tree control, do nothing.
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}
	// Change screen coordinates to client coordinates
	posInView = pos - rect.TopLeft();

	itemSelected = m_view.HitTest( posInView, NULL );

	CMenu menu;
	CMenu newSubMenu;
	CMenuHandle subMenu;

	menu.LoadMenu( MAKEINTRESOURCE(IDR_CONTEXT_MENU) );
	subMenu = menu.GetSubMenu(0);
	if ( subMenu.IsNull() )
	{
		newSubMenu.CreatePopupMenu();
		subMenu = newSubMenu;
	}
	if ( itemSelected.IsNull() )
	{
		// Display default menu
		subMenu.TrackPopupMenu(
			TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
			pos.x, 
			pos.y, 
			m_hWnd
			);
	}
	else
	{
		// Change select
		m_view.SelectItem(itemSelected);

		// Display context menu
		CDiskObjectPtr obj = m_mapObject[itemSelected.GetData()];
		ATLASSERT( obj.get() != NULL );
		CObjectUIHandler::GetUIHandler(obj)->InsertMenu(obj, subMenu);
		subMenu.TrackPopupMenu(
			TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
			pos.x, 
			pos.y, 
			m_hWnd
			);
	}

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
}
예제 #11
0
LRESULT CChildFrame::OnTvnSelChanged(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled)
{ 
    USES_CONVERSION; 
    HRESULT hr = E_FAIL; 

    idCtrl, pNMHDR, bHandled; 
    CTreeViewCtrl ctrlTree = m_wndCatalog; 

    bHandled = FALSE; 

    NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; 
    ATLASSERT( pNMTreeView ); 

    { 
        m_pData.m_hTreeItem = pNMTreeView->itemNew.hItem; 
        m_pData.m_pTreeView = &m_wndCatalog; 
    } 

    CTreeItem hItem(pNMTreeView->itemNew.hItem, &m_wndCatalog); 

    TREE_ITEM_DATA * pCurrSel = NULL; 
    pCurrSel = (TREE_ITEM_DATA *) ctrlTree.GetItemData(hItem); 

    if (pCurrSel && STGTY_STREAM == pCurrSel->dwStgType) 
    { 
        CComPtr<IStream> spStrm; 
        hr = pCurrSel->spStgOrStrm->QueryInterface(&spStrm); 
        if (FAILED(hr)) return hr; 

        STATSTG st = { 0 }; 
        hr = spStrm->Stat(&st, STATFLAG_NONAME); 
        if (FAILED(hr)) return hr; 

        LARGE_INTEGER liBegin = { 0 }; 
        hr = spStrm->Seek(liBegin, STREAM_SEEK_SET, NULL); 

        BYTE * byBuff = new BYTE[st.cbSize.QuadPart+1]; 
        ZeroMemory(byBuff, (st.cbSize.QuadPart+1)*sizeof(BYTE)); 
        ULONG ulSize = 0; 
        hr = spStrm->Read(byBuff, st.cbSize.QuadPart, &ulSize); 

		ATLASSERT(SUCCEEDED(hr));

        if(st.cbSize.QuadPart) 
        { 
            CComSafeArray data; 
            data.CreateOneDim(VT_UI1, st.cbSize.QuadPart, (const void *)byBuff); 
            m_wndHexEdit.SetData(data); 
        } 
        else 
        {
            CComVariant data; 
            m_wndHexEdit.SetData(data); 
        }

        { 
            m_wndFileDetails.ShowWindow(SW_HIDE); 
            m_wndHexEdit.ShowWindow(SW_NORMAL); 
            SetSplitterPane(SPLIT_PANE_RIGHT, m_wndHexEdit); 
        } 

        delete [] byBuff; 
    } 
    else if (pCurrSel && STGTY_STORAGE == pCurrSel->dwStgType) 
    { 
        CComVariant data; 
        m_wndHexEdit.SetData(data); 
        m_wndHexEdit.ShowWindow(SW_HIDE); 

        std::vector<STATSTG_EX> vecFileInfo; 

        CTreeItem tiChild = hItem.GetChild(); 
        while (FALSE == tiChild.IsNull()) 
        { 
            TREE_ITEM_DATA * pData = (TREE_ITEM_DATA *)tiChild.GetData(); 

            STATSTG_EX statstgex; 

            do 
            { 
                if (pData->dwStgType == STGTY_STREAM) 
                { 
                    CComPtr<IStream> spStrm; 
                    hr = pData->spStgOrStrm->QueryInterface(&spStrm); 
                    if (FAILED(hr)) break; 
                    
                    hr = spStrm->Stat(&statstgex, STATFLAG_NONAME); 
                    if (FAILED(hr)) break; 
                } 
                else if (pData->dwStgType == STGTY_STORAGE) 
                { 
                    CComPtr<IStorage> spStg; 
                    hr = pData->spStgOrStrm->QueryInterface(&spStg); 
                    if (FAILED(hr)) break; 
                    
                    hr = spStg->Stat(&statstgex, STATFLAG_NONAME); 
                    if (FAILED(hr)) break; 
                } 
            } while(0); 
            
            statstgex.htiHost = tiChild.m_hTreeItem; 
            
            TCHAR szSwap[MAX_PATH] = { 0 }; 
            tiChild.GetText(szSwap, _countof(szSwap)); 
            TCHAR2WCHAR(szSwap, statstgex.szwName, _countof(statstgex.szwName)); 
            
            vecFileInfo.push_back(statstgex); 

            tiChild = tiChild.GetNextSibling(); 
        } 

        m_wndFileDetails.SetFileInfo(vecFileInfo); 

        m_wndFileDetails.ShowWindow(SW_NORMAL); 
        SetSplitterPane(SPLIT_PANE_RIGHT, m_wndFileDetails); 
    } 

    return 0;
} 
예제 #12
0
void CMainFrame::OnRepair(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hwndCtl*/)
{
	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	BOOL bResults;
	BOOL bReturn = FALSE;

	CTreeItem itemSelected = m_viewTree.GetSelectedItem();

	if ( itemSelected.IsNull() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}
	
	CDiskObjectPtr obj = m_mapObject[itemSelected.GetData()];


	if( dynamic_cast<CDiskObjectComposite *>(obj.get()) == NULL )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}

	CDiskObjectCompositePtr DiskObjectComposite =
		boost::dynamic_pointer_cast<CDiskObjectComposite>(obj);

	if(!((NMT_RAID1 == DiskObjectComposite->GetNDASMediaType() ||
		NMT_RAID4 == DiskObjectComposite->GetNDASMediaType()) &&
		1 == DiskObjectComposite->GetMissingMemberCount()))
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		// TODO : No disk is available
		WTL::CString strMsg;
		strMsg.LoadString( IDS_MAINFRAME_NOT_READY_REPAIR );
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox(
			strMsg,
			strTitle, 
			MB_OK | MB_ICONERROR
			);
		return;
	}		


	CSelectDiskDlg dlgSelect(IDD_REPAIR);
	CDiskObjectList singleDisks;
	CFindIfVisitor<FALSE> singleDiskFinder;
	singleDisks = singleDiskFinder.FindIf(m_pRoot, IsWritableUnitDisk);

	if ( singleDisks.size() == 0 )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		// TODO : No disk is available
		WTL::CString strMsg;
		strMsg.LoadString( IDS_MAINFRAME_NO_DISK_REPAIR );
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox(
			strMsg,
			strTitle, 
			MB_OK | MB_ICONWARNING
			);
		return;
	}

	dlgSelect.SetSingleDisks(singleDisks);

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

	CUnitDiskObjectPtr replaceDisk, sourceDisk;
	sourceDisk = DiskObjectComposite->GetAvailableUnitDisk();
	replaceDisk = dlgSelect.GetSelectedDisk();

	if(NULL == sourceDisk.get())
		return;
	
	NDASCOMM_CONNECTION_INFO ci, ciReplace;

	ZeroMemory(&ci, sizeof(NDASCOMM_CONNECTION_INFO));

	ci.address_type = NDASCOMM_CONNECTION_INFO_TYPE_ADDR_LPX;
	ci.login_type = NDASCOMM_LOGIN_TYPE_NORMAL;
	ci.UnitNo = sourceDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
	ci.bWriteAccess = TRUE;
	ci.ui64OEMCode = NULL;
	ci.protocol = NDASCOMM_TRANSPORT_LPX;
	CopyMemory(ci.AddressLPX, 
		sourceDisk->GetLocation()->GetUnitDiskLocation()->MACAddr,
		LPXADDR_NODE_LENGTH);

	ZeroMemory(&ciReplace, sizeof(NDASCOMM_CONNECTION_INFO));

	ciReplace.address_type = NDASCOMM_CONNECTION_INFO_TYPE_ADDR_LPX;
	ciReplace.login_type = NDASCOMM_LOGIN_TYPE_NORMAL;
	ciReplace.UnitNo = replaceDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
	ciReplace.bWriteAccess = TRUE;
	ciReplace.ui64OEMCode = NULL;
	ciReplace.protocol = NDASCOMM_TRANSPORT_LPX;
	CopyMemory(ciReplace.AddressLPX, 
		replaceDisk->GetLocation()->GetUnitDiskLocation()->MACAddr,
		LPXADDR_NODE_LENGTH);

	bResults = NdasOpRepair(&ci, &ciReplace);

	if(!bResults)
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);

		WTL :: CString strMsg;

		DWORD dwLastError = ::GetLastError();
		strMsg.LoadString(IDS_REPAIR_FAIL);

		ShowErrorMessageBox(strMsg);

		return;
	}

	CNdasHIXChangeNotify HixChangeNotify(pGetNdasHostGuid());
	bResults = HixChangeNotify.Initialize();
	if(bResults)
	{
		CUnitDiskObjectPtr UnitDiskObjectPtr;
		NDAS_UNITDEVICE_ID unitDeviceId;

		CDiskObjectComposite::const_iterator itr;
		for ( itr = DiskObjectComposite->begin(); itr != DiskObjectComposite->end(); ++itr )
		{
			if((dynamic_cast<CEmptyDiskObject*>((*itr).get()) != NULL))
				continue;

			UnitDiskObjectPtr = 
				boost::dynamic_pointer_cast<CUnitDiskObject>(*itr);

			CopyMemory(unitDeviceId.DeviceId.Node, 
				UnitDiskObjectPtr->GetLocation()->GetUnitDiskLocation()->MACAddr, 
				sizeof(unitDeviceId.DeviceId.Node));
			unitDeviceId.UnitNo = 
				UnitDiskObjectPtr->GetLocation()->GetUnitDiskLocation()->UnitNumber;
			HixChangeNotify.Notify(unitDeviceId);
		}

		CopyMemory(unitDeviceId.DeviceId.Node, 
			replaceDisk->GetLocation()->GetUnitDiskLocation()->MACAddr, 
			sizeof(unitDeviceId.DeviceId.Node));
		unitDeviceId.UnitNo = 
			replaceDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
		HixChangeNotify.Notify(unitDeviceId);
	}


	CRecoverDlg dlgRecover(
		TRUE, 
        (NMT_RAID1 == DiskObjectComposite->GetNDASMediaType()) ?
		IDS_LOGDEV_TYPE_DISK_RAID1 : IDS_LOGDEV_TYPE_DISK_RAID4,
		IDS_RECOVERDLG_TASK_REPAIR);

	dlgRecover.SetMemberDevice(sourceDisk);
	dlgRecover.DoModal();

	OnRefreshStatus(NULL, NULL, NULL);

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
	return;
}
예제 #13
0
void CMainFrame::OnContextMenu(HWND /*hWnd*/, CPoint pos)
{
	if(m_bRefreshing)
		return;

	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);


	int selectedItemData;

	// get selectedItemData
	{
		CRect rect;
		CPoint posInView;
		CTreeItem itemSelected;		

		// if clicked on tree, we need to change selection
		if (m_viewTree.GetWindowRect( rect ) && rect.PtInRect(pos) )
		{
			// clicked point is inside the tree control
			// Change screen coordinates to client coordinates
			posInView = pos - rect.TopLeft();

			itemSelected = m_viewTree.HitTest( posInView, NULL );

			if(itemSelected.IsNull())
			{
				LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
				return;
			}

			// an item is really selected
			// Change select
			m_viewTree.SelectItem(itemSelected);

			selectedItemData = itemSelected.GetData();
		}
		else if(m_viewList.GetWindowRect( rect ) && rect.PtInRect(pos))
		{
			selectedItemData = m_viewList.GetSelectedItemData();
		}

		if(-1 == selectedItemData)
		{
			LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
			return;
		}

		ATLTRACE(_T("selectedItemData = %d\n"), selectedItemData);

	}

	// Display context menu
	{
		CMenu menu;
		CMenuHandle subMenu;
		CDiskObjectPtr obj = m_mapObject[selectedItemData];
		ATLASSERT( obj.get() != NULL );
		menu.LoadMenu( MAKEINTRESOURCE(IDR_CONTEXT_MENU) );
		subMenu = menu.GetSubMenu(0);
		CObjectUIHandler::GetUIHandler(obj)->InsertMenu(obj, subMenu);
		ATLTRACE(_T("Menu Count : %d"), subMenu.GetMenuItemCount());
		subMenu.RemoveMenu(IDM_AGGR_PROPERTY, MF_BYCOMMAND);
//		subMenu.RemoveMenu(MF_BYPOSITION, subMenu.GetMenuItemCount());
		subMenu.TrackPopupMenu(
			TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
			pos.x, 
			pos.y, 
			m_hWnd
			);
	}

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
	return;

}