예–FolderNames에 대해 사용자 유효성 검사 추가

작업: 현재 수준에 존재하지 않는 새 폴더 이름을 확인합니다.

해결 방법:

  1. 사용자 유효성 검사 $Prop["_FolderName"].CustomValidation을 함수 InitializeWindow, 섹션 FolderWindow에 추가합니다.

    function InitializeWindow
    {	
    	…
    	$mWindowName = $dsWindow.Name
    	Switch ( $mWindowName)
    	{
    		"FileWindow"
    		{
    			#rules applying for File
    		}
    		"FolderWindow"
    		{
    			#rules applying for Folder
    			$Prop["_FolderName"].CustomValidation = { FolderNameCustomValidation }
    		}
    		…
    
  2. 함수 “FolderNameCustomValidation” 및 폴더에 대한 관련 검색을 추가합니다.

  3. function FolderNameCustomValidation
    {
    	if(-not $dsWindow.FindName("DSNumSchmsCtrl").NumSchmFieldsEmpty)
    	{
    		return $true
    	}
    	if($Prop["_FolderName"].Value)
    	{
    		$rootFolder = $vault.DocumentService.GetFolderByPath($Prop["_FolderPath"].Value)
    		$mFldExist = mFindFolder $Prop["_FolderName"].Value $rootFolder
    		if($mFldExist)
    		{
    			$Prop["_FolderName"].CustomValidationErrorMessage = "Folder name exists, select a new unique one."
    			return $false
    		}
    		return $true
    	}
    	else
    	{
    		return $false
    	}
    }
    
    function mFindFolder($FolderName, $rootFolder)
    {
    	$FolderPropDefs = $vault.PropertyService.GetPropertyDefinitionsByEntityClassId("FLDR")
        $FolderNamePropDef = $FolderPropDefs | where {$_.SysName -eq "Name"}
        $srchCond = New-Object 'Autodesk.Connectivity.WebServices.SrchCond'
        $srchCond.PropDefId = $FolderNamePropDef.Id
        $srchCond.PropTyp = "SingleProperty"
        $srchCond.SrchOper = 3 #is equal
        $srchCond.SrchRule = "Must"
        $srchCond.SrchTxt = $FolderName
    
        $bookmark = ""
        $status = $null
        $totalResults = @()
        while ($status -eq $null -or $totalResults.Count -lt $status.TotalHits)
        {
            $results = $vault.DocumentService.FindFoldersBySearchConditions(@($srchCond),$null, @($rootFolder.Id), $false, [ref]$bookmark, [ref]$status)
    
            if ($results -ne $null)
            {
                $totalResults += $results
            }
            else {break}
        }
        return $totalResults;
    }
    
  4. 대화상자 정의 File.xaml 업데이트: 텍스트 상자 "FILENAME"으로 이동하여 바인딩 Text="{WPF:ValidatedBinding Name}" Text="{WPF:ValidatedBinding Prop[_FolderName].Value}"로 업데이트합니다. 새 텍스트 상자 정의가 다음과 같습니다.
<TextBox Text="{WPF:ValidatedBinding Prop[_FolderName].Value}" x:Name="FOLDERNAME" 
                     IsReadOnly="{Binding EditMode}"
                     Visibility="{Binding NumSchmFieldsEmpty, ElementName=DSNumSchmsCtrl, Converter={StaticResource BooleanToVisibilityConverter}}" 
                     Grid.Column="1" Grid.Row="3" />