다음을 통해 공유


방법: 격리된 저장소의 저장소 열거

업데이트: 2007년 11월

GetEnumeratorIsolatedStorageScope 값을 받아 IsolatedStorageFile 열거자를 반환합니다. IsolatedStorageScope 값 중 User만 지원됩니다. 저장소를 열거하려면 IsolatedStorageContainmentAdministerIsolatedStorageByUser를 지정하는 IsolatedStorageFilePermission을 사용해야 합니다. IsolatedStorageScopeUser를 사용하여 호출하면 GetEnumerator는 현재 사용자에 대해 정의된 IsolatedStorageFiles 배열을 반환합니다.

EnumeratingStores 예제

다음 코드 예제에서는 사용자 및 어셈블리별로 격리된 저장소를 가져오고 몇 개의 파일을 만듭니다. GetEnumerator 메서드가 호출되고 IEnumerator에 결과가 배치됩니다. 그런 다음 IEnumerator에서 코드를 반복하면서 파일 크기를 추가하고 결과를 콘솔에 기록합니다. 혼동을 피하기 위해 파일 아래쪽의 나머지 코드와 구분된 개인 EnumerateTheStore 메서드에서 실제 열거가 수행됩니다.

Imports System
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Collections

Public Module modmain

    Sub Main()

        ' Get an isolated store for this assembly and put it into an
        ' IsolatedStorageFile object.

        Dim isoStore As IsolatedStorageFile
        isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

        ' This code creates a few files so that they can be enumerated.

        Dim FileA As IsolatedStorageFileStream
        FileA = New IsolatedStorageFileStream("TestFileA.Txt", FileMode.Create, isoStore)
        Dim FileB As IsolatedStorageFileStream
        FileB = New IsolatedStorageFileStream("TestFileB.Txt", FileMode.Create, isoStore)
        Dim FileC As IsolatedStorageFileStream
        FileC = New IsolatedStorageFileStream("TestFileC.Txt", FileMode.Create, isoStore)
        Dim FileD As IsolatedStorageFileStream
        FileD = New IsolatedStorageFileStream("TestFileD.Txt", FileMode.Create, isoStore)

        FileA.Close()
        FileB.Close()
        FileC.Close()
        FileD.Close()

        ' There might be a small delay between when the above code
        ' executes and when the files are created in the store. 
        ' Closing and opening the store in this example ensures that
        ' the common language runtime has finished creating the files.

        isoStore.Close()
        isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly, Nothing, Nothing)


        ' This line of code calls a method at the bottom of the program
        ' that puts all the files in isoStore into an IEnumerator.

        Dim allFiles As IEnumerator
        allFiles = EnumerateTheStore(isoStore)

        Dim totalSize As Long

        ' This code counts up the sizes of all the stores.

        While (allFiles.MoveNext())
            Dim store As IsolatedStorageFile

            ' Explicity convert the current object in allFiles
            ' into an IsolatedStorageFile.

            store = CType(allFiles.Current, IsolatedStorageFile)

            ' Find the current size of the IsolatedStorageFile as
            ' an UInt64, and convert that to a string. Get the value
            ' of the string as a double and convert that to a Long.

            totalSize += CLng(Val(store.CurrentSize.ToString))

        End While

        ' Print out the value.

        System.Console.WriteLine("The size of all the isolated stores in the user scope = " + totalSize.ToString)

    End Sub

    Function EnumerateTheStore(ByVal isoStore As IsolatedStorageFile) As IEnumerator

        Return isoStore.GetEnumerator(IsolatedStorageScope.User)

    End Function
End Module
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections;

public class EnumeratingStores{

    public static int Main(){

        // Get an isolated store for this assembly and put it into an
        // IsolatedStorageFile object.

        IsolatedStorageFile isoStore =  IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

        // This code creates a few files so that they can be enumerated.

        IsolatedStorageFileStream streamA = new IsolatedStorageFileStream("TestFileA.Txt", FileMode.Create, isoStore);
        IsolatedStorageFileStream streamB = new IsolatedStorageFileStream("TestFileB.Txt", FileMode.Create, isoStore);
        IsolatedStorageFileStream streamC = new IsolatedStorageFileStream("TestFileC.Txt", FileMode.Create, isoStore);
        IsolatedStorageFileStream streamD = new IsolatedStorageFileStream("TestFileD.Txt", FileMode.Create, isoStore);

        streamA.Close();
        streamB.Close();
        streamC.Close();
        streamD.Close();

        // There might be a small delay between when the above code
        // executes and when the files are created in the store. 
        // Closing and opening the store in this example ensures that
        // the common language runtime has finished creating the files.
        isoStore .Close();
        isoStore =  IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
        
        
        // This line of code calls a method at the bottom of the program
        // that puts all the files in isoStore into an IEnumerator.

        IEnumerator allFiles = EnumerateTheStore (isoStore);
        long totalsize = 0;

        // This code counts up the sizes of all the stores.

        while(allFiles .MoveNext()){
            IsolatedStorageFile store = (IsolatedStorageFile)allFiles.Current;
            totalsize += (long)store.CurrentSize;
        }

        Console.WriteLine("The total size = "+totalsize);
        return 0;
    }

    // This method returns an IEnucontaining all the files for a user.

    private static IEnumerator EnumerateTheStore(IsolatedStorageFile isoStore){
      
        IEnumerator e = IsolatedStorageFile.GetEnumerator(IsolatedStorageScope.User);
        
        return e;
    }
}

참고 항목

참조

IsolatedStorageFile

기타 리소스

격리된 저장소 작업 수행